Securing & Customizing Actuator
Securing & Customizing Actuator
Spring Boot Actuator is tremendously useful in production — but by default it exposes a lot of internal detail about your application: environment variables, configuration properties, bean graph, thread dumps, and more. Leaving these endpoints wide open is a serious security risk. In this lesson you will learn exactly which endpoints to expose, how to protect them behind Spring Security, and how to tailor the output so it reveals only what each consumer legitimately needs.
The Default Exposure Surface
Actuator endpoints are available in two transports: HTTP and JMX. Their default exposure policies differ deliberately:
- HTTP: only
healthandinfoare exposed by default. - JMX: all endpoints are exposed by default (JMX is usually firewall-restricted anyway).
The first rule of Actuator security is: expose the minimum you actively need over HTTP. Configure this in application.properties:
env, heapdump, or shutdown to the public internet. The env endpoint lists every resolved property — including secrets that leak through environment variables. A heap dump contains the full JVM heap, which can be parsed offline to extract passwords, tokens, and session data. The shutdown endpoint terminates the process.
Moving Actuator to a Separate Port
A clean architectural decision is to serve Actuator on a different port reachable only inside your private network or VPN. Your load balancer never forwards external traffic to that port:
With this configuration all Actuator traffic is served on port 8081 bound to loopback. External clients cannot reach it regardless of Spring Security rules. This is your network-layer defence — it works even if your security configuration has a bug.
Protecting Actuator with Spring Security
When Actuator shares the same port as the main application you must protect its endpoints with Spring Security. Add the starter if it is not already present:
Then write a SecurityFilterChain bean that applies different rules to Actuator paths versus regular application paths. In Spring Boot 3 / Spring Security 6 the lambda DSL is the idiomatic approach:
Key points in this configuration:
/actuator/healthispermitAll()so load-balancer health probes work without credentials.- All other
/actuator/**paths require theACTUATOR_ADMINrole — a dedicated role keeps Actuator access separate from application-level admin privileges. - Order matters in
requestMatchers: the more specific/actuator/healthrule must come before the broader/actuator/**wildcard.
Customizing the Health Endpoint
The health endpoint can show different levels of detail depending on whether the caller is authenticated. Configure this in application.properties:
An unauthenticated load-balancer probe therefore sees only:
While an authenticated monitoring agent sees the full breakdown including database, disk space, and custom health indicators — without leaking that detail to the public.
Filtering Sensitive Data from the env Endpoint
If you must expose env on an internal network, Spring Boot automatically sanitizes property values whose keys match a built-in list of patterns such as password, secret, key, token, and credentials. The value is replaced with ****** in the response. You can extend this list with your own patterns:
env endpoint can try to reconstruct a masked value via trial and error if they already know the format. Treat sanitization as a last line of defence — your first line is not exposing env at all on a public network.
Writing a Custom Actuator Endpoint
Sometimes the built-in endpoints do not cover what you need. You can write your own endpoint using @Endpoint (both HTTP and JMX) or @WebEndpoint (HTTP only). Annotate operations with @ReadOperation, @WriteOperation, or @DeleteOperation:
The endpoint ID (releaseinfo) becomes the URL segment. Spring Boot automatically registers it and applies the same security rules you defined for /actuator/**. No extra wiring is needed.
Renaming the Actuator Base Path
Changing the Actuator base path from /actuator to something less predictable adds a small but real layer of obscurity — attackers running automated scans for /actuator/env will not find it:
The health endpoint is now at /internal/ops/health. Update any monitoring tool or load-balancer probe configuration to match.
Summary
Securing Actuator is not a single setting — it is a deliberate, layered strategy:
- Expose minimally: use
exposure.includeto whitelist only endpoints you need. - Isolate at the network level: bind
management.server.portto a private address when possible. - Authenticate with Spring Security: keep
/actuator/healthpublic for probes; protect everything else behind a dedicated role. - Control detail visibility: set
show-details=when_authorizedso unauthenticated callers see only a status summary. - Sanitize sensitive keys: extend the sanitization list if you expose
envinternally. - Rename the base path: adds obscurity on top of authentication.
With these controls in place, Actuator becomes a powerful, safe operational window into your running service.