# Vaults and Secret Stores
> Centralized systems (HashiCorp Vault/OpenBao, AWS Secrets Manager, cloud KMS-backed stores, Kubernetes integrations, SOPS-encrypted files) that hold secrets encrypted, gate access by identity, audit every read and ideally mint short-lived dynamic credentials.
## How it works
A store moves the problem from "where is the value?" to "**who may decrypt it?**" Encryption at rest is table stakes; the real perimeter is the set of identities allowed to read or decrypt, and the moment a secret leaves the store to be used. Core properties (OWASP Secrets Management Cheat Sheet):
- **Centralize and standardize**, with HA and a break-glass/backup path.
- **Least-privilege access** per secret or version, not account-wide.
- **Audit** every access; feed it to detection.
- **Lifecycle**: creation, rotation, revocation, expiration — see [[Credential Rotation and Revocation]].
- **Dynamic over static**: lease-bound credentials created per consumer, revoked on lease expiry.
### Dynamic secrets (Vault AWS engine)
```bash
vault secrets enable aws
vault write aws/config/root access_key=... secret_key=... region=us-east-1
vault write -f aws/config/rotate-root # Vault rotates its own root key
vault write aws/roles/deploy credential_type=iam_user \
policy_arns=arn:aws:iam::aws:policy/AmazonEC2ReadOnlyAccess
vault read aws/creds/deploy # new IAM user + key per lease
```
`credential_type` can also be `assumed_role` or federation tokens (STS, short-lived). Note that a static root credential still bootstraps the engine — OWASP flags that dynamic secrets usually require long-term static secrets to create them.
### Getting secrets into workloads
| Method | Notes |
|---|---|
| Mounted file / tmpfs volume | Preferred; orchestrator mounts at runtime, never baked into image |
| Sidecar / init fetch (Vault Agent Injector: `vault.hashicorp.com/agent-inject: "true"`, `agent-inject-secret-<name>: "secret/login"`) | App never talks to the store directly |
| Secrets Store CSI Driver | Mounts external secrets; `--enable-secret-rotation=true` + `--rotation-poll-interval` re-syncs; apps must re-read or restart |
| Vault Secrets Operator | Syncs Vault KV v1/v2, PKI and dynamic secrets into native K8s Secrets |
| Environment variables | Last resort: readable via `/proc/<pid>/environ`, inherited by children, dumped in crash logs; `docker ENV/ARG` bakes them into image metadata |
Kubernetes `Secret` objects are base64-encoded, not encrypted — committing one (e.g. in a Helm chart) commits a working credential. For GitOps, encrypt in the repo instead:
```yaml
# .sops.yaml
creation_rules:
- path_regex: k8s/.*\.yaml
encrypted_regex: ^(data|stringData)$
kms: arn:aws:kms:... # or age / PGP / GCP KMS / Azure KV / Vault transit
```
SOPS uses envelope encryption plus a MAC to detect tampering; decrypt at build or reconcile time (`sops -d … > "$RUNNER_TEMP/secrets.yaml"`, Flux). Sealed Secrets (`kubeseal`) is the cluster-public-key alternative.
## Hardening the store itself (Vault)
- Run as an unprivileged user; disable swap and core dumps; no SSH/RDP to Vault hosts — API only.
- Disable shell history for the `vault` CLI; short TTLs for tokens and certs; avoid long-lived root tokens.
- Single tenancy, firewall traffic, restrict storage-backend access, enable audit device logs, immutable upgrades, configure user lockout.
## Notable cases
- **Railway (Oct 2026)** — envelope-encrypted customer env vars; an attacker escalated in the multi-tenant build system, stole CI credentials that could decrypt, and decrypted variables for up to ~100,000 workspaces hunting AI keys. Railway couldn't tell from the DB query which keys were decrypted, so it rotated everything and pushed keys to vendors for revocation.
- **AWS AgentCore Identity** — Unit 42 showed the harness's default-on `shell` tool (root) can read credentials after they are resolved to plaintext in memory; prompt injection then exfiltrates them. AWS closed it as shared-responsibility: scope `allowedTools`, least-privilege identity-vault accounts, egress monitoring. See [[MCP Security]].
- **Vault CVEs** — CVE-2026-5807 (HCSEC-2026-08): unauthenticated `sys/generate-root` / `sys/rekey` start-cancel loop locks the single operation slot (fixed in 2.0.0). CVE-2026-3605 (HCSEC-2026-05): KVv2 metadata glob-policy bypass lets authenticated users delete secrets outside their scope. Vault integrated-storage SSRF (GHSA-wfcg-cjg6-q966).
- **OpenBao** — authentication bypass fixed in 2.6.5 / 2.7.2 (GHSA-j3xj-r26p-rh3h).
## Defenses / review checklist
- Can any CI identity or build runner decrypt production secrets? (Railway path.)
- Are secrets resolved into env vars or agent tool contexts where another process or a prompt-injected tool can read them?
- Vault coverage: what fraction of discovered credentials actually live in the vault vs copies in code, CI variables and tickets? A vault entry does not mean the hardcoded copy is gone.
- Prefer [[Workload Identity Federation]] so there is no static secret to store.
## Related
- [[Secrets Management]]
- [[Credential Rotation and Revocation]] · [[Workload Identity Federation]] · [[Hardcoded Secrets]]
- [[SSRF in Kubernetes and Containers]] · [[CI-CD Pipeline Attacks]] · [[MCP Security]]
## Sources
- [[raw/cheatsheetseries.owasp.org/secrets-management-owasp-cheat-sheet-series-2716|Secrets Management - OWASP Cheat Sheet Series]]
- [[raw/developer.hashicorp.com/hashicorp-vault-production-hardening-guide-4062|HashiCorp Vault Production Hardening Guide]]
- [[raw/developer.hashicorp.com/aws-secrets-engine-hashicorp-vault-2769|AWS Secrets Engine | HashiCorp Vault]]
- [[raw/developer.hashicorp.com/manage-kubernetes-native-secrets-with-vault-secrets-operator-4501|Manage Kubernetes native secrets with Vault Secrets Operator]]
- [[raw/medium.com/a-hands-on-guide-to-vault-in-kubernetes-4499|A Hands-On Guide to Vault in Kubernetes]]
- [[raw/secrets-store-csi-driver.sigs.k8s.io/secret-auto-rotation-with-secrets-store-csi-driver-4058|Secret Auto Rotation with Secrets Store CSI Driver]]
- [[raw/blog.gitguardian.com/sops-guide-how-to-encrypt-and-manage-secrets-in-git-kubernetes-and-ci-12208|SOPS Guide: How to Encrypt and Manage Secrets in Git, Kubernetes and CI]]
- [[raw/blog.gitguardian.com/how-to-handle-secrets-in-helm-13515|How to Handle Secrets in Helm]]
- [[raw/developer.cyberark.com/environment-variables-don-t-keep-secrets-4345|Environment Variables Don't Keep Secrets]]
- [[raw/nodejs-security.com/do-not-use-secrets-in-environment-variables-4344|Do Not Use Secrets in Environment Variables]]
- [[raw/medium.com/the-railway-breach-from-a-build-system-privilege-escalation-to-decrypt-13147|The Railway Breach: From a Build-System Privilege Escalation to Decrypted Customer Secrets]]
- [[raw/unit42.paloaltonetworks.com/a-vault-with-a-heap-view-the-uncomfortable-space-between-agentcore-har-12056|A Vault with a Heap-View: AgentCore Harness]]
- [[raw/discuss.hashicorp.com/hcsec-2026-08-vault-dos-via-unauthenticated-root-token-generation-4943|HCSEC-2026-08: Vault DoS via Unauthenticated Root Token Generation]]
- [[raw/discuss.hashicorp.com/hcsec-2026-05-vault-kvv2-metadata-policy-bypass-dos-4944|HCSEC-2026-05: Vault KVv2 Metadata Policy Bypass DoS]]
- [[raw/github.com/hashicorp-vault-integrated-storage-ssrf-14361|HashiCorp Vault integrated storage SSRF]]
- [[raw/github.com/openbao-authentication-bypass-14742|OpenBao authentication bypass]]
- [[raw/blog.gitguardian.com/vault-coverage-is-the-missing-metric-in-nhi-programs-11296|Vault Coverage Is the Missing Metric in NHI Programs]]
- [[raw/blog.gitguardian.com/why-is-credential-rotation-so-hard-follow-one-leaked-production-key-15022|Why Is Credential Rotation So Hard? Follow One Leaked Production Key]]