← Policy catalog
</> ValidatingAdmissionPolicy · Apache-2.0

Binds a Privileged Role to a System Group

rolebinding-system-groups

severityModerate resourceRoleBindings productKubernetes bundles1

Naming system:authenticated, system:unauthenticated or system:serviceaccounts as a subject grants the role to every account in the cluster at once, so the namespace permissions extend to anyone who can reach the API server.

Rejects unless

!has(object.subjects) || object.subjects.all(s,
  !(s.kind == "Group" && variables.riskyGroups.exists(g, g == s.name))
)

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

Variables

riskyGroups

["system:authenticated","system:unauthenticated","system: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

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

Manifest

apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicy
metadata:
  name: rolebinding-system-groups
  annotations:
    kubeapt.io/uuid: "d92ff4b2-9bd9-417b-af8b-dffedcc93e43"
    security.kubeapt.io/displayName: "Binds a Privileged Role to a System Group"
    security.kubeapt.io/description: "Naming system:authenticated, system:unauthenticated or system:serviceaccounts as a subject grants the role to every account in the cluster at once, so the namespace permissions extend to anyone who can reach the API server."
    security.kubeapt.io/resource: "RoleBindings"
    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:
      - rolebindings
  variables:
  - name: riskyGroups
    expression: |
      ["system:authenticated","system:unauthenticated","system:serviceaccounts"]
  validations:
  - expression: |
      !has(object.subjects) || object.subjects.all(s,
        !(s.kind == "Group" && variables.riskyGroups.exists(g, g == s.name))
      )
    message: |
      RoleBindings must not bind powerful roles to broad system groups (authenticated/unauthenticated/serviceaccounts).

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

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

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