From 651e9efef0c55e8707bd8997ba0c473868b587e6 Mon Sep 17 00:00:00 2001 From: Kalpa Vidusha Pathirana Date: Tue, 16 Dec 2025 00:23:19 +0530 Subject: [PATCH] Integrate HashiCorp Vault & Secure Database Configs - Downgraded Spring Boot to 3.2.5 to support Spring Cloud Vault compatibility. - Added 'spring-cloud-starter-vault-config' dependency. - Migrated 'application.properties' to 'application.yml'. - Externalized database credentials to HashiCorp Vault to implement Zero Trust security. --- pom.xml | 240 +++++++++++----------- src/main/resources/application.properties | 20 -- src/main/resources/application.yml | 55 +++++ 3 files changed, 172 insertions(+), 143 deletions(-) delete mode 100644 src/main/resources/application.properties create mode 100644 src/main/resources/application.yml diff --git a/pom.xml b/pom.xml index 2df110b..a330caf 100644 --- a/pom.xml +++ b/pom.xml @@ -1,129 +1,123 @@ - 4.0.0 - - org.springframework.boot - spring-boot-starter-parent - 4.0.0 - - - com.CSO2 - support-service - 0.0.1-SNAPSHOT - support-service - support-service of CSO2 - - - - - - - - - - - - - - - 17 - 1.18.42 - - - - org.springframework.boot - spring-boot-starter-data-jpa - - - org.springframework.boot - spring-boot-starter-data-mongodb - - - org.springframework.boot - spring-boot-starter-web - - - org.springframework.boot - spring-boot-starter-security - - - org.springframework.boot - spring-boot-devtools - true - - - org.springframework.cloud - spring-cloud-starter-openfeign - - - org.springframework.cloud - spring-cloud-starter-loadbalancer - + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 3.2.5 + + com.CSO2 + support-service + 0.0.1-SNAPSHOT + support-service + support-service of CSO2 - - org.postgresql - postgresql - runtime - - - org.projectlombok - lombok - ${lombok.version} - true - - - org.springframework.boot - spring-boot-starter-test - test - - - org.springframework.security - spring-security-test - test - - + + 17 + 1.18.42 + 2023.0.0 - - - - org.springframework.cloud - spring-cloud-dependencies - 2025.1.0 - pom - import - - - + + + + org.springframework.cloud + spring-cloud-dependencies + ${spring-cloud.version} + pom + import + + + - - - - org.apache.maven.plugins - maven-compiler-plugin - - - - org.projectlombok - lombok - ${lombok.version} - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - org.projectlombok - lombok - - - - - - + + + org.springframework.cloud + spring-cloud-starter-vault-config + - + + org.springframework.boot + spring-boot-starter-data-jpa + + + org.springframework.boot + spring-boot-starter-data-mongodb + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-security + + + org.springframework.boot + spring-boot-devtools + true + + + + org.springframework.cloud + spring-cloud-starter-openfeign + + + org.springframework.cloud + spring-cloud-starter-loadbalancer + + + + org.postgresql + postgresql + runtime + + + org.projectlombok + lombok + ${lombok.version} + true + + + org.springframework.boot + spring-boot-starter-test + test + + + org.springframework.security + spring-security-test + test + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + + org.projectlombok + lombok + ${lombok.version} + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + org.projectlombok + lombok + + + + + + + \ No newline at end of file diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties deleted file mode 100644 index 076e5ae..0000000 --- a/src/main/resources/application.properties +++ /dev/null @@ -1,20 +0,0 @@ -spring.application.name=support-service -server.port=${SERVER_PORT:8085} - -# PostgreSQL Configuration (override via env vars in production) -spring.datasource.url=${DATABASE_URL:jdbc:postgresql://localhost:5432/CSO2_support_service} -spring.datasource.username=${DATABASE_USERNAME:cso2} -spring.datasource.password=${DATABASE_PASSWORD:password123} -spring.jpa.hibernate.ddl-auto=update -spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect - -# MongoDB Configuration (override via env vars in production) -spring.data.mongodb.uri=${MONGODB_URI:mongodb://localhost:27017/CSO2_support_service} - -# Feign Configuration -spring.cloud.openfeign.client.config.default.connectTimeout=5000 -spring.cloud.openfeign.client.config.default.readTimeout=5000 - -# Service URLs for Feign clients (override via env vars) -order.service.url=${ORDER_SERVICE_URL:http://localhost:8083} - diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml new file mode 100644 index 0000000..3ab9d82 --- /dev/null +++ b/src/main/resources/application.yml @@ -0,0 +1,55 @@ +# --- Support Service Configuration --- +spring: + application: + name: support-service + + # 1. Config Import: Load properties from Vault first + config: + import: "optional:vault://" + + # 2. Vault Configuration + cloud: + vault: + enabled: true + uri: http://localhost:8200 + token: my-root-token + kv: + enabled: true + backend: kv + default-context: cs02-app + authentication: TOKEN + + # 3. PostgreSQL Configuration + datasource: + # Correct Database Name + url: jdbc:postgresql://localhost:5432/CSO2_support_service + # Secrets fetched from Vault + username: ${db_username} + password: ${db_password} + + # 4. JPA Configuration + jpa: + hibernate: + ddl-auto: update + properties: + hibernate: + dialect: org.hibernate.dialect.PostgreSQLDialect + + # 5. MongoDB Configuration (Standard, not using Vault for now) + data: + mongodb: + uri: mongodb://localhost:27017/CSO2_support_service + +# --- Server Port --- +server: + port: 8085 + +# --- Feign Configuration --- +spring.cloud.openfeign.client.config.default: + connectTimeout: 5000 + readTimeout: 5000 + +# --- Custom Service URLs --- +order: + service: + url: ${ORDER_SERVICE_URL:http://localhost:8083} \ No newline at end of file