Role Based Access Control

The kube guy
3 min readNov 6, 2023

This article is part of Kubernetes security series, If you wish to recieve more do follow The kube guy

In our Kubernetes security series, we are now going to learn about Role based access control. For this specific topic I’ve chosen a new way to explain by taking The office analogy. Though, the name explains most of the concept. I’ve added a little layer which simplifies the concept much better.

Role based access control in kubernetes

RBAC in Kubernetes: The Basics

RBAC in Kubernetes is a framework that allows you to define who can do what within your cluster. Much like assigning roles and access in your organization, it’s about setting permissions and controlling actions on various resources. Let’s dive into the office analogy..

The Office Analogy

Imagine you manage a thriving tech startup, much like your Kubernetes cluster. Within your organization, different departments handle specific tasks. The same is true for your cluster, where various resources and components require different levels of access and control.

Key Elements in Our Analogy:

  1. Your Office: This is your Kubernetes cluster, a dynamic environment with various resources.
  2. Departments: These represent different components within your Kubernetes cluster, such as namespaces or API resources.
  3. Employees: They symbolize different users or roles in your Kubernetes cluster who need varying degrees of access.
  4. Access Passes: These are the permissions assigned to users to access specific resources. In Kubernetes, RBAC revolves around defining and managing these access passes.

Scenario: Employee Access

In your startup, you have different categories of employees, each with distinct roles and access levels:

  • Developers: They have access to the source code repository, development tools, and the resources related to the development department.
  • HR Managers: Their access is limited to employee records, without permissions to modify source code or alter configurations.
  • Security Team: They possess broader access to monitor activities and take security-related actions.

RBAC in Kubernetes operates on a similar principle, allowing you to grant different levels of access to users or roles based on their responsibilities.

Key Components of RBAC in Kubernetes

To understand how RBAC works, let’s compare it to the tools in your office:

1. Roles and ClusterRoles

  • Roles: These resemble job descriptions for employees. They specify what actions are allowed on which resources within a namespace.
  • ClusterRoles: Think of these as high-level roles applicable across your entire organization, rather than specific departments.

2. RoleBindings and ClusterRoleBindings

  • RoleBindings: These associate specific roles with employees. They connect a role (job description) with an employee (user or service account) to define their access.
  • ClusterRoleBindings: These connect cluster-wide roles (like top management roles) to employees (users or service accounts) throughout your organization (cluster).

Scenario: Assigning Roles

Consider your “Code Deployment Role” in your startup. It permits employees to access code repositories and deploy software. A “RoleBinding” is equivalent to assigning this role to your development team. Only developers have the Code Deployment Role, which is akin to accessing the development resources. Other departments have their own role assignments tailored to their responsibilities.

Real-Life Scenario: Implementing RBAC in Kubernetes

Suppose you manage a Kubernetes cluster with different namespaces. You can define roles and role bindings as follows:

  • Namespace: Development
  • Role: DevelopmentRole (Allows creating and updating pods)
  • RoleBinding: Developers (Connects the Development Role to the developers)
  • Namespace: HR
  • Role: HRRole (Allows reading config maps and services)
  • RoleBinding: HRUsers (Connects the HR Role to the HR team)

With this setup, developers can manage resources within the Development namespace, but can’t access or modify HR resources in the HR namespace.

Implementing RBAC in Kubernetes

To implement RBAC in your Kubernetes cluster:

  1. Define Roles and Cluster Roles: Specify the actions and resources that roles can access within namespaces or across the entire cluster.
  2. Create RoleBindings and ClusterRoleBindings: Assign roles to users or service accounts in your cluster.
  3. Testing and Monitoring: Ensure your RBAC configuration works as expected. Regularly monitor and update permissions as your cluster evolves.



The kube guy

I'll help you sail through the ocean of Kubernetes with minimal efforts