Kubernetes 1.25Dev & Eng

Content type: Concept

5 min read

Pod Security Admission Has Been Stable Since Kubernetes 1.25: A Guide to Migrating PodSecurityPolicy in Production

Article · Dev & Eng
Reading
5 min
Tables
2
Code
1
In short

PodSecurityPolicy was removed, and pod security control is now handled through namespace labels. Official Kubernetes documentation shows how to migrate without breaking existing workloads.

A Timeline Correction That Matters

A clarification is worth making before getting into practice: the official Kubernetes documentation itself marks Pod Security Admission as Stable since Kubernetes v1.25. The documentation consulted already covers Kubernetes 1.37 and advises anyone still running an older version to migrate from PodSecurityPolicy before upgrading to a Kubernetes version that no longer includes PodSecurityPolicies.

The official Kubernetes page shows the title 'Pod Security Admission' with the status badge 'Stable since Kubernetes v1.25' highlighted
The official Kubernetes page shows the title 'Pod Security Admission' with the status badge 'Stable since Kubernetes v1.25' highlighted. Reprodução: kubernetes.io.

The reason this topic remains relevant isn't the age of the feature, but the fact that many teams still carry legacy PSP configurations in clusters that were upgraded in fits and starts. If your team never formally migrated, the security behavior of your namespaces today may, in practice, be none at all.

What Pod Security Admission Actually Does

Pod Security Admission is an admission controller built into the kube-apiserver that applies the Pod Security Standards at pod creation time. Unlike PodSecurityPolicy, which required separate PodSecurityPolicy objects and dedicated RBAC to bind them, PSA works through labels directly on the namespace. There's no longer a policy object to create, version, and debug: there's a label.

The Pod Security Standards define three isolation profiles, from the most permissive to the most restrictive:

Expert views

What people are saying about it.

In response to NSA guidance published on December 2, Vercel detailed how the platform's TLS, certificates, and authentication tokens already incorporate post-quantum cryptography, some of it in place since November 2025.

Carina Ferreirain an iMasters article · Read the article: NSA calls for faster post-quantum cryptography adoption, and Vercel says it has complied since 2025

Since December 3, 2026, it has been possible to create repositories on GitHub using SHA-256 instead of SHA-1. The algorithm has existed in Git since 2020, but it's only now arriving on github.com, with no conversion for existing repositories.

Bisneto Bragain an iMasters article · Read the article: GitHub Enables Creation of Git Repositories with SHA-256 in Public Preview
LevelWhat it allows
privilegedNo restrictions; equivalent to having no policy at all
baselineBlocks known privilege escalations, maintains broad compatibility
restrictedApplies pod hardening best practices, most restrictive

Three Modes, Not a Single Switch

The part that tends to confuse people coming from PSP's binary model is that PSA doesn't just have "allowed" or "blocked". There are three independent modes, and the same namespace can combine different levels for each one:

ModeEffect
enforceRejects the pod that violates the policy
auditLets it pass, but records an annotation in the audit log
warnLets it pass, but returns a visible warning to the user (e.g., in kubectl apply)

The label syntax follows the pattern pod-security.kubernetes.io/<MODE>: <LEVEL>, and there's also an optional version label to pin the policy to a specific Kubernetes minor version:

yaml
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/audit: restricted
 pod-security.kubernetes.io/warn: restricted

This combination of three modes is exactly what makes a drama-free migration possible: you can run audit and warn at restricted for weeks, observing what would break, before flipping the enforce switch.

Why the Deployment Isn't Blocked, But the Pod Is

A technical detail that catches people off guard: according to the documentation, enforce mode is only applied to the resulting Pod object, never to the workload (Deployment, Job, StatefulSet) that generated it. audit and warn, on the other hand, are applied to both the workload and the pod. In practice, this means a kubectl apply of a problematic Deployment is accepted by the kube-apiserver, but the child ReplicaSets get stuck trying to create pods that are silently rejected, from the perspective of an operator who only looked at the Deployment.

In short: relying only on the output of kubectl apply to know whether the policy passed is a common mistake. You need to check the actual status of the pods, not the workload.

Exemptions: The Escape Valve That Demands Discipline

PSA allows exempting certain requests from policy evaluation, along three dimensions: username, RuntimeClassName, and namespace. The exemption is static, configured in the kube-apiserver's AdmissionConfiguration, and must be explicitly enumerated.

The Kubernetes documentation itself issues a direct warning about the most common mistake in this configuration:

Most pods are created by a controller in response to a workload resource, meaning that exempting an end user will only exempt them from enforcement when creating pods directly, but not when creating a workload resource. Controller service accounts should generally not be exempted, as doing so would implicitly exempt any user that can create the corresponding workload resource.

Official Kubernetes documentation

Exempting the service account system:serviceaccount:kube-system:replicaset-controller, for example, unlocks the policy for any Deployment in the entire cluster. It's an easy hole to dig without noticing.

A Migration Strategy That Doesn't Break Production

The recommended path for a cluster that still depends on legacy PodSecurityPolicy (or that simply never configured anything) follows a predictable sequence:

  1. Apply audit and warn at restricted across all namespaces, without enforce
  2. Monitor audit log events and the warnings returned on deploys for at least one full release cycle
  3. Fix manifests that flag violations (securityContext, runAsNonRoot, allowPrivilegeEscalation, capabilities)
  4. Roll out enforce namespace by namespace, starting with the least critical ones
  5. Pin the policy version with enforce-version to prevent a Kubernetes minor upgrade from changing behavior without warning

To track the impact at scale, the kube-apiserver exposes three specific Prometheus metrics: pod_security_evaluations_total (how many policy evaluations ran), pod_security_errors_total (errors that prevented normal evaluation, which cause the controller to fall back to the most recent restricted profile for safety), and pod_security_exemptions_total (how many requests went through via exemption). A spike in pod_security_errors_total before enabling enforce is a sign the migration isn't ready.

Where It Still Hurts

The real trade-off of PSA versus PodSecurityPolicy is the loss of fine-grained, per-workload granularity: PSP allowed custom policies per ServiceAccount with RBAC; PSA only works with the three predefined profiles, per namespace. Teams with very specific needs (a pod that needs one particular capability outside of restricted, but doesn't want to give up the policy for the rest of the namespace) end up turning to tools like Kyverno or OPA Gatekeeper as a complement, not a replacement. The migration is worth it for almost every cluster; complementing it with an external policy engine is only worth it when the restricted profile is genuinely insufficient for the workload.

Translated from the Brazilian Portuguese original · Read the original