Kubernetes gives you a lot of power out of the box, but very little of it is locked down by default. A fresh cluster will happily run a container as root, let any pod talk to any other pod, and mount a service account token into every workload. None of that is a bug. It is a flexible starting point, and it is your job to tighten it.
This guide turns the official Kubernetes Security Checklist into a practical, area by area list you can work through with your team. Each section explains why the items matter in plain language, and the hands-on section shows commands taken straight from the Kubernetes documentation. Treat it as a baseline, not a finish line: the Kubernetes docs themselves say a checklist is only the first step, and that some items may be too strict or too loose for your situation.
1. Authentication and authorization
Most serious cluster incidents start with someone, or something, holding more access than it needs. Role Based Access Control (RBAC) is the main tool for fixing that, and the Kubernetes RBAC Good Practices page is worth reading in full.
- Do not use the
system:mastersgroup for users or components after the cluster is bootstrapped. Members of this group skip every RBAC check, and removing bindings cannot take that access away. Keep it for break glass use only. - Run kube-controller-manager with
--use-service-account-credentialsenabled, so each controller uses its own identity. - Prefer namespaced Roles and RoleBindings over ClusterRoleBindings, and avoid wildcard permissions. A wildcard also covers resource types that are added to the cluster later.
- Treat some verbs and resources as high risk:
listandwatchon Secrets reveal their contents, theescalate,bindandimpersonateverbs can lead to privilege escalation, andgetonnodes/proxygives access to the kubelet API. - Remember that permission to create Pods in a namespace effectively grants access to the Secrets, ConfigMaps and service accounts in that namespace.
- Protect the root certificate authority, keep intermediate and leaf certificate lifetimes to three years or less, and review access at least every 24 months.
If you are new to RBAC, our earlier guide on Kubernetes RBAC security best practices walks through Roles and bindings step by step.
2. Network security
By default, every pod in a cluster can reach every other pod. That is convenient for getting started and risky in production, because a single compromised workload can then probe everything else.
- Make sure your CNI plugin actually enforces NetworkPolicy. If it does not, NetworkPolicy objects are accepted by the API but have no effect.
- Add a default deny policy in each namespace that selects all pods, then allow only the traffic each workload needs. Cover both ingress and egress.
- Encrypt traffic inside the cluster where it matters. Not every CNI plugin offers encryption in transit, so a service mesh is one way to fill the gap.
- Never expose the Kubernetes API server, the kubelet API or etcd directly to the internet. Many managed offerings expose the API server publicly by default, so check yours. etcd should use mutual TLS with its own certificate authority.
- On cloud providers, filter or block pod access to the metadata API at
169.254.169.254unless a workload truly needs it. - Restrict use of LoadBalancer Services and
externalIPs. TheDenyServiceExternalIPsadmission controller exists to mitigate CVE-2020-8554.
3. Pod and workload security
The Pod Security Standards define three policy levels: privileged (no restrictions), baseline (blocks known privilege escalations such as host namespaces, privileged containers and hostPath volumes) and restricted (adds controls such as running as non-root, disallowing privilege escalation, limiting volume types, dropping capabilities and requiring a seccomp profile). The built in Pod Security Admission controller enforces these levels per namespace, using three modes: enforce, audit and warn.
- Apply a Pod Security Standards level to every namespace, and aim for restricted wherever your workloads allow it.
- Only grant create, update, patch and delete rights on workloads when they are needed.
- Set a memory limit on workloads that is equal to or lower than the request. A memory limit higher than the request can expose the whole node to out of memory problems.
- Consider CPU limits for sensitive workloads, keeping in mind that CPU limits throttle usage and can affect autoscaling.
- Enable seccomp with a suitable profile. Since Kubernetes 1.27 you can make
RuntimeDefaultthe default seccomp profile for all workloads. - Where your nodes support it, use AppArmor or SELinux profiles for extra mandatory access control.
For a deeper look at the three levels, see our full guide to Pod Security Standards.
4. Secrets, service accounts and images
Secrets and tokens
- Do not keep confidential data in ConfigMaps. Use Secrets.
- Configure encryption at rest for the Secret API so data stored in etcd is not readable in plain form.
- Prefer mounting Secrets as files over environment variables. Environment variables are more likely to leak through logs and crash dumps.
- If you keep secrets in an external store, a tool such as the Secrets Store CSI Driver can mount them as volumes.
- Set
automountServiceAccountToken: falsefor pods that do not call the Kubernetes API, and use bound, time limited service account tokens instead of long lived ones.
Container images
- Keep images minimal. Production images should not ship shells or debugging tools; use an ephemeral debug container when you need to troubleshoot.
- Build images that run as an unprivileged user, using the
USERinstruction in the Dockerfile. - Reference images by sha256 digest rather than by tag, especially
latest, or verify image signatures at deploy time with an admission controller. - Scan images during the build and in deployment, and patch known vulnerable software.
5. Admission control, placement and auditing
Admission controllers are the gatekeepers that check or modify every object before it is stored. They make strong guardrails, but they extend the API server, so they must be configured carefully themselves.
- Keep the default security related admission plugins enabled, including
PodSecurity,LimitRanger,ResourceQuotaand the certificate related plugins. - Consider enabling
NodeRestriction, which limits what each kubelet can modify, andDenyServiceExternalIPs. - Enforce pod security with Pod Security Admission, a webhook based policy engine, or both, and secure any webhooks you add.
- Place workloads by sensitivity. Keep sensitive applications on separate nodes or use a sandboxed runtime through RuntimeClass. Node selectors, the PodNodeSelector admission controller and PodTolerationRestriction can help enforce this.
- If you enable audit logging, protect the audit logs from general access.
Hands-on: three quick wins
Prerequisites: a test cluster you control, kubectl configured against it, and permission to manage namespaces and NetworkPolicies. For the network step, your CNI plugin must support NetworkPolicy. Try these in a non-production cluster first.
Step 1: check what an identity can do. These examples come from the kubectl auth can-i reference. The --as flag requires impersonation rights.
# List all allowed actions in namespace "foo"
kubectl auth can-i --list --namespace=foo
# Check to see if service account "foo" of namespace "dev" can list pods in the namespace "prod"
kubectl auth can-i list pods --as=system:serviceaccount:dev:foo -n prod
Step 2: roll out Pod Security Standards safely. The official task page suggests a server side dry run first, so you can see which existing pods would fail a level before you enforce it.
kubectl label --dry-run=server --overwrite ns --all \
pod-security.kubernetes.io/enforce=baseline
Then switch on warnings and audit annotations across namespaces, and find namespaces that have no enforce label yet:
kubectl label --overwrite ns --all \
pod-security.kubernetes.io/audit=baseline \
pod-security.kubernetes.io/warn=baseline
kubectl get namespaces --selector='!pod-security.kubernetes.io/enforce'
Step 3: add a default deny policy. This manifest from the Network Policies documentation selects every pod in the namespace and blocks all ingress and egress until you add allow rules. Apply it with kubectl apply -n <namespace> -f default-deny-all.yaml, and remember that blocking egress also blocks DNS until you allow it.
---
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: default-deny-all
spec:
podSelector: {}
policyTypes:
- Ingress
- Egress
For more kubectl based practice with RBAC, NetworkPolicies and Secrets, see Kubernetes Security 101.
Key takeaways
- Kubernetes defaults favor flexibility, so security is something you configure on purpose.
- Least privilege RBAC, with no routine use of
system:mastersor wildcards, is the foundation. - Default deny NetworkPolicies only work if your CNI plugin enforces them.
- Pod Security Admission with the restricted level, rolled out through warn and audit first, closes many common escape paths.
- Encrypt Secrets at rest, disable unneeded service account tokens, and pin images by digest.
- Revisit this checklist regularly. Security posture needs ongoing attention, not a one time setup.
Sources
Kubernetes Security Checklist, RBAC Good Practices, Pod Security Standards, Pod Security Admission, Enforce Pod Security Standards with Namespace Labels, Network Policies, Good practices for Kubernetes Secrets, Encrypting Confidential Data at Rest, Auditing and the kubectl auth can-i reference, all on kubernetes.io.
