github.com/khulnasoft-lab/defsec@v1.0.5-0.20230827010352-5e9f46893d95/rules/kubernetes/policies/pss/restricted/4_runs_with_a_root_uid.rego (about) 1 # METADATA 2 # title: "Containers must not set runAsUser to 0" 3 # description: "Containers should be forbidden from running with a root UID." 4 # scope: package 5 # schemas: 6 # - input: schema["kubernetes"] 7 # related_resources: 8 # - https://kubernetes.io/docs/concepts/security/pod-security-standards/#restricted 9 # custom: 10 # id: KSV105 11 # avd_id: AVD-KSV-0105 12 # severity: LOW 13 # short_code: containers-not-run-as-root 14 # recommended_action: "Set 'securityContext.runAsUser' to a non-zero integer or leave undefined." 15 # input: 16 # selector: 17 # - type: kubernetes 18 package builtin.kubernetes.KSV105 19 20 import data.lib.kubernetes 21 import data.lib.utils 22 23 failRootUserId[securityContext] { 24 container := kubernetes.containers[_] 25 securityContext := container.securityContext 26 securityContext.runAsUser == 0 27 } 28 29 failRootUserId[securityContext] { 30 pod := kubernetes.pods[_] 31 securityContext := pod.spec.securityContext 32 securityContext.runAsUser == 0 33 } 34 35 deny[res] { 36 cause := failRootUserId[_] 37 msg := "securityContext.runAsUser should be set to a value greater than 0" 38 res := result.new(msg, cause) 39 }