[ISSUE-149] Fix actuator security to allow unauthenticated health/info on management port #161

Merged
hitanshu merged 1 commits from Dave/CFTunnels:ISSUE-149 into main 2026-08-02 17:34:55 +00:00
2 changed files with 10 additions and 2 deletions
Showing only changes of commit b9c39ad990 - Show all commits

View File

@ -2,9 +2,11 @@ package com.hithomelabs.cftunnels.Config.Security;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order; import org.springframework.core.annotation.Order;
import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.web.SecurityFilterChain; import org.springframework.security.web.SecurityFilterChain;
import org.springframework.boot.actuate.autoconfigure.security.servlet.EndpointRequest;
/** /**
* Security configuration for Spring Boot Actuator endpoints. * Security configuration for Spring Boot Actuator endpoints.
@ -12,15 +14,20 @@ import org.springframework.security.web.SecurityFilterChain;
* This configuration permits unauthenticated access to /actuator/health and /actuator/info * This configuration permits unauthenticated access to /actuator/health and /actuator/info
* endpoints, enabling health monitoring by Uptime Kuma without requiring OIDC authentication. * endpoints, enabling health monitoring by Uptime Kuma without requiring OIDC authentication.
* All other actuator endpoints remain protected and require authentication. * All other actuator endpoints remain protected and require authentication.
*
* Uses @Order(Ordered.HIGHEST_PRECEDENCE) to ensure this filter chain is evaluated BEFORE
* any auto-configured management security filter chains (e.g., ManagementWebSecurityAutoConfiguration).
* Without this, the catch-all SecurityFilterChain in SecuirtyConfig can intercept actuator
* requests on the separate management port (management.server.port=8081) and redirect to OIDC login.
Review

Using Ordered.HIGHEST_PRECEDENCE (Integer.MIN_VALUE) is correct but aggressive. Consider @Order(0) instead — it's the conventional 'go first' order and leaves headroom if other security filter chains are added later. Not blocking for this PR, but a consideration for future-proofing.

Using `Ordered.HIGHEST_PRECEDENCE` (Integer.MIN_VALUE) is correct but aggressive. Consider `@Order(0)` instead — it's the conventional 'go first' order and leaves headroom if other security filter chains are added later. Not blocking for this PR, but a consideration for future-proofing.
*/ */
@Configuration @Configuration
@Order(Ordered.HIGHEST_PRECEDENCE)
public class ActuatorSecurityConfig { public class ActuatorSecurityConfig {
@Bean @Bean
@Order(1)
public SecurityFilterChain actuatorSecurityChain(HttpSecurity http) throws Exception { public SecurityFilterChain actuatorSecurityChain(HttpSecurity http) throws Exception {
http http
.securityMatcher("/actuator/**") .securityMatcher(EndpointRequest.toAnyEndpoint())
.authorizeHttpRequests(auth -> auth .authorizeHttpRequests(auth -> auth
.requestMatchers("/actuator/health", "/actuator/info").permitAll() .requestMatchers("/actuator/health", "/actuator/info").permitAll()
.anyRequest().authenticated() .anyRequest().authenticated()

View File

@ -29,6 +29,7 @@ public class SecuirtyConfig {
http http
.authorizeHttpRequests(auth -> auth .authorizeHttpRequests(auth -> auth
//.requestMatchers( "/v3/api-docs/**", "/swagger-ui/**", "/swagger-ui.html" ).permitAll() //.requestMatchers( "/v3/api-docs/**", "/swagger-ui/**", "/swagger-ui.html" ).permitAll()
.requestMatchers("/actuator/health", "/actuator/info").permitAll()
.anyRequest().authenticated() .anyRequest().authenticated()
Review

Good belt-and-suspenders approach. With management.server.port=8081, actuator requests won't normally reach this filter chain, but this serves as a safety net. Consider adding a brief comment explaining the fallback intent:

// Fallback: permit actuator health/info for non-separated management port configs
.requestMatchers("/actuator/health", "/actuator/info").permitAll()
Good belt-and-suspenders approach. With `management.server.port=8081`, actuator requests won't normally reach this filter chain, but this serves as a safety net. Consider adding a brief comment explaining the fallback intent: ```java // Fallback: permit actuator health/info for non-separated management port configs .requestMatchers("/actuator/health", "/actuator/info").permitAll() ```
).csrf(csrf -> csrf.disable()) ).csrf(csrf -> csrf.disable())
.with(new OAuth2LoginConfigurer<>(), .with(new OAuth2LoginConfigurer<>(),