Sub topic 1
Why pod-level security controls matter
Prerequisites
This chapter assumes you can do the following:
- Run basic
kubectlcommands such asget,apply, anddescribe. - Read Kubernetes YAML for Pods, Deployments, and Namespaces.
- Explain in general terms what a Linux container, a user ID, and a Linux capability are.
- Describe an admission controller as a step in the API server that can accept or reject a request.
You do not need to know the Pod Security Standards yet. The next chapters introduce them.
A container is not a virtual machine
A container is a normal Linux process with extra limits. The kernel uses namespaces to hide other processes, files, and network interfaces from it. Cgroups limit its resources. All containers on a node share one kernel.
A pod spec can weaken these limits. Because of this, the pod spec is a security boundary. A person who can create a pod can often decide how much isolation that pod gets.
What a risky pod spec can do
Some pod settings remove isolation on purpose. Each one has a legitimate use, such as a node agent or a network tool. Each one also gives an attacker who controls the container more reach.
| Setting | What it allows | Possible consequence |
|---|---|---|
| `privileged: true` | Nearly all host devices and capabilities | Escape to the node, read host disks |
| `hostNetwork: true` | Use the node's network stack | Reach node-local services, sniff traffic |
| `hostPID: true` | See and signal host processes | Inspect or kill other workloads |
| `hostPath` volume | Mount a node directory | Read credentials, write to host files |
| Running as root (UID 0) | Full privileges inside the container | Easier use of any kernel or runtime flaw |
| Added capabilities such as `SYS_ADMIN` | Extra kernel privileges | Mount filesystems, change kernel state |
An attacker who compromises one container, for example through a vulnerable web application, starts with whatever the pod spec granted. A locked-down pod limits the damage. A privileged pod can turn one bug into control of the node. From the node, the attacker may reach the kubelet credentials and other pods' secrets.
Why RBAC alone does not solve this
Role-based access control (RBAC) decides who may create pods. It does not look inside the pod spec. A developer who may create Deployments in a namespace can also write privileged: true in the template. RBAC sees only "create a Deployment".
You need a control that inspects the pod's contents. Kubernetes provides one: Pod Security Admission. It checks each pod against a named set of rules called the Pod Security Standards.
The idea behind the Pod Security Standards
The Pod Security Standards (PSS) define three profiles, from permissive to strict:
- Privileged: no restrictions.
- Baseline: blocks known privilege escalations and keeps common workloads easy to run.
- Restricted: follows current hardening practice and may require changes to your images and manifests.
Pod Security Admission (PSA) is the built-in admission controller that applies a profile to a namespace. The following chapters cover each profile and how to enable PSA.
A concrete example
This pod asks for host networking and a privileged container:
apiVersion: v1
kind: Pod
metadata:
name: privileged-demo
namespace: payments
spec:
hostNetwork: true
containers:
- name: app
image: busybox:1.36
command: ["sleep", "3600"]
securityContext:
privileged: trueWithout a pod-level control, the API server accepts this manifest if RBAC allows pod creation. The container then runs with broad access to the node. In a namespace that enforces the Baseline profile, the API server rejects it with a Forbidden error. You will set that up in a later chapter.
Exercise
A developer has RBAC permission to create Deployments in a namespace. Why can RBAC alone not stop them from deploying a container with privileged: true, and what kind of control can?
Show answer
RBAC decides who may perform an action, such as creating a Deployment. It does not inspect the fields inside the pod template. An admission control that checks the pod spec against a policy, such as Pod Security Admission with the Pod Security Standards, can reject the privileged container.
Exercise
Name two pod settings that reduce isolation between a container and its node, and give one risk for each.
Show answer
Any two from the table work. For example, hostPath volumes can expose node files such as credentials, and hostPID: true lets the container see and signal host processes.