Vault Secrets: Dynamic Credentials & Leases
How HashiCorp Vault replaces static passwords with short-lived, leased credentials, PKI certificates, and Transit encryption—plus seal/unseal and Raft backup rules.
Intent
Understand how Vault acts as an identity broker with a cryptographic barrier: workloads trade platform identities (Kubernetes ServiceAccounts, OIDC JWTs, AppRoles) for short-lived tokens and leased dynamic credentials instead of static shared passwords.
Problem
Static database passwords stored in .env files, CI variables, or Kubernetes Secrets are shared across replicas, rarely rotated, and painful to revoke after a leak because you cannot tell which workload is using which copy.
Solution
Vault separates authentication (who you are), authorization (HCL policies on method + path), and secret engines:
- Authenticate to get a token: A workload proves its identity via Kubernetes auth, AppRole, or OIDC/JWT and receives a scoped Vault token.
- Issue dynamic, leased credentials: Instead of reading a shared password from KV, Vault's Database, PKI, or Cloud engines generate a unique credential on demand and attach a
lease_idwith attlandmax_ttl. - Renew or revoke: Vault Agent (or the External Secrets Operator) renews leases in the background and re-authenticates before
max_ttl. During an incident,vault lease revoke -prefix database/creds/appdrops every active credential for that role immediately.
Real-world analogy
▶ Flow: watch it work
Dynamic Database Credentials & Lease Lifecycle
Press Start or tap any step dot to trace the path.
▸All steps (6)
Structure
Essential Vault CLI commands for daily operations:
# Authenticate and inspect token capabilities (not run)
vault login -method=oidc
vault token lookup
vault token capabilities kv/data/app/config
# Dynamic database credentials & emergency revocation (not run)
vault read database/creds/app-ro
vault lease revoke -prefix database/creds/app-ro
# Raft HA snapshot backup (not run)
vault operator raft list-peers
vault operator raft snapshot save snap-$(date +%F).snapWhen to use / when to avoid
- Use Vault when you run multi-environment or regulated infrastructure needing dynamic database/PKI credentials, Transit encryption-as-a-service, and a unified audit log.
- Avoid self-hosting Vault HA for a tiny single-cloud app where your cloud provider's managed Secrets Manager + IAM/OIDC roles already cover your needs without Raft/unseal ops.
Pros / Cons
- Pros: Eliminates static shared credentials; instant prefix revocation; built-in audit trail and Transit encryption.
- Cons: Tier-0 dependency (if Vault is sealed or down, new leases fail); requires KMS/HSM auto-unseal, Raft snapshot drills, and dual audit devices so a full disk does not halt the cluster.
Relations
- Complements Secrets Management Basics and Kubernetes ConfigMaps & Secrets.
- Pairs with Short-Lived OIDC in CI to remove static tokens from pipelines.
Check yourself
Check Yourself
1. A token has `ttl=1h` and `max_ttl=720h` (30 days). What happens on day 31 if the application only calls lease renewal and never re-authenticates?
2. You want to grant read access to `kv/app/config` in a Vault KV v2 mount. Which path belongs in the HCL policy?
Sources
Related Notes
API Gateway Choice: Kong vs Gravitee
Decide between Kong (programmable DB-less API gateway) and Gravitee (full API management with developer portal, plans, and subscriptions).
VPN & Private Access: WireGuard, Split-Horizon DNS & Zero Trust
Why network reachability is not authorization—how to combine WireGuard or IPsec VPNs, split-horizon DNS, bastions, and per-app OIDC without creating a flat internal trust zone.