← Policy catalog
</> ValidatingAdmissionPolicy · Apache-2.0

Sets Volume Ownership to the Root Group (GID 0)

pod-fsgroup

severityLow resourcePods productKubernetes bundles1

An fsGroup of 0 chowns every attached volume to the root group and gives pod processes root group membership, so volume contents and other root-group-owned files become writable by a compromised process.

Rejects unless

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

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

Remediation

Set fsGroup to a non-zero GID such as 2000, or omit it and manage volume ownership in the image. Field: spec.securityContext.fsGroup.

Applies to

  • pods · v1 · CREATE, UPDATE

Manifest

apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicy
metadata:
  name: pod-fsgroup
  annotations:
    kubeapt.io/uuid: "c39ebbef-d72a-4b00-aebf-1ece6992ee7c"
    security.kubeapt.io/displayName: "Sets Volume Ownership to the Root Group (GID 0)"
    security.kubeapt.io/description: "An fsGroup of 0 chowns every attached volume to the root group and gives pod processes root group membership, so volume contents and other root-group-owned files become writable by a compromised process."
    security.kubeapt.io/resource: "Pods"
    security.kubeapt.io/severity: "Low"
    security.kubeapt.io/remediation: "Set fsGroup to a non-zero GID such as 2000, or omit it and manage volume ownership in the image. Field: spec.securityContext.fsGroup."
    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.fsGroup) || object.spec.securityContext.fsGroup > 0
    message: |
      spec.securityContext.fsGroup must be undefined or a non-zero value (> 0).

Save it as pod-fsgroup.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-fsgroup.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-fsgroup -r ./manifests

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

$ kubeapt validate --policy-name pod-fsgroup -A