← Policy catalog
</> ValidatingAdmissionPolicy · Apache-2.0

Grants Write Access to PersistentVolumeClaims

clusterrole-pvc-write

severityModerate resourceClusterRoles productKubernetes bundles1

Creating PersistentVolumeClaims in any namespace can bind a volume that still holds data from another workload into an attacker-controlled pod, while delete destroys the backing data and unbounded provisioning exhausts the storage quota.

Rejects unless

!has(object.rules) || object.rules.all(r,
  !(has(r.apiGroups) && has(r.resources) && has(r.verbs) &&
    r.apiGroups.exists(ag, ag == "") &&
    r.resources.exists(res, res == "persistentvolumeclaims") &&
    r.verbs.exists(v, v in ["create","update","patch","delete"]))
)

ClusterRoles must not grant create/update/patch/delete on PersistentVolumeClaims without tight controls.

Remediation

Remove create, update, patch and delete from every rule covering persistentvolumeclaims in the core API group, leaving get, list and watch where a workload only needs to inspect them. Fields: rules[*].apiGroups, rules[*].resources, rules[*].verbs.

Applies to

  • clusterroles · rbac.authorization.k8s.io/v1 · CREATE, UPDATE

Manifest

apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicy
metadata:
  name: clusterrole-pvc-write
  annotations:
    kubeapt.io/uuid: "269e256d-3917-4e36-9de2-ea79619ab700"
    security.kubeapt.io/displayName: "Grants Write Access to PersistentVolumeClaims"
    security.kubeapt.io/description: "Creating PersistentVolumeClaims in any namespace can bind a volume that still holds data from another workload into an attacker-controlled pod, while delete destroys the backing data and unbounded provisioning exhausts the storage quota."
    security.kubeapt.io/resource: "ClusterRoles"
    security.kubeapt.io/severity: "Moderate"
    security.kubeapt.io/remediation: "Remove create, update, patch and delete from every rule covering persistentvolumeclaims in the core API group, leaving get, list and watch where a workload only needs to inspect them. Fields: rules[*].apiGroups, rules[*].resources, rules[*].verbs."
    security.kubeapt.io/product: "Kubernetes"
spec:
  failurePolicy: Fail
  matchConstraints:
    resourceRules:
    - apiGroups:
      - rbac.authorization.k8s.io
      apiVersions:
      - v1
      operations:
      - CREATE
      - UPDATE
      resources:
      - clusterroles
  validations:
  - expression: |
      !has(object.rules) || object.rules.all(r,
        !(has(r.apiGroups) && has(r.resources) && has(r.verbs) &&
          r.apiGroups.exists(ag, ag == "") &&
          r.resources.exists(res, res == "persistentvolumeclaims") &&
          r.verbs.exists(v, v in ["create","update","patch","delete"]))
      )
    message: |
      ClusterRoles must not grant create/update/patch/delete on PersistentVolumeClaims without tight controls.

Save it as clusterrole-pvc-write.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 ./clusterrole-pvc-write.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 clusterrole-pvc-write -r ./manifests

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

$ kubeapt validate --policy-name clusterrole-pvc-write -A