From 5186ce403449766fdb565824c83098ea1158cd28 Mon Sep 17 00:00:00 2001 From: Kalpa Vidusha Pathirana Date: Tue, 16 Dec 2025 00:21:34 +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 | 222 +++++++++++----------- src/main/resources/application.properties | 21 -- src/main/resources/application.yml | 53 ++++++ 3 files changed, 160 insertions(+), 136 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 f8591c0..768029c 100644 --- a/pom.xml +++ b/pom.xml @@ -1,78 +1,83 @@ - 4.0.0 - - org.springframework.boot - spring-boot-starter-parent - 4.0.0 - - - com.CSO2 - shoppingcart-wishlist-service - 0.0.1-SNAPSHOT - shoppingcart-wishlist-service - shoppingcart-wishlist-service of CSO2 - - - - - - - - - - - - - - - 17 - 2025.1.0 - 1.18.42 - - - - org.springframework.boot - spring-boot-starter-data-redis - - - org.springframework.boot - spring-boot-starter-data-mongodb - - - org.springframework.cloud - spring-cloud-starter-openfeign - - - org.springframework.cloud - spring-cloud-starter-loadbalancer - - - org.springframework.boot - spring-boot-starter-validation - - - org.springframework.boot - spring-boot-starter-web - - - org.springframework.boot - spring-boot-devtools - true - + 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 + shoppingcart-wishlist-service + 0.0.1-SNAPSHOT + shoppingcart-wishlist-service + shoppingcart-wishlist-service of CSO2 - - org.projectlombok - lombok - ${lombok.version} - true - - - org.springframework.boot - spring-boot-starter-test - test - + + 17 + 1.18.42 + 2023.0.0 + + + + + org.springframework.cloud + spring-cloud-dependencies + ${spring-cloud.version} + pom + import + + + + + + + org.springframework.cloud + spring-cloud-starter-vault-config + + + + org.springframework.boot + spring-boot-starter-data-redis + + + org.springframework.boot + spring-boot-starter-data-mongodb + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.cloud + spring-cloud-starter-openfeign + + + org.springframework.cloud + spring-cloud-starter-loadbalancer + + + org.springframework.boot + spring-boot-starter-validation + + + + org.springframework.boot + spring-boot-devtools + true + + + org.projectlombok + lombok + ${lombok.version} + true + + + org.springframework.boot + spring-boot-starter-test + test + org.springframework.boot spring-boot-starter-actuator @@ -80,53 +85,40 @@ com.fasterxml.jackson.core jackson-databind - 2.15.2 com.fasterxml.jackson.datatype jackson-datatype-jsr310 - - - - 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.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 2c7bee9..0000000 --- a/src/main/resources/application.properties +++ /dev/null @@ -1,21 +0,0 @@ -spring.application.name=shoppingcart-wishlist-service -server.port=${SERVER_PORT:8084} - -# Redis Configuration (override via env vars in production) -spring.data.redis.host=${REDIS_HOST:localhost} -spring.data.redis.port=${REDIS_PORT:6379} -spring.data.redis.password=${REDIS_PASSWORD:} - -# MongoDB Configuration (override via env vars in production) -spring.data.mongodb.uri=${MONGODB_URI:mongodb://localhost:27017/CSO2_shoppingcart_wishlist_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) -catalog.service.url=${CATALOG_SERVICE_URL:http://localhost:8082} - -# Fix for Spring Cloud startup error -spring.autoconfigure.exclude=org.springframework.cloud.autoconfigure.LifecycleMvcEndpointAutoConfiguration,org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration,org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration - diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml new file mode 100644 index 0000000..fe656aa --- /dev/null +++ b/src/main/resources/application.yml @@ -0,0 +1,53 @@ +# --- Shopping Cart & Wishlist Service --- +spring: + application: + name: shoppingcart-wishlist-service + + # 1. Config Import: Load Vault first + config: + import: "optional:vault://" + + # 2. Vault Configuration + cloud: + vault: + enabled: true + uri: ${VAULT_URI:http://localhost:8200} + token: ${VAULT_TOKEN:my-root-token} + kv: + enabled: true + backend: kv + default-context: cs02-app + authentication: TOKEN + + # 3. Redis Configuration (Secrets from Vault) + data: + redis: + host: ${redis_host:localhost} + port: ${redis_port:6379} + # If you set a password in docker/vault, use ${redis_password} + # password: ${redis_password:} + + # 4. MongoDB Configuration (Secrets from Vault) + mongodb: + # We will store the full connection string in Vault for simplicity + uri: ${mongodb_uri:mongodb://localhost:27017/CSO2_shoppingcart_wishlist_service} + + # 5. Disable Relational DB Auto-config (Since we only use Mongo/Redis) + autoconfigure: + exclude: + - org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration + - org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration + +# --- Server Port --- +server: + port: 8084 + +# --- Feign Clients --- +spring.cloud.openfeign.client.config.default: + connectTimeout: 5000 + readTimeout: 5000 + +# --- Service Discovery (Local URLs) --- +catalog: + service: + url: ${CATALOG_SERVICE_URL:http://localhost:8082} \ No newline at end of file