首页 > 解决方案 > Spring-Boot 执行器/关闭端点被禁止

问题描述

我第一次使用 Spring Boot 应用程序时,执行器是不安全的,因此很容易通过 /actuator/shutdown 端点远程关闭。最近,我使用 Spring security 保护了我的执行器,并且它有效。现在我需要提供 http 基本凭据来访问端点,但现在 curl 对 /actuator/shutdown 端点的调用失败并出现 Forbidden 错误。我必须在某处配置不正确。

我的卷曲命令:

curl -XPOST -u 执行器:密码http://host:port/actuator/shutdown -k

我可以调用其他端点,似乎只有关闭端点是被禁止的。

我的配置:

management.endpoints.web.exposure.include=*
management.endpoint.health.show-details=always
management.info.git.mode=full
management.endpoint.shutdown.enabled=true
management.server.port=8081
spring.security.user.name=actuator
spring.security.user.roles=ACTUATOR
spring.security.user.password=password

编辑:

    @Configuration
public static class ActuatorWebSecurityConfigurationAdapter extends WebSecurityConfigurerAdapter {
    protected void configure(HttpSecurity http) throws Exception {
        http.requestMatcher(EndpointRequest.toAnyEndpoint()).authorizeRequests()
                .anyRequest().hasRole("ACTUATOR")
                .and()
                .httpBasic();
    }
}

标签: spring-bootcurlspring-boot-actuator

解决方案


解决方案是在 WebSecurityConfigureAdapter 配置方法中禁用 csrf。

http.csrf().disable();

推荐阅读