Skip to content

Pod Security Standards — enforcing baseline and restricted

Apply the Pod Security Admission to namespaces — baseline vs restricted, the runAsNonRoot + readOnlyRootFilesystem trio, and how to migrate workloads off PSP defaults.

PodSecurityPolicy is gone. The replacement is Pod Security Admission (PSA), a built-in admission controller that enforces three Pod Security Standards levels — privileged, baseline, restricted — at the namespace level. This article covers what each level means in practice, the Pod fields that decide whether your workload passes, and the operational pattern for moving an existing cluster from “anything goes” to enforced baseline (and eventually restricted) without breaking everything.

How to verify

What’s in effect now:

kubectl get ns -o custom-columns=NS:.metadata.name,ENFORCE:.metadata.labels.pod-security\\.kubernetes\\.io/enforce,WARN:.metadata.labels.pod-security\\.kubernetes\\.io/warn,AUDIT:.metadata.labels.pod-security\\.kubernetes\\.io/audit

To dry-run a stricter level against a namespace before flipping enforce, set the warn label and apply existing workloads — PSA will print warnings for every Pod that would fail:

kubectl label ns team-payments \
  pod-security.kubernetes.io/warn=restricted \
  pod-security.kubernetes.io/audit=restricted
kubectl rollout restart deployment -n team-payments
kubectl get events -n team-payments | grep -i 'pod-security'

What’s happening

PSA is a built-in admission controller — no install, just labels. Three labels per namespace control three modes:

  • pod-security.kubernetes.io/enforce=<level> — blocks Pods that violate the level.
  • pod-security.kubernetes.io/audit=<level> — logs violations to the API audit log, doesn’t block.
  • pod-security.kubernetes.io/warn=<level> — prints warnings to the kubectl user, doesn’t block.

Levels are cumulative. privileged is no restrictions. baseline blocks host namespaces, privileged containers, hostPath, hostNetwork, NET_RAW and other dangerous capabilities — designed to be a low-friction “stop accidents” floor. restricted adds positive requirements: runAsNonRoot, allowPrivilegeEscalation: false, a seccomp profile of RuntimeDefault or Localhost, a tight capability drop, and (in newer versions) requirements around volume types.

You can also pin a version: pod-security.kubernetes.io/enforce-version=v1.28. This protects you from a Kubernetes upgrade tightening the standard underneath you — sticky version pinning is the conservative choice.

A common pattern: label everything baseline for enforce, with restricted for warn+audit. New workloads get warnings; existing ones still run. You promote namespace by namespace once their Pods are clean.

The procedure

  1. Audit the cluster against restricted without enforcing anything, so you know what’s broken:

    for ns in $(kubectl get ns -o name | cut -d/ -f2); do
      kubectl label ns "$ns" pod-security.kubernetes.io/audit=restricted --overwrite
    done

    Then watch the API audit log (or the namespace events) for would violate PodSecurity "restricted" entries.

  2. Apply baseline enforce to a namespace for new workloads:

    kubectl label ns team-payments \
      pod-security.kubernetes.io/enforce=baseline \
      pod-security.kubernetes.io/enforce-version=v1.28 \
      pod-security.kubernetes.io/warn=restricted \
      pod-security.kubernetes.io/audit=restricted
  3. Bring a Pod up to restricted by editing its securityContext. The minimum that passes restricted:

    spec:
      securityContext:
        runAsNonRoot: true
        runAsUser: 10001
        seccompProfile:
          type: RuntimeDefault
      containers:
        - name: app
          image: registry.example.com/app:1.4.2
          securityContext:
            allowPrivilegeEscalation: false
            readOnlyRootFilesystem: true
            runAsNonRoot: true
            capabilities:
              drop: ["ALL"]
          volumeMounts:
            - name: tmp
              mountPath: /tmp
      volumes:
        - name: tmp
          emptyDir: {}
  4. Set the seccomp default at the cluster level so workloads without an explicit profile still get RuntimeDefault. Add to the kubelet config:

    # /var/lib/kubelet/config.yaml
    seccompDefault: true
  5. Exempt system namespaces from restricted. kube-system and controllers that need privileged access stay on privileged:

    kubectl label ns kube-system \
      pod-security.kubernetes.io/enforce=privileged --overwrite
  6. Promote a namespace from baseline to restricted once the warnings are clean:

    kubectl label ns team-payments \
      pod-security.kubernetes.io/enforce=restricted --overwrite
  7. Use a more flexible policy engine (Kyverno, OPA Gatekeeper) for the rules PSS doesn’t cover — required image registries, mandatory labels, network exposure restrictions. PSA is for the security baseline; a policy engine is for the rest.

Common pitfalls

  • runAsNonRoot: true requires the image to set USER to a non-zero UID or the Pod’s securityContext to set runAsUser — otherwise the kubelet refuses to start the container because it cannot determine the UID statically.
  • readOnlyRootFilesystem: true breaks any app that writes to /tmp, /var/run, or wherever it caches things — add explicit emptyDir mounts for the writable paths.
  • Pinning enforce-version to an older Kubernetes version keeps the rules of that version even when the cluster upgrades — without pinning, a cluster upgrade silently tightens enforcement.
  • kube-system and CNI/operator namespaces routinely need privileged — labelling them restricted will eventually cause an outage on the next upgrade when controllers get rejected.
  • Init containers and sidecars must also comply — a non-compliant init container fails the whole Pod even if the main container is clean.

We operate Pod Security Admission for clients with baseline enforced everywhere by default, restricted on the namespaces where it lands cleanly, version-pinned standards, and a policy engine layered on top for cluster-specific rules. See /en/services/managed-operations/.