kubernetes

Kubernetes Pod Security Standards Explained

Kubernetes Pod Security Standards Explained

By Shubhankar Tripathi • • 5 min read

Kubernetes Pod Security Standards Explained

bitcodematrix.com | Kubernetes Series

1. Introduction

The previous article in this series showed how the securityContext of a Pod controls what its containers may do: which user they run as, which capabilities they hold, whether they can write to their file system. But a securityContext is only a request made by whoever writes the manifest. Nothing in it forces a developer to ask for safe settings. If a team deploys a privileged container that mounts the host's root directory, the cluster will happily run it unless something stops it.

The Pod Security Standards (PSS) define what "safe enough" means, in three clearly specified profiles. The Pod Security Admission controller enforces those profiles at the namespace level. Together, they give every cluster a built-in, low-effort guardrail against the most dangerous Pod configurations. This article explains the three profiles in detail, how the admission controller works, how to roll the standards out without breaking running workloads, how to handle system components that legitimately need more privileges, and what the standards do not cover. It complements the articles on SecurityContext, RBAC and ServiceAccounts.

2. From PodSecurityPolicy to Pod Security Admission

Kubernetes has had a built-in mechanism for restricting Pod settings since its early versions. Understanding its history explains the design of the current one.

Mechanism

Status and characteristics

PodSecurityPolicy (PSP)

The original admission mechanism. It was powerful but notoriously hard to use: policies were authorised through RBAC in ways that confused many users, there was no easy way to test a policy before enforcing it, and behaviour could differ from what people expected. It was deprecated in Kubernetes 1.21 and removed in Kubernetes 1.25

Pod Security Standards

A fixed, documented set of three profiles that describe levels of restriction. They are a specification, not a mechanism

Pod Security Admission (PSA)

The built-in admission controller that applies the standards to namespaces through labels. It reached beta in 1.23 and general availability in Kubernetes 1.25, as the replacement for PSP

 

The design goal of PSA was simplicity. Instead of writing custom policy objects, you choose one of three standard profiles for each namespace and the controller does the rest. This is a deliberate trade-off: it is easy to adopt and understand, but it is less flexible than a general policy engine, as Section 12 explains.

3. The Three Profiles

Profile

Intent

Typical use

Privileged

Unrestricted. Allows all known privilege escalations, including full host access

Trusted infrastructure components such as CNI plugins, CSI node drivers and some monitoring agents, in dedicated namespaces

Baseline

Minimally restrictive. Prevents known privilege escalations while staying easy to adopt for most existing workloads

A sensible minimum for general application namespaces, and a stepping stone towards restricted

Restricted

Heavily restricted. Follows current Pod hardening best practices, at the expense of some compatibility

Security-sensitive applications, multi-tenant clusters and any new workload that you control

 

The profiles are cumulative: restricted includes everything in baseline and adds further controls. The privileged profile is effectively "no profile", and Kubernetes documents it so that the choice to allow everything is explicit rather than accidental.

Each profile is defined as a list of controls, and each control restricts specific fields of the Pod specification. The two sections that follow describe them. The exact list evolves with Kubernetes releases, with the documentation of your version being authoritative, so treat the tables below as a clear summary and not as the final word.

4. The Baseline Profile in Detail

The baseline profile blocks the settings that are most directly linked to container escapes and host takeover:

Control

What baseline requires

Host namespaces

hostNetwork, hostPID and hostIPC must not be true, so that Pods do not share the node's network, process or IPC namespaces

Privileged containers

securityContext.privileged must be false or unset

Capabilities

Containers may add only a limited allowlist of capabilities: AUDIT_WRITE, CHOWN, DAC_OVERRIDE, FOWNER, FSETID, KILL, MKNOD, NET_BIND_SERVICE, SETFCAP, SETGID, SETPCAP, SETUID and SYS_CHROOT. Powerful ones such as SYS_ADMIN, NET_ADMIN and SYS_PTRACE are not allowed

