Kubernetes Secrets Management — You deploy secrets unencrypted in etcd. Anyone with etcd access reads everything in plaintext. Data leak, your CEO fired the CISO.
You deploy secrets unencrypted in etcd. Anyone with etcd access reads everything in plaintext. Data leak, your CEO fired the CISO. Here's how to prevent it.
What is K8s Secrets Management? Simply explained.
Kubernetes secrets management means: store, rotate, and scope secrets securely. By default, secrets are only base64-encoded — no real protection. Good secrets management: etcd encryption, strict RBAC, External Secrets Operator (Vault, AWS SM), secret leak detection with OpenClaw.
↓ Jump to technical depth4 Security Layers for K8s Secrets
By default, Kubernetes Secrets are stored as base64 in etcd — not encrypted. Anyone with etcd access reads all secrets in plaintext.
# Enable encryption at rest for Secrets in etcd
# /etc/kubernetes/encryption-config.yaml
apiVersion: apiserver.config.k8s.io/v1
kind: EncryptionConfiguration
resources:
- resources:
- secrets
providers:
- aescbc:
keys:
- name: key1
# Generate: head -c 32 /dev/urandom | base64
secret: <base64-encoded-32-byte-key>
- identity: {} # Fallback for unencrypted (remove after migration)
# Apply to kube-apiserver:
# --encryption-provider-config=/etc/kubernetes/encryption-config.yaml
# Verify encryption (check etcd value is not plaintext):
ETCDCTL_API=3 etcdctl get /registry/secrets/default/my-secret \
--endpoints=https://127.0.0.1:2379 \
--cacert=/etc/kubernetes/pki/etcd/ca.crt \
--cert=/etc/kubernetes/pki/etcd/server.crt \
--key=/etc/kubernetes/pki/etcd/server.key
# Should start with /k8s/aescbc/ prefix — NOT readable plaintextKubernetes RBAC for Secrets is dangerously broad by default. ServiceAccounts with cluster-wide get/list/watch on Secrets can read all secrets in the cluster.
# WRONG — common misconfiguration: # ClusterRole with wildcard resource access includes secrets kind: ClusterRole rules: - apiGroups: ["*"] resources: ["*"] # Includes secrets! verbs: ["*"] # CORRECT — minimal secret access kind: Role metadata: namespace: my-app # Namespace-scoped, not cluster-wide rules: - apiGroups: [""] resources: ["secrets"] resourceNames: ["my-app-db-credentials"] # Only specific secret(s) verbs: ["get"] # Read-only, not list/watch # Check who can read secrets across cluster: kubectl auth can-i list secrets --all-namespaces --as=system:serviceaccount:default:my-sa # Audit: find ServiceAccounts with broad secret access kubectl get clusterrolebindings -o json | \ jq '.items[] | select(.roleRef.name=="cluster-admin") | .subjects'
Store secrets in HashiCorp Vault, AWS Secrets Manager, or Azure Key Vault — not in Kubernetes etcd. ESO syncs them as K8s Secrets at runtime.
# External Secrets Operator setup
# 1. Install ESO:
helm repo add external-secrets https://charts.external-secrets.io
helm install external-secrets external-secrets/external-secrets -n external-secrets --create-namespace
# 2. SecretStore pointing to Vault:
apiVersion: external-secrets.io/v1beta1
kind: SecretStore
metadata:
name: vault-backend
namespace: my-app
spec:
provider:
vault:
server: "https://vault.internal:8200"
path: "secret"
version: "v2"
auth:
kubernetes:
mountPath: "kubernetes"
role: "my-app-role"
serviceAccountRef:
name: my-app-sa
# 3. ExternalSecret (creates K8s Secret from Vault):
apiVersion: external-secrets.io/v1beta1
kind: ExternalSecret
metadata:
name: my-app-db-secret
spec:
refreshInterval: 1h
secretStoreRef:
name: vault-backend
target:
name: my-app-db-credentials # Created K8s Secret name
data:
- secretKey: password
remoteRef:
key: my-app/db
property: passwordDetect when secrets are exposed: logged to stdout, written to files, passed as env vars in pod specs (visible in kubectl describe), or present in container images.
# OpenClaw: scan for common secret patterns in cluster
openclaw secrets-scan --namespace production
# Falco rule: alert when a process reads a mounted secret file
- rule: Secret File Read by Unexpected Process
desc: A process other than the app read a secret volume mount
condition: >
open_read and
fd.name startswith /var/run/secrets and
not proc.name in (allowed_secret_readers)
output: >
Secret file accessed (proc=%proc.name file=%fd.name
container=%container.name pod=%k8s.pod.name)
priority: WARNING
# Detect secrets in environment variables (bad pattern):
kubectl get pods --all-namespaces -o json | \
jq '.items[].spec.containers[].env[]? |
select(.value? | test("(?i)(password|secret|token|key|api_key)"))' | head -20
# Any results: secrets in env vars (visible to anyone with pod describe access)Real-World Scars: Production Incidents
No etcd encryption, secrets base64 in etcd. etcd backup exposed, all secrets in plaintext. Fix: Enable etcd encryption with KMS provider.
Secrets in environment variables, visible in kubectl describe pod. Crash dump exposes secrets. Fix: Use volume mounts instead of env vars.
Immediate Actions: What to do today?
Enable etcd encryption
Configure KMS provider, apply EncryptionConfig.
RBAC scoping
Limit secret access to specific namespaces and secret names.
External Secrets Operator
Install ESO, use Vault as backend.
Secret leak detection
Run OpenClaw secrets-scan regularly.
Interactive K8s Secrets Security Checklist
K8s Secrets Security Score Calculator
Industry Average: 25/100
Frequently Asked Questions
Are Kubernetes Secrets actually secret?
By default, no — only base64-encoded, not encrypted. Anyone with etcd access sees all secrets in plaintext. Three real mitigations: 1) etcd encryption at rest (AES-CBC/GCM with KMS). 2) Strict RBAC limiting to specific secrets. 3) External secret management (Vault, AWS Secrets Manager) — never store secrets in etcd.
Vault vs External Secrets Operator — which to use?
Both are complementary: Vault as secret backend (stores, rotates, audits secrets). ESO as Kubernetes integration layer (syncs secrets from Vault to K8s). Typical setup: Vault + ESO. Alternative: Vault Agent Injector (sidecar) or Vault CSI Provider (mount as files). ESO is simpler; Vault Agent gives slightly better isolation.
Environment variables or volume mounts for secrets?
Volume mounts are significantly more secure: Env vars visible in 'kubectl describe pod', accessible to any process, captured in crash dumps/logs, not rotatable without restart. Volume mounts: not visible in pod describe, accessible only via file open, updatable by ESO without restart, can use tmpfs (in-memory, not on disk).
How do I rotate secrets without downtime?
Secret rotation without downtime: 1) Dynamic Secrets (best): Vault generates short-lived credentials on-demand. 2) ESO with refreshInterval: ESO polls Vault/AWS SM, updates K8s Secret. App detects change via inotify, reloads without restart. 3) Rolling restart: trigger after ESO update. 4) Dual-active secrets: old and new both valid during transition.