Kubernetes ships with a capable, deny-by-default authorization model: no subject can do anything until a role grants it. That is the good news. The bad news is how quickly real clusters erode it: a cluster-admin binding handed out to unblock a deployment, a wildcard verb copied from a Stack Overflow answer, a service account token mounted into pods that never call the API. Getting RBAC right depends less on knowing the API objects than on resisting the small, reasonable-looking grants that add up to a flat trust model.
RBAC has four objects and one rule. Roles and ClusterRoles are sets of permissions, verbs (get, list, create and so on) on resources (pods, secrets and so on). RoleBindings and ClusterRoleBindings attach those permission sets to subjects: users, groups, or service accounts. A Role is namespaced; a ClusterRole is cluster-wide. The one rule: permissions are purely additive and there are no deny rules, so the effective access of any subject is the union of everything bound to it.
The three grants that flatten a cluster
cluster-adminto humans and service accounts. It gives full control of the whole cluster, so every binding to it turns one leaked credential into a full compromise. Reserve it for break-glass use.- Wildcards.
verbs: ["*"]orresources: ["*"]grants permissions you did not consciously decide to give, including on resource types that did not exist when you wrote the rule. - Broad
secretsaccess.get/listonsecretsin a namespace hands over every credential in it. And the right tocreatepods often equals the right to read secrets, because a pod can mount them.
The privilege-escalation edges people miss
Some permissions are more dangerous than they look because they are transitive. The verb escalate lets a subject grant itself permissions it does not already hold; bind lets it attach existing roles to new subjects; impersonate lets it act as another user or group entirely. Rights over workload controllers (Deployments, DaemonSets, Jobs) are effectively rights to run arbitrary pods, which can lead to node-level access. And anyone who can create a pod with a chosen service account inherits that account's permissions. Auditing RBAC means reasoning about these reachability edges as well as reading role names, and tooling that computes the closure over those edges does this at scale.
Working practices that hold up
- Start from zero and add. Grant the specific verbs on the specific resources a workload needs, scoped to a namespace with a Role wherever a ClusterRole is not truly required.
- One service account per workload. Never share the default. Set
automountServiceAccountToken: falseon pods that make no API calls, which includes most application pods. - Prefer groups for humans. Bind roles to groups from your identity provider, not individual users, so access follows joiners and leavers automatically.
- Review the dangerous verbs explicitly. Regularly enumerate who holds
escalate,bind,impersonate, secret access, and pod-create, and justify each. - Audit continuously. Use
kubectl auth can-i --listand RBAC analysis tooling to see effective permissions, and alert on new bindings to privileged roles.
metadata: { namespace: payments, name: app-reader }
rules:
- apiGroups: [""]
resources: ["configmaps"]
resourceNames: ["app-config"] # scoped to one object, one verb
verbs: ["get"]
RBAC is never finished. It is a standing practice of granting narrowly and reviewing often, against the entropy that pulls every cluster toward flat, over-permissioned trust. It also presupposes you know what is running: an unaudited workload with a mounted admin token is a privilege-escalation path you cannot close because you cannot see it. You cannot scope access for a service account you never knew existed.