role-pvc-write
Creating PersistentVolumeClaims in the 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.
!has(object.rules) || object.rules.all(r,
!(r.apiGroups.exists(ag, ag == "") &&
r.resources.exists(res, res == "persistentvolumeclaims") &&
r.verbs.exists(v, v in ["create","update","patch","delete"]))
)
Roles must not grant create/update/patch/delete on PersistentVolumeClaims without tight controls.
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.
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicy
metadata:
name: role-pvc-write
annotations:
kubeapt.io/uuid: "ae1a5db5-99a9-46bc-84b6-aa2d175767ef"
security.kubeapt.io/displayName: "Grants Write Access to PersistentVolumeClaims"
security.kubeapt.io/description: "Creating PersistentVolumeClaims in the 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: "Roles"
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:
- roles
validations:
- expression: |
!has(object.rules) || object.rules.all(r,
!(r.apiGroups.exists(ag, ag == "") &&
r.resources.exists(res, res == "persistentvolumeclaims") &&
r.verbs.exists(v, v in ["create","update","patch","delete"]))
)
message: |
Roles must not grant create/update/patch/delete on PersistentVolumeClaims without tight controls.Save it as role-pvc-write.yaml — the commands below assume that name.
Check a workload against this one policy, before anything is installed on a cluster.
$ kubeapt validate -p ./role-pvc-write.yaml -r ./workload.yamlOr without the file, from the published policy set — -r takes a directory too:
$ kubeapt policies download && kubeapt validate --policy-name role-pvc-write -r ./manifestsOr against every namespace in the cluster your kubeconfig points at:
$ kubeapt validate --policy-name role-pvc-write -A