在微服务架构中,监控系统的安全防护至关重要。Spring Boot Actuator作为内置的监控工具,若配置不当可能成为安全漏洞的源头。
安全配置要点
1. 端点访问控制
# application.yml
management:
endpoints:
web:
exposure:
include: health,info,metrics
path-mapping:
health: /health
endpoint:
health:
show-details: never
2. 认证授权
@Configuration
public class ActuatorSecurityConfig {
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http
.requestMatchers(EndpointRequest.toAnyEndpoint())
.authorizeHttpRequests(authz -> authz
.requestMatchers(
EndpointRequest.to("health", "info"))
.permitAll()
.anyRequest().authenticated()
)
.httpBasic();
return http.build();
}
}
3. 敏感信息过滤
通过配置management.endpoint.health.show-details: never避免暴露数据库连接等敏感信息。
复现步骤
- 部署未加固的Actuator应用
- 访问
/actuator端点 - 观察是否暴露所有监控数据
- 尝试访问敏感端点验证权限控制
安全防护的核心在于最小权限原则和敏感信息脱敏。

讨论