Secret Security

Difficulty: Advanced

Question

Are Kubernetes Secrets secure by default? What would you do to properly protect them?

Answer

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 Kubernetes does and does not give you

What you get by default:

  • Secrets are a separate resource type, so RBAC can restrict them separately from ConfigMaps.
  • When mounted as volumes, they live on tmpfs on the node, not on disk.
  • The kubelet only fetches Secrets for Pods scheduled on its node.
  • API traffic is over TLS.

What you do not get by default on a self-managed cluster:

  • Encryption of Secret data in etcd and in etcd snapshots.
  • Protection from anyone with get or list on secrets, which returns full values.
  • Protection from users who can create Pods: a Pod can mount any Secret in its namespace, so "create pods" effectively means "read secrets".

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.

Layers of protection

  1. Encryption at rest: configure the API server with an 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.
  2. RBAC: grant get on specific named Secrets rather than list on all. Watch out for list, which returns values too, and for wildcard roles.
  3. Namespace isolation: put sensitive workloads in their own namespaces, since Secret access is namespaced.
  4. External secret managers: keep the source of truth in Vault, AWS Secrets Manager or GCP Secret Manager, and sync with External Secrets Operator or mount via the Secrets Store CSI Driver.
  5. GitOps safety: never commit raw Secret YAML. Use Sealed Secrets or SOPS-encrypted files.
  6. Hygiene: mark static Secrets 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.

Comparing approaches

ApproachWhere the secret livesMain benefitTrade-off
Plain SecretetcdSimpleReadable by anyone with etcd or broad RBAC access
Secret + KMS encryptionetcd, encrypted with KMS keyProtects etcd and backupsStill exposed via API to RBAC-allowed users
External Secrets OperatorVault / cloud manager, synced to SecretCentral rotation and auditExtra component to run
Secrets Store CSI DriverVault / cloud manager, mounted as filesCan avoid creating a Secret objectPod startup depends on external service

Gotchas worth mentioning

  • echo <value> | base64 -d is all it takes to read a Secret you can get.
  • Encrypting etcd does nothing for someone with RBAC access through the API.
  • Secrets in Helm values files often end up in Git and in Helm release records.

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.

Code examples

Enable KMS v2 encryption at rest for Secrets

# /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.

Prove base64 is not encryption, then re-encrypt existing Secrets

# 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.

Key points

  • base64 is encoding, not encryption.
  • Without encryption config, Secrets sit unencrypted in etcd and its backups on self-managed clusters.
  • KMS v2 envelope encryption is stable since 1.29 and is the recommended provider.
  • Anyone who can create Pods in a namespace can effectively read its Secrets.
  • External Secrets Operator, Secrets Store CSI Driver, Sealed Secrets and SOPS cover external storage and GitOps.

Common follow-up questions

  • How does envelope encryption with KMS work?
  • How would you store Secrets safely in a GitOps repository?
  • Why are Secrets in environment variables considered riskier than mounted files?
  • How do you rotate a database password used by running Pods?

Interview tips

  • Start by correcting the myth: base64 is not encryption. Interviewers expect it.
  • Cover more than one layer: encryption at rest, RBAC and external managers.
  • Mentioning the "create pods means read secrets" RBAC issue shows real security awareness.

Concepts covered

Secrets, Encryption at Rest, KMS Provider, RBAC, External Secrets

More Kubernetes & Orchestration questions