forked from Hithomelabs/CFTunnels
Hithomelabs/CFTunnels#149: Add Spring Boot Actuator health check endpoints
- Add spring-boot-starter-actuator dependency - Configure management port (8081) separate from application port (8080) - Expose /actuator/health and /actuator/info endpoints publicly - Block other actuator endpoints without authentication - Add ActuatorSecurityConfig for actuator-specific security rules - Update Docker Compose to expose management port (5003:8081) - Update Dockerfile to expose ports 8080 and 8081 - Add actuator configuration to all profile-specific properties files
This commit is contained in:
parent
52f40e3d92
commit
3de734dbc5
@ -1,4 +1,5 @@
|
||||
CLOUDFLARE_ACCOUNT_ID="<cloudflare account id>"
|
||||
CLOUDFLARE_API_KEY="<cloudflare account key>"
|
||||
CLOUDFLARE_EMAIL="<cloudflare email>"
|
||||
ENV="<deployment env>"
|
||||
ENV="<deployment env>"
|
||||
MGMT_PORT="5003"
|
||||
@ -9,4 +9,5 @@ RUN ./gradlew :cftunnels-service:bootJar
|
||||
|
||||
FROM openjdk:17-jdk-slim
|
||||
COPY --from=build /app/cftunnels-service/build/libs/*.jar app.jar
|
||||
EXPOSE 8080 8081
|
||||
ENTRYPOINT ["java", "-jar", "/app.jar"]
|
||||
|
||||
@ -7,6 +7,7 @@ dependencies {
|
||||
implementation 'org.springframework.boot:spring-boot-starter-oauth2-client'
|
||||
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
|
||||
implementation 'org.springframework.boot:spring-boot-starter-security'
|
||||
implementation 'org.springframework.boot:spring-boot-starter-actuator'
|
||||
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.8.5'
|
||||
implementation 'org.hibernate.validator:hibernate-validator'
|
||||
|
||||
|
||||
@ -0,0 +1,32 @@
|
||||
package com.hithomelabs.cftunnels.Config.Security;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||
import org.springframework.security.web.SecurityFilterChain;
|
||||
|
||||
/**
|
||||
* Security configuration for Spring Boot Actuator endpoints.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
@Configuration
|
||||
public class ActuatorSecurityConfig {
|
||||
|
||||
@Bean
|
||||
@Order(1)
|
||||
public SecurityFilterChain actuatorSecurityChain(HttpSecurity http) throws Exception {
|
||||
http
|
||||
.securityMatcher("/actuator/**")
|
||||
.authorizeHttpRequests(auth -> auth
|
||||
.requestMatchers("/actuator/health", "/actuator/info").permitAll()
|
||||
.anyRequest().authenticated()
|
||||
)
|
||||
.csrf(csrf -> csrf.disable());
|
||||
|
||||
return http.build();
|
||||
}
|
||||
}
|
||||
@ -4,4 +4,8 @@ spring.datasource.url=jdbc:h2:mem:testdb
|
||||
spring.datasource.driver-class-name=org.h2.Driver
|
||||
spring.datasource.username=sa
|
||||
spring.datasource.password=
|
||||
spring.jpa.hibernate.ddl-auto=none
|
||||
spring.jpa.hibernate.ddl-auto=none
|
||||
|
||||
# Actuator configuration for CI
|
||||
management.endpoints.web.exposure.include=health,info
|
||||
management.endpoint.health.show-details=never
|
||||
@ -1,8 +1,10 @@
|
||||
api.baseUrl=http://localhost:8080
|
||||
|
||||
management.health.db.enabled=true
|
||||
management.endpoints.web.exposure.include=health
|
||||
# Actuator configuration for local development
|
||||
management.server.port=8081
|
||||
management.endpoints.web.exposure.include=health,info
|
||||
management.endpoint.health.show-details=always
|
||||
management.health.db.enabled=true
|
||||
|
||||
logging.level.org.hibernate.SQL=DEBUG
|
||||
debug=true
|
||||
|
||||
@ -9,4 +9,8 @@ spring.datasource.driver-class-name=org.postgresql.Driver
|
||||
# JPA Configuration
|
||||
spring.jpa.hibernate.ddl-auto=create-drop
|
||||
spring.jpa.show-sql=false
|
||||
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
|
||||
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
|
||||
|
||||
# Actuator configuration
|
||||
management.endpoints.web.exposure.include=health,info
|
||||
management.endpoint.health.show-details=when-authorized
|
||||
@ -10,3 +10,7 @@ spring.datasource.driver-class-name=org.postgresql.Driver
|
||||
spring.jpa.hibernate.ddl-auto=update
|
||||
spring.jpa.show-sql=true
|
||||
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
|
||||
|
||||
# Actuator configuration
|
||||
management.endpoints.web.exposure.include=health,info
|
||||
management.endpoint.health.show-details=when-authorized
|
||||
|
||||
@ -35,4 +35,9 @@ spring.jpa.hibernate.ddl-auto=update
|
||||
spring.jpa.show-sql=true
|
||||
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
|
||||
|
||||
spring.jpa.open-in-view=false
|
||||
spring.jpa.open-in-view=false
|
||||
|
||||
# Actuator configuration - management port and exposed endpoints
|
||||
management.server.port=8081
|
||||
management.endpoints.web.exposure.include=health,info
|
||||
management.endpoint.health.show-details=when-authorized
|
||||
@ -4,6 +4,7 @@ services:
|
||||
container_name: cftunnels_${ENV}
|
||||
ports:
|
||||
- ${HOST_PORT}:8080
|
||||
- ${MGMT_PORT:-5003}:8081
|
||||
environment:
|
||||
- CLOUDFLARE_ACCOUNT_ID=${CLOUDFLARE_ACCOUNT_ID}
|
||||
- CLOUDFLARE_API_KEY=${CLOUDFLARE_API_KEY}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user