More Info:
Do not generally permit containers to be run as the root user.Risk Level
CriticalAddress
SecurityCompliance Standards
- CIS Kubernetes
Triage and Remediation
- Remediation
Remediation
Manual Steps
Manual Steps
-
On any machine with kubectl access, list all namespaces and identify those that should strongly forbid root containers (typically all except system namespaces):
Decide which namespaces must enforce non-root (e.g., all except: kube-system, kube-public, kube-node-lease, default if needed for legacy workloads).
-
For each target namespace, inspect existing Pod Security/Admission policy mechanisms to see whether they already prevent root containers:
Review whether any mechanism enforces
runAsNonRoot: trueorrunAsUserranges that exclude UID 0. -
For each policy mechanism in use, examine the detailed rules to confirm they require non-root UIDs:
Verify that they enforce either
MustRunAsNonRoot(or equivalentrunAsNonRoot: true) orMustRunAswith UID ranges that do not include 0 for containers and pods in the target namespaces. -
Where no such enforcement exists for a target namespace, design or update a namespace‑scoped policy to require non‑root containers, using the mechanism your cluster supports. For example, with PodSecurityPolicy still enabled, you might define a PSP that contains:
or:Then bind this policy (or the equivalent Gatekeeper/Kyverno policy) so that it applies to all service accounts in the target namespace.
-
Before enforcing the new or updated policy, audit existing workloads in each namespace to find pods or workloads that currently run as root and would be blocked:
For any listed workloads, review their manifests and application requirements; update them to run as a non‑root UID or formally document and justify an exception.
-
After updating policies and workloads, verify that the policies are active and effective:
- Confirm the policy objects and their bindings/assignments:
- Attempt to deploy a simple pod that runs as root into a target namespace; it should be rejected by admission control. For example:
Confirm that this creation fails and the error message indicates the non‑root requirement from your policy.
- Confirm the policy objects and their bindings/assignments:
Using kubectl
Using kubectl
Using kubectl
1. List all namespaces (scope of review)
Run on: any machine with kubectl access.2. Check PodSecurityPolicies (if PSP is enabled)
.spec.runAsUser:-
Compliant examples:
rule: MustRunAsNonRootrule: MustRunAswithrangeswhere allmin/maxare > 0 (no range including UID 0).
-
Problematic indicators:
rule: RunAsAnyrule: MustRunAswith any range including0(for examplemin: 0ormax: 0or a range spanning 0).
RunAsAny or UID 0.3. Check Pod Security Standards labels on namespaces (if used)
pod-security.kubernetes.io/enforce, pod-security.kubernetes.io/audit, pod-security.kubernetes.io/warn.-
Compliant indicators:
- Namespaces used for general workloads have
enforceset tobaselineorrestricted. - For stronger guarantees against root containers,
restrictedis preferred.
- Namespaces used for general workloads have
-
Problematic indicators:
- Missing
pod-security.kubernetes.io/enforcelabel on application namespaces. enforce=privilegedor no label at all, combined with no other admission mechanism controlling user IDs.
- Missing
4. Inspect common policy controllers (Kyverno, Gatekeeper) for runAsUser rules
If you use Kyverno:runAsUser, runAsNonRoot, or Pod security context:-
Compliant indicators:
- Policies that deny pods where
securityContext.runAsNonRoot=falseorrunAsUser=0. - Policies that require
runAsNonRoot=trueorrunAsUserwithin non-zero ranges.
- Policies that deny pods where
-
Problematic indicators:
- No policies referencing
runAsUserorrunAsNonRoot. - Policies scoped only to a subset of namespaces, leaving important namespaces without protection.
- No policies referencing
5. Spot-check workloads in each namespace for actual root usage
This cannot replace policy, but helps you see current behavior.List all pods in a namespace:.spec.securityContext.runAsUser.spec.securityContext.runAsNonRoot.spec.containers[*].securityContext.runAsUser.spec.containers[*].securityContext.runAsNonRoot
runAsUser: 0anywhere.runAsNonRoot: false.- No
runAsUser/runAsNonRootat pod or container level, and you know there is no enforced policy at namespace/cluster level (from steps 2–4); in that case, root containers are possible and not prevented by admission control.
- The namespace has an admission policy that effectively enforces
MustRunAsNonRootorMustRunAswith UID ranges excluding 0, or - It is currently allowing root containers and needs a stricter policy.
Automation
Automation
- PodSecurity Admission:
- Namespaces with
ENFORCEofprivilegedor-(unset).
- Namespaces with
- PodSecurityPolicy:
- PSP lines ending with
YES (RunAsAny/UNSET allows root)or
YES (MustRunAs ranges include UID 0)orREVIEW (unknown rule).
- PSP lines ending with
- Namespace defaults:
- Any annotation (if present) that sets a default UID of
0or otherwise includes0.
- Any annotation (if present) that sets a default UID of
- Existing Pods:
- Any row in the “Sample of running Pods that are effectively root (UID 0)” table.

