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
HighAddress
SecurityCompliance Standards
- Cloudanix Best Practice
Triage and Remediation
- Remediation
Remediation
Manual Steps
Manual Steps
-
On any machine with kubectl access, list non-compliant pods using the audit command and capture the output for reference:
-
For each non-compliant pod that is managed by a higher-level controller (Deployment, StatefulSet, DaemonSet, Job, CronJob), identify its owner and edit that resource to set
runAsNonRoot: trueat the pod level. Example for a Deployment owner in namespacemy-namespacenamedmy-app(replace with actual values fromowner=in the audit output):In the opened manifest, underspec.template.spec, add or update:Save and exit to apply the change. -
If you prefer to patch instead of interactive edit, on any machine with kubectl access run a JSON patch for each affected controller. Example for the same Deployment (adjust kind/name/namespace per resource):
-
For non-compliant pods that are not controlled by a higher-level resource (no
owner=field in the audit output), retrieve the current pod manifest and recreate it withrunAsNonRoot: trueset. On any machine with kubectl access:Edit/tmp/my-pod.yamland underspecadd:Then delete and recreate the pod (it will not be automatically recreated because it has no controller): -
If any container must explicitly override the pod-level setting, ensure each container and initContainer that should be non-root has
securityContext.runAsNonRoot: truedefined. In the relevant controller or pod manifest, under each container:Apply the updated manifest using: -
After changes have rolled out and pods are running with updated specs, verify compliance from any machine with kubectl access by re-running the audit command and confirming no
is_compliant=falselines remain:
Using kubectl
Using kubectl
On any machine with kubectl access:Edit Apply:Example: Deployment (container-level DaemonSet:Job:CronJob:Edit or per container:Delete fields that must not be reused (
-
Identify non-compliant pods (from the audit output you already have) and note their controllers (Deployment/StatefulSet/DaemonSet/Job/CronJob) if present in the
owner=field. Always fix the controller, not the live Pod. -
Edit the owning controller manifest and add
runAsNonRoot: trueundersecurityContextat the pod level (preferred) or per container.
securityContext)/tmp/deploy-nonroot.yaml and under spec.template.spec add:securityContext if you cannot set pod-level)- Repeat the same pattern for other controller types:
- For standalone Pods (no
owner=in audit output), recreate them with a manifest that includesrunAsNonRoot: true:
/tmp/pod-nonroot.yaml to add:status, metadata.uid, metadata.resourceVersion, metadata.creationTimestamp, metadata.managedFields), then:- Verification (on any machine with kubectl):
Automation
Automation

