Pod Security (Admission)

Difficulty: Advanced

Question

What is Pod Security Admission (PSA), how does it replace PodSecurityPolicy, and how do you enforce the Restricted standard on a namespace?

Answer

Pod Security Admission is a built-in admission controller that checks Pods against the Pod Security Standards (privileged, baseline and restricted) and is configured per namespace with labels. It replaced PodSecurityPolicy, which was deprecated in 1.21 and removed in 1.25, the same release in which PSA became GA.

The three Pod Security Standards

  • privileged: no restrictions. Meant for trusted system workloads like CNI plugins, CSI drivers and logging agents.
  • baseline: blocks known privilege escalations. No privileged: true, no hostNetwork, hostPID or hostIPC, no hostPath volumes, no host ports, and no adding capabilities beyond the default set.
  • restricted: baseline plus hardening best practices. Containers must set runAsNonRoot: true, allowPrivilegeEscalation: false, drop ALL capabilities (only NET_BIND_SERVICE may be added back), use a seccompProfile of RuntimeDefault or Localhost, and use only safe volume types like configMap, secret, emptyDir and PVCs.

Modes: enforce, audit and warn

Each namespace can set a level for three independent modes using labels:

LabelEffect on a violating Pod
pod-security.kubernetes.io/enforcePod creation is rejected
pod-security.kubernetes.io/auditAllowed, but an annotation is added to the audit log event
pod-security.kubernetes.io/warnAllowed, but the user sees a warning in kubectl

Each mode also has a -version label (for example enforce-version: v1.34 or latest) that pins which version of the standard is applied, so a Kubernetes upgrade does not suddenly break workloads.

Why PodSecurityPolicy was removed

PSP was powerful but confusing. Which policy applied depended on RBAC use permissions of both the user and the Pod's ServiceAccount, policies could mutate Pods, and it was easy to think you were protected when you were not. PSA trades flexibility for simplicity: three fixed profiles, namespace labels, no mutation. If you need custom rules (only images from your registry, required labels, resource limits), use a policy engine like Kyverno, OPA Gatekeeper, or the built-in ValidatingAdmissionPolicy with CEL, which is GA since 1.30.

Rolling it out without breaking production

  1. Label namespaces with warn and audit at restricted first and watch what would fail.
  2. Use kubectl label --dry-run=server --overwrite ns <ns> pod-security.kubernetes.io/enforce=restricted to see warnings for existing Pods.
  3. Fix securityContext in charts, then switch on enforce.
  4. Keep system namespaces like kube-system at privileged, or exempt them in the cluster-wide AdmissionConfiguration.

A classic gotcha: enforce only checks Pods, while warn and audit also check workload objects. So a Deployment that violates restricted is created successfully, but its ReplicaSet fails to create Pods, and the error only shows up in kubectl describe rs or the events, not on the Deployment you applied.

What happens when a Pod is created in a PSA namespace. PSA runs in admission, after authentication and authorization, before the Pod is stored.
  1. Request reaches the API server: A controller or user submits a Pod spec.
  2. Read namespace labels: PSA finds the enforce, audit and warn levels.
  3. Check against the standard: The spec is evaluated for the chosen level and version.
  4. Warn and audit: Violations add kubectl warnings and audit annotations.
  5. Enforce decision: A violation of the enforce level rejects the Pod.
  6. Pod stored in etcd: Compliant Pods continue to scheduling.

Code examples

Enforce restricted on a namespace

apiVersion: v1
kind: Namespace
metadata:
  name: payments
  labels:
    pod-security.kubernetes.io/enforce: restricted
    pod-security.kubernetes.io/enforce-version: latest
    pod-security.kubernetes.io/warn: restricted
    pod-security.kubernetes.io/audit: restricted

Any Pod in payments that does not meet the restricted standard is rejected, and violations are also logged and shown as warnings.

A container spec that passes restricted

spec:
  securityContext:
    runAsNonRoot: true
    seccompProfile:
      type: RuntimeDefault
  containers:
    - name: api
      image: ghcr.io/acme/api:2.1.0
      securityContext:
        allowPrivilegeEscalation: false
        readOnlyRootFilesystem: true
        capabilities:
          drop: ["ALL"]

These are the fields most charts are missing; readOnlyRootFilesystem is not required by restricted but is a good extra.

Key points

  • PSP deprecated in 1.21, removed in 1.25; PSA is GA since 1.25
  • Three levels: privileged, baseline, restricted
  • Three modes per namespace: enforce, audit, warn, each with an optional -version pin
  • PSA validates only; it never mutates Pods
  • enforce checks Pods, not Deployments, so failures appear on the ReplicaSet

Common follow-up questions

  • How would you migrate a cluster from PodSecurityPolicy to PSA?
  • What does the restricted profile require that baseline does not?
  • When would you need Kyverno or Gatekeeper on top of PSA?
  • Why might a Deployment apply successfully but never create Pods?

Interview tips

  • Give the exact timeline: PSP removed in 1.25, PSA GA in 1.25
  • Name the three levels and three modes; that alone covers most of the question
  • Describe a safe rollout using warn and audit before enforce

Concepts covered

Pod Security Admission, Pod Security Standards, Restricted Profile, PodSecurityPolicy Removal, Namespace Labels

More Kubernetes & Orchestration questions