2015-12-21 60 views
6

我試圖禁止用於生產環境中的所有驅動器端點application.yml配置文件:春季啓動器 - 無法禁用/信息端點

endpoints.enabled: false 

它適用於除/信息所有端點。 如何關閉給定環境的所有端點?

UPDATE:

項目我工作也充當尤里卡客戶端。 在Spring Cloud Netflix的狀態頁面和健康指示器http://cloud.spring.io/spring-cloud-netflix/spring-cloud-netflix.html)文檔中,它表示「Eureka實例分別默認爲」/ info「和」/ health「。

是否有解決方案來禁用這些端點?

我能夠禁用與endpoints.enabled: false/健康端點,而不是/信息端點。

+0

保護端點可能是你唯一的選擇。由於您關閉了使用執行器的能力,因此禁用生產似乎是一個奇怪的選擇。 – code

+0

我能夠通過附加的網絡安全配置(除了執行機構的默認安全配置外)來保護/信息端點。我不喜歡的是除了_/info_之外的所有執行器端點都可以通過執行器配置來保護,即'management.security.enabled:true'。但爲了保護_/info_端點,我需要爲此端點創建單獨的Web安全配置。好像我在代碼中做了一些破解。 – Sasa

回答

10

最後我設法解決我的問題我只在執行器中啓用了/ info和/ health端點,並且允許只有ADMIN角色的用戶才能訪問/ info端點我需要混合執行器管理安全和彈簧安全配置

所以我的application.yml看起來像這樣:

endpoints.enabled: false 

endpoints: 
    info.enabled: true 
    health.enabled: true 

management.security.role: ADMIN 

和春天這樣的安全配置(在這裏我需要改變ManagementSecurityConfig的纔能有更高的優先級):

@Configuration 
@EnableWebSecurity 
@EnableGlobalMethodSecurity(prePostEnabled = true) 
public class SecurityConfiguration { 


    @Configuration 
    protected static class AuthenticationSecurity extends GlobalAuthenticationConfigurerAdapter { 

     @Autowired 
     private AuthenticationProvider authenticationProvider; 

     public AuthenticationSecurity() { 
      super(); 
     } 

     @Override 
     public void init(AuthenticationManagerBuilder auth) throws Exception { 
      auth.inMemoryAuthentication().withUser("admin").password("secret").roles("ADMIN"); 
     } 
    } 

    @Configuration 
    @Order(Ordered.HIGHEST_PRECEDENCE + 2) 
    public static class ManagementSecurityConfig extends WebSecurityConfigurerAdapter { 


     @Override 
     protected void configure(HttpSecurity http) throws Exception { 
      http.csrf().disable() 
        .requestMatchers() 
        .antMatchers("/info/**") 
        .and() 
        .authorizeRequests() 
        .anyRequest().hasRole("ADMIN") 
        .and() 
        .httpBasic(); 
     } 
    } 

    @Configuration 
    public static class ApiWebSecurityConfigurationAdapter extends WebSecurityConfigurerAdapter { 

     protected void configure(HttpSecurity http) throws Exception { 
      // API security configuration 
     } 

    } 
} 
0

您的示例配置對我來說看起來很可疑。我猜你的意思

endpoints: 
    enabled: true 

在任何情況下,我只是嘗試(使用1.3.1把它添加到香草春天啓動的應用程序和所有的端點被禁用(如預期)。

+0

我剛剛更新了我的問題。事情也是在項目中使用尤里卡。無論如何,我需要禁用端點,因此我需要將端點設置爲false,即'endpoints.enabled:false'。事情是否適用於/健康端點,但不適用於/ info。 – Sasa