rolebinding-system-groups
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.
!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).
riskyGroups
["system:authenticated","system:unauthenticated","system:serviceaccounts"]
Replace the system group subject with the specific users, groups or ServiceAccounts that need the role. Fields: subjects[*].kind, subjects[*].name.
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.
Check a workload against this one policy, before anything is installed on a cluster.
$ kubeapt validate -p ./rolebinding-system-groups.yaml -r ./workload.yamlOr without the file, from the published policy set — -r takes a directory too:
$ kubeapt policies download && kubeapt validate --policy-name rolebinding-system-groups -r ./manifestsOr against every namespace in the cluster your kubeconfig points at:
$ kubeapt validate --policy-name rolebinding-system-groups -A