clusterrolebinding-anonymous-subjects
Binding a ClusterRole to system:anonymous grants it cluster-wide to every unauthenticated caller that reaches the API server, and catch-all names like everyone or all-users leave nobody accountable for who exercises it.
!has(object.subjects) || object.subjects.all(s,
!(s.kind == "User" && variables.anonymousNames.exists(n, n == s.name))
)
ClusterRoleBindings must not bind roles to anonymous or broadly shared user identities.
anonymousNames
["system:anonymous","everyone","all-users"]
Replace the anonymous or shared user subject with the specific named users, groups or ServiceAccounts that need the role. Fields: subjects[*].kind, subjects[*].name.
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicy
metadata:
name: clusterrolebinding-anonymous-subjects
annotations:
kubeapt.io/uuid: "2cf111fd-543c-4375-aca7-a3ffd4e6f700"
security.kubeapt.io/displayName: "Binds a Role to an Anonymous Identity"
security.kubeapt.io/description: "Binding a ClusterRole to system:anonymous grants it cluster-wide to every unauthenticated caller that reaches the API server, and catch-all names like everyone or all-users leave nobody accountable for who exercises it."
security.kubeapt.io/resource: "ClusterRoleBindings"
security.kubeapt.io/severity: "Moderate"
security.kubeapt.io/remediation: "Replace the anonymous or shared user subject with the specific named 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
variables:
- name: anonymousNames
expression: |
["system:anonymous","everyone","all-users"]
validations:
- expression: |
!has(object.subjects) || object.subjects.all(s,
!(s.kind == "User" && variables.anonymousNames.exists(n, n == s.name))
)
message: |
ClusterRoleBindings must not bind roles to anonymous or broadly shared user identities.Save it as clusterrolebinding-anonymous-subjects.yaml — the commands below assume that name.
Check a workload against this one policy, before anything is installed on a cluster.
$ kubeapt validate -p ./clusterrolebinding-anonymous-subjects.yaml -r ./workload.yamlOr without the file, from the published policy set — -r takes a directory too:
$ kubeapt policies download && kubeapt validate --policy-name clusterrolebinding-anonymous-subjects -r ./manifestsOr against every namespace in the cluster your kubeconfig points at:
$ kubeapt validate --policy-name clusterrolebinding-anonymous-subjects -A