Difficulty: Advanced
What is Pod Security Admission (PSA), how does it replace PodSecurityPolicy, and how do you enforce the Restricted standard on a namespace?
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.
privileged: true, no hostNetwork, hostPID or hostIPC, no hostPath volumes, no host ports, and no adding capabilities beyond the default 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.Each namespace can set a level for three independent modes using labels:
| Label | Effect on a violating Pod |
|---|---|
pod-security.kubernetes.io/enforce | Pod creation is rejected |
pod-security.kubernetes.io/audit | Allowed, but an annotation is added to the audit log event |
pod-security.kubernetes.io/warn | Allowed, 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.
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.
warn and audit at restricted first and watch what would fail.kubectl label --dry-run=server --overwrite ns <ns> pod-security.kubernetes.io/enforce=restricted to see warnings for existing Pods.enforce.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.
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.
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.
Pod Security Admission, Pod Security Standards, Restricted Profile, PodSecurityPolicy Removal, Namespace Labels