Compare commits

...

6 Commits

Author SHA1 Message Date
48cd8d242f Hithomelabs/CFTunnels#150: Add Spring Boot Actuator health check endpoints for portainer-automation
- Add spring-boot-starter-actuator dependency to portainer-automation/build.gradle
- Configure management.server.port=8082 with health,info exposure in application.properties
- Map 5005:8082 in portainer-automation/docker-compose.yaml
- Add MGMT_PORT=5005 to portainer-automation/.env.example
- EXPOSE 8081 8082 in portainer-automation Dockerfile
- No ActuatorSecurityConfig needed: service has no Spring Security/OIDC
- Management port stays LAN-only, NOT added to any tunnel ingress
2026-08-02 23:57:44 +05:30
b9c39ad990 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
2026-07-28 11:45:33 +05:30
3de734dbc5 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
2026-07-28 11:02:19 +05:30
52f40e3d92 Hithomelabs/CFTunnels#122: Add trust-all SSL RestTemplate for prod profile
Extract trust-all SSL logic into buildTrustAllRestTemplate() helper.
Add @Profile("prod") bean that also trusts self-signed certs.
Change @Profile("!local") to @Profile("!local & !prod") so standard
strict SSL is only used for CI/test profiles.
Rename portainerRestTemplate() to portainerRestTemplateDefault().
2026-07-10 02:24:23 +05:30
3bffa43d6a Hithomelabs/CFTunnels#0: Revert dummy commit - remove CI test comment from test_build.yml 2026-07-09 23:48:13 +05:30
63660928c9 Hithomelabs/CFTunnels#0: Add comment to test_build.yml for CI testing 2026-07-09 23:29:18 +05:30
17 changed files with 110 additions and 16 deletions

View File

@ -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"

View File

@ -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"]

View File

@ -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'

View File

@ -0,0 +1,39 @@
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.
*
* 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
public SecurityFilterChain actuatorSecurityChain(HttpSecurity http) throws Exception {
http
.securityMatcher(EndpointRequest.toAnyEndpoint())
.authorizeHttpRequests(auth -> auth
.requestMatchers("/actuator/health", "/actuator/info").permitAll()
.anyRequest().authenticated()
)
.csrf(csrf -> csrf.disable());
return http.build();
}
}

View File

@ -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<>(),

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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}

View File

@ -36,3 +36,6 @@ ENV=dev
# Host port to map to container port 8081
HOST_PORT=8081
# Host port to map to actuator management port 8082 (health checks, LAN only)
MGMT_PORT=5005

View File

@ -9,4 +9,5 @@ RUN ./gradlew :portainer-automation:bootJar
FROM openjdk:17-jdk-slim
COPY --from=build /app/portainer-automation/build/libs/*.jar app.jar
EXPOSE 8081 8082
ENTRYPOINT ["java", "-jar", "/app.jar"]

View File

@ -5,6 +5,7 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.apache.httpcomponents.client5:httpclient5'
compileOnly 'org.projectlombok:lombok'

View File

@ -3,7 +3,8 @@ services:
image: gitea.hithomelabs.com/hithomelabs/portainer-automation:${ENV:-test}
container_name: portainer-automation_${ENV:-test}
ports:
- "${HOST_PORT:-8081}:8081"
- "${HOST_PORT:-8081}:8081" # Application port (internal service)
- "${MGMT_PORT:-5005}:8082" # Health management port (LAN only)
environment:
- SPRING_PROFILES_ACTIVE=${SPRING_PROFILES_ACTIVE:-local}
- PORTAINER_API_KEY=${PORTAINER_API_KEY}

View File

@ -22,12 +22,11 @@ import java.security.cert.X509Certificate;
public class PortainerClientConfig {
/**
* Trust-all SSL RestTemplate for the "local" profile.
* Used when connecting via Cloudflare Tunnel (self-signed certs).
* Builds a RestTemplate that trusts all SSL certificates.
* Used when connecting via Cloudflare Tunnel (self-signed certs)
* or to the prod Portainer instance (also self-signed).
*/
@Profile("local")
@Bean(name = "portainerRestTemplate")
public RestTemplate portainerRestTemplateLocal() throws Exception {
private static RestTemplate buildTrustAllRestTemplate() throws Exception {
TrustManager[] trustAllCerts = new TrustManager[]{
new X509TrustManager() {
public X509Certificate[] getAcceptedIssuers() { return new X509Certificate[0]; }
@ -47,12 +46,32 @@ public class PortainerClientConfig {
}
/**
* Standard validating SSL RestTemplate for non-local profiles
* (CI, test, prod internal Docker network).
* Trust-all SSL RestTemplate for the "local" profile.
* Used when connecting via Cloudflare Tunnel (self-signed certs).
*/
@Profile("!local")
@Profile("local")
@Bean(name = "portainerRestTemplate")
public RestTemplate portainerRestTemplate() {
public RestTemplate portainerRestTemplateLocal() throws Exception {
return buildTrustAllRestTemplate();
}
/**
* Trust-all SSL RestTemplate for the "prod" profile.
* Prod Portainer at https://192.168.0.100:9443 uses a self-signed certificate.
*/
@Profile("prod")
@Bean(name = "portainerRestTemplate")
public RestTemplate portainerRestTemplateProd() throws Exception {
return buildTrustAllRestTemplate();
}
/**
* Standard validating SSL RestTemplate for profiles other than local and prod
* (CI, test internal Docker network with valid certs).
*/
@Profile("!local & !prod")
@Bean(name = "portainerRestTemplate")
public RestTemplate portainerRestTemplateDefault() {
return new RestTemplate();
}

View File

@ -3,3 +3,9 @@ portainer.base-url=https://192.168.0.100:9442
portainer.api-key=${PORTAINER_API_KEY:}
portainer.endpoint-id=1
portainer.service.api-key=${PORTAINER_SERVICE_API_KEY:change-me}
# Actuator configuration - management port and exposed endpoints
# App runs on server.port=8081, so management port must differ (8082)
management.server.port=8082
management.endpoints.web.exposure.include=health,info
management.endpoint.health.show-details=when-authorized