【问题标题】:Trying to secure actuator health endpoint giving 403 Forbidden error试图保护执行器健康端点给出 403 禁止错误
【发布时间】:2022-07-08 15:07:19
【问题描述】:

我正在尝试使用 spring security 保护执行器健康端点:

为此,我添加了以下内容:

@Configuration
@EnableWebSecurity
public class ActuatorSecurityConfiguration extends WebSecurityConfigurerAdapter implements ApplicationContextAware {
    private static final String ACTUATOR_ROLE = System.getenv("actuatorRole");

    @Override
    public void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests()

                .antMatchers("/actuator/**")
                .hasRole(ACTUATOR_ROLE)
                .anyRequest().authenticated();
    }
}

我在 application.properties 文件中定义了以下属性:

spring.security.user.name=${username}
spring.security.user.password=${actuatorPassword}
spring.security.user.roles=${actuatorRole}
management.endpoint.health.roles=${actuatorRole}

但是当我在这个配置之后尝试运行健康检查时,它给了我 403 Forbidden 错误。谁能帮助我为什么会收到此错误?

【问题讨论】:

  • 您可以将logging.level.org.springframework.security=TRACE 添加到您的application.properties 并查看403 的来源吗?
  • 如何传递用户名和密码?你是用 Postman 测试的吗?
  • @Nemanja 是的,我正在使用 Postman 通过基本身份验证传递用户名和密码。
  • 你定义了actuorRole环境变量吗?您能否验证您在属性文件中提供的角色和您从 env.variable 获取的角色是否相同?
  • 是的,它们都是从同一个环境变量中挑选出来的。

标签: java spring-boot spring-security spring-boot-actuator


【解决方案1】:

这有帮助吗:

application.properties:
management.endpoints.enabled-by-default=false
management.endpoints.web.exposure.include=health
management.endpoint.health.enabled=true
management.endpoint.health.show-details=always

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-12-28
    • 2023-01-22
    • 2020-05-24
    • 2013-08-29
    • 1970-01-01
    • 2019-11-12
    • 2019-03-10
    相关资源
    最近更新 更多