clusterrolebinding-default-serviceaccount
Every pod that names no ServiceAccount runs as default, so a ClusterRoleBinding to it spreads cluster-wide permissions across unrelated workloads in that namespace and any single compromised container inherits them immediately.
!has(object.subjects) || object.subjects.all(s,
!(s.kind == "ServiceAccount" && s.name == "default")
)
Do not bind powerful roles to the default ServiceAccount.
Create a dedicated ServiceAccount for the workload, bind the role to that name, and select it from the pods with spec.serviceAccountName. Fields: subjects[*].kind, subjects[*].name.
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicy
metadata:
name: clusterrolebinding-default-serviceaccount
annotations:
kubeapt.io/uuid: "e56cfce0-5f49-429b-b31e-06796251a1cd"
security.kubeapt.io/displayName: "Binds a Privileged Role to the Default ServiceAccount"
security.kubeapt.io/description: "Every pod that names no ServiceAccount runs as default, so a ClusterRoleBinding to it spreads cluster-wide permissions across unrelated workloads in that namespace and any single compromised container inherits them immediately."
security.kubeapt.io/resource: "ClusterRoleBindings"
security.kubeapt.io/severity: "Moderate"
security.kubeapt.io/remediation: "Create a dedicated ServiceAccount for the workload, bind the role to that name, and select it from the pods with spec.serviceAccountName. 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 == "ServiceAccount" && s.name == "default")
)
message: |
Do not bind powerful roles to the default ServiceAccount.Save it as clusterrolebinding-default-serviceaccount.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-default-serviceaccount.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-default-serviceaccount -r ./manifestsOr against every namespace in the cluster your kubeconfig points at:
$ kubeapt validate --policy-name clusterrolebinding-default-serviceaccount -A