【问题标题】:Unable to secure Spring boot management actuator endpoints无法保护 Spring Boot 管理执行器端点
【发布时间】:2014-06-18 20:48:33
【问题描述】:

我正在尝试保护 Spring Boot 执行器端点。我的/api REST 接口上具有工作安全性,但尝试在内置端点上添加安全性似乎不起作用。

我在application.properties 中设置了端点分组:

management.context-path=/management

我的 Java 配置中有这个

@Override
protected void configure( HttpSecurity http ) throws Exception
{
    http.csrf().disable();
    http.sessionManagement().sessionCreationPolicy( SessionCreationPolicy.STATELESS );

    http.authorizeRequests()
        .antMatchers( "/api/**" ).hasRole( "READONLY" )
        .antMatchers( "/management/**" ).hasRole( "ADMIN" );


    SecurityConfigurer<DefaultSecurityFilterChain, HttpSecurity> securityConfigurer = new XAuthTokenConfigurer( userDetailsServiceBean() );
    http.apply( securityConfigurer );
}

当我使用浏览器转到/api 以下的任何内容时,我会按预期返回 403。例如,当转到 /management/info 时,我看到 JSON 被返回,我也期望 403。

我也尝试将此添加到我的 application.properties 文件中:

management.security.role=ADMIN

但这也无济于事。

DEBUG 输出显示:

2014-05-02 10:15:30 DEBUG [localhost-startStop-1] ExpressionBasedFilterInvocationSecurityMetadataSource - 
Adding web access control expression 'hasRole('ROLE_READONLY')', for Ant [pattern='/api/**']

2014-05-02 10:15:30 DEBUG [localhost-startStop-1] ExpressionBasedFilterInvocationSecurityMetadataSource - 
Adding web access control expression 'hasRole('ROLE_ADMIN')', for Ant [pattern='/management/**']

然后我为什么要尝试 HTTP GET:

2014-05-02 10:16:39 DEBUG [http-nio-8443-exec-4] AntPathRequestMatcher - Checking match of request : '/management/info'; against '/css/**'
2014-05-02 10:16:39 DEBUG [http-nio-8443-exec-4] AntPathRequestMatcher - Checking match of request : '/management/info'; against '/js/**'
2014-05-02 10:16:39 DEBUG [http-nio-8443-exec-4] AntPathRequestMatcher - Checking match of request : '/management/info'; against '/images/**'
2014-05-02 10:16:39 DEBUG [http-nio-8443-exec-4] AntPathRequestMatcher - Checking match of request : '/management/info'; against '/**/favicon.ico'
2014-05-02 10:16:39 DEBUG [http-nio-8443-exec-4] AntPathRequestMatcher - Checking match of request : '/management/info'; against '/management/info'
2014-05-02 10:16:39 DEBUG [http-nio-8443-exec-4] FilterChainProxy - /management/info has an empty filter list

【问题讨论】:

    标签: java spring-security spring-boot


    【解决方案1】:

    讲述这个故事的日志是:“/management/info 有一个空的过滤器列表”,因为它被明确标记为忽略(/info 应该始终可用)。尝试其他执行器端点之一,看看它们的行为是否符合您的预期。如果你真的需要保护 info 端点,你可以设置 endpoints.info.sensitive=true (我认为)。

    【讨论】:

    • 完全正确!我试过的两个是/info/health,它们似乎总是可用的。例如,如果我使用/beans,我会得到预期的 403。您也许可以添加此信息in the docs?
    • 确实,我似乎没有注意到表格中的Sensitive 列。
    • 我遇到了同样的问题,我仍然无法保护敏感的 API(例如:/env)我正在 application.properties management.context-path=/ 中进行配置management management.security.enabled=true management.security.roles=SOME_ROLE 是否足够或是否需要配置类中的配置?
    • 您必须在类路径中添加 Spring Security 吗?
    猜你喜欢
    • 2018-12-06
    • 1970-01-01
    • 2022-11-01
    • 2020-06-01
    • 2019-09-30
    • 1970-01-01
    • 2016-08-26
    • 2019-07-10
    • 2015-12-14
    相关资源
    最近更新 更多