2015-12-21 56 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