ServiceAccount shared between workloads

Sharing one ServiceAccount across different workloads can make permission separation and incident investigation harder.

Description

Pods using the same serviceAccountName in a namespace share API permissions even when they receive separate Pod-bound tokens. Replicas of one application can share an account if they need the same access.

Potential impact

When workloads need different permissions, either can use grants intended for the other. A token exposed by one Pod puts the shared account’s resources at risk, and requests can be difficult to attribute.

Remediation

Assign separate ServiceAccounts to workloads with different access requirements. Check each account’s role bindings and verify it can perform only the operations it needs.

Examples

Both Pods run in the same namespace. Create the referenced accounts and role bindings first.

Before

yaml
apiVersion: v1
kind: Pod
metadata:
  name: pod1
spec:
  serviceAccountName: service1
  containers:
    - name: mycontainer
      image: redis
---
apiVersion: v1
kind: Pod
metadata:
  name: pod2
spec:
  serviceAccountName: service1
  containers:
    - name: envars-test-container
      image: nginx

After

yaml
apiVersion: v1
kind: Pod
metadata:
  name: pod1
spec:
  serviceAccountName: service1
  containers:
    - name: mycontainer
      image: redis
---
apiVersion: v1
kind: Pod
metadata:
  name: pod2
spec:
  serviceAccountName: service2
  containers:
    - name: envars-test-container
      image: nginx

Explanation:

  • Before: Both pod1 and pod2 use the permissions of service1.
  • After: pod2 now uses service2. Give each account bindings that reflect its Pod’s needs.

References