Explain Role, ClusterRole, RoleBinding and ClusterRoleBinding.
BeginnerConceptKubernetes Security
Answer
A Role grants verbs on resources inside one namespace; a ClusterRole defines permissions cluster-wide or for cluster-scoped resources (nodes, namespaces). A RoleBinding attaches a Role or ClusterRole to subjects inside one namespace; a ClusterRoleBinding attaches a ClusterRole across the whole cluster.
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata: { name: pod-reader, namespace: payments }
rules:
- apiGroups: [""]
resources: ["pods", "pods/log"]
verbs: ["get", "list", "watch"]
In production we define reusable ClusterRoles and bind them per namespace with RoleBindings. RBAC is additive only: there are no deny rules.
More on Kubernetes Security
What are the 4Cs of cloud native security?BeginnerWhat happens to a request between `kubectl apply` and etcd from a security point of view?IntermediateHow do you check what a user or service account is allowed to do?BeginnerWhich RBAC permissions are effectively cluster-admin in disguise?AdvancedHow do service account tokens work now, and what is `automountServiceAccountToken`?IntermediateWhat are the three Pod Security Standards?Beginner