- Defining a Role
- Binding a Role to a User
- Inspecting Roles and RoleBindings
- Verifying Permissions with
kubectl auth can-i - Restricting Access to Specific Resource Names
1. Defining a Role in a Namespace
A Role grants a set of permissions within a single namespace. Each Role rule comprises:
*Optional field to scope rules to named resources only.
Example: create a Role named developer that can manage Pods and create ConfigMaps.
role-developer.yaml and apply:
Roles are namespace-scoped by default. To apply this Role in another namespace, add
namespace: your-namespace under metadata:.2. Binding a Role to a User with RoleBinding
A RoleBinding associates one or more subjects (users, groups, or service accounts) with a Role.rolebinding-devuser.yaml and run:
Ensure your Role and RoleBinding share the same namespace unless you intend to bind across namespaces.
3. Inspecting Roles and RoleBindings
Usekubectl to list or describe your RBAC resources:
-
List all Roles in the current namespace
-
List all RoleBindings in the current namespace
-
Describe a specific Role to view its rules
Sample output:
-
Describe a RoleBinding to see bound subjects
Sample output:
4. Verifying Permissions with kubectl auth can-i
Check whether a user can perform specific actions:5. Restricting Access to Specific Resource Names
Limit Role permissions to named resources usingresourceNames: