From d21d9c14b5695c7a19612bb40826a661fe77646a Mon Sep 17 00:00:00 2001 From: Kalpa Vidusha Pathirana Date: Tue, 16 Dec 2025 00:19:36 +0530 Subject: [PATCH] Integrate HashiCorp Vault & Secure Database Configs - Downgraded Spring Boot to 3.2.5 to support Spring Cloud Vault. - 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 | 211 +++++++++++----------- src/main/resources/application.properties | 14 -- src/main/resources/application.yml | 47 +++++ 3 files changed, 150 insertions(+), 122 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 670fb39..50267f9 100644 --- a/pom.xml +++ b/pom.xml @@ -1,83 +1,79 @@ - 4.0.0 - - org.springframework.boot - spring-boot-starter-parent - 4.0.0 - - - com.CSO2 - reporting-and-analysis-service - 0.0.1-SNAPSHOT - reporting-and-analysis-service - reporting-and-analysis of CSO2 - - - - - - - - - - - - - - - 17 - 1.18.42 - - - - org.springframework.boot - spring-boot-starter-amqp - - - org.springframework.boot - spring-boot-starter-batch - - - org.springframework.boot - spring-boot-starter-data-jpa - - - org.springframework.boot - spring-boot-starter-validation - - - org.springframework.boot - spring-boot-starter-web - + 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 + reporting-and-analysis-service + 0.0.1-SNAPSHOT + reporting-and-analysis-service + reporting-and-analysis of CSO2 + + + 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-jpa + + + org.springframework.boot + spring-boot-starter-batch + + + org.springframework.boot + spring-boot-starter-amqp + + + org.springframework.boot + spring-boot-starter-web + + + org.postgresql + postgresql + runtime + - - org.postgresql - postgresql - runtime - - - org.projectlombok - lombok - ${lombok.version} - true - - - org.springframework.boot - spring-boot-starter-test - test - - - org.springframework.amqp - spring-rabbit-test - test - - - org.springframework.batch - spring-batch-test - test - + + org.projectlombok + lombok + ${lombok.version} + true + + + org.springframework.boot + spring-boot-starter-test + test + + + org.springframework.batch + spring-batch-test + test + org.springframework.boot spring-boot-starter-actuator @@ -90,34 +86,33 @@ - - - - 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 0870038..0000000 --- a/src/main/resources/application.properties +++ /dev/null @@ -1,14 +0,0 @@ -spring.application.name=reporting-and-analysis-service -server.port=${SERVER_PORT:8088} - -# PostgreSQL Configuration (override via env vars in production) -spring.datasource.url=${DATABASE_URL:jdbc:postgresql://localhost:5432/CSO2_reporting_and_analysis_service} -spring.datasource.username=${DATABASE_USERNAME:cso2} -spring.datasource.password=${DATABASE_PASSWORD:password123} -spring.datasource.driver-class-name=org.postgresql.Driver - -# JPA Configuration -spring.jpa.hibernate.ddl-auto=update -spring.jpa.show-sql=${JPA_SHOW_SQL:true} -spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect - diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml new file mode 100644 index 0000000..fe8b796 --- /dev/null +++ b/src/main/resources/application.yml @@ -0,0 +1,47 @@ +# --- Reporting & Analysis Service --- +spring: + application: + name: reporting-and-analysis-service + + # 1. Load Vault + config: + import: "optional:vault://" + + # 2. Vault Config + cloud: + vault: + enabled: true + uri: http://localhost:8200 + token: my-root-token + kv: + enabled: true + backend: kv + default-context: cs02-app + authentication: TOKEN + + # 3. Database Config (Secrets from Vault) + datasource: + # Service specific database name + url: jdbc:postgresql://localhost:5432/CSO2_reporting_and_analysis_service + driver-class-name: org.postgresql.Driver + username: ${db_username} + password: ${db_password} + + # 4. JPA / Hibernate + jpa: + hibernate: + ddl-auto: update + show-sql: ${JPA_SHOW_SQL:true} + properties: + hibernate: + dialect: org.hibernate.dialect.PostgreSQLDialect + format_sql: true + + # 5. Batch Job Config (Optional: initialize schema) + batch: + jdbc: + initialize-schema: always + +# --- Server Port --- +server: + port: 8088 \ No newline at end of file