Sub topic 11
Default roles: cluster-admin, admin, edit, and view
This chapter assumes you can write Roles and bindings and know the difference between a RoleBinding and a ClusterRoleBinding. Kubernetes ships with ClusterRoles that cover common needs, so you often don't have to write your own.
The four user-facing roles
Four default ClusterRoles are meant for people and not for system components.
| ClusterRole | Intended scope | What it allows |
|---|---|---|
| `cluster-admin` | Whole cluster, or one namespace | Every action on every resource |
| `admin` | One namespace | Read and write most namespaced resources, including Roles and RoleBindings |
| `edit` | One namespace | Read and write most namespaced resources, but not Roles or RoleBindings |
| `view` | One namespace | Read-only access to most namespaced resources, excluding Secrets, Roles, and RoleBindings |
The scope depends on the binding you choose. These roles are ClusterRoles, so you can reuse them in any namespace by pointing a RoleBinding at them.
cluster-adminwith a ClusterRoleBinding gives full control of the whole cluster. With a RoleBinding it gives full control of one namespace, including the namespace object itself.adminis meant for a RoleBinding. It can create Roles and RoleBindings inside the namespace, so the holder can delegate access. It cannot change the ResourceQuota or the namespace object.editcan read Secrets and run pods as any service account in the namespace. That makes it a path to the permissions of those service accounts.viewexcludes Secrets because reading a Secret can expose service account tokens and so lead to escalation.
Choosing a role
Binding a default role
This RoleBinding gives the user jane edit rights in the dev namespace only.
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: jane-edit
namespace: dev
subjects:
- kind: User
name: jane
apiGroup: rbac.authorization.k8s.io
roleRef:
kind: ClusterRole
name: edit
apiGroup: rbac.authorization.k8s.ioThe roleRef names a ClusterRole, but the binding lives in dev, so the grant stops at that namespace boundary. You can create the same binding from the command line and then check it.
kubectl create rolebinding jane-edit --clusterrole=edit --user=jane --namespace dev
kubectl auth can-i create deployments --namespace dev --as jane
kubectl auth can-i create deployments --namespace prod --as janeThe first check should print yes and the second no.
System roles and reconciliation
Run kubectl get clusterroles and you will see many more roles with a system: prefix, such as system:node and system:kube-scheduler. Control plane components use them. Default roles carry the label kubernetes.io/bootstrapping=rbac-defaults.
The API server recreates missing default roles and permissions each time it starts. This is called auto-reconciliation. Any edit you make to a default role is overwritten unless you set the annotation rbac.authorization.kubernetes.io/autoupdate: "false" on it. Don't edit defaults. Create a new ClusterRole, or use aggregation, covered in a later chapter.
The group system:masters is bound to cluster-admin. Anyone authenticated into that group has unrestricted access, and authorization checks never deny them. Treat credentials with that group as root credentials.
Common mistakes
- Granting
cluster-adminwith a ClusterRoleBinding whenadminin one namespace is enough. - Assuming
viewshows Secrets. It does not. - Modifying a default role and finding the change gone after an API server restart.
Exercise
A developer needs to deploy and update Deployments in the staging namespace, but must not create RoleBindings or touch other namespaces. Which default role and which kind of binding do you use?
Show answer
Use the edit ClusterRole with a RoleBinding in the staging namespace. The RoleBinding limits the grant to staging, and edit does not allow creating Roles or RoleBindings. Note that edit can still read Secrets in that namespace.