Hithomelabs/CFTunnels#149: Fix actuator security to allow unauthenticated health/info on management port
All checks were successful
Daily cloudflare API integration test / cloudflare-api-test (push) Successful in 1m46s
sample gradle build and test / build (pull_request) Successful in 1m58s
Build & Push Portainer Automation / version (push) Successful in 6s
Build & Push Portainer Automation / build-and-push (push) Successful in 2m11s
Build & Push CFTunnels / version (push) Successful in 6s
Build & Push CFTunnels / build-and-push (push) Successful in 2m45s
All checks were successful
Daily cloudflare API integration test / cloudflare-api-test (push) Successful in 1m46s
sample gradle build and test / build (pull_request) Successful in 1m58s
Build & Push Portainer Automation / version (push) Successful in 6s
Build & Push Portainer Automation / build-and-push (push) Successful in 2m11s
Build & Push CFTunnels / version (push) Successful in 6s
Build & Push CFTunnels / build-and-push (push) Successful in 2m45s
- 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.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()
|
||||||
|
|||||||
@ -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<>(),
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user