Skip to main content
In this lesson we explore Kubernetes Role-Based Access Control (RBAC): what a Role is, how to create Roles and RoleBindings, and how to test and restrict permissions.
A presentation slide titled "Role-Based Access Control (RBAC)" displayed on a mostly white background with a dark blue curved section showing a padlock icon and a pointing hand. The design includes simple vector graphics and a small copyright notice.

What is a Role?

A Role is a namespace-scoped RBAC object that defines a set of permissions (rules) for resources inside a specific namespace. Roles are composed of one or more rules that specify which API groups, resources, and verbs (actions) are allowed. Optionally, a rule can restrict access to specific resource names. Key fields in a Role rule:

Example: create a namespaced Role

developer-role.yaml
Apply the Role:

Granting the Role: RoleBinding

To grant the permissions defined in a Role to a user, group, or service account within the same namespace, create a RoleBinding. RoleBindings are namespace-scoped and must live in the same namespace as the Role (unless you reference a ClusterRole). Example RoleBinding manifest:
Apply the RoleBinding:
Important: Roles and RoleBindings are namespace-scoped. For cluster-wide permissions, use a ClusterRole and bind it with a ClusterRoleBinding.

Common kubectl commands to view RBAC objects

Examples:
Describe the created Role:
Example output:
Describe the RoleBinding:
Example output:

Testing permissions with kubectl auth can-i

Use kubectl auth can-i to test whether a user has a given permission. As the current user:
Example:
As an administrator you can impersonate a user with --as to test their permissions:
Include a namespace to check namespace-scoped permissions:
If dev-user only has pod creation rights in the default namespace, the previous command for the test namespace will return no.

Restricting access to specific named resources

To limit a rule so it only applies to specific named resources, use resourceNames in the rule. Example: allow get on only two pods named blue and orange:
This prevents access to any other pods in the namespace.
Remember: Roles and RoleBindings are namespace-scoped. If you need cluster-wide permissions (across all namespaces), use ClusterRole and ClusterRoleBinding instead.

Further reading and references

That’s it — try creating Roles and RoleBindings in a practice cluster, and use kubectl auth can-i (with --as if needed) to validate permissions.

Watch Video

Practice Lab