Skip to main content

More Info:

Verifies runAsNonRoot is set at pod or container level. Running as root inside a container widens the impact of a container escape.

Risk Level

High

Address

Security

Compliance Standards

  • Cloudanix Best Practice

Triage and Remediation

Remediation

Manual Steps

  1. Identify the non-compliant pod(s) (run on any machine with kubectl access):
  2. If the pod is controlled by a higher-level object (Deployment, DaemonSet, etc.), get that manifest instead of editing the pod directly (run on any machine with kubectl access, adjust KIND, NAMESPACE, NAME as shown in the audit output owner= field):
  3. Edit the manifest to set runAsNonRoot: true at the pod level securityContext (preferred) (edit /tmp/workload.yaml on the same machine):
    If you cannot use pod-level context (for example, only some containers must be non-root), set it per container instead:
  4. Apply the updated manifest (run on any machine with kubectl access):
  5. For standalone Pods not managed by a controller, export, modify, and recreate them (run on any machine with kubectl access, replace NAMESPACE and POD_NAME):
  6. Verify all containers now run as non-root (run on any machine with kubectl access):
On any machine with kubectl access:
  1. Identify the non-compliant pod (example name/namespace used below; substitute your own from the audit output):
  1. Edit the manifest to add a pod-level securityContext.runAsNonRoot: true. In /tmp/myapp-pod.yaml, under spec:, add:
  1. Delete and recreate the pod from the edited manifest (works only for pods not managed by a controller like Deployment/ReplicaSet/DaemonSet; for those, edit the controller instead—see Manual Steps section):
  1. Verification (same scope as the audit):