Secrets, and what they do not protect
What a Kubernetes Secret really is: base64 not encryption, plaintext in etcd by default, encryption at rest and KMS, and the RBAC paths that leak it.
Secrets, and what they do not protect
The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.
Not started
What you'll learn
- A Secret is a ConfigMap-shaped object with a type and base64-encoded values. Base64 is an encoding for bytes, not encryption, and anyone who can read the object can read the value.
- By default the API server writes Secrets to etcd unencrypted. An EncryptionConfiguration with aesgcm, secretbox or a KMS v2 plugin encrypts them at rest, but only objects written after it is enabled.
- Reading Secrets is a permission, and list or watch give the values just as get does. Anyone who can create Pods in a namespace can mount any Secret in it.
- Secret volumes live in tmpfs on the node, and they update in place like ConfigMap volumes. Environment variables are easier to leak, through child processes, crash dumps and debug endpoints.
- What Secrets do give you is separation: a distinct resource that RBAC, audit policy and encryption at rest can treat differently from ordinary config.
A separate drawer, not a safe
Your app needs a database password, an API token and a TLS key. You could put them in a ConfigMap. Everything would work. The problem is everything else that can read ConfigMaps: every developer with read access to the namespace, every dashboard, every backup.
Kubernetes gives sensitive values their own resource, the Secret, so they can be treated differently. The name promises more than the object delivers, though. A Secret is a separate drawer in the same filing cabinet. It can have its own lock, but out of the box the lock is the same as the other drawers, and the papers inside aren’t sealed. This lesson is about what the drawer gives you and what you have to add.
What a Secret is
apiVersion: v1
kind: Secret
metadata:
name: db-creds
type: Opaque
stringData:
username: app
password: s3cr3t-Pa55
It is shaped like a ConfigMap, with a type and with data holding base64. You can write plain text in stringData and the API server encodes it into data for you. The same 1 MiB limit applies. The type tells tools what keys to expect: Opaque for anything, kubernetes.io/tls for a tls.crt and tls.key pair, kubernetes.io/dockerconfigjson for registry credentials that a Pod’s imagePullSecrets uses.
There’s one type you should stop seeing. Long-lived kubernetes.io/service-account-token Secrets used to be created for every ServiceAccount. Since 1.24 they aren’t, and Pods get short-lived projected tokens instead (the next lesson shows how). Since 1.30 the control plane cleans up legacy token Secrets that have gone unused.
Base64 is not encryption
Here is the whole attack:
$ kubectl get secret db-creds -o jsonpath='{.data.password}' | base64 -d
s3cr3t-Pa55
Base64 exists so arbitrary bytes, like a binary keystore, can travel inside JSON. It has no key. Treat a base64 value in a manifest as plaintext, because it is. A Secret YAML committed to Git is a leaked password.
Plaintext in etcd
The second surprise is where the API server stores Secrets. By default, it stores them as they are. We created db-creds on a local v1.37.3 cluster and read the key /registry/secrets/default/db-creds straight from etcd. The stored value begins with k8s\0, the protobuf envelope, and the bytes s3cr3t-Pa55 sit in it unencoded, not even base64. Anyone with an etcd backup or read access to etcd’s disk has every Secret in the cluster.
Encryption at rest fixes that layer. You pass the API server an EncryptionConfiguration:
apiVersion: apiserver.config.k8s.io/v1
kind: EncryptionConfiguration
resources:
- resources: [secrets]
providers:
- aesgcm:
keys:
- name: key1
secret: <32 random bytes, base64>
- identity: {}
The first provider encrypts new writes. Every listed provider is tried on reads, which is how identity (no encryption) keeps old plaintext objects readable during the switch. We started a second API server with this file against the same etcd. A Secret written through it was stored as k8s:enc:aesgcm:v1:key1: followed by ciphertext, and the password bytes were gone. The old db-creds was still plaintext until we read and replaced it through the new server. Enabling encryption doesn’t rewrite existing data. And the original API server, without the key, now failed to read it: identity transformer tried to read encrypted data. Lose the key and you lose the Secrets.
A static key in a file on the control-plane node only moves the problem: whoever reads the node’s disk gets the key next to the data. In production use the kms provider, version 2 (GA since 1.29). The API server encrypts each object with a data key, and only that data key is wrapped by an external KMS such as AWS KMS, Cloud KMS, Azure Key Vault or Vault. That’s envelope encryption, and key rotation and access logging move to the KMS. KMS v1 has been deprecated and off by default since 1.29. Managed clusters often offer this as a checkbox. Some encrypt etcd’s disk anyway, which isn’t the same thing.
Who can read it
Encryption at rest protects backups and disks. It does nothing against the API, which decrypts for anyone allowed to ask. So RBAC is the main control, and it has two traps we checked as a user called dev.
list is as good as get. A user with only list on secrets was refused kubectl get secret db-creds, but kubectl get secrets -o jsonpath='{.items[0].data.password}' printed the password. A list response carries whole objects. The same is true of watch.
Creating Pods implies reading Secrets. A user with create on pods and nothing on secrets (kubectl auth can-i get secrets said no) applied a Pod that mounts db-creds and prints it, and the API server accepted it. Admission checks that you may create the Pod, not what it mounts. That’s why the namespace, not the Secret, is the real security boundary. Put workloads that need different secrets in different namespaces.
Then there’s the node. Secret volumes are backed by tmpfs, so they never hit the node’s disk, and the Node authorizer only lets a kubelet read Secrets for Pods bound to it. Inside the container, prefer files to environment variables. Env vars are inherited by every child process, readable at /proc/<pid>/environ, and commonly dumped by crash reporters and debug pages. They also never update, while a Secret volume updates in place like a ConfigMap volume.
About the video
The embed is Mischa van den Burg’s “Kubernetes Secrets Explained With Simple Examples!”, June 2025, 18 minutes. Its chapters move from how Secrets work and “base64 is not encryption” through creating Secrets from the CLI and YAML, consuming them as env vars, envFrom and volumes, a chapter on RBAC and etcd encryption, and a brief look at SOPS with Flux and the External Secrets Operator. That’s this lesson’s spine, though at about a minute the RBAC and etcd chapter is lighter than the section above. It doesn’t mention the list and Pod-creation paths. Judged from chapters and description, since transcripts can’t be fetched here, and from its “English (US) original” audio track. Is it Observable’s video in deeper spends longer on the fixes: SOPS, ESO with Vault, the Vault injector and encryption at rest.
What was run: against a local v1.37.3 API server whose nodes run no containers, we created the Secret, decoded it, and read the raw value from etcd’s key-value API to confirm the plaintext. We started a second API server with the aesgcm configuration above, saw new writes stored encrypted, rewrote the old Secret, and saw the unencrypted server fail to read it. As users with only list, and only Pod create, we reproduced both RBAC paths, short of the Pod actually running. KMS v2, tmpfs volumes and the token changes are from the docs and v1.37.3 source, checked 2026-11-28.
Where this fits
Secrets and ConfigMaps aren’t the only things a Pod can see as files. Next: the downward API and projected volumes.
Check yourself
A teammate says the Secrets in your Git repo are safe because the values are base64-encoded. What do you tell them?
Base64 is reversible by anyone with echo and base64 -d. Those values are effectively plaintext in Git. They need encrypting before they are committed, with Sealed Secrets or SOPS, or keeping out of Git entirely with an external store.
You enable encryption at rest with aesgcm and restart the API servers. Are your existing Secrets encrypted now?
No. Only writes after the change are encrypted. Rewrite every Secret, for example kubectl get secrets -A -o json | kubectl replace -f -, so each one is stored again through the new provider.
A developer can create Pods in the payments namespace but has no permission on Secrets. Can they read the database password Secret there?
Yes, indirectly. They can create a Pod that mounts the Secret or loads it into env and prints it. The API server only checks that they may create Pods. Pod creation in a namespace implies access to its Secrets, which is why namespaces are the real boundary.
Why is a role that grants list on secrets but not get still dangerous?
A list response contains the full objects, data included. kubectl get secrets -o yaml with only list permission prints every value in the namespace.
Go deeper
Notes
Notes are saved to your account.
Everything else on this page works without one — progress and bookmarks keep themselves in this browser and come with you when you sign in. Notes are the one thing worth not trusting to a browser you might clear.
Your notes could not be loaded.