← Policy catalog
</> ValidatingAdmissionPolicy · Apache-2.0

Runs With the Root Group (GID 0)

pod-run-as-group

severityModerate resourcePods productKubernetes bundles1

A pod running with GID 0 places its processes in the root group, which owns or can write many files in images and mounted host volumes, widening what a compromised process reaches.

Rejects unless

!has(object.spec.securityContext) || !has(object.spec.securityContext.runAsGroup) || object.spec.securityContext.runAsGroup > 0

spec.securityContext.runAsGroup must be undefined or a non-zero value (> 0).

Remediation

Set runAsGroup to a non-zero GID such as 1000, or leave it unset. Field: spec.securityContext.runAsGroup.

Applies to

  • pods · v1 · CREATE, UPDATE

Manifest

apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicy
metadata:
  name: pod-run-as-group
  annotations:
    kubeapt.io/uuid: "3b7b754a-0c21-4bf4-bbb4-aaed4b8a5e91"
    security.kubeapt.io/displayName: "Runs With the Root Group (GID 0)"
    security.kubeapt.io/description: "A pod running with GID 0 places its processes in the root group, which owns or can write many files in images and mounted host volumes, widening what a compromised process reaches."
    security.kubeapt.io/resource: "Pods"
    security.kubeapt.io/severity: "Moderate"
    security.kubeapt.io/remediation: "Set runAsGroup to a non-zero GID such as 1000, or leave it unset. Field: spec.securityContext.runAsGroup."
    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.runAsGroup) || object.spec.securityContext.runAsGroup > 0
    message: |
      spec.securityContext.runAsGroup must be undefined or a non-zero value (> 0).

Save it as pod-run-as-group.yaml — the commands below assume that name.

Validate with kubeapt

Check a workload against this one policy, before anything is installed on a cluster.

$ kubeapt validate -p ./pod-run-as-group.yaml -r ./workload.yaml

Or without the file, from the published policy set — -r takes a directory too:

$ kubeapt policies download && kubeapt validate --policy-name pod-run-as-group -r ./manifests

Or against every namespace in the cluster your kubeconfig points at:

$ kubeapt validate --policy-name pod-run-as-group -A