← Policy catalog
</> ValidatingAdmissionPolicy · Apache-2.0

Binds a Privileged Role to the Default ServiceAccount

rolebinding-default-serviceaccount

severityModerate resourceRoleBindings productKubernetes bundles1

Every pod that names no ServiceAccount runs as default, so a RoleBinding to it shares the granted namespace permissions across every unrelated workload there and one compromised container immediately gains them all.

Rejects unless

!has(object.subjects) || object.subjects.all(s,
  !(s.kind == "ServiceAccount" && s.name == "default")
)

Do not bind powerful roles to the default ServiceAccount.

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.

Applies to

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

Manifest

apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicy
metadata:
  name: rolebinding-default-serviceaccount
  annotations:
    kubeapt.io/uuid: "f715428d-63e6-4690-8e54-8da84f12fa51"
    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 RoleBinding to it shares the granted namespace permissions across every unrelated workload there and one compromised container immediately gains them all."
    security.kubeapt.io/resource: "RoleBindings"
    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:
      - rolebindings
  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 rolebinding-default-serviceaccount.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-default-serviceaccount.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-default-serviceaccount -r ./manifests

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

$ kubeapt validate --policy-name rolebinding-default-serviceaccount -A