rolebinding-anonymous-subjects
Binding a role to system:anonymous hands its namespace permissions to every unauthenticated caller that reaches the API server, and catch-all names like everyone or all-users leave nobody accountable for who exercises them.
!has(object.subjects) || object.subjects.all(s,
!(s.kind == "User" && variables.anonymousNames.exists(n, n == s.name))
)
RoleBindings 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: rolebinding-anonymous-subjects
annotations:
kubeapt.io/uuid: "369f4d61-481b-4213-89c7-4d0dbeaa3121"
security.kubeapt.io/displayName: "Binds a Role to an Anonymous Identity"
security.kubeapt.io/description: "Binding a role to system:anonymous hands its namespace permissions to every unauthenticated caller that reaches the API server, and catch-all names like everyone or all-users leave nobody accountable for who exercises them."
security.kubeapt.io/resource: "RoleBindings"
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:
- rolebindings
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: |
RoleBindings must not bind roles to anonymous or broadly shared user identities.Save it as rolebinding-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 ./rolebinding-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 rolebinding-anonymous-subjects -r ./manifestsOr against every namespace in the cluster your kubeconfig points at:
$ kubeapt validate --policy-name rolebinding-anonymous-subjects -A