Skip to content
StackDecode
AdvancedLesson 22 of 35

RBAC and ServiceAccounts

Who can do what to which resources.

  • Role / ClusterRole: a set of permissions (verbs on resources).
  • RoleBinding / ClusterRoleBinding: grants a Role to a user, group or ServiceAccount.
  • ServiceAccount: the identity a pod uses to call the API.
yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata: { name: pod-reader, namespace: staging }
rules:
  - apiGroups: ['']
    resources: ['pods']
    verbs: ['get', 'list', 'watch']
bash
kubectl auth can-i list pods --as system:serviceaccount:staging:ci -n staging

Follow least privilege: avoid cluster-admin and wildcards, and give each workload its own ServiceAccount.