clusterrole-rbac-write
Write, bind or escalate permission over RBAC objects lets the grantee author new roles and bindings for itself, turning a limited account into cluster-admin without stealing any other credential.
!has(object.rules) || object.rules.all(r,
!(has(r.apiGroups) && has(r.resources) && has(r.verbs) &&
r.apiGroups.exists(ag, ag == "rbac.authorization.k8s.io") &&
r.resources.exists(res, variables.rbacResources.exists(rr, rr == res)) &&
r.verbs.exists(v, variables.rbacWriteVerbs.exists(rv, rv == v))
)
)
ClusterRoles must not grant write/bind/escalate on RBAC resources.
rbacResources
["roles","rolebindings","clusterroles","clusterrolebindings"]
rbacWriteVerbs
["create","update","patch","delete","bind","escalate"]
Drop create, update, patch, delete, bind and escalate from every rule covering roles, rolebindings, clusterroles or clusterrolebindings, leaving only the read verbs the workload needs. Fields: rules[*].apiGroups, rules[*].resources, rules[*].verbs.
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicy
metadata:
name: clusterrole-rbac-write
annotations:
kubeapt.io/uuid: "6024fa30-ba1d-4c34-adda-fa9fd967bb42"
security.kubeapt.io/displayName: "Grants Write Access to RBAC Resources"
security.kubeapt.io/description: "Write, bind or escalate permission over RBAC objects lets the grantee author new roles and bindings for itself, turning a limited account into cluster-admin without stealing any other credential."
security.kubeapt.io/resource: "ClusterRoles"
security.kubeapt.io/severity: "High"
security.kubeapt.io/remediation: "Drop create, update, patch, delete, bind and escalate from every rule covering roles, rolebindings, clusterroles or clusterrolebindings, leaving only the read verbs the workload needs. 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
variables:
- name: rbacResources
expression: |
["roles","rolebindings","clusterroles","clusterrolebindings"]
- name: rbacWriteVerbs
expression: |
["create","update","patch","delete","bind","escalate"]
validations:
- expression: |
!has(object.rules) || object.rules.all(r,
!(has(r.apiGroups) && has(r.resources) && has(r.verbs) &&
r.apiGroups.exists(ag, ag == "rbac.authorization.k8s.io") &&
r.resources.exists(res, variables.rbacResources.exists(rr, rr == res)) &&
r.verbs.exists(v, variables.rbacWriteVerbs.exists(rv, rv == v))
)
)
message: |
ClusterRoles must not grant write/bind/escalate on RBAC resources.Save it as clusterrole-rbac-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 ./clusterrole-rbac-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 clusterrole-rbac-write -r ./manifestsOr against every namespace in the cluster your kubeconfig points at:
$ kubeapt validate --policy-name clusterrole-rbac-write -A