forked from Hithomelabs/CFTunnels
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:
parent
3de734dbc5
commit
b9c39ad990
@ -2,9 +2,11 @@ package com.hithomelabs.cftunnels.Config.Security;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||
import org.springframework.security.web.SecurityFilterChain;
|
||||
import org.springframework.boot.actuate.autoconfigure.security.servlet.EndpointRequest;
|
||||
|
||||
/**
|
||||
* 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
|
||||
* endpoints, enabling health monitoring by Uptime Kuma without requiring OIDC 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
|
||||
@Order(Ordered.HIGHEST_PRECEDENCE)
|
||||
public class ActuatorSecurityConfig {
|
||||
|
||||
@Bean
|
||||
@Order(1)
|
||||
public SecurityFilterChain actuatorSecurityChain(HttpSecurity http) throws Exception {
|
||||
http
|
||||
.securityMatcher("/actuator/**")
|
||||
.securityMatcher(EndpointRequest.toAnyEndpoint())
|
||||
.authorizeHttpRequests(auth -> auth
|
||||
.requestMatchers("/actuator/health", "/actuator/info").permitAll()
|
||||
.anyRequest().authenticated()
|
||||
|
||||
@ -29,6 +29,7 @@ public class SecuirtyConfig {
|
||||
http
|
||||
.authorizeHttpRequests(auth -> auth
|
||||
//.requestMatchers( "/v3/api-docs/**", "/swagger-ui/**", "/swagger-ui.html" ).permitAll()
|
||||
.requestMatchers("/actuator/health", "/actuator/info").permitAll()
|
||||
.anyRequest().authenticated()
|
||||
).csrf(csrf -> csrf.disable())
|
||||
.with(new OAuth2LoginConfigurer<>(),
|
||||
|
||||
Loading…
Reference in New Issue
Block a user