← Policy catalog
</> ValidatingAdmissionPolicy · Apache-2.0

Grants Write Access to RBAC Resources

clusterrole-rbac-write

severityHigh resourceClusterRoles productKubernetes bundles1

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.

Rejects unless

!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.

Variables

rbacResources

["roles","rolebindings","clusterroles","clusterrolebindings"]

rbacWriteVerbs

["create","update","patch","delete","bind","escalate"]

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.

Applies to

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

Manifest

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.

Validate with kubeapt

Check a workload against this one policy, before anything is installed on a cluster.

$ kubeapt validate -p ./clusterrole-rbac-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-rbac-write -r ./manifests

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

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