SecurityKubernetes
Pod Security Standards: baseline, restricted and how to enforce them
Kubernetes defines three security levels for pods and ships an admission controller that applies them per namespace. Six labels control it, and a mode with no label falls back to the documented default, which is privileged.

Three levels
The Pod Security Standards define three policies. They are cumulative and range from highly permissive to highly restrictive.
- Privileged is unrestricted. The standard aims it at system and infrastructure workloads managed by privileged, trusted users.
- Baseline prevents known privilege escalations and allows the default, minimally specified pod configuration. Among its controls: privileged containers, sharing the host namespaces (
hostNetwork,hostPID,hostIPC) andhostPathvolumes are disallowed. Capabilities may be added only from a fixed list. - Restricted applies the current best practices for hardening pods and gives up some compatibility to do so. It includes everything in baseline. Containers must also set
allowPrivilegeEscalation: false, run as non-root, dropALLcapabilities and set a seccomp profile ofRuntimeDefaultorLocalhost. The only capability they may add back isNET_BIND_SERVICE. Volumes are limited to eight types:configMap,csi,downwardAPI,emptyDir,ephemeral,persistentVolumeClaim,projectedandsecret.
The six namespace labels
Pod Security Admission is the built-in admission controller that enforces the standards. It is stable since Kubernetes v1.25 and reads labels on the namespace. It has three modes:
enforce: policy violations cause the pod to be rejected.audit: violations are allowed and add an audit annotation to the event in the audit log.warn: violations are allowed and trigger a user-facing warning.
A namespace can set any or all modes, and a different level for each. Every mode takes a level label and an optional version label. This is the example from the Kubernetes documentation:
apiVersion: v1
kind: Namespace
metadata:
name: my-baseline-namespace
labels:
pod-security.kubernetes.io/enforce: baseline
pod-security.kubernetes.io/enforce-version: v1.37
pod-security.kubernetes.io/audit: restricted
pod-security.kubernetes.io/audit-version: v1.37
pod-security.kubernetes.io/warn: restricted
pod-security.kubernetes.io/warn-version: v1.37It blocks pods that do not satisfy baseline. It warns and adds an audit annotation for pods that do not meet restricted. The version label pins the policy to the version that shipped with a Kubernetes minor version, and it also accepts latest. The example pins v1.37, the release that page covers today. Set the version you want.
A mode with no label uses the default from the admission controller's configuration. The documented defaults are level privileged and version latest.
The enforce mode is applied to pod objects only. The audit and warn modes are also applied to workload resources that hold a pod template, such as a Deployment or a Job.
Rollout with warn and audit first
Start with a server-side dry run of the level you plan to enforce:
kubectl label --dry-run=server --overwrite ns --all \
pod-security.kubernetes.io/enforce=baselineThe checks run against existing pods and no policy is updated. The command returns a warning for each existing pod that is not valid under the proposed level.
Next, set audit and warn on every namespace. The documentation calls this a suitable first step:
kubectl label --overwrite ns --all \
pod-security.kubernetes.io/audit=baseline \
pod-security.kubernetes.io/warn=baselineThis sets no enforce level, so the namespaces that nobody has evaluated can still be told apart. List them:
kubectl get namespaces --selector='!pod-security.kubernetes.io/enforce'The documentation describes audit mode as the better option for catching workloads that are not running at the time of the dry run. The audit event carries the annotation pod-security.kubernetes.io/audit-violations, which names the level and the fields that were violated.
When a namespace is ready, enforce a level on it:
kubectl label --overwrite ns my-existing-namespace \
pod-security.kubernetes.io/enforce=restricted \
pod-security.kubernetes.io/enforce-version=v1.37Keep warn at the same level as enforce. Clients then receive a warning when they create a pod, or a resource with a pod template, that does not pass validation.
Exemptions and cluster defaults
Exemptions are configured statically in the admission controller configuration. That is a file passed to the API server with --admission-control-config-file. The same file holds the defaults that apply when a mode label is not set. This is the documented file with its default values:
apiVersion: apiserver.config.k8s.io/v1
kind: AdmissionConfiguration
plugins:
- name: PodSecurity
configuration:
apiVersion: pod-security.admission.config.k8s.io/v1
kind: PodSecurityConfiguration
defaults:
enforce: "privileged"
enforce-version: "latest"
audit: "privileged"
audit-version: "latest"
warn: "privileged"
warn-version: "latest"
exemptions:
usernames: []
runtimeClasses: []
namespaces: []The three exemption lists take authenticated usernames, runtime class names and namespaces. A request that meets an exemption is ignored by the admission controller: all enforce, audit and warn behavior is skipped.
The documentation warns against exempting controller service accounts such as system:serviceaccount:kube-system:replicaset-controller. Doing so implicitly exempts any user who can create the corresponding workload resource.
Limits of the built-in controller
- It supports the three standard levels only. For more control over specific constraints, the documentation points to a validating admission webhook.
- It is a non-mutating admission controller. It does not modify pods before it validates them.
- It works per namespace. Binding different policies to different service accounts or users inside one namespace needs a third-party webhook.
- The restrictions are applied when pods are created.
The Kubernetes documentation names Kubewarden, Kyverno and OPA Gatekeeper as other ways to enforce policies in the Kubernetes ecosystem.
First steps in an existing cluster
- List the namespaces with no
enforcelabel. The documentation treats an unlabeled namespace as one that has yet to be evaluated. - Set
auditandwarnon all namespaces to the level you want to enforce later, and read the warnings and audit annotations. - Dry-run, then enforce, one namespace at a time.
- For each namespace that allows
privilegedworkloads, set up and enforce access controls. The documentation asks for that explicitly.
Sources
- Pod Security Standards
- Pod Security Admission
- Enforce Pod Security Standards with Namespace Labels
- Enforce Pod Security Standards by Configuring the Built-in Admission Controller
- Enforcing Pod Security Standards
- Migrate from PodSecurityPolicy to the Built-In PodSecurity Admission Controller
- Audit Annotations
Want a second pair of eyes on yours? We do this work for a living.
More guides

securityContext: the settings every pod should carry
Security · 4 min read
Six settings, where each one goes, and a Deployment you can copy.

Kyverno policies: block what should never deploy
Security · 4 min read
Five policy types, one documented example, and what happened to ClusterPolicy in 1.20.

S3 bucket security: the settings to check on every bucket
Security · 4 min read
Seven S3 settings to check on each bucket, with the commands that read and set them.