role-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 full control of the namespace without stealing any other credential.
!has(object.rules) || object.rules.all(r,
!(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))
)
)
Roles must not grant write/bind/escalate permissions 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: role-rbac-write
annotations:
kubeapt.io/uuid: "2b67fb51-a58c-4a4e-8888-bb4eb1a00ef6"
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 full control of the namespace without stealing any other credential."
security.kubeapt.io/resource: "Roles"
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:
- roles
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,
!(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: |
Roles must not grant write/bind/escalate permissions on RBAC resources.Save it as role-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 ./role-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 role-rbac-write -r ./manifestsOr against every namespace in the cluster your kubeconfig points at:
$ kubeapt validate --policy-name role-rbac-write -A