Mastering Azure AKS Kubernetes RBAC: A Comprehensive Guide

Muhammad Imran
3 min readMay 2, 2024

Azure Kubernetes Service (AKS) is Microsoft’s managed Kubernetes platform, making it easy to deploy and manage Kubernetes clusters on Azure. As organizations adopt Kubernetes, it’s crucial to implement robust role-based access control (RBAC) to manage who can access and interact with your Kubernetes resources.

Authenticating with Microsoft Entra ID

The first step in managing access to your AKS cluster is to integrate it with Microsoft Entra ID, Microsoft’s enterprise-ready identity management solution. By integrating Entra ID, you can leverage your existing user accounts and groups to control access to your Kubernetes resources.

Defining Kubernetes RBAC

Once you’ve integrated Entra ID, you can use Kubernetes RBAC to define the permissions for your users and groups. Kubernetes RBAC consists of two main components: Roles/ClusterRoles and RoleBindings/ClusterRoleBindings.

- Roles and ClusterRoles: Define the set of permissions that can be granted to users or groups. Roles are scoped to a specific namespace, while ClusterRoles are cluster-wide.
- RoleBindings and ClusterRoleBindings: Bind Roles or ClusterRoles to users or groups, granting them the defined permissions.

By creating these RBAC resources, you can granularly control access to your Kubernetes resources, ensuring that users and groups only have the necessary permissions to perform their tasks.

Leveraging Azure RBAC

In addition to Kubernetes RBAC, you can also use Azure RBAC to manage access to your AKS resources. Azure RBAC allows you to define permissions at the Azure resource level, such as the AKS cluster itself, the Kubernetes API, and the kubeconfig file.[1][3]

This two-pronged approach, combining Kubernetes RBAC and Azure RBAC, provides a comprehensive access control solution for your AKS environment, allowing you to manage permissions at both the Kubernetes and Azure resource levels.

Practical Examples

To illustrate the concepts, let’s consider a few practical examples:

  • Granting Full Access to the Finance Team: Create a Kubernetes ClusterRole with full permissions, then bind it to the “finance-team” group from Entra ID.
# Create a ClusterRole with full permissions
kubectl create clusterrole finance-team-full-access --verb=* --resource=*

# Bind the ClusterRole to the "finance-team" group
kubectl create clusterrolebinding finance-team-full-access --clusterrole=finance-team-full-access --group=finance-team
  • Restricting Access to the Development Namespace: Create a Kubernetes Role with limited permissions in the “development” namespace, then bind it to the “dev-team” group from Entra ID.
# Create a Role with limited permissions in the "development" namespace
kubectl create role dev-team-access --namespace=development --verb=get,list,watch --resource=pods,deployments

# Bind the Role to the "dev-team" group
kubectl create rolebinding dev-team-access --role=dev-team-access --group=dev-team --namespace=development
  • Allowing Read-Only Access to the Kubernetes Dashboard: Use Azure RBAC to grant the “AKS RBAC Reader” role to the “dashboard-viewers” group, restricting their access to the Kubernetes Dashboard.
# Assign the "AKS RBAC Reader" role to the "dashboard-viewers" group
az role assignment create --role "AKS RBAC Reader" --assignee-object-id $(az ad group show --group dashboard-viewers --query objectId -o tsv) --scope /subscriptions/<subscription-id>/resourceGroups/<resource-group>/providers/Microsoft.ContainerService/managedClusters/<cluster-name>

By following these best practices and leveraging the power of Kubernetes RBAC and Azure RBAC, you can effectively manage access to your AKS clusters, ensuring that users and groups only have the necessary permissions to perform their tasks.

References:

  1. https://learn.microsoft.com/en-us/azure/aks/manage-azure-rbac
  2. https://learn.microsoft.com/en-us/azure/aks/hybrid/kubernetes-rbac-azure-ad
  3. https://learn.microsoft.com/en-us/azure/aks/operator-best-practices-identity

--

--

Muhammad Imran

Azure Solution Architect Expert | Microsoft Certified Trainer | AWS Community Builder | Author