← Policy catalog
</> ValidatingAdmissionPolicy · Apache-2.0

Binds a Privileged Role to a System Group

clusterrolebinding-system-groups

severityModerate resourceClusterRoleBindings productKubernetes bundles1

Binding a ClusterRole to a system group grants it cluster-wide to a whole population at once, and groups like system:authenticated or system:serviceaccounts cover every account in the cluster including ones an attacker controls.

Rejects unless

!has(object.subjects) || object.subjects.all(s,
  !(s.kind == "Group" && s.name.matches("system:.*"))
)

ClusterRoleBindings must not bind powerful roles to broad system groups (authenticated/unauthenticated/serviceaccounts).

Remediation

Replace the system group subject with the specific users, groups or ServiceAccounts that need the role. Fields: subjects[*].kind, subjects[*].name.

Applies to

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

Manifest

apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicy
metadata:
  name: clusterrolebinding-system-groups
  annotations:
    kubeapt.io/uuid: "48b8600b-24d9-49f1-b74c-e2f6d9f55659"
    security.kubeapt.io/displayName: "Binds a Privileged Role to a System Group"
    security.kubeapt.io/description: "Binding a ClusterRole to a system group grants it cluster-wide to a whole population at once, and groups like system:authenticated or system:serviceaccounts cover every account in the cluster including ones an attacker controls."
    security.kubeapt.io/resource: "ClusterRoleBindings"
    security.kubeapt.io/severity: "Moderate"
    security.kubeapt.io/remediation: "Replace the system group subject with the specific users, groups or ServiceAccounts that need the role. Fields: subjects[*].kind, subjects[*].name."
    security.kubeapt.io/product: "Kubernetes"
spec:
  failurePolicy: Fail
  matchConstraints:
    resourceRules:
    - apiGroups:
      - rbac.authorization.k8s.io
      apiVersions:
      - v1
      operations:
      - CREATE
      - UPDATE
      resources:
      - clusterrolebindings
  validations:
  - expression: |
      !has(object.subjects) || object.subjects.all(s,
        !(s.kind == "Group" && s.name.matches("system:.*"))
      )
    message: |
      ClusterRoleBindings must not bind powerful roles to broad system groups (authenticated/unauthenticated/serviceaccounts).

Save it as clusterrolebinding-system-groups.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 ./clusterrolebinding-system-groups.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 clusterrolebinding-system-groups -r ./manifests

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

$ kubeapt validate --policy-name clusterrolebinding-system-groups -A