HostPath volumes

hostPath volumes are forbidden

Host ports

hostPort must not be used

AppArmor

The profile must not be set to anything other than the runtime default or a localhost profile

SELinux

The SELinux type must be unset or one of a small set of container types, and custom user and role values are forbidden

/proc mount type

procMount must be unset or Default, so the masked /proc is kept

Seccomp

The profile must not be explicitly set to Unconfined

Sysctls

Only a short allowlist of safe sysctls may be set, such as net.ipv4.ip_unprivileged_port_start and net.ipv4.ip_local_port_range

Windows HostProcess

Windows HostProcess containers are forbidden

 

Notice what baseline does not require. A container may still run as root, may still lack a seccomp profile (as long as it is not explicitly unconfined), may have a writable root file system, and may keep the default capability set. That is why many existing applications already pass baseline with no change, and why it works as an easy first target.

5. The Restricted Profile in Detail

Restricted includes all baseline controls and adds the following:

Control

What restricted requires

Volume types

Only these volume types are allowed: configMap, csi, downwardAPI, emptyDir, ephemeral, persistentVolumeClaim, projected and secret. Others, such as hostPath, nfs and iscsi volumes defined inline, are not

Privilege escalation

allowPrivilegeEscalation must be set to false for every container

Running as non-root

runAsNonRoot must be true, at the Pod level or for every container

Running as non-root user

runAsUser must not be 0

Seccomp

The profile must be explicitly set to RuntimeDefault or Localhost, at the Pod level or for every container

Capabilities

Containers must drop ALL capabilities. The only capability that they may add back is NET_BIND_SERVICE

 

Several points are worth knowing:

  • The restricted profile is a Linux-only policy. Pods that declare their operating system as Windows are not evaluated against the Linux-specific controls.

  • Restricted does not require readOnlyRootFilesystem, resource limits or a particular user ID range. It sets a strong floor, but good hardening goes further, as the SecurityContext article describes.

  • Recent Kubernetes versions relax some of these controls for Pods that use user namespaces (hostUsers set to false), because root inside the container is then unprivileged on the host. Check the documentation for your version before relying on this.

  • The volume allowlist matters in practice: a Pod that mounts a hostPath or an inline network file system volume fails restricted, so such workloads must use PersistentVolumeClaims or CSI volumes instead.

6. Pod Security Admission: Modes, Labels and Versions

6.1 The Three Modes

PSA is configured with labels on namespaces. For each namespace, you choose a profile for each of three modes:

Mode

What happens on a violation

enforce

The Pod is rejected. The API server returns an error that lists the violated controls

audit

The request is allowed, but an annotation recording the violation is added to the audit log event

warn

The request is allowed, and the client receives a warning message, which kubectl shows to the user

 

The modes are independent, so a namespace can enforce baseline while warning and auditing for restricted. That combination is the core of a safe migration path: it blocks the worst settings today and shows exactly what would break when you tighten the rules.

6.2 Labels

apiVersion: v1

kind: Namespace

metadata:

  name: shop

  labels:

    pod-security.kubernetes.io/enforce: baseline

    pod-security.kubernetes.io/enforce-version: latest

    pod-security.kubernetes.io/audit: restricted

    pod-security.kubernetes.io/audit-version: latest

    pod-security.kubernetes.io/warn: restricted

    pod-security.kubernetes.io/warn-version: latest

The label format is pod-security.kubernetes.io/<mode> for the profile, and pod-security.kubernetes.io/<mode>-version for the version of the standard to apply. The version can be latest, or a specific Kubernetes minor version such as v1.30. Pinning a version keeps the rules stable across cluster upgrades, because the definition of a profile can gain new controls in later releases. Using latest means that an upgrade may start to flag new violations. Many teams pin the enforce version and use latest for warn and audit, to get early notice of changes.

