For AI agents: A markdown version of this page is available at https://docs.datadoghq.com/security/code_security/iac_security/iac_rules/kubernetes-root-containers-admitted.md.
A documentation index is available at /llms.txt.
To ensure containers do not run with root privileges:
Set privileged, allowPrivilegeEscalation, and readOnlyRootFilesystem to false.
Set runAsUser.rule to MustRunAsNonRoot.
Configure fsGroup and supplementalGroups with MustRunAs, ensuring the root range (GID 0) and root group are not permitted.
Compliant Code Examples
#this code is a correct code for which the query should not find any resultapiVersion:policy/v1beta1kind:PodSecurityPolicymetadata:name:restrictedannotations:seccomp.security.alpha.kubernetes.io/allowedProfileNames:'docker/default,runtime/default'apparmor.security.beta.kubernetes.io/allowedProfileNames:'runtime/default'seccomp.security.alpha.kubernetes.io/defaultProfileName:'runtime/default'apparmor.security.beta.kubernetes.io/defaultProfileName:'runtime/default'spec:privileged:false# Required to prevent escalations to root.allowPrivilegeEscalation:false# This is redundant with non-root + disallow privilege escalation,# but we can provide it for defense in depth.requiredDropCapabilities:- ALL# Allow core volume types.volumes:- 'configMap'- 'emptyDir'- 'projected'- 'secret'- 'downwardAPI'# Assume that persistentVolumes set up by the cluster admin are safe to use.- 'persistentVolumeClaim'hostNetwork:falsehostIPC:falsehostPID:falserunAsUser:# Require the container to run without root privileges.rule:'MustRunAsNonRoot'seLinux:# This policy assumes the nodes are using AppArmor rather than SELinux.rule:'RunAsAny'supplementalGroups:rule:'MustRunAs'ranges:# Forbid adding the root group.- min:1max:65535fsGroup:rule:'MustRunAs'ranges:# Forbid adding the root group.- min:1max:65535readOnlyRootFilesystem:true
Non-Compliant Code Examples
#this is a problematic code where the query should report a result(s)apiVersion:policy/v1beta1kind:PodSecurityPolicymetadata:name:restrictedannotations:seccomp.security.alpha.kubernetes.io/allowedProfileNames:'docker/default,runtime/default'apparmor.security.beta.kubernetes.io/allowedProfileNames:'runtime/default'seccomp.security.alpha.kubernetes.io/defaultProfileName:'runtime/default'apparmor.security.beta.kubernetes.io/defaultProfileName:'runtime/default'spec:privileged:trueallowPrivilegeEscalation:truerequiredDropCapabilities:- ALLvolumes:- 'configMap'- 'emptyDir'- 'projected'- 'secret'- 'downwardAPI'- 'persistentVolumeClaim'hostNetwork:falsehostIPC:falsehostPID:falserunAsUser:rule:'RunAsAny'seLinux:rule:'RunAsAny'supplementalGroups:rule:'RunAsAny'fsGroup:rule:'MustRunAs'ranges:- min:0max:65535
1
2
rulesets:- Kubernetes # Rules to enforce .
Request a personalized demo
Get Started with Datadog
Ask AI
AI-generated responses may be inaccurate. Verify important info.