Sub topic 3
Securing Actuator Endpoints with Spring Security
Assume a basic Spring Boot application, YAML configuration, Maven dependencies, HTTP, and Spring Security concepts. Actuator endpoints expose operational data, so treat them as administrative APIs.
Secure endpoints and isolate management traffic
Use a dedicated filter chain for Actuator endpoints. This example leaves health and info public but protects every other endpoint with the ACTUATOR role:
@Configuration
class ActuatorSecurityConfig {
@Bean
SecurityFilterChain actuatorSecurity(HttpSecurity http) throws Exception {
http.securityMatcher(EndpointRequest.toAnyEndpoint())
.authorizeHttpRequests(auth -> auth
.requestMatchers(EndpointRequest.to("health", "info")).permitAll()
.anyRequest().hasRole("ACTUATOR"))
.httpBasic(Customizer.withDefaults());
return http.build();
}
}Expose only endpoints that operators need:
management:
endpoints:
web:
exposure:
include: health,info,metrics,prometheus,loggers,env,threaddump
server:
port: 9090
base-path: /manageThe metrics URL is now /manage/metrics on port 9090. A separate port reduces accidental exposure through the application’s public ingress, but it still requires network controls and authentication.
Diagnose a running application
The loggers endpoint can inspect or change logger levels at runtime. env shows property sources and resolved configuration, while mappings lists request mappings. threaddump helps identify blocked or deadlocked threads. Protect these endpoints and use them temporarily during diagnosis.
Create a custom endpoint
A custom endpoint can expose operational state without adding a controller route:
@Component
@Endpoint(id = "features")
class FeaturesEndpoint {
private final Map<String, Boolean> flags = new ConcurrentHashMap<>();
@ReadOperation
Map<String, Boolean> read() {
return flags;
}
@WriteOperation
void write(@Selector String name, boolean enabled) {
flags.put(name, enabled);
}
}Expose features explicitly before using /manage/features. Write operations need strong authorization because they change application behavior.
Extend monitoring with tracing
Micrometer observations connect metrics, logs, and distributed traces around an operation. A trace follows one request across services; its trace ID lets operators correlate a slow request with its downstream calls. Add tracing only when its storage, sampling, and privacy costs are understood.
Production practices
Use dashboards for latency, error rate, traffic, saturation, and health. Alert on symptoms such as sustained error rates or failed readiness probes, not every individual exception. Set retention and access policies for metrics and traces.
Exercise
Which Actuator endpoints should normally be public?
Show answer
Usually only a deliberately limited health response. Protect info, metrics, configuration, diagnostic, and custom write endpoints.