Sub topic 10
Pinning policy versions
This chapter assumes you can apply the pod-security.kubernetes.io labels to a namespace and know the difference between the enforce, audit, and warn modes.
Why versions exist
The Pod Security Standards are not frozen. Kubernetes occasionally adjusts what Baseline and Restricted check. A release might add a new check or relax an existing one. If your namespace always uses the current definitions, a cluster upgrade can change which pods are admitted, even though you did not touch the namespace.
Each mode has a companion version label that fixes which release's definition of the profile is used. The label has the form pod-security.kubernetes.io/<mode>-version. Its value is either latest or a Kubernetes minor version such as v1.30.
The version labels
There are three version labels, one per mode:
| Label | Applies to |
|---|---|
| `pod-security.kubernetes.io/enforce-version` | Rejection of pods |
| `pod-security.kubernetes.io/audit-version` | Audit annotations |
| `pod-security.kubernetes.io/warn-version` | User-facing warnings |
The modes are independent, so each can use a different version. If you set a level label without a version label, the version defaults to latest.
Pinning enforcement, tracking the newest for feedback
A common pattern is to pin enforce so upgrades cannot start rejecting pods. You then leave audit and warn on latest, so you see what the newest definitions would flag.
apiVersion: v1
kind: Namespace
metadata:
name: payments
labels:
pod-security.kubernetes.io/enforce: baseline
pod-security.kubernetes.io/enforce-version: v1.30
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: latestWith this setup, admission applies the Baseline checks as they were defined in Kubernetes v1.30, even if the cluster later runs v1.33. Warnings and audit events still reflect the current definitions. When a warning shows that a newer check would flag a workload, you can fix the workload and then move the pin forward.
How the version is resolved
The namespace label wins. If it is absent, the default from the cluster's AdmissionConfiguration applies, for example enforce-version in the defaults block. If that is also absent, the version is latest. The cluster-wide configuration is covered in a later chapter.
Checking what is set
List the version labels on a namespace:
kubectl get ns payments --show-labelsTo change a pin, relabel the namespace:
kubectl label --overwrite ns payments \
pod-security.kubernetes.io/enforce-version=v1.31Use --overwrite because the label already exists. Changing only enforce-version does not re-check pods that are already running. Admission evaluates pods when they are created or updated. Existing pods keep running, but a Deployment's next rollout is checked against the new pin.
Common errors
- Assuming a pin freezes everything. It freezes only the definition of the profile for that mode. The level label still decides which profile applies.
- Typos in the value. Write
v1.30, not1.30orv1.30.2. Only the minor version is used, with a leadingv. A malformed value is not honored as you intended, so check the labels withkubectl get ns --show-labelsafter editing. - Pinning and forgetting. An old pin means you miss newer checks. Revisit pins at each cluster upgrade.
- Pinning a version newer than the cluster. A version ahead of the API server's own is evaluated as
latest. Pin to a version the cluster actually runs.
Exercise
A namespace has enforce: restricted and enforce-version: v1.28, and the cluster is upgraded. A new Kubernetes release changes a Restricted check. Which definition does enforcement use, and how can the team learn early that the new check would flag one of their Deployments?
Show answer
Enforcement keeps using the v1.28 definition of Restricted, so the upgrade does not change what is admitted. To learn about the new check early, add warn: restricted and warn-version: latest (and optionally the audit equivalents). Warnings and audit annotations then show workloads that the newest definition would flag, and the team can fix them before moving enforce-version forward.