Key Concepts
Role
A namespace-scoped set of permissions defined as rules with verbs, resources, and API groups.
Rules
Permission definitions specifying what actions (verbs) are allowed on which resources.
Namespace
The namespace where the Role exists and can grant permissions.
System Role
Built-in Roles managed by Kubernetes (prefixed with
system: or containing kubernetes.io).Roles are namespace-scoped resources. They can only grant access to resources within the same namespace. For cluster-wide permissions, use ClusterRoles.
Required Permissions
| Action | Permission |
|---|---|
| View Roles | iam:project:infrastructure:kubernetes:read |
| Create Role | iam:project:infrastructure:kubernetes:write |
| Edit Role | iam:project:infrastructure:kubernetes:write |
| Delete Role | iam:project:infrastructure:kubernetes:delete |
Role Types
| Type | Description |
|---|---|
| System | Built-in Kubernetes roles (should not be modified) |
| Custom | User-created Roles |
How to View Roles
How to View Role Details
How to Create a Role
Write YAML
Enter the Role manifest in YAML format. Key fields:
metadata.namespace- Target namespacerules- Array of permission rules
How to Edit a Role
How to Delete a Role
Rule Structure
Each rule in a Role specifies:| Field | Description |
|---|---|
| apiGroups | API groups containing the resources (empty string for core API) |
| resources | Resource types to grant access to |
| verbs | Actions allowed on the resources |
| resourceNames | Optional: specific resource names to restrict access |
Common Verbs
| Verb | Description |
|---|---|
get | Read a single resource |
list | List resources |
watch | Watch for changes |
create | Create new resources |
update | Update existing resources |
patch | Partially update resources |
delete | Delete resources |
deletecollection | Delete multiple resources |
* | All verbs (full access) |
Example Roles
Pod Reader
Deployment Manager
ConfigMap and Secret Manager
Specific Resource Access
Full Namespace Admin
Role vs ClusterRole
| Aspect | Role | ClusterRole |
|---|---|---|
| Scope | Single namespace | Cluster-wide |
| Can access | Namespace resources only | All resources including cluster-scoped |
| Use case | Team/app specific permissions | Admin, operators, cross-namespace access |
| Binding | RoleBinding only | RoleBinding or ClusterRoleBinding |
Troubleshooting
User cannot access namespace resources
User cannot access namespace resources
- Verify a RoleBinding exists binding the user to a Role
- Check the Role has the necessary rules
- Verify the Role and RoleBinding are in the same namespace
- Use
kubectl auth can-i --as=<user> -n <namespace>to test permissions
Cannot delete Role
Cannot delete Role
- System roles cannot be deleted
- Verify you have delete permission
- Check for finalizers blocking deletion
Permission changes not taking effect
Permission changes not taking effect
- RBAC changes are immediate, no restart needed
- Verify the RoleBinding references the correct Role
- Check if there are multiple Roles/bindings affecting the user
- Clear any client-side caching
Role in wrong namespace
Role in wrong namespace
- Roles only grant permissions in their namespace
- Delete and recreate the Role in the correct namespace
- Or use a ClusterRole with RoleBinding for reusability
Cannot access resources in other namespaces
Cannot access resources in other namespaces
- Roles are namespace-scoped
- Create separate Roles in each namespace, or
- Use ClusterRole with RoleBinding per namespace, or
- Use ClusterRole with ClusterRoleBinding for all namespaces
FAQ
What is the difference between Role and ClusterRole?
What is the difference between Role and ClusterRole?
Role is namespace-scoped and can only grant access to resources within that namespace.ClusterRole is cluster-scoped and can grant access to cluster-scoped resources (nodes, PVs), non-resource endpoints, and resources across all namespaces.
Can a Role grant access to cluster-scoped resources?
Can a Role grant access to cluster-scoped resources?
No. Roles can only grant access to namespace-scoped resources within their namespace. For cluster-scoped resources like nodes, PVs, or namespaces themselves, use ClusterRoles.
How do I reuse a Role across namespaces?
How do I reuse a Role across namespaces?
You have two options:
- Create identical Roles in each namespace
- Use a ClusterRole and bind it with RoleBindings in each namespace (recommended)
Can I bind a ClusterRole with a RoleBinding?
Can I bind a ClusterRole with a RoleBinding?
Yes. A RoleBinding can reference a ClusterRole, but permissions are limited to the RoleBinding’s namespace. This is the recommended way to reuse permission sets across namespaces.
What happens if I delete a namespace with Roles?
What happens if I delete a namespace with Roles?
When a namespace is deleted, all Roles and RoleBindings in that namespace are automatically deleted. This is part of Kubernetes garbage collection.
How do I check what permissions a Role grants?
How do I check what permissions a Role grants?
View the Role details to see all rules. Use
kubectl describe role <name> -n <namespace> or click on the Role in the UI to see the complete rule list.Can a Role grant permissions to resources it doesn't have?
Can a Role grant permissions to resources it doesn't have?
No. You cannot escalate privileges. A user can only create Roles with permissions they already have. This prevents privilege escalation attacks.
Should I create Roles or use built-in ClusterRoles?
Should I create Roles or use built-in ClusterRoles?
Use built-in ClusterRoles (
admin, edit, view) with RoleBindings for common scenarios. Create custom Roles when you need fine-grained, namespace-specific permissions that don’t match built-in roles.