Kubernetes Secrets in plain sight: red vs blue
Vinnie, on the red team, sniffs out where Kubernetes Secrets really leak: base64 in git, env vars and ConfigMaps, images, broad RBAC and an unencrypted etcd; Space Llama, on the blue team, mounts them as files, tightens who can read them, and moves the real values to an external store.
Diagrams in this video · 1Free in archhy
Now try it on a real cluster
The videos are free. Gazeek's hands-on labs give you a real Kubernetes cluster in your browser for every lab, with checks that tell you when you've got it right: the practice the CKA and CKAD exams need.
The diagrams, full size
Copy any of them into archhy, free, and change it for your own system.
After this lesson you can
- Explain why base64 is not protection, and where Secrets leak
- Mount a Secret as read-only files, only where it's needed
- Check who can read Secrets in a namespace with kubectl auth can-i
Transcript
Kubernetes Secrets in plain sight: red vs blue
Space Llama. Blue team. Today, Kubernetes Secrets. Vinnie. Red team. And they're rarely as secret as you think. They're called Secrets. And I'm called Vinnie. A name isn't a promise.
Where Kubernetes Secrets leak
Here's where my nose finds them. One. A Secret's values are base64. That's an encoding, not encryption. Commit the manifest to git, and anyone who can read the repo can read the password. Two. Environment variables. They're more likely to leak, in crash dumps and logs. And a password in a ConfigMap isn't a secret at all. Three. Baked into an image. Everyone who can pull that image has the key. Four. Who can read them. Role-based access control, RBAC. List or watch on Secrets returns every value in the namespace. And anyone who can create a Pod there can read any Secret in it. Five. At rest. By default, the API server stores Secrets in etcd unencrypted. Five ways in. And none of them break anything. Why pick a lock when there's a sticky note on the door?
Blue closes it: files, not env vars
Blue's turn. Mount the Secret as files, where you can. Read-only, and only in the container that needs it. The kubelet keeps mounted Secret data in memory, on a tmpfs, not on the node's disk. And a Secret only goes to a node that runs a Pod needing it. Environment variables can be more prone to leaking, in crash dumps and logs, than files. The Kubernetes security checklist says so too.
Blue closes it: who can read them
Next, access. Ask who can list Secrets. Kubectl auth can-i, list secrets, as the app's service account. And who can create Pods there, or Deployments, because a Pod they create can mount any Secret in the namespace. For almost every app, the answers should be no.
Keep the real values outside
Bigger setups keep the real values outside the cluster. In HashiCorp Vault, or your cloud's secret manager. The External Secrets Operator syncs them into Kubernetes Secrets. The Secrets Store CSI Driver, that's Container Storage Interface, mounts them straight into the Pod as a volume. And turn on encryption at rest, so etcd doesn't hold them in the clear. That's episode eight.
Red asks, blue answers
Question for blue. Env vars are so easy. Why not just use them? Sometimes you must. Some apps only read env vars. Then keep access to the Secret tight, and never log it. Question for red. What do you sniff out first? Git history. People delete the file, but the old commit still has it. Then that secret's spent. Rotate it. Deleting the file doesn't take it back.
Check your own cluster
Now check your own cluster. For each app's service account: can it get or list Secrets? Can it create Pods, or Deployments? Look for passwords in ConfigMaps, in images and in git. Image scanners such as Trivy look for secrets too. And find out whether etcd encrypts them. Upstream Kubernetes doesn't, out of the box; some managed services do. Assume no until you've checked.
Who won?
Round three. I'm calling it a draw. A draw? Your YAML's lovely. But I only need one password, in one repo. And I only need one rotation.
The full article, and what's next
Next time, network policies. What a Pod can reach, once red is inside. Everything, usually. See you there.
Hands-on labs
Now try it on a real cluster
A real Kubernetes cluster in your browser for every lab, checked as you go.
See the labs









