DEV Community

Code Reacher
Code Reacher

Posted on

πŸ” Securing Spring Boot Actuator Endpoints: A Must for Production

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

πŸ”Ή 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();
    }
}
Enter fullscreen mode Exit fullscreen mode

πŸ”Ή 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
Enter fullscreen mode Exit fullscreen mode

πŸ”Ή 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

Top comments (0)