RBAC roles with multiple namespaces
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction to RBAC in Kubernetes
Role-Based Access Control (RBAC) is an essential mechanism in Kubernetes for managing permissions in your cluster. It is designed to restrict access based on the roles assigned to users within an organization. RBAC is especially useful in multi-tenant environments, where multiple teams share the same cluster. By enabling precise permissions, RBAC helps prevent accidental or malicious intervention between tenants.
Understanding Roles and RoleBindings
In RBAC, Roles are sets of permissions associated with resources. A RoleBinding assigns these roles to users or groups within a namespace. The fundamental RBAC resources are:
- Role: Defines permissions on a set of resources within a specific namespace.
- ClusterRole: Similar to a Role, but it's cluster-wide and can be used across all namespaces.
- RoleBinding: Assigns a Role to users or groups within a specific namespace.
- ClusterRoleBinding: Assigns a ClusterRole to users or groups across all namespaces.
Roles with Multiple Namespaces
Let's dive deeper into the creation and application of roles across multiple namespaces. In Kubernetes, roles are typically namespace-specific. However, the use of ClusterRoles and strategically placed RoleBindings enables administrators to apply consistent security policies across multiple namespaces.
Example: Creating a ClusterRole
Suppose you want to allow users to read Pods and list Deployments across all namespaces. This can be achieved by creating a `ClusterRole`:
- apiGroups: [""] # "" indicates the core API group
- apiGroups: ["apps"]
- kind: User
- Granular Permissions: Use roles to grant only the necessary permissions. Adopting the principle of least privilege can significantly reduce security risks.
- ClusterRoles for Reuse: Create reusable `ClusterRoles` for permissions that are consistent across namespaces. This approach reduces redundancy and enhances maintainability.
- Namespace-Specific RoleBindings: Control which users/groups have access in each namespace individually by binding roles as appropriate.
- Audit and Review Regularly: Periodically review the roles and bindings to ensure they align with the current operational and security requirements.
Related reading
- ReactiveSecurityContextHolder is empty in Spring WebFlux
- Read-only filesystem pod with Spring Boot application on Kubernetes
- Read only file system on Android
- Received fatal alert handshake_failure through SSLHandshakeException
- Recommended GCE service account authentication inside Docker container?
- Recommended way to manage credentials with multiple AWS accounts?
- Refreshing OAuth token using Retrofit without modifying all calls
- Regex for password must contain at least eight characters, at least one number and both lower and uppercase letters and special characters

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.