Video in progress
How should you safely expose Actuator endpoints in prod?
Open only the endpoints you need with exposure.include, put them on a separate management port or protect them with Spring Security. heapdump, env, threaddump and loggers should never be open to the internet without authentication.
📖 Answer
A real risk: if /actuator/heapdump is left open, anyone can download the heap, and it holds DB passwords, the JWT secret and users' sessions. /actuator/env can also reveal some values (it's hidden by default in Boot 3, but it depends on the configuration).
The approach in practice:
management:
server:
port: 8081 # only 8080 is exposed outside
endpoints:
web:
exposure:
include: health,info,prometheus
endpoint:
health:
show-details: when-authorized
You close the separate port at the ingress or firewall, and Prometheus reads it from the internal network.
If you can't separate the port, use Security:
@Bean
SecurityFilterChain actuator(HttpSecurity http) throws Exception {
http.securityMatcher(EndpointRequest.toAnyEndpoint())
.authorizeHttpRequests(a -> a
.requestMatchers(EndpointRequest.to(HealthEndpoint.class)).permitAll()
.anyRequest().hasRole("OPS"))
.httpBasic(Customizer.withDefaults());
return http.build();
}
include: "*" is convenient for a local environment, but check that it hasn't ended up in the prod profile. This mistake is very common.
Sign up to mark studied questions and save your progress.