This is a complete, hands-on HashiCorp Vault cheat sheet: install, configure, operate, automate and secure it - with copy-paste commands grouped by task. Bookmark it for day-to-day work, incidents and interviews alike.
Vault stores and controls access to secrets, issues short-lived dynamic credentials for databases and clouds, and provides encryption-as-a-service - all behind identity-based policies and a full audit log.
Why you reach for it
- Central, audited secret storage instead of secrets scattered in env files
- Dynamic, short-lived credentials that expire automatically
- Encryption-as-a-service so apps never hold key material
Installation
docker run --cap-add=IPC_LOCK -p 8200:8200 -e VAULT_DEV_ROOT_TOKEN_ID=root hashicorp/vault
export VAULT_ADDR=http://127.0.0.1:8200 VAULT_TOKEN=root
vault statusConfiguration reference
Enable KV, write a secret, and define a least-privilege policy.
vault secrets enable -path=secret kv-v2
vault kv put secret/app/db password=s3cr3t
cat <<EOF | vault policy write app -
path "secret/data/app/*" { capabilities = ["read"] }
EOFCore commands you use daily
vault kv get secret/app/db
# dynamic, expiring database credentials
vault read database/creds/app-roleAuth & KV secrets
vault login -method=oidc
vault secrets enable -path=secret kv-v2
vault kv put secret/app/db password=s3cr3t
vault kv get -field=password secret/app/db
vault kv list secret/appPolicies, tokens, dynamic creds
vault policy write app app-policy.hcl
vault token create -policy=app -ttl=1h
vault read database/creds/app-role # dynamic, expiring creds
vault lease revoke -prefix database/creds/app-role
vault audit enable file file_path=/var/log/vault_audit.logUse it in CI/CD
Pull a secret in CI with the Vault CLI (auth via OIDC/JWT).
- run: |
export VAULT_TOKEN=$(vault write -field=token auth/jwt/login role=ci jwt=$CI_JOB_JWT)
export DB_PASS=$(vault kv get -field=password secret/app/db)Best-practice checklist
- Use auth methods (Kubernetes, OIDC, AppRole) with least-privilege policies
- Prefer dynamic secrets with short TTLs over static ones
- Enable audit devices and monitor them
Common pitfalls to avoid
- Running the dev server (in-memory, unsealed) in anything but demos
- Long-lived root tokens instead of scoped auth methods
- No audit device enabled, so access is untraceable
Security quick wins
- Auto-unseal with a cloud KMS and tightly control unseal keys
- Rotate static secrets and encryption keys on a schedule
Works well with
- Kubernetes - Declarative orchestration for containers at scale - self-healing, rolling updates and service discovery.
- Terraform - Declarative, provider-agnostic infrastructure as code with a planned, reviewable change workflow.
- Trivy - A fast, all-in-one scanner for container images, filesystems, IaC and Kubernetes.
A cheat sheet is muscle memory on paper - keep it close until the commands live in your fingers.
Want senior help putting HashiCorp Vault to work - or a team bootcamp on it? CodeWizard runs Israel's largest DevOps community and embeds named senior engineers with a transparent hours log. Book a free consult or explore the Academy.