pod-run-as-user
Running a pod as UID 0 gives every process the in-container root identity, so writable host mounts, setuid binaries and isolation weaknesses become exploitable with root file ownership and the full capability set.
!has(object.spec.securityContext) || !has(object.spec.securityContext.runAsUser) || object.spec.securityContext.runAsUser > 0
spec.securityContext.runAsUser must be undefined or a non-zero value (> 0).
Set runAsUser to a non-zero UID such as 1000, or leave it unset so the image user applies. Field: spec.securityContext.runAsUser.
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicy
metadata:
name: pod-run-as-user
annotations:
kubeapt.io/uuid: "d950f1c9-b31f-47b1-bc31-86901ff9dda8"
security.kubeapt.io/displayName: "Runs as Root (UID 0)"
security.kubeapt.io/description: "Running a pod as UID 0 gives every process the in-container root identity, so writable host mounts, setuid binaries and isolation weaknesses become exploitable with root file ownership and the full capability set."
security.kubeapt.io/resource: "Pods"
security.kubeapt.io/severity: "Moderate"
security.kubeapt.io/remediation: "Set runAsUser to a non-zero UID such as 1000, or leave it unset so the image user applies. Field: spec.securityContext.runAsUser."
security.kubeapt.io/product: "Kubernetes"
spec:
failurePolicy: Fail
matchConstraints:
resourceRules:
- apiGroups:
- ''
apiVersions:
- v1
operations:
- CREATE
- UPDATE
resources:
- pods
validations:
- expression: |
!has(object.spec.securityContext) || !has(object.spec.securityContext.runAsUser) || object.spec.securityContext.runAsUser > 0
message: |
spec.securityContext.runAsUser must be undefined or a non-zero value (> 0).Save it as pod-run-as-user.yaml — the commands below assume that name.
Check a workload against this one policy, before anything is installed on a cluster.
$ kubeapt validate -p ./pod-run-as-user.yaml -r ./workload.yamlOr without the file, from the published policy set — -r takes a directory too:
$ kubeapt policies download && kubeapt validate --policy-name pod-run-as-user -r ./manifestsOr against every namespace in the cluster your kubeconfig points at:
$ kubeapt validate --policy-name pod-run-as-user -A