Skip to content

Lesson 5 of 12 · 17m

Kubernetes Secrets and Sealed Secrets

A Secret is base64 in etcd, readable by anyone with get rights in the namespace — encrypt at rest and deliver via sealed-secrets or an external store.

kubectl create secret generic db --from-literal=password=hunter2 writes an object to etcd with password: aHVudGVyMg==. That is base64. kubectl get secret db -o jsonpath='{.data.password}' | base64 -d undoes it. Nothing about the type Secret implies encryption: by default it sits in etcd exactly as submitted, and any principal — user, controller, service account — with get on secrets in that namespace can read it back. RBAC is the access control; etcd encryption at rest is a separate switch that many clusters never flip.

The blast radius is wider than RBAC alone suggests. list on secrets returns every secret in the namespace in one call — a compromised namespace-scoped SA token is a bulk exfiltration, not a targeted read. Every node running a pod that mounts the secret holds a copy in the kubelet's tmpfs. And etcd snapshots — the ones your backup cron writes nightly — contain the plaintext of every secret in the cluster unless at-rest encryption is on, which makes the backup bucket part of your secrets perimeter whether you meant it or not.

Encrypting etcd

EncryptionConfiguration on the API server declares providers in preference order:

providers:
  - kms:
      name: kmsv2
      endpoint: unix:///opt/kms/kms.sock
      timeout: 3s
  - secretbox: {}
  - identity: {}

kms v2 delegates to an external KMS plugin over a unix socket — strongest, key never lives on the node. secretbox uses XSalsa20-Poly1305 with a local key — fast and safe, but the key file must be protected. aescbc works but CBC without integrity is the weakest real option. identity is plaintext — it's there for migration order, not as a choice. Write the config, restart the kube-apiserver, then rewrite existing secrets (kubectl get secrets --all-namespaces -o json | kubectl replace -f -) — encryption applies to new writes only.

Sealed Secrets vs External Secrets

Bitnami's sealed-secrets flips the delivery problem. kubeseal fetches the controller's public key and encrypts your Secret client-side into a SealedSecret CRD — ciphertext you can safely commit. The controller holds the private key and materializes a real Secret in-cluster. Scope matters: strict binds the sealed value to name+namespace (default), namespace-wide relaxes name, cluster-wide relaxes both. The wrong model here is "the YAML in git is the secret" — with sealing, git holds ciphertext and only the cluster can open it. The tradeoff: anyone who can kubeseal can mint new secrets for the namespace, and rotating the controller's private key means resealing everything.

External Secrets Operator goes the other direction: an ExternalSecret CRD declares which keys to pull from AWS Secrets Manager, Vault, or GCP SM, and the controller syncs them into a Secret on an interval. Git holds only references. This is the better answer when a central store already exists — rotation happens upstream and propagates — at the cost of a sync delay and a running controller with real cloud permissions.

The delivery trap: env vs volume

env: { valueFrom: { secretKeyRef: … } } injects the value at container start and it never changes for the life of the process — rotation requires a restart. A secret volume mounts to tmpfs and kubelet refreshes it (within roughly a minute; pods using the mount see the update, apps still must re-read the file). If you rotate secrets on any schedule shorter than "deploy," env injection fights you.

Concrete practice

  • EncryptionConfiguration with kms on every cluster; rewrite existing secrets after enabling.
  • RBAC audit: kubectl auth can-i get secrets --as=system:serviceaccount:prod:app -n prod for every SA that shouldn't read them.
  • Pick one GitOps delivery path: sealed-secrets for self-contained clusters, ESO when Vault/cloud SM is the source of truth.
  • Secrets that rotate go on volumes or through a sidecar, never env: literals.

Base64 is a delivery format, not a defense. Encrypt etcd, then decide who may hand a pod its creds.

Was this lesson helpful?

Sign in to rate

Keep reading

Related articles from the SudoSecurity blog.