Use this when giving containers passwords, tokens and keys safely.
Secrets · Container Security
Container secrets should be injected at runtime from a secret store or orchestrator secrets, mounted as files with tight permissions, never baked into images or committed in Dockerfiles.
1. Container secrets: from secret managers via CSI/External Secrets.
2. Kubernetes Secrets need encryption at rest (KMS) and RBAC.
3. Avoid env vars in logs.
4. Never bake into images.
5. Rotate.
secret store → CSI/external secrets → pod
Context & applicabilityCommon mistakes · platform/version boundaries
Operational reference
Fast context before you go deeper.
Verification & Troubleshooting
Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.
Use the operational verification above to establish the expected state.
Capture the concrete output, symptom, packet, log or counter before changing anything.
Step 1 Common mistakes Narrow the fault
- Secrets in Dockerfile
ENVor build args. - Kubernetes Secrets in Git without SOPS/Sealed Secrets.
Evidence · 1 on this Topic
Expected observations and documentation recipes are reference material. Record actual output, device identity, scope and time before claiming a verified result.
- Inject at runtime, not at build time.
- Mount as files with tight permissions.
- Use external secret stores for GitOps.
kubectl get secrets -A— (check RBAC to secrets)kubectl get pods -A -o yaml | grep -i -A2 'env:'— secrets in env (review)- External Secrets/CSI driver usage — vault integration
ReferenceWhy it matters1 section · depth on demand
Options
| Method | Note |
|---|---|
| Environment variables | Simple; visible in docker inspect and process environment |
| Mounted files (tmpfs) | Preferred; Docker/Kubernetes secrets |
| External manager (Vault, cloud) | Rotation, audit |
| Kubernetes Secret | Base64, not encrypted unless etcd encryption is on |
ReferenceImportant terms & boundaries1 section · depth on demand
In depth
Secrets in containers must never be baked into images — anyone who can pull the image (or inspect its layers) can read them, and they remain in layer history even if deleted later.
Better options:
| Method | Notes |
|---|---|
| Kubernetes Secrets mounted as files | Enable encryption at rest; restrict RBAC |
| External secret stores via operators/CSI | Vault, cloud secret managers |
| Workload identity | Cloud access without stored credentials |
Build secrets (BuildKit --secret) | Secrets during build without persisting in layers |
docker build --secret id=npmrc,src=$HOME/.npmrc .
trivy image --scanners secret registry.example.com/app:1.4.0
ReferenceConfiguration & state1 section · depth on demand
Lifecycle
Use least privilege, bounded rollout and explicit exception handling.
Preserve a known-good pre-state, validate dependencies and trust anchors before disruptive changes, and avoid weakening a control merely to make a test pass.
Secrets, private keys, tokens and sensitive indicators remain redacted while stable references survive.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Verification history & basis
When and against what this Topic was checked. Later text edits do not count as a new check.
Authoritative/upstream documentation reviewed for bounded claims in Container Security → Secrets. Documentation verification only; this is not observed lab or production Evidence.
Basis: https://csrc.nist.gov/pubs/sp/800/190/final · confidence 94%