Skip to Content
Mengty Learns
Platform tools

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.

explanationintermediateTested with vault 2.2.2 (docs)Updated Nov 27, 2026

Intent

TL;DR

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:

  1. Authenticate to get a token: A workload proves its identity via Kubernetes auth, AppRole, or OIDC/JWT and receives a scoped Vault token.
  2. 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_id with a ttl and max_ttl.
  3. 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/app drops every active credential for that role immediately.

Real-world analogy

▶ Flow: watch it work

Dynamic Database Credentials & Lease Lifecycle

Overview of Dynamic Database Credentials & Lease Lifecycle. 6 steps.
Overview6 steps in this flow

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).snap

When 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

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