Spring Boot Actuator is a powerful tool that provides insights, monitoring, and management for applications. However, exposing these endpoints without proper security can leak sensitive data or even compromise your application.
🚨 Common Security Risks with Actuator
🔴 Problem: Unauthorized Access to Actuator Endpoints
Actuator exposes endpoints like /health, /metrics, /env, and /beans. If not secured, attackers can:
View system health status (potentially exposing vulnerabilities)
Access application configurations (e.g., environment variables)
Discover sensitive internal details (like database URLs)
🔍 Example:
If Actuator is enabled without security, anyone can access:
curl http://yourdomain.com/actuator/health
This could expose private system information!
🔐 How to Secure Spring Boot Actuator Endpoints
1️⃣ Restrict Access Using management.endpoints.web.exposure.include
By default, Actuator exposes only a few endpoints. You can explicitly specify which endpoints to expose in application.properties or application.yml:
✅ Recommended Secure Configuration:
# Expose only necessary endpoints
management.endpoints.web.exposure.include=health,info
This prevents exposing sensitive endpoints like /env
, /beans
, and /mappings
.
2️⃣ Secure Actuator Endpoints with Spring Security
Spring Security can restrict access to Actuator endpoints. Add the following configuration in your security setup:
✅ Secure Endpoints in application.properties:
# Require authentication for Actuator endpoints
management.endpoints.web.exposure.include=*
management.endpoint.health.show-details=when_authorized
management.endpoints.web.base-path=/admin
🔹 This makes Actuator endpoints accessible only to authenticated users under /admin/actuator
.
3️⃣ Protect with Role-Based Access Control (RBAC)
To ensure only admin users can access Actuator, update your Spring Security configuration:
✅ Secure Actuator with Spring Security (Java Config)
@Configuration
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/actuator/**").hasRole("ADMIN") // Restrict Actuator to ADMIN only
.antMatchers("/public/**").permitAll()
.and()
.httpBasic();
}
}
🔹 This restricts Actuator access to users with the ADMIN role.
4️⃣ Hide Sensitive Information in Actuator Responses
Even with restricted access, some Actuator endpoints expose sensitive data. Limit details using:
management.endpoint.health.show-details=never
management.endpoint.env.show-values=never
🔹 This prevents sensitive configurations from being displayed.
🚀 Conclusion
Spring Boot Actuator is a powerful tool, but securing it is crucial to avoid exposing sensitive system details. Always:
✅ Restrict exposed endpoints
✅ Use Spring Security to enforce authentication
✅ Apply role-based access control
✅ Hide sensitive configuration values
📢 Have you faced security issues with Actuator? Let’s discuss in the comments! ⬇️
📌 Helpful Links:
🔗 Spring Boot Actuator Docs
🔗 Spring Security Basics
#SpringBoot #Java #SpringSecurity #Microservices #BackendDevelopment #DevOps #CyberSecurity #WebDevelopment