In brief
Container and Kubernetes security rests on four layers: a clean image, a pod with minimal privileges, accounts with narrow RBAC roles, and a network where traffic between pods is blocked by default. You build the image from a small base, scan it in CI and run it as a non-root user. Each namespace gets the “restricted” Pod Security Standards profile and each application its own NetworkPolicy. You compare the cluster configuration against the CIS Kubernetes Benchmark.
Where the risk is: image, registry, orchestrator, host
NIST SP 800-190, the application container security guide, groups risks into five areas: images, registries, the orchestrator, the containers themselves and the host operating system. The split helps organize the work because each area has a different owner:
| Layer | Typical risk | Who owns it |
|---|---|---|
| Image | vulnerable libraries, secrets baked into a layer, unnecessary tools | application team |
| Registry | an image is swapped or pulled by someone unauthorized | platform team |
| Orchestrator | overly broad roles, a dashboard or API reachable from the internet | platform team |
| Container | running as root, privileged mode, writes to the file system | application and platform teams |
| Host | an outdated kernel, extra services on the node | infrastructure team |
Whether a company needs Kubernetes at all is covered in a separate article on Kubernetes in the enterprise. Here we assume the cluster is already running.
Images: small base, scan, signature
- Small base. An image with only the application runtime (for example a distroless or minimal OS image) has fewer packages, so fewer vulnerabilities to patch. No shell, package manager or debugging tools in a production image.
- Multi-stage build. The compiler and build dependencies stay in the build stage. Only the result goes into the final image.
- Scan in CI. Every image goes through a vulnerability scan before it is pushed to the registry, and the blocking threshold is written into the pipeline. How to choose thresholds is covered in the article on SAST, DAST and SCA.
- Pin by digest. The deployment references the image by digest, not by a “latest” tag that can change.
- Signature and SBOM. A signed image and a component list let you verify provenance at deploy time, with details in the article on the software supply chain.
- No secrets in the image. A password written into an image layer stays there even if a later layer deletes the file. Secrets are supplied at runtime, as described in the article on secrets in applications.
Pods: minimal privileges
Kubernetes defines three Pod Security Standards profiles: privileged (unrestricted), baseline (blocks known privilege escalations) and restricted (the strictest, following hardening best practices). The built-in Pod Security Admission controller attaches a profile to a namespace with a label and works in three modes: enforce rejects the pod, audit records the violation in the audit log, and warn shows a warning to the user.
The restricted profile requires, among other things, running as a non-root user, no privilege escalation, dropping all capabilities and a seccomp profile. A container spec fragment that meets these conditions:
securityContext:
runAsNonRoot: true
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
capabilities:
drop: ["ALL"]
seccompProfile:
type: RuntimeDefaultA good rollout order: warn and audit mode on every namespace first, then fix the manifests, then switch to enforce. Turning on enforce straight away will stop deployments that have run as root for years.
Accounts and RBAC: who can do what in the cluster
Kubernetes RBAC consists of roles (Role within a namespace, ClusterRole cluster-wide) and bindings (RoleBinding, ClusterRoleBinding). Good practices from the Kubernetes documentation:
- Keep cluster-admin for a handful of people and break-glass procedures, not for CI pipelines.
- Grant permissions within a namespace instead of cluster-wide whenever possible.
- Avoid “*” wildcards in resources and verbs.
- Be careful with read access to Secret objects and with the right to create pods, because the latter lets someone run a pod with any service account in the namespace.
- Pods that do not talk to the Kubernetes API get no service account token (automountServiceAccountToken: false).
Human access to the cluster is best tied to the corporate identity system and reviewed like any other access, as described in the article on identity and access management.
Network: deny by default and NetworkPolicy
Without network policies, any pod in the cluster can connect to any other. A NetworkPolicy changes that for the pods it selects: from then on, only explicitly allowed traffic gets through. Policies only work if the cluster's network plugin (CNI) supports them, so verify that with a test before rollout, not by reading documentation.
A practical setup:
- a “deny all” policy for ingress and egress in every namespace;
- a policy per application that admits traffic only from specific pods, such as the ingress controller;
- outbound internet traffic only where needed, ideally through a gateway with an allowlist;
- a separate rule allowing DNS, without which name resolution breaks once egress is blocked.
This kind of separation is effectively the microsegmentation of the zero trust approach.
How to audit the cluster
The CIS Kubernetes Benchmark collects configuration recommendations for the control plane, etcd, worker nodes and policies. The Kubernetes documentation also has its own security checklist. Go through both once a quarter or after a major change and record the results as tasks with owners. A penetration test from the point of view of a compromised pod also works well: what the attacker sees on the network, which tokens they find and whether they can escape to the node. What such a program looks like at a telecom operator is shown in the case of a Kubernetes platform for network functions.
Questions and answers
Is a container as isolated as a virtual machine?
No. Containers on the same node share the operating system kernel, so a kernel bug or a privileged pod can give access to the host and other containers. That is why the restricted profile, an up-to-date kernel and placing applications with different trust levels on separate nodes matter. When stronger isolation is needed, teams use runtimes with lightweight virtualization.
Are Kubernetes Secrets encrypted?
Not by default. The Kubernetes documentation notes that Secret objects are stored unencrypted in etcd, and a base64 value is only an encoding. You need to enable encryption at rest, restrict read access to secrets in RBAC and consider an external vault from which the application fetches secrets at startup.
Where do you start hardening an existing cluster?
With an inventory: which pods run as root or in privileged mode, who has cluster-admin, whether any NetworkPolicy exists. Then enable Pod Security Admission in warn and audit mode on all namespaces, fix the manifests based on the warnings and move to enforce. In parallel, list the accounts with broad roles and narrow them down.
What is the CIS Kubernetes Benchmark?
It is a set of configuration recommendations for Kubernetes published by the Center for Internet Security. It covers API server settings, etcd, the kubelet on worker nodes, and RBAC and pod policies, among others. Benchmark versions track Kubernetes releases, and managed cloud services have separate variants because part of the control plane configuration is in the provider's hands.
Sources
- NIST SP 800-190, Application Container Security Guide
- Kubernetes documentation: Pod Security Standards
- Kubernetes documentation: Pod Security Admission
- Kubernetes documentation: Role Based Access Control Good Practices
- Kubernetes documentation: Network Policies
- Kubernetes documentation: Secrets
- Kubernetes documentation: Security Checklist
- CIS Kubernetes Benchmarks