Review policies replacing SecurityContextDeny

Restrict Pod security contexts with policies supported by the actual Kubernetes version.

Description

Kubernetes deprecated SecurityContextDeny in 1.27 and removed it in 1.30. On current clusters, restrict Pod security contexts with Pod Security Admission or a supported policy engine.

Potential impact

Privileged execution, privilege escalation or host access can extend the impact of a compromised workload to the host or other resources.

Remediation

Choose a policy level that fits the workloads and review warnings or audit results before enforcing it. Approve only necessary exceptions and verify that new Pod requests with disallowed settings are rejected.

Examples

These excerpts toggle the legacy plugin on Kubernetes 1.24.17. When upgrading to 1.30 or later, remove SecurityContextDeny from either the enabled or disabled list wherever it appears.

Before

yaml
apiVersion: v1
kind: Pod
metadata:
  name: command-demo
spec:
  containers:
    - name: command-demo-container
      image: registry.k8s.io/kube-apiserver:v1.24.17
      command: ["kube-apiserver"]
      args: ["--disable-admission-plugins=SecurityContextDeny"]

After

yaml
apiVersion: v1
kind: Pod
metadata:
  name: command-demo
spec:
  containers:
    - name: command-demo-container
      image: registry.k8s.io/kube-apiserver:v1.24.17
      command: ["kube-apiserver"]
      args:
        ["--enable-admission-plugins=SecurityContextDeny"]

References