项目作者: RitreshGirdhar

项目描述 :
Spring cloud application integration with Hashicorp-Vault.
高级语言: Java
项目地址: git://github.com/RitreshGirdhar/microservice-vault-integration.git


Spring Cloud application integration with Hashcorp vault

Pre-requisite

  • Some knowledge of Spring boot and docker will be helpful.

Here, I am using docker for ease of set up

Run below command to run vault server in development mode

  1. docker run --cap-add=IPC_LOCK -d --name=dev-vault -p8200:8200 -e 'VAULT_DEV_ROOT_TOKEN_ID=myroot' vault

Confirm that docker is up using below command

  1. ritgirdh$ docker ps
  2. CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
  3. 9ad13a11b2d5 vault "docker-entrypoint.s…" 25 hours ago Up 25 hours 0.0.0.0:8200->8200/tcp dev-vault

Login http://localhost:8200/ui/ with token value myroot
// TODO - screen shot

Now create secret for weather service

  1. docker exec -it 9ad13a11b2d5 sh
  2. / # vault kv put secret/weather-service weather.username=demouser weather.password=demopassword
  3. Get "https://127.0.0.1:8200/v1/sys/internal/ui/mounts/secret/weather-service": http: server gave HTTP response to HTTPS client
  4. / # export VAULT_ADDR="http://127.0.0.1:8200"
  5. / # export export VAULT_TOKEN="myroot"
  6. / # vault kv put secret/weather-service weather.username=demouser weather.password=demopassword
  7. Key Value
  8. --- -----
  9. created_time 2021-05-05T15:45:20.1485816Z
  10. deletion_time n/a
  11. destroyed false
  12. version 1

Now add for QA and prod profile

  1. docker exec -it 9ad13a11b2d5 sh
  2. / # vault kv put secret/weather-service/qa weather.username=qauser weather.password=qapassword
  3. Key Value
  4. --- -----
  5. created_time 2021-05-05T15:46:25.801457Z
  6. deletion_time n/a
  7. destroyed false
  8. version 1
  1. docker exec -it 9ad13a11b2d5 sh
  2. / # vault kv put secret/weather-service/prod weather.username=produser weather.password=prodpassword
  3. Key Value
  4. --- -----
  5. created_time 2021-05-05T15:46:50.5295174Z
  6. deletion_time n/a
  7. destroyed false
  8. version 1
  1. //TODO Screen shot

Build microservice

  1. ritgirdh$ cd microservice/
  2. ritgirdh$ mvn clean install
  3. ....

Run

  1. docker run -d -p8080:8080 weather-service -spring.active.profile=qa

curl -ivk http://locahost:8080/weather
In qa Sunny
In prod Rainy

Now make change in vault and see whether its getting reflected in the application

Happy learning!