我们已经看到了许多与Spring Boot的Health Actuator endpoints 1.5版相关的问题 . 经历了其中的一些,我们仍然处于亏损状态 .
我们的目标是:
-
利用Spring Boot / Spring Security自动配置安全过滤器链(即不必完全实现/配置
HttpSecurity
) -
启用 secured Health 访问(查看应用程序 Health 信息的完整视图)
-
启用 unsecured 运行状况访问(允许 endpoints 在Kubernetes中用作活动探测)
我们尝试过:
-
使用
WebSecurityConfigurerAdapter
并配置WebSecurity
对象以忽略/health
endpoints 的安全性,然后根据Routing multiple URLs to Spring Boot Actuator's health endpoint将单独的 endpoints 映射到/health
endpoints ,以希望启用安全路径 . -
确保https://github.com/spring-projects/spring-boot/issues/5072中推荐
security.oauth2.resource.filter-order=3
. 这将OAuth2AuthenticationProcessingFilter
放在Actuator的Mvc endpoints 之前,并允许处理包含预先认证的Authorization: Bearer ...
标头(例如JWT授权)的请求 . 但是,它规定所有请求都包含授权 - 否则,FilterSecurityInterceptor
触发Secure object: FilterInvocation: URL: /health; Attributes: [#oauth2.throwOnError(authenticated)]
和AccessDeniedException
对其他所有内容使用 /health
和OAuth2的基本身份验证是不行的(请参阅Spring boot oauth2 management httpbasic authentication&https://github.com/spring-projects/spring-boot/issues/5072) .
我们不断回顾的问题是我们如何得到:
-
匿名请求
/health
endpoints 充当 unsecured -
经过身份验证的请求(即包含预先经过身份验证的
Authorization: Bearer ...
标头的请求)到/health
endpoints not having 适当的授权或角色,以充当 unsecured -
预先认证的请求(即那些包含预先认证的
Authorization: Bearer ...
Headers 的请求)到/health
endpoints having 适当的授权或角色,以充当 secured
我们可以通过以下方式轻松允许任何请求访问 /health
:
@Configuration
@Order(SecurityProperties.ACCESS_OVERRIDE_ORDER)
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
public void configure(WebSecurity web) throws Exception {
super.configure(web);
web.ignoring().antMatchers(HttpMethod.GET, "/health", "/info");
}
}
而这仅仅是作为准备/活力探测的工作 . 但是,当用户实际经过身份验证时,它不会提供查看哪些支持服务可能行为不当的好处 .
提前致谢!
2 回答
我遇到了类似的问题,这有点工作:为 Actuator 添加一个hacky访问规则,例如:#oauth2.clientHasRole('ROLE_CLIENT')或hasRole('ROLE_ANONYMOUS'),它可以为 Actuator endpoints 填充安全上下文(对于两个已经过身份验证的 endpoints )和未经过身份验证的请求)并调整“敏感” Actuator endpoints 配置 . / health应返回匿名和完整信息的基本信息,以便在此情况下进行身份验证,前提是您启用了管理安全性并将其标记为非敏感 . 您仍需要保留过滤器配置 .
试试这个,为我工作