ServiceAccount name not specified

A missing or empty serviceAccountName uses the namespace’s default ServiceAccount, which may have unintended permissions.

Description

If a Pod omits serviceAccountName or leaves it empty, Kubernetes assigns the default ServiceAccount in that namespace.

Potential impact

Workloads sharing the default account can use any API permissions granted to it. Their requests can be hard to distinguish in audit logs.

Remediation

  • Create a dedicated ServiceAccount in the workload’s namespace and grant only the RBAC permissions it needs.
  • Set its name on the Pod or Pod template. Check the account assigned to a newly created Pod and the operations it can perform.

Examples

Use your deployment images in place of the examples. Create the build-robot account separately.

Before

yaml
apiVersion: v1
kind: Pod
metadata:
  name: nginx3
spec:
  containers:
    - image: nginx3
      name: nginx3
  serviceAccountName: ""

After

yaml
apiVersion: v1
kind: Pod
metadata:
  name: nginx
spec:
  containers:
    - image: nginx
      name: nginx
  serviceAccountName: build-robot

Explanation:

  • Before: The empty name assigns the default account to the nginx3 Pod.
  • After: The new nginx Pod uses the permissions granted to build-robot.

References