【发布时间】:2017-10-25 03:28:44
【问题描述】:
我们已经看到了许多与 Spring Boot 1.5+ 版本的 Health Actuator 端点相关的问题。经历了其中的一些,我们仍然不知所措。
我们的目标是:
- 利用 Spring Boot/Spring Security 的安全过滤器链的自动配置(即不必完全实现/配置
HttpSecurity) - 启用安全健康访问(查看应用健康信息的完整视图)
- 启用不安全健康访问(允许端点在 Kubernetes 中充当活性探针)
我们已经尝试过:
- 使用
WebSecurityConfigurerAdapter并配置WebSecurity对象以忽略/health端点的安全性,然后根据Routing multiple URLs to Spring Boot Actuator's health endpoint 将单独的端点映射到/health端点以希望启用安全路径。 - 确保
security.oauth2.resource.filter-order=3符合https://github.com/spring-projects/spring-boot/issues/5072 中的建议。这会将OAuth2AuthenticationProcessingFilter放在 Actuator 的 Mvc 端点之前,并允许处理包含预先验证的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端点的匿名请求作为不安全 - 到
/health端点的预认证请求(即包含预认证Authorization: Bearer ...标头的请求)没有适当的授权或角色作为不安全 - 对
/health端点的预认证请求(即那些包含预认证Authorization: Bearer ...标头的请求)具有适当的授权或角色以充当安全
我们可以通过以下方式轻松允许任何请求访问/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");
}
}
这仅作为准备就绪/活跃度探测非常有效。但是,当用户实际通过身份验证时,它并没有提供查看哪些支持服务可能行为不端的好处。
提前致谢!
【问题讨论】:
-
我不确定我是否完全理解这些问题。您是否只想将 Spring Security 与 Spring Actuator 一起使用并只允许所有用户进行 /health 检查?!我的意思是只允许任何请求访问/health?!
标签: spring-boot spring-security jwt spring-security-oauth2 spring-boot-actuator