Hithomelabs/CFTunnels#149: Fix actuator security to allow unauthenticated health/info on management port

- Upgrade ActuatorSecurityConfig to @Order(Ordered.HIGHEST_PRECEDENCE) at class level
  to ensure filter chain is evaluated before auto-configured management security
- Replace string-based securityMatcher with EndpointRequest.toAnyEndpoint() for
  proper Spring Boot actuator endpoint matching
- Add belt-and-suspenders permitAll() for /actuator/health and /actuator/info in
  SecuirtyConfig so health endpoints are accessible even if filter chain ordering fails
- Root cause: SecuirtyConfig catch-all (no securityMatcher) was intercepting actuator
  requests on the separate management port (management.server.port=8081) and
  redirecting to OIDC login before ActuatorSecurityConfig filter chain could apply
This commit is contained in:
hitanshu310 2026-07-28 11:45:33 +05:30
parent 3de734dbc5
commit b9c39ad990
2 changed files with 10 additions and 2 deletions

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.
*/ */
@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()
).csrf(csrf -> csrf.disable()) ).csrf(csrf -> csrf.disable())
.with(new OAuth2LoginConfigurer<>(), .with(new OAuth2LoginConfigurer<>(),