Actuator endpoints give important info about your app. Securing them stops strangers from seeing or changing this info.
Securing actuator endpoints in Spring Boot
management.endpoints.web.exposure.include=health,info,env management.endpoint.health.show-details=when_authorized spring.security.user.name=admin spring.security.user.password=secret spring.security.user.roles=ADMIN # In Java config @Bean public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { http .authorizeHttpRequests(auth -> auth .requestMatchers("/actuator/health", "/actuator/info").permitAll() .requestMatchers("/actuator/**").hasRole("ADMIN") .anyRequest().authenticated() ) .httpBasic(); return http.build(); }
You configure which endpoints are exposed using management.endpoints.web.exposure.include.
Use Spring Security to require login or roles for actuator URLs.
health, info, and env endpoints are visible over HTTP.management.endpoints.web.exposure.include=health,info,env
management.endpoint.health.show-details=when_authorized
spring.security.user.name=admin spring.security.user.password=secret spring.security.user.roles=ADMIN
@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
http
.authorizeHttpRequests(auth -> auth
.requestMatchers("/actuator/health", "/actuator/info").permitAll()
.requestMatchers("/actuator/**").hasRole("ADMIN")
.anyRequest().authenticated()
)
.httpBasic();
return http.build();
}This Spring Boot app configures security so anyone can see /actuator/health and /actuator/info without login. Other actuator endpoints need login with ADMIN role. Basic auth is used.
package com.example.demo; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.Bean; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.web.SecurityFilterChain; @SpringBootApplication public class DemoApplication { public static void main(String[] args) { SpringApplication.run(DemoApplication.class, args); } @Bean public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { http .authorizeHttpRequests(auth -> auth .requestMatchers("/actuator/health", "/actuator/info").permitAll() .requestMatchers("/actuator/**").hasRole("ADMIN") .anyRequest().authenticated() ) .httpBasic(); return http.build(); } }
Always test actuator security in your environment before deploying.
Use HTTPS to protect credentials sent with basic auth.
You can customize roles and users with Spring Security for better control.
Actuator endpoints show app info and need protection.
Use management.endpoints.web.exposure.include to choose visible endpoints.
Use Spring Security to require login or roles for actuator URLs.
Practice
Solution
Step 1: Understand actuator endpoints role
Actuator endpoints provide information about the app's health, metrics, and configuration.Step 2: Recognize security importance
Since these endpoints expose sensitive data, securing them prevents unauthorized users from accessing this info.Final Answer:
To protect sensitive application information from unauthorized access -> Option DQuick Check:
Actuator security = protect info [OK]
- Thinking actuator endpoints improve performance
- Assuming all endpoints should be open
- Believing security auto-applies without config
application.properties?Solution
Step 1: Identify correct property name
The correct property to expose endpoints ismanagement.endpoints.web.exposure.include.Step 2: Verify property value format
Comma-separated list of endpoints likehealth,infois correct.Final Answer:
management.endpoints.web.exposure.include=health,info -> Option BQuick Check:
Correct property = management.endpoints.web.exposure.include [OK]
- Using 'expose' instead of 'exposure.include'
- Missing 'web' in the property path
- Incorrect property structure or spelling
http
.authorizeHttpRequests(auth -> auth
.requestMatchers("/actuator/**").hasRole("ADMIN")
.anyRequest().authenticated()
)Solution
Step 1: Analyze requestMatchers rule
The matcher "/actuator/**" requires users to have role ADMIN to access.Step 2: Understand anyRequest rule
All other requests require authentication but no specific role.Final Answer:
Only users with ADMIN role can access any actuator endpoint -> Option AQuick Check:
Actuator access = ADMIN role required [OK]
- Assuming actuator is open to all
- Confusing authentication with authorization
- Ignoring the role requirement
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http
.authorizeHttpRequests(auth -> auth
.requestMatchers("/actuator/**").authenticated()
.anyRequest().permitAll()
);
return http.build();
}Solution
Step 1: Review authorization rules order
Actuator endpoints require authentication, but all other requests are permitted without login.Step 2: Identify security risk
This means non-actuator URLs are open, which might expose sensitive parts unintentionally.Final Answer:
Actuator endpoints require login but other URLs are open, risking security -> Option CQuick Check:
PermitAll on anyRequest risks open access [OK]
- Thinking method return type is wrong
- Assuming requestMatchers syntax is invalid
- Believing security is fully disabled
Solution
Step 1: Set exposure property
Usemanagement.endpoints.web.exposure.include=healthto expose only health publicly.Step 2: Configure security rules
Permit all access to/actuator/healthand require ADMIN role for other actuator endpoints using requestMatchers.Final Answer:
Expose health only and configure security to permit all on /actuator/health and ADMIN role on /actuator/** except health -> Option AQuick Check:
Expose health public + secure others ADMIN [OK]
- Exposing too many endpoints publicly
- Not securing non-health actuator endpoints
- Allowing anonymous access to sensitive endpoints
Ready to prove it?
Pass the test and this pattern moves unknown
