Cloud Native Security 04: Check Before It Runs¶
Kubernetes will run a container as root, with full access to the machine under it, if you ask it to. Nothing in a new cluster says no. It also writes no audit log until you configure one.
This post covers the rules that stand between a deployment file and a running container, and the cluster settings worth changing on day one.
Prefer to watch? This 5-minute video covers the whole post. It's in Thai, and the voice and presenter are AI versions of me.
The Cloud Native Security series
Four gates before anything runs¶
Each gate answers one question. The first two usually work out of the box. The third lets almost everything through until you add rules.
Gate 3: refuse dangerous containers¶
Pod Security Admission is built into Kubernetes and needs no extra software. You label a namespace with a level, and Kubernetes rejects pods that break it.
| Level | What it blocks |
|---|---|
| privileged | Nothing |
| baseline | The known ways to take over a machine |
| restricted | That, plus running as root and unneeded privileges |
See what would break first. This changes nothing:
Then enforce baseline on one namespace, with warnings for restricted:
kubectl label --overwrite ns my-app \
pod-security.kubernetes.io/enforce=baseline \
pod-security.kubernetes.io/warn=restricted \
pod-security.kubernetes.io/audit=restricted
If you still see "PodSecurityPolicy" in a guide, the guide is out of date. Kubernetes removed it in 2022.
Add your own rules¶
You'll want rules Pod Security doesn't have, such as "images come only from our registry" or "every deployment has an owner label".
| You need | Use |
|---|---|
| A few simple rules | ValidatingAdmissionPolicy, built into Kubernetes |
| Signed images, automatic fixes, reports | Kyverno |
| You already use Open Policy Agent | Gatekeeper |
Roll out every rule in audit mode, fix what it finds, then switch it to deny.
If you run Kyverno, read the notes for 1.20 before you upgrade. It ignores the older ClusterPolicy rules, so a cluster that looked protected would stop enforcing them1.
Run only images you signed¶
Post 3 signed the images. The cluster has to check the signature, or signing did nothing. Kyverno's ImageValidatingPolicy does this, and you tell it which repository and pipeline are allowed to sign.
Test that it covers every kind of container. Pods can also have init containers, which run before the app, and temporary debug containers. Try to start an unsigned image as each of them.
Let Git deploy, and nobody else¶
With GitOps, a tool in the cluster reads the wanted state from Git and applies it. People change Git through a reviewed pull request, so they don't need write access to the cluster. Every change has an author, and the tool spots anything edited by hand.
That tool is very powerful, so tighten it:
| Argo CD | Flux |
|---|---|
| Turn off the built-in admin after company login works | Block references between namespaces |
Lock down the default project, which allows everything | Set a default service account with few rights |
| Run at least 3.6.3, 3.5.9 or 3.4.15, which fix three serious flaws2 | Don't load files from remote addresses |
Tighten the cluster itself¶
| Setting | Why | What to do |
|---|---|---|
| RBAC | Some permissions are stronger than they look | Remove wildcards. Treat "list secrets", "create pods" and nodes/proxy as admin access |
| Audit log | Without it you can't answer "who did this?" | Log everything at Metadata level and send it off the cluster |
| Secrets at rest | Stored in plain text by default | Turn on encryption with a key service (KMS v2) |
| Seccomp | Limits what a container can ask the kernel to do, and is off by default | Set seccompDefault: true on the nodes |
| Process limit | One container can start processes until the machine dies | Set podPidsLimit on the nodes |
| Service account tokens | Every pod gets one, and most never use it | Set automountServiceAccountToken: false |
| Memory and CPU | One app can starve the others | Add a LimitRange and a ResourceQuota per namespace |
Managed services such as EKS, GKE and AKS handle some of these and hide others. Check which ones are yours.
"Create pods" is in the list because whoever can create a pod can use any service account in that namespace.
Choose a node that does less¶
A general-purpose Linux server has a shell, a package manager and dozens of services. A container node needs almost none of it.
| Node system | Pick it when |
|---|---|
| Talos | You run your own clusters. It has no shell or SSH, and you manage it through an API |
| Bottlerocket | You're on AWS |
| Flatcar | You need SSH |
If your hardware supports it, turn on secure boot, so a machine with a tampered system won't start. Keep very sensitive workloads on their own nodes, because containers on one machine share its kernel.
Remove what nobody maintains¶
| Still running this? | Status | Move to |
|---|---|---|
| ingress-nginx | No security fixes since March 20263 | Gateway API, or a maintained ingress controller |
| Kubernetes Dashboard | Archived | Headlamp |
| Kubernetes 1.34 or older | Unsupported since October 2026 | 1.35 or newer |
None of the replacements for ingress-nginx is a drop-in, so plan time for the move.
Check your work¶
kube-bench compares your nodes with the CIS Benchmark, a widely used hardening checklist. Kubescape scans the whole cluster against several lists, including the NSA's:
Use the score to find work, and don't chase 100%. A benchmark doesn't know which of your systems matter. Run it monthly, since clusters drift.
Summary¶
| Question | Tool to start with | Alternative |
|---|---|---|
| Is this pod dangerous? | Pod Security Admission | Kyverno |
| Does it follow our rules? | ValidatingAdmissionPolicy | Gatekeeper |
| Did we build it? | Kyverno | Sigstore policy-controller |
| Who changed this? | Argo CD or Flux, plus audit logs | |
| Is the cluster hardened? | kube-bench | Kubescape |
- Run the dry-run label command, and read the warnings
- Turn on audit logs and secrets encryption
- Look for ingress-nginx and unsupported versions
- Review who can create pods and read secrets
Next: Protect what's running
-
Kyverno, Announcing 1.20. ↩
-
Argo CD, release notes, November 2026. ↩
-
Kubernetes, Statement on ingress-nginx. The settings in this post are documented in the Kubernetes pages on Pod Security Admission, RBAC good practices, auditing and encrypting data at rest. ↩
Discussion
Have thoughts on this post? Share them below — questions, corrections, or your own experience are all welcome.
