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 those without an enforce label or with an incorrect value (excluding system namespaces):
  2. For each non-system namespace that should be set to baseline, apply the label:
  3. For each non-system namespace that should be set to restricted, apply the label:
  4. (Optional but recommended) Set the enforce-version label so behavior is consistent across upgrades (replace v1.28 with the API version you target):
  5. (Optional) If you use GitOps/manifests for namespace definitions, add the labels to the Namespace manifests and re-apply them from any machine with kubectl access:
    Apply:
  6. Verification (on any machine with kubectl access): run the same audit logic and confirm all non-exempt namespaces show enforce=baseline or enforce=restricted with is_compliant=true:
On any machine with kubectl access:
  1. Create a manifest labeling all existing non-system namespaces with baseline (edit to restricted if desired):
  1. Apply the manifest:
  1. For any new namespace you create, include the label in its manifest, for example:
Apply it with:
  1. Verification (same logic as the audit, using kubectl):