Pod Security Standards — replacement for PodSecurityPolicy (deprecated in 1.25).
Three levels:
Enable on namespace:
1apiVersion: v12kind: Namespace3metadata:4 name: production5 labels:6 pod-security.kubernetes.io/enforce: restricted7 pod-security.kubernetes.io/audit: restricted8 pod-security.kubernetes.io/warn: restricted
Restricted — what is prohibited:
1# This Pod WILL BE BLOCKED2apiVersion: v13kind: Pod4spec:5 containers:6 - name: app7 image: myapp8 securityContext:9 runAsRoot: true # FORBIDDEN10 privileged: true # FORBIDDEN11 capabilities:12 add: ["NET_ADMIN"] # FORBIDDEN
Restricted — requirements:
1# This Pod IS ALLOWED2apiVersion: v13kind: Pod4spec:5 securityContext:6 runAsNonRoot: true7 runAsUser: 10008 fsGroup: 10009 seccompProfile:10 type: RuntimeDefault11 containers:12 - name: app13 image: myapp14 securityContext:15 allowPrivilegeEscalation: false16 capabilities:17 drop: ["ALL"]18 readOnlyRootFilesystem: true19 volumeMounts:20 - name: tmp21 mountPath: /tmp22 volumes:23 - name: tmp24 emptyDir: {}
PSS vs PSP: PSS is simpler, built into K8s. PSP is deprecated. Kyverno/OPA Gatekeeper — alternatives.