Securing Actuator Endpoints
Protect sensitive operational endpoints.
Securing Actuator Endpoints is a free Spring Boot 4 Microservices & REST APIs lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Spring Boot 4 Microservices & REST APIs learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Why Actuator Needs Securing
Actuator endpoints can reveal environment variables, beans, mappings, and even heap dumps. Left open, they leak sensitive information and may allow dangerous operations like shutdown. They must be protected in production.
Minimize the Attack Surface First
Security starts with exposure. Expose only the endpoints operators truly need over HTTP, and exclude sensitive ones like env, beans, and heapdump.
management:
endpoints:
web:
exposure:
include: health,info,prometheus
exclude: env,beans,heapdump,threaddumpAdding Spring Security
To authenticate access, add Spring Security. Once on the classpath, it secures the application — including Actuator endpoints — and you define the rules.
<!-- pom.xml -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>The EndpointRequest Matcher
Spring Boot provides EndpointRequest matchers so your security config can target Actuator endpoints precisely, without hardcoding the /actuator path.
import static org.springframework.boot.actuate.autoconfigure.security.servlet.EndpointRequest.*;
// EndpointRequest.toAnyEndpoint()
// EndpointRequest.to("health", "info")Locking Down the Endpoints
A typical policy: allow health and info anonymously (for probes), but require an authenticated role for everything else.
@Bean
SecurityFilterChain actuatorSecurity(HttpSecurity http) throws Exception {
http.securityMatcher(EndpointRequest.toAnyEndpoint())
.authorizeHttpRequests(a -> a
.requestMatchers(EndpointRequest.to("health", "info")).permitAll()
.anyRequest().hasRole("ADMIN"))
.httpBasic(Customizer.withDefaults());
return http.build();
}Role-Based Access
Restrict management endpoints to an operations role such as ADMIN. Combine with your existing user store — in-memory for demos, a real identity provider in production.
@Bean
UserDetailsService users(PasswordEncoder encoder) {
UserDetails admin = User.withUsername("ops")
.password(encoder.encode("change-me"))
.roles("ADMIN").build();
return new InMemoryUserDetailsManager(admin);
}Isolating with a Management Port
Run Actuator on a separate port that is only reachable inside your network or cluster. Public traffic hits the app port; operators reach management through internal routing.
management:
server:
port: 8081
# expose 8081 only to the internal network / sidecarProbes Without Credentials
Kubernetes probes call health/liveness and health/readiness without auth. Permit those specific paths while still protecting the rest of health details and other endpoints.
.requestMatchers(EndpointRequest.to("health")).permitAll()
// keep show-details restricted so anonymous probes see only statusHiding Health Details
Even when health is public, do not leak component internals to anonymous callers. Set show-details to when-authorized so probes see only UP/DOWN.
management:
endpoint:
health:
show-details: when-authorizedDisable Dangerous Endpoints
Some endpoints can change runtime state. Keep shutdown disabled, and avoid exposing heapdump or threaddump publicly, as they reveal memory contents and aid attackers.
management:
endpoint:
shutdown:
enabled: falseDefense in Depth
No single control suffices. Combine measures:
- Minimal exposure
- Authentication and roles
- Network isolation / separate port
- Restricted health details
Quick Check
Test your understanding of securing Actuator.
Recap
Treat Actuator as a security perimeter.
- Expose minimally; exclude
env,beans,heapdump - Add Spring Security and use
EndpointRequestmatchers - Permit
health/infofor probes; require a role for the rest - Restrict
show-detailsand disableshutdown - Isolate via a separate management port
Frequently asked questions
Is the “Securing Actuator Endpoints” lesson free?
Yes — the full text of “Securing Actuator Endpoints” is free to read here on the web, and the Spring Boot 4 Microservices & REST APIs course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Spring Boot 4 Microservices & REST APIs course, upgrade to CoddyKit PRO.
What will I learn in “Securing Actuator Endpoints”?
Protect sensitive operational endpoints. You practise Spring Boot 4 Microservices & REST APIs with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Spring Boot 4 Microservices & REST APIs?
No prior experience is required. Spring Boot 4 Microservices & REST APIs on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Securing Actuator Endpoints” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Spring Boot 4 Microservices & REST APIs lesson?
Yes. Every Spring Boot 4 Microservices & REST APIs lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Enabling Actuator Endpoints
- Health Indicators
- Custom Metrics with Micrometer
- Securing Actuator Endpoints