← Policy catalog
</> ValidatingAdmissionPolicy · Apache-2.0

Uses an Aggregation Rule to Inherit Permissions

clusterrole-aggregation

severityModerate resourceClusterRoles productKubernetes bundles1

An aggregated ClusterRole silently absorbs the rules of every ClusterRole carrying a matching label, so anyone able to create a labeled role grows its permissions with no review of the binding.

Rejects unless

!has(object.aggregationRule) || !has(object.aggregationRule.clusterRoleSelectors) || size(object.aggregationRule.clusterRoleSelectors) == 0

ClusterRoles must not use aggregationRule; avoid implicit privilege aggregation.

Remediation

Remove the aggregation block and list the required rules explicitly on the ClusterRole instead. Field: aggregationRule.clusterRoleSelectors.

Applies to

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

Manifest

apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicy
metadata:
  name: clusterrole-aggregation
  annotations:
    kubeapt.io/uuid: "e8429efe-3c57-4656-8155-f2f3423f8a5f"
    security.kubeapt.io/displayName: "Uses an Aggregation Rule to Inherit Permissions"
    security.kubeapt.io/description: "An aggregated ClusterRole silently absorbs the rules of every ClusterRole carrying a matching label, so anyone able to create a labeled role grows its permissions with no review of the binding."
    security.kubeapt.io/resource: "ClusterRoles"
    security.kubeapt.io/severity: "Moderate"
    security.kubeapt.io/remediation: "Remove the aggregation block and list the required rules explicitly on the ClusterRole instead. Field: aggregationRule.clusterRoleSelectors."
    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.aggregationRule) || !has(object.aggregationRule.clusterRoleSelectors) || size(object.aggregationRule.clusterRoleSelectors) == 0
    message: |
      ClusterRoles must not use aggregationRule; avoid implicit privilege aggregation.

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

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

$ kubeapt validate --policy-name clusterrole-aggregation -A