Secret managers and the path from store to process
Examine the lifecycle of credentials from centralized secret managers to application runtime memory: contrast Kubernetes Secrets with dedicated secret vaults, evaluate file mounts vs environment variables, and enforce least-privilege access.
Contentsand lesson path
On this page
- Secret Storage Primitives: Kubernetes Secrets vs. Dedicated Vaults
- The Path from Store to Process: File Mounts vs. Environment Variables
- Workload Identity Federation: Shrinking the Secret Zero Problem
- Check your understanding
- Apply it
- Review prompt
Lessons of Secrets Management
- How secrets escape, and what to do when one does Concept · 20 min
- Lab: scan a repository and an image for leaked credentials Lab · 20 min
- Secret managers and the path from store to process Concept · 15 min
- Lab: sync a secret from a manager into Kubernetes Lab · 30 min
- Keyless CI and rotating credentials without an outage Worked example · 25 min
- Check: secrets design review Knowledge check · 6 questions
What you will learn
- Store secrets in a manager (Vault or a cloud secret manager) and deliver them to applications and Kubernetes through External Secrets or SOPS-encrypted files under least-privilege access.
01. Secret Storage Primitives: Kubernetes Secrets vs. Dedicated Vaults
A common misconception among developers transitioning to containerized environments is assuming that Kubernetes Secret objects encrypt the credentials they hold. In reality, a standard Kubernetes Secret manifest stores sensitive data as plain base64-encoded strings (echo "bXlwYXNzd29yZA==" | base64 -d). Base64 is an encoding format designed for transmitting binary data across text protocols; it provides no confidentiality at all.
Furthermore, in standard Kubernetes installations, Secrets are stored in plaintext within the etcd key-value store unless administrators explicitly configure an EncryptionConfiguration provider (such as an AWS KMS, GCP KMS, or HashiCorp Vault plugin). Under KMS envelope encryption, the Kubernetes API server communicates over a local gRPC UNIX domain socket with an external KMS plugin. When a secret is saved, the API server encrypts the payload with a Data Encryption Key (DEK) that it generates itself, and asks the KMS plugin to encrypt that DEK with a Key Encryption Key (KEK) that never leaves the external KMS. Without this configuration, anyone with physical disk access or snapshot backup access to etcd can read every credential in every namespace.
In contrast, dedicated secret management systems—such as HashiCorp Vault, AWS Secrets Manager, Google Cloud Secret Manager, and Azure Key Vault—are built for this job and add controls that a plain Secret lacks:
-
Envelope Encryption at Rest: Stored secrets are encrypted with data keys that are themselves protected by a root or master key, which can be held in a cloud KMS or a Hardware Security Module (HSM).
-
Audit Logging: Once audit logging is enabled, each read, write, update and revocation is recorded with a timestamp, the caller's identity and source address (Vault, for example, writes an HMAC of secret values rather than the values).
-
Granular Least-Privilege Policies: Access is governed by expressive path-based policies (e.g.
path "secret/data/payments/*" { capabilities = ["read"] }). -
Dynamic and Ephemeral Secrets: Rather than storing static passwords, a secret manager can generate just-in-time, short-lived credentials (e.g. creating a PostgreSQL user valid for only 60 minutes) that expire automatically.
# Permit read-only access to web-service database secrets
path "secret/data/production/web-service" {
capabilities = ["read"]
}
# Explicitly deny access to all other application secrets
path "secret/data/*" {
capabilities = ["deny"]
}02. The Path from Store to Process: File Mounts vs. Environment Variables
Once credentials are securely stored in a vault, how do they safely reach the application process running inside a Kubernetes container? Teams generally choose between three delivery patterns, and a fourth point concerns the node itself:
-
Environment Variables (
spec.containers[].envFrom.secretRef): The simplest and most widely used pattern. While convenient, environment variables introduce substantial operational vulnerabilities: they are inherited by all child processes spawned by the container, they leak in plaintext whenever debugging utilities dump/proc/$PID/environ, and they appear in unredacted error tracking logs and crash dumps. Some crash reporters and error-tracking agents can be configured, or extended, to attach the process environment to error reports, which then sends the passwords to an external service. -
In-Memory File Volume Mounts (
spec.volumes[].secret): The usual recommendation. Kubernetes projects the Secret into an in-memorytmpfsfilesystem mounted inside the container (e.g./etc/secrets/db-password).tmpfslives in RAM and is not written to the node's filesystem. On nodes with swap enabled its pages could be swapped to disk, which is why current kubelets mount secret volumes with thenoswapoption where the kernel supports it (Linux 6.3 or later, or a backport) and log a warning where it does not. A child process does not receive a file's value automatically, as it does with environment variables; it has to open the file. When the Secret changes, the kubelet writes the new files to a timestamped hidden directory and switches the..datasymlink with an atomic rename, so a reader sees either the complete old set of files or the complete new set, never a half-written file (a volume mounted withsubPathdoes not receive updates at all). -
Direct Application SDK Ingestion: The application code uses the Vault or Cloud SDK to authenticate and retrieve secrets directly into process memory upon boot. This keeps the value out of Kubernetes Secret objects and
etcd, but it couples application source code to a proprietary secrets API. -
Memory Swapping Protections and mlock: In multi-tenant Linux worker nodes, unencrypted RAM pages can be swapped to physical swap partitions during memory pressure. If a container holds database credentials in memory, swapping exposes the plaintext password to the host disk. Some secret stores call
mlockto keep their own memory out of swap (Vault does on Linux unlessdisable_mlockis set); your application process usually does not, so the practical controls are no swap or encrypted swap on nodes that handle secrets, andnoswapfor secret volumes.
03. Workload Identity Federation: Shrinking the Secret Zero Problem
A classic security paradox is the "Secret Zero" dilemma: if an application needs a credential to log in to Vault, where do you store the credential that unlocks the Vault?
Platforms replace a stored Secret Zero with Workload Identity Federation: the platform itself gives the workload a short-lived identity token, so nobody has to store a long-lived bootstrap credential. In Kubernetes, every Pod runs as a ServiceAccount, and the kubelet can give it a signed JSON Web Token (JWT) issued by the API server. When the Pod boots, it presents its ServiceAccount token to Vault's Kubernetes Auth backend. Vault validates the JWT against the Kubernetes API server and issues a short-lived, scoped Vault token bound to that workload's identity, so no static bootstrap password is needed.
Which token the Pod presents matters. The default token at /var/run/secrets/kubernetes.io/serviceaccount/token is meant for the Kubernetes API server: its audience is the API server, and with the default --service-account-extend-token-expiration its validity can be extended up to a year for legacy clients, even though kubelet refreshes it about every hour. A stolen default token therefore works against the Kubernetes API, and against a Vault Kubernetes auth role that does not check the audience.
For Vault, mount a separate projected token whose audience is vault and whose lifetime is short, and configure the Vault role to accept only that audience. A stolen token is then useful only against Vault, only for a few minutes, and only for that role.
apiVersion: v1
kind: Pod
metadata:
name: payments-api
spec:
serviceAccountName: payments-api
containers:
- name: app
image: registry.internal/payments-api:2.4.0
volumeMounts:
- name: vault-token
mountPath: /var/run/secrets/vault
readOnly: true
volumes:
- name: vault-token
projected:
sources:
- serviceAccountToken:
path: token
audience: vault # only Vault should accept this token
expirationSeconds: 600 # kubelet refreshes it before expiryvault write auth/kubernetes/role/payments-api \
bound_service_account_names=payments-api \
bound_service_account_namespaces=payments \
audience=vault \
token_policies=payments-read \
token_ttl=15m04. Check your understanding
05. Apply it
Incorporate these secret management standards into your workload deployment manifests:
- Enable etcd KMS Encryption: Configure Kubernetes API servers with
EncryptionConfigurationusing AWS KMS, Google Cloud KMS, or Vault. - Mount Secrets as Volumes: Deliver credentials via
volumeMountsrather thanenvFromto prevent process environment leakage. - Never Commit Raw Secret Manifests: Forbid plain Kubernetes Secret YAMLs in Git repositories; use External Secrets or SOPS.
- Scope Vault Policies per Service: Give every workload a dedicated Vault policy restricting read access exclusively to its own path.
- Adopt Kubernetes ServiceAccount Auth: Authenticate workloads to Vault using ephemeral projected ServiceAccount tokens.
- Review Secret Audit Logs: Monitor Vault access logs for anomalous credential access patterns or privilege escalation attempts.
06. Review prompt
Contrast the security properties of standard Kubernetes Secrets with dedicated enterprise secret managers like HashiCorp Vault. Explain why delivering credentials via in-memory tmpfs file volume mounts is superior to container environment variables, and describe how Kubernetes ServiceAccount authentication solves the "Secret Zero" dilemma through workload identity federation.
References
Your progress
Reading state
Sign in to save that you finished reading this lesson.
Prove this skill
6 questions · about 5 minutes · scored automatically. Marking a lesson as read never demonstrates a skill.