6.3 How Evaluation Works

  • The check happens at admission time, when a Pod is created or updated. Pods that are already running are never evicted or restarted by a policy change.

  • For workload resources such as Deployments, StatefulSets, Jobs and CronJobs, the warn and audit modes also evaluate the Pod template, so you get feedback when you apply the Deployment itself.

  • The enforce mode applies to Pod objects only. A Deployment with a non-compliant template is accepted, but its ReplicaSet cannot create Pods, and the failures appear as events on the ReplicaSet. This catches many people out: kubectl apply succeeds, and then no Pods appear.

  • Changing the labels of a namespace does not touch existing Pods, but warn and audit may report how many existing Pods would violate the new level, and a server-side dry run can preview this before you commit to the change.

6.4 Exemptions and Cluster-Wide Defaults

Administrators can configure the controller through an AdmissionConfiguration file on the API server. It sets defaults for namespaces without labels, and lists exemptions by username, runtime class or namespace:

apiVersion: apiserver.config.k8s.io/v1

kind: AdmissionConfiguration

plugins:

- name: PodSecurity

  configuration:

    apiVersion: pod-security.admission.config.k8s.io/v1

    kind: PodSecurityConfiguration

    defaults:

      enforce: "baseline"

      enforce-version: "latest"

      audit: "restricted"

      audit-version: "latest"

      warn: "restricted"

      warn-version: "latest"

    exemptions:

      usernames: []

      runtimeClasses: []

      namespaces: ["kube-system"]

Without such a configuration, namespaces that have no labels get no enforcement, which means the privileged profile applies. On managed Kubernetes services you often cannot change the API server's admission configuration, so namespace labels are your main tool, and the provider may set its own defaults. Use exemptions sparingly, because every exemption is a hole in the guardrail.

7. Choosing a Profile for Each Workload

Workload

Suggested profile

Reasoning

CNI plugins, CSI node drivers, kube-proxy, node-level agents

Privileged, in dedicated namespaces

They legitimately need host access. Restrict who can deploy into those namespaces

Cluster add-ons that need a few extras (for example hostPath for logs)

Baseline or privileged, case by case

Grant only what is needed, and keep the add-on isolated in its own namespace

Existing business applications

Baseline now, with a plan for restricted

Most pass baseline without changes, and the warnings show the work remaining

New applications and services

Restricted from the start

It is much cheaper to build for restricted than to retrofit

Multi-tenant namespaces and untrusted code

Restricted, with additional isolation

Limits what a compromised or malicious workload can do

Build, CI and test environments

Baseline at least

They often run less trusted code, so avoid privileged and host-level access

 

8. A Pod That Satisfies the Restricted Profile

The following minimal Pod meets every restricted control. Each setting addresses a specific line in the table of Section 5:

apiVersion: v1

kind: Pod

metadata:

  name: compliant

  namespace: shop

spec:

  securityContext:

    runAsNonRoot: true

    runAsUser: 10001

    seccompProfile:

      type: RuntimeDefault

  containers:

  - name: app

    image: example/app:1.0

    securityContext:

      allowPrivilegeEscalation: false

      capabilities:

        drop: ["ALL"]

    volumeMounts:

    - name: tmp

      mountPath: /tmp

  volumes:

  - name: tmp

    emptyDir: {}

The manifest passes the restricted profile, although it is not yet fully hardened. Adding a read-only root file system, resource limits, a dedicated ServiceAccount with token mounting disabled and a network policy would bring it closer to the full recommendations in the earlier articles. Passing PSS is a minimum, not the finish line.

9. Rolling Out Without Breaking Production

Turning on enforcement in a cluster with running workloads needs a plan. A proven sequence is:

  1. Inventory. List the namespaces and decide the target profile for each, using the table in Section 7. Identify the system namespaces that need privileged.

  2. Observe with warn and audit. On each application namespace, set warn and audit to the target profile, without enforce. Deploy and redeploy workloads, and collect warnings from kubectl, CI pipelines and the audit log.

  3. Preview with a server-side dry run. Check which existing Pods would be rejected, before changing enforcement:

kubectl label --dry-run=server --overwrite namespace shop \

  pod-security.kubernetes.io/enforce=restricted

  1. Fix the findings. Update manifests, Helm charts and base images. Typical fixes are adding the securityContext fields, replacing hostPath volumes, and moving ports above 1024. Contact the vendors of third-party charts that do not comply.

  2. Enforce baseline first. Set enforce to baseline, because it blocks the most dangerous settings with the least disruption. Keep warn and audit at restricted.

  3. Move to restricted. When the warnings are gone, raise enforce to restricted, one namespace at a time, starting with the least critical.

  4. Pin and review. Decide whether to pin the version labels, add the labels to your namespace templates so that new namespaces start compliant, and schedule regular reviews, especially before Kubernetes upgrades.

A helpful safety habit is to remember that enforcement affects new and recreated Pods. A node drain, a rolling update or an autoscaling event will recreate Pods that were created before the label existed, and those can suddenly be rejected. Test rollouts and restarts in staging, with the same labels, before enforcing in production.

10. System Components and Add-Ons

Many infrastructure components need privileges that baseline or restricted forbid. Plan for them, and do not weaken the whole cluster to accommodate them:

Component

Typical needs and handling

CNI plugins and kube-proxy

Host networking, host paths and elevated capabilities. Run in a privileged namespace, usually kube-system, which is often exempted

CSI node plugins

Privileged containers and hostPath mounts of the kubelet directory (see the CSI article). Run in a dedicated privileged namespace

Node-level monitoring and log agents

Host paths, sometimes host networking or PID access. Privileged or baseline-with-exceptions namespace; prefer designs that need fewer host mounts

Service mesh sidecar injection

Init containers that configure networking often need NET_ADMIN and NET_RAW, which baseline does not allow. Use the mesh's CNI-based mode, which moves that work into a privileged node component, or place those workloads where the profile permits it

Ingress controllers

Often need only NET_BIND_SERVICE or a high port, so they can meet restricted when configured accordingly

Operators and controllers

Usually need no special privileges at the Pod level, because their power comes from RBAC. They can normally run as restricted

Debug and break-glass Pods

Use a dedicated, tightly controlled namespace or process with audit, and remove them after use

 

The rule is to keep privileged workloads few, isolated and watched. Put them in their own namespaces labelled with the privileged profile, restrict who may create Pods there with RBAC, and review the list regularly.

11. Protecting the Labels Themselves

PSA works through namespace labels, which means the label becomes a security control. Anyone who can update a namespace can change enforce to privileged and then deploy a dangerous Pod. This is a frequent gap in multi-tenant clusters. Reduce the risk by:

  • Restricting update and patch permissions on namespaces to the platform team. Namespace admins in the built-in admin role cannot modify the namespace object itself, but custom roles may be broader.

  • Creating namespaces through a controlled process, such as a GitOps repository or a namespace-as-a-service operator, which always applies the standard labels.

  • Using an admission policy to prevent the weakening or removal of the pod-security labels.

  • Auditing changes to namespace labels, and alerting when enforcement is reduced.

Also remember the rest of the path: even a perfectly labelled namespace can be bypassed by a ServiceAccount or user that may create Pods in an exempted namespace, or by workloads that run as a privileged DaemonSet elsewhere. PSA is one control in a layered design.

12. What the Pod Security Standards Do Not Do

PSS is intentionally narrow. It checks a fixed list of Pod fields against three fixed profiles. It does not:

  • Let you write custom rules, for example "all Pods must run with UID in the range 10000 to 20000" or "only images from our registry".

  • Mutate Pods, so it cannot add missing settings. A rejected Pod must be fixed by its author.

  • Require read-only root file systems, resource limits, probes, labels, or a particular ServiceAccount configuration.

  • Control images, registries, signatures or vulnerabilities.

  • Limit network traffic, RBAC permissions or access to the Kubernetes API.

  • Apply different rules to different workloads within the same namespace, except through exemptions by user or runtime class.

For these needs, combine PSA with a policy mechanism:

Mechanism

Role alongside PSA

ValidatingAdmissionPolicy (built in)

Custom validation rules written in CEL, evaluated inside the API server without webhooks. Good for simple custom rules

Kyverno

Policy engine that can validate, mutate and generate resources, with ready-made policies that mirror the Pod Security Standards and more

OPA Gatekeeper

Policy engine using constraint templates written in Rego, suited to complex logic and existing OPA expertise

NetworkPolicy, RBAC and runtime tools

Cover traffic, permissions and runtime detection, which no admission control can replace

 

A practical split is to let PSA provide the universal baseline, and use a policy engine for the organisation-specific requirements and for automatic defaults that make it easy for developers to comply.

13. Hands-On Walkthrough

  1. Create a namespace that enforces baseline, and warns and audits for restricted.

kubectl create namespace pss-demo

kubectl label namespace pss-demo \

  pod-security.kubernetes.io/enforce=baseline \

  pod-security.kubernetes.io/warn=restricted \

  pod-security.kubernetes.io/audit=restricted

  1. Try a Pod with default settings.

kubectl run basic -n pss-demo --image=busybox:1.36 \

  --restart=Never --command -- sleep 3600

The Pod is created, because it satisfies baseline, but kubectl prints a warning that it would violate the restricted profile, and lists the missing settings: allowPrivilegeEscalation, capabilities, runAsNonRoot and the seccomp profile.

  1. Try a Pod that violates baseline.

apiVersion: v1

kind: Pod

metadata:

  name: bad

  namespace: pss-demo

spec:

  hostNetwork: true

  containers:

  - name: app

    image: busybox:1.36

    command: ["sleep", "3600"]

    securityContext:

      privileged: true

    volumeMounts:

    - name: host

      mountPath: /host

  volumes:

  - name: host

    hostPath:

      path: /

The API server rejects it, and the error lists several violated controls: host namespaces, privileged containers and hostPath volumes. Nothing was created.

  1. See the Deployment trap. Apply a Deployment with the same bad settings.

kubectl create deployment bad-deploy -n pss-demo --image=busybox:1.36 \

  -- sleep 3600

kubectl patch deployment bad-deploy -n pss-demo --type=json -p='[

  {"op":"add","path":"/spec/template/spec/hostNetwork","value":true}]'

kubectl get deployment,replicaset -n pss-demo

kubectl describe replicaset -n pss-demo | grep -i -A3 "forbidden"

The Deployment exists, but it has no ready Pods. The ReplicaSet events show that Pod creation was forbidden by PodSecurity, which demonstrates that enforcement applies to Pods rather than to the Deployment object.

  1. Preview the effect of enforcing restricted on the namespace.

kubectl label --dry-run=server --overwrite namespace pss-demo \

  pod-security.kubernetes.io/enforce=restricted

The output warns that existing Pods, such as the basic Pod, would violate the restricted profile.

  1. Apply the compliant Pod from Section 8 into the namespace after switching enforcement to restricted, and confirm that it is admitted.

kubectl label namespace pss-demo \

  pod-security.kubernetes.io/enforce=restricted --overwrite

kubectl apply -f compliant.yaml -n pss-demo

  1. Clean up.

kubectl delete namespace pss-demo

14. Reading Violation Messages

A rejection message follows a consistent pattern: it names the profile and version, then lists each violated control with the container or field involved. The wording can vary slightly between versions, but these are the common ones and the fix for each:

Message (abbreviated)

Fix

privileged (container "app" must not set securityContext.privileged=true)

Remove privileged. If the workload truly needs it, move it to a privileged namespace under strict control

host namespaces (hostNetwork=true)

Set hostNetwork, hostPID and hostIPC to false, or redesign to avoid host access

hostPath volumes (volume "x")

Replace with a PersistentVolumeClaim, emptyDir, ConfigMap or CSI volume

non-default capabilities or unrestricted capabilities (container must set capabilities.drop=["ALL"])

Add capabilities.drop with ALL, and add back only NET_BIND_SERVICE if needed

allowPrivilegeEscalation != false

Set allowPrivilegeEscalation to false on every container, including init containers

runAsNonRoot != true

Set runAsNonRoot to true at the Pod or container level, with a numeric runAsUser

runAsUser=0

Choose a non-zero user ID

seccompProfile (must set type to "RuntimeDefault" or "Localhost")

Add seccompProfile with type RuntimeDefault at the Pod level

restricted volume types (volume "x" uses restricted volume type)

Use only the allowed volume types

unsafe sysctls

Use only sysctls in the safe allowlist

 

Remember that the rules apply to every container, including init containers and ephemeral debug containers, so a single forgotten init container can cause a rejection.

15. Troubleshooting

Symptom

Likely cause and check

Deployment applied, but no Pods are created

The ReplicaSet cannot create Pods because of enforcement. Run kubectl describe replicaset and read the forbidden event

Pods that ran for months are rejected after a restart

They were created before enforcement was enabled, and recreation triggers the check. Fix the manifests and test restarts before enforcing

Warnings appear but nothing is blocked

Only warn and audit are set. Add the enforce label when ready

Enforcement seems not to apply at all

The namespace has no labels and no cluster defaults, the namespace or user is exempted, or the label has a typo. Check the labels and the API server configuration

Helm chart or operator Pods rejected

The chart sets insecure defaults. Look for values that configure the securityContext, or put the component in a more permissive namespace and ask the maintainers to improve it

Service mesh or CNI-injected containers rejected

Injected init containers use capabilities that are not allowed. Use CNI-mode injection, or place them in a suitable namespace

Behaviour changed after a cluster upgrade

The version label is latest and the standard changed. Pin the version, and review the release notes

Users bypassed the policy

They could edit namespace labels, or use an exempted user or namespace. Restrict namespace updates and review exemptions

Job or CronJob fails with Pod creation errors

Pod templates of Jobs are evaluated like any other. Fix the template, as for Deployments

Windows Pods behave differently

The restricted profile is Linux-focused. Check the OS-specific controls in the documentation

 

16. Best Practices

  • Label every namespace explicitly, and create namespaces through a process that applies the labels automatically.

  • Aim for restricted for application namespaces, with baseline as the minimum, and privileged only for isolated infrastructure namespaces.

  • Always use warn and audit alongside enforce, to see what the next level would break.

  • Roll out gradually: observe, preview with a dry run, fix, enforce baseline, and then restricted.

  • Pin the version for enforce, and use latest for warn and audit to get early notice of changes.

  • Restrict who can edit namespaces, and monitor label changes.

  • Keep exemptions and privileged namespaces to a minimum, and review them regularly.

  • Remember that enforcement affects new Pods, and test restarts, drains and scaling before you enforce in production.

  • Combine PSA with a policy engine or ValidatingAdmissionPolicy for custom rules and automatic defaults, and with RBAC, NetworkPolicy and image controls for the rest.

  • Build secure defaults into your shared Helm charts and base manifests, so that passing the standard is the easy path.

17. Conclusion

The Pod Security Standards turn the general idea of "hardening your Pods" into three precise, shared definitions, and Pod Security Admission turns those definitions into a guardrail that is built into every modern cluster. Baseline stops the known paths to host compromise, restricted encodes current best practice, and privileged documents the cases where neither applies. The mechanism is simple enough to adopt in an afternoon and strict enough to prevent a whole class of serious mistakes.

Use it as the floor, not the ceiling. Label your namespaces, roll out in stages with warn and audit, protect the labels, isolate the few components that need privileges, and add policy engines, RBAC, network policies and image controls for everything the standards deliberately leave out. With that layered approach, an insecure Pod becomes something your cluster refuses at the door, instead of something you discover during an incident.