【问题标题】:Why are all my Spring boot actuator endpoints publicly available?为什么我的所有 Spring Boot 执行器端点都是公开可用的?
【发布时间】:2016-08-07 07:11:02
【问题描述】:

我的类路径上有 Spring Security(并且经过验证可用于我自己的 REST 控制器),但我的 Actuator 端点默认情况下都是公开可用的(/shutdown 除外)。

我可以随意禁用端点(在阅读完this 问题后),但启用的端点始终可用,无需身份验证,也无需我的属性中management.security.role 所需的角色。

例如,即使我明确设置了endpoints.beans.sensitive=true,它仍然可以在没有身份验证的情况下访问。

使用 LDAP 进行身份验证的我的安全配置:

@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
    @Autowired
    private LdapContextSource contextSource;

    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth
                .ldapAuthentication()
                .contextSource(contextSource)
                .groupRoleAttribute("<hidden>")
                .groupSearchBase("<hidden>")
                .groupSearchFilter("<hidden>")
                .userDnPatterns("<hidden>");
    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.httpBasic();
    }
}

我在这个测试期间的 application.properties:

# Log4J properties
logging.file=${user.home}/nubis-log.log
logging.level.org.springframework.web=INFO
logging.level.org.hibernate=INFO
logging.register-shutdown-hook=true

# SSL configuration
server.ssl.key-store=<hidden>
server.ssl.key-store-password=<hidden>
server.ssl.keyStoreType=<hidden>
server.ssl.key-password=<hidden>

# Spring actuator
endpoints.enabled=false
endpoints.info.enabled=true
endpoints.health.enabled=true
endpoints.beans.enabled=true
endpoints.beans.sensitive=true
management.security.role=ADMIN

我的控制台输出:

[2016-04-15 12:30:05.742] boot - 2754  INFO [localhost-startStop-1] --- DelegatingFilterProxyRegistrationBean: Mapping filter: 'springSecurityFilterChain' to: [/*]
[2016-04-15 12:30:05.742] boot - 2754  INFO [localhost-startStop-1] --- FilterRegistrationBean: Mapping filter: 'webRequestLoggingFilter' to: [/*]
[2016-04-15 12:30:05.743] boot - 2754  INFO [localhost-startStop-1] --- FilterRegistrationBean: Mapping filter: 'CORSFilter' to: [/*]
[2016-04-15 12:30:05.743] boot - 2754  INFO [localhost-startStop-1] --- FilterRegistrationBean: Mapping filter: 'applicationContextIdFilter' to: [/*]
[2016-04-15 12:30:05.743] boot - 2754  INFO [localhost-startStop-1] --- ServletRegistrationBean: Mapping servlet: 'dispatcherServlet' to [/]
[2016-04-15 12:30:05.800] boot - 2754 DEBUG [localhost-startStop-1] --- DelegatingFilterProxy: Initializing filter 'springSecurityFilterChain'
[2016-04-15 12:30:07.059] boot - 2754  INFO [localhost-startStop-1] --- EndpointHandlerMapping: Mapped "{[/info || /info.json],methods=[GET],produces=[application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
[2016-04-15 12:30:07.061] boot - 2754  INFO [localhost-startStop-1] --- EndpointHandlerMapping: Mapped "{[/beans || /beans.json],methods=[GET],produces=[application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
[2016-04-15 12:30:07.063] boot - 2754  INFO [localhost-startStop-1] --- EndpointHandlerMapping: Mapped "{[/health || /health.json],produces=[application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.HealthMvcEndpoint.invoke(java.security.Principal)

是否有某个配置/属性阻止了 Spring Security?我是否需要配置一些额外的东西才能使其与 LD​​AP 一起使用?

【问题讨论】:

  • 您可能错误地配置了 Spring Security?试试http.authorizeRequests().anyRequest().authenticated().and().formLogin().and().httpBasic();docs.spring.io/spring-security/site/docs/current/reference/html/…
  • @XtremeBiker 这可行,但我不希望所有请求都经过身份验证。这就是我使用@EnableGlobalMethodSecurity 的原因。还是我用错了?
  • 您自己配置安全,因此application.properties 中的安全配置没有任何作用。您基本上是在自己覆盖它,并且由于您没有保护任何东西,所以一切都可以访问。
  • 好吧,这对我来说很有意义。那么有没有办法为我的休息控制器使用@EnableGlobalMethodSecurity,为Spring Actuator使用http.authorizeRequests().anyRequest().authenticated()?

标签: java spring-security spring-boot


【解决方案1】:

所有端点都有一个敏感属性,需要设置为true

看看 Apedenix A https://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html

在该页面上搜索 ACTUATOR PROPERTIES。

【讨论】:

  • 根据this page,大部分端点的灵敏度默认为true。
  • 发布此答案时并非如此。
猜你喜欢
  • 2019-05-07
  • 1970-01-01
  • 2021-09-02
  • 2020-01-10
  • 2018-12-06
  • 1970-01-01
  • 2021-04-22
  • 2016-03-05
  • 2011-10-06
相关资源
最近更新 更多