Kubernetes RBAC and service accounts
Identify the caller and permission
Kubernetes authenticates a caller before authorization. A ServiceAccount represents a workload identity in a namespace. Role-based access control (RBAC) grants verbs on API resources; a RoleBinding attaches a Role or ClusterRole to subjects within a namespace. A ClusterRoleBinding grants at cluster scope.
Read a narrow role
Static example, not to apply: a Role in reports allows only get on ConfigMap named layout; a RoleBinding in reports refers to that Role and the reports/renderer ServiceAccount. The role rules are:
apiGroups: [""]resources: [configmaps]resourceNames: [layout]verbs: [get]These are fields of one rule, not a complete Role. With only this grant, reading layout in reports is permitted; listing all ConfigMaps or reading a Secret has no matching grant.
Scope and identity lifetime
RBAC grants accumulate; a narrow Role does not cancel a broader binding. Review every applicable binding and authorizer. A workload that never calls the API can set automountServiceAccountToken: false on its Pod. Where needed, use bounded projected tokens with suitable audience and expiry. Federation to an external service is a separate trust and authorization decision; a valid Kubernetes token does not automatically grant cloud access.
Avoid overgranting
Do not grant all verbs and resources simply because one read failed. Namespace names alone do not provide strong tenant isolation. Review access to workload creation as sensitive because workloads can receive identities and mounted data. Avoid long-lived service account token secrets. Confirm that the approved workflow still functions after reducing access.
Practice with an authorization matrix
For the role above, compare get layout in reports, get layout in billing, and update layout in reports. Only the first matches. Write a negative and a positive test and state which other bindings must be reviewed. Use chapter 21 for authorization regression tests and chapter 33 for workload identity.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Kubernetes RBAC and service accounts — knowledge check
Review container trust, runtime, access and telemetry.
What is a ServiceAccount?
What happens to matching RBAC grants?
Which scope does a RoleBinding grant within?
What should a Pod with no API need consider?
Which action matches a grant of get configmaps/layout in reports?