Security & multi-tenancyLesson 4 of 13
Pod Security Standards and securityContext
If a Pod runs as root (the admin account) or borrows node privileges, one breached container can put the whole node at risk. Let's follow where a namespace's security standard stops a risky Pod, and what a developer must fix to get it through.
Reject level (enforce)None
Submit result—
Running Pods0
RequestResponse / reportWatchAppears in a later step
What you will learn
- privileged vs baseline vs restricted
- What the enforce, audit and warn modes do
- Why rejections are less visible with a Deployment
- Threats blocked by four securityContext fields
What each level blocks, and securityContext fields
| Item | What it blocks | What happens when you apply it |
|---|---|---|
| baseline | Privileged containers, sharing node network or processes, mounting node paths | Most regular applications pass as is |
| restricted | baseline + running as root, privilege escalation, kernel capabilities, missing seccomp | Images built to run as root are rejected or fail to start |
runAsNonRoot | Gaining node root after a container escape | Images built to run as root fail to start |
readOnlyRootFilesystem | Changing executables or planting tools | You must attach a separate writable volume for temp files |
capabilities.drop | Abuse of special privileges like network config or file ownership changes | Using a port below 1024 needs one capability added back |
allowPrivilegeEscalation: false | Gaining privileges at runtime | Usually no impact |
The full set of API server gates (authentication, authorization, admission) is covered in How an API Request Gets Stored.
Try it yourself
kubectl get namespaces -L pod-security.kubernetes.io/enforce,pod-security.kubernetes.io/warn # Level and mode per namespace
kubectl run psa-test --image=nginx --privileged -n <namespace> --dry-run=server # baseline rejects it; nothing is stored
kubectl get events -n <namespace> --field-selector reason=FailedCreate # Deployed but no Pods: rejection events
kubectl get pod <pod> -n <namespace> -o jsonpath='{.spec.containers[*].securityContext}' # Current securityContext
kubectl label --dry-run=server --overwrite namespace <namespace> pod-security.kubernetes.io/enforce=restricted # Which Pods break before raising enforce
Check yourself
Further reading: Pod Security Standards · Pod Security Admission · Configure a security context for a Pod or container