Difficulty: Advanced
Are Kubernetes Secrets secure by default? What would you do to properly protect them?
Not fully. A Secret's values are only base64 encoded, which is an encoding and not encryption, and on a self-managed cluster they are stored in etcd in plain form unless you turn on encryption at rest. Anyone who can read Secrets through RBAC, read etcd or its backups, or create Pods in the namespace can get the values. Securing them takes encryption at rest (ideally with a KMS provider), tight RBAC, and often an external secret manager.
What you get by default:
tmpfs on the node, not on disk.What you do not get by default on a self-managed cluster:
get or list on secrets, which returns full values.Many managed services now encrypt etcd storage and some enable envelope encryption by default, so check your provider's documentation rather than assuming either way.
EncryptionConfiguration (--encryption-provider-config). The kms v2 provider (stable since 1.29) uses envelope encryption with a key held in AWS KMS, Google Cloud KMS, Azure Key Vault or Vault. aescbc, aesgcm and secretbox work but keep the key on the control plane. identity means no encryption. After enabling it, rewrite existing Secrets so they get encrypted.get on specific named Secrets rather than list on all. Watch out for list, which returns values too, and for wildcard roles.immutable: true, rotate credentials, audit Secret reads via API audit logs, and prefer volume mounts over env vars, since env vars are inherited by child processes and more often end up in logs and crash dumps.| Approach | Where the secret lives | Main benefit | Trade-off |
|---|---|---|---|
| Plain Secret | etcd | Simple | Readable by anyone with etcd or broad RBAC access |
| Secret + KMS encryption | etcd, encrypted with KMS key | Protects etcd and backups | Still exposed via API to RBAC-allowed users |
| External Secrets Operator | Vault / cloud manager, synced to Secret | Central rotation and audit | Extra component to run |
| Secrets Store CSI Driver | Vault / cloud manager, mounted as files | Can avoid creating a Secret object | Pod startup depends on external service |
echo <value> | base64 -d is all it takes to read a Secret you can get.For a fintech handling UPI or card credentials, the usual baseline is KMS encryption at rest, Secrets synced from a central manager, and RBAC that lets only the specific service account read its own Secret.
# /etc/kubernetes/enc/encryption-config.yaml
# Passed to kube-apiserver with --encryption-provider-config
apiVersion: apiserver.config.k8s.io/v1
kind: EncryptionConfiguration
resources:
- resources:
- secrets
providers:
- kms:
apiVersion: v2
name: cloud-kms
endpoint: unix:///var/run/kmsplugin/socket.sock
timeout: 3s
- identity: {} # lets the API server still read old, unencrypted data
The first provider is used to encrypt new writes; the rest are tried for reads. Keeping `identity` last lets the server read existing plaintext Secrets until you rewrite them.
# Anyone with get access can read the value
kubectl get secret payments-db -o jsonpath='{.data.password}' | base64 -d
# After enabling encryption, rewrite all Secrets so they are stored encrypted
kubectl get secrets -A -o json | kubectl replace -f -
# Check who can read secrets in a namespace
kubectl auth can-i get secrets -n payments --as=system:serviceaccount:payments:api
Encryption config only applies to new writes, so the replace step is needed to encrypt Secrets that already existed.
Secrets, Encryption at Rest, KMS Provider, RBAC, External Secrets