Kubernetes Pod Security Standards Explained
Kubernetes Pod Security Standards Explained
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.
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
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:
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:
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:
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
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:
Inventory. List the namespaces and decide the target profile for each, using the table in Section 7. Identify the system namespaces that need privileged.
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.
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
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.
Enforce baseline first. Set enforce to baseline, because it blocks the most dangerous settings with the least disruption. Keep warn and audit at restricted.
Move to restricted. When the warnings are gone, raise enforce to restricted, one namespace at a time, starting with the least critical.
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:
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:
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
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
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.
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.
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.
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.
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
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:
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
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.