Skip to main content

More Info:

Verifies each namespace is labeled with pod-security.kubernetes.io/enforce set to baseline or restricted so the built-in Pod Security Admission controller rejects unsafe pods.

Risk Level

High

Address

Security

Compliance Standards

  • Cloudanix Best Practice

Triage and Remediation

Remediation

Manual Steps

  1. On any machine with kubectl access, list all namespaces and identify ones missing an enforce label or with an incorrect value:
  2. For a single non-excluded namespace (example: my-app), set the enforce level to baseline (or restricted if you choose stricter):
  3. To label all non-excluded namespaces at once with baseline, run:
  4. If you prefer restricted for specific namespaces (example: prod-app), override as needed:
  5. (Optional) Review labels on a specific namespace to confirm:
  6. Verification (on any machine with kubectl access):
On any machine with kubectl access to the cluster:
  1. Create a manifest to enforce Pod Security Admission (choose baseline or restricted as appropriate). Example for baseline:
Edit the file to include all target namespaces and the desired level (baseline or restricted). Do not include kube-system, kube-public, or kube-node-lease unless you have explicitly decided to.
  1. Apply the labels declaratively:
If you prefer imperative labeling for a few namespaces, you can run (example for restricted):
  1. Verification (same logic as the audit):