gpt4 book ai didi

java - Spring Boot Actuator - 无法禁用/信息端点

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:52:28 25 4
gpt4 key购买 nike

我尝试在 application.yml 配置文件中禁用生产环境的所有执行器端点:

endpoints.enabled: false

它适用于除/info 之外的所有端点。如何关闭给定环境的所有端点?

更新:

我正在做的项目也是 Eureka 客户端。在 Status Page and Health Indicator(http://cloud.spring.io/spring-cloud-netflix/spring-cloud-netflix.html)部分的 Spring Cloud Netflix 文档中,它说“Eureka 实例分别默认为“/info”和“/health”。

是否有任何解决方案可以禁用这些端点?

我能够使用 endpoints.enabled: false 禁用 /health 端点,但不能禁用 /info 端点。

最佳答案

最后我设法解决了我的问题。我在执行器中只启用了/info 和/health 端点。为了只允许具有 ADMIN 角色的用户访问/info 端点,我需要混合执行器管理安全和 spring 安全配置。

所以我的application.yml 看起来像这样:

endpoints.enabled: false

endpoints:
info.enabled: true
health.enabled: true

management.security.role: ADMIN

像这样的 spring 安全配置(我需要更改 ManagementSecurityConfig 的顺序以获得更高的优先级):

@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class SecurityConfiguration {


@Configuration
protected static class AuthenticationSecurity extends GlobalAuthenticationConfigurerAdapter {

@Autowired
private AuthenticationProvider authenticationProvider;

public AuthenticationSecurity() {
super();
}

@Override
public void init(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication().withUser("admin").password("secret").roles("ADMIN");
}
}

@Configuration
@Order(Ordered.HIGHEST_PRECEDENCE + 2)
public static class ManagementSecurityConfig extends WebSecurityConfigurerAdapter {


@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable()
.requestMatchers()
.antMatchers("/info/**")
.and()
.authorizeRequests()
.anyRequest().hasRole("ADMIN")
.and()
.httpBasic();
}
}

@Configuration
public static class ApiWebSecurityConfigurationAdapter extends WebSecurityConfigurerAdapter {

protected void configure(HttpSecurity http) throws Exception {
// API security configuration
}

}
}

关于java - Spring Boot Actuator - 无法禁用/信息端点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34399972/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com