Skip to content

An enviroment to play with Hashicorp Vault & learn it in depth

Notifications You must be signed in to change notification settings

escalopa/vault-playground

Repository files navigation

vault-playground 🔒

An enviroment to play with Hashicorp Vault & learn it in depth

Pre-requisites 📚

Run 💨

  1. Start the docker containers
docker compose up -d
  1. Run the migration scripts
make migrate
  1. Start vault in insecure mode
make vault
  1. Set vault address in shell (On TLS use https)
export VAULT_ADDR=http://127.0.0.1:8200
  1. Enable role path in vault
vault auth enable approle
  1. Create role for app
make role-create
  1. Set role policy
make policy-create
  1. Set database dsn secret
make dns-create
  1. Run the app
make run
  1. Get user orders
curl -q http://localhost:8080/order/101 | jq

Production Use Case 🏘

  1. Create directory ./vault/data
mkdir -p ./vault/data
  1. Start server
sudo make vault-prod
  1. Init the server
vault operator init
  1. Unseal the server using 3 secrets, Secrets can be found in the output of the 3rd command
vault operator unseal
  1. Login to the server, Token can be found in the output of the 3rd command
vault login

Database & Dynamic Secrets 🗄

Before we start make sure vault is up and running

  1. Create a role for vault in postgres db
docker exec -i  db psql -U postgres -c "CREATE ROLE \"vault-ro\" NOINHERIT;"
  1. Grant the ability to read all tables to vault role
docker exec -i  db psql -U postgres -c "GRANT SELECT ON ALL TABLES IN SCHEMA public TO \"vault-ro\";"
  1. Enable database secrets engine
vault secrets enable database
  1. Create database configuration in vault
make vault-db
  1. Create database role in vault
make db-role-create
  1. Get sample database credentials
vault read database/creds/readonly
  1. Check the database credentials in postgres
docker exec -i \       
    db \
    psql -U postgres -c "SELECT usename, valuntil FROM pg_user;"

Milestones 🚀

v1.0.0 🎯

  • Read secrets from Vault
  • Write secrets to Vault
  • Connect to databse with secrets from Vault

v2.0.0 🎯

  • Create approle, policy for application
  • Create a vault client with approle
  • Read secrets from vault with approle policies
  • Run vault in production mode

v3.0.0 🎯

  • Link vault with postgres
  • Create/Read dynamic secrets

About

An enviroment to play with Hashicorp Vault & learn it in depth

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published