Blog Post

Startups at Microsoft
21 MIN READ

From zero to hero with identity and access control in Azure Kubernetes Service

rmmartins's avatar
rmmartins
Icon for Microsoft rankMicrosoft
Feb 26, 2025

Kubernetes administrators transitioning to Azure Kubernetes Service (AKS) often face challenges in understanding how authentication and authorization work in Azure.

Unlike standalone Kubernetes clusters, AKS integrates with Azure RBAC and Microsoft Entra ID (formerly Azure Active Directory) to provide a centralized and secure identity management system.

This blog post is a comprehensive guide that explains:

  • How to integrate Microsoft Entra ID with AKS.
  • The differences between Azure RBAC and Kubernetes RBAC and how they complement each other.
  • How to use Azure RBAC for Kubernetes authorization.
  • How to assign roles and permissions in AKS.
  • The impact of Entra ID integration on local Kubernetes admin accounts.
  • How to implement managed identities and workload identities for secure workload authentication.
  • A step-by-step practical exercise for integrating Microsoft Entra ID with AKS.
  • Best practices for AKS authentication and authorization.

1. Integrating AKS with Microsoft Entra ID

Microsoft Entra ID integration enables centralized identity and access management for AKS. Instead of relying on local Kubernetes credentials, users authenticate using their Microsoft Entra ID credentials, and authorization is managed through Azure RBAC and Kubernetes RBAC.

Why Use Microsoft Entra ID in AKS?

  • Centralized Authentication: No need to manage separate Kubernetes credentials.
  • Enhanced Security: Azure RBAC enforces security policies across AKS.
  • Seamless User Management: AKS permissions are managed using Microsoft Entra ID groups.

Enabling Microsoft Entra ID integration in AKS

You can enable Microsoft Entra ID authentication when creating a new AKS cluster or by updating an existing cluster.

Creating a new AKS cluster with Entra ID authentication

To create an AKS cluster that uses Microsoft Entra ID for authentication, run:

az aks create                                           \
  --resource-group MyResourceGroup                      \
  --name MyAKSCluster                                   \
  --enable-aad                                          \
  --enable-azure-rbac                                   \
  --aad-admin-group-object-ids <Admin_Group_Object_ID>  \
  --generate-ssh-keys

Replace <Admin_Group_Object_ID> with the Object ID of your Microsoft Entra ID group that should have admin access to the AKS cluster.

Enabling Microsoft Entra ID on an existing AKS cluster

If your AKS cluster was created without Entra ID integration, you can enable it later using:

az aks update                       \ 
  --resource-group MyResourceGroup  \ 
  --name MyAKSCluster               \ 
  --enable-aad

Verifying Entra ID authentication

To confirm that Entra ID authentication is enabled, run:

az aks show                         \ 
  --resource-group MyResourceGroup  \ 
  --name MyAKSCluster               \ 
  --query "aadProfile.managed"

If the result is true, your cluster is using managed Microsoft Entra ID.

2. Understanding Azure RBAC vs. Kubernetes RBAC

In Azure Kubernetes Service (AKS), managing access and permissions involves two primary systems: Azure Role-Based Access Control (Azure RBAC) and Kubernetes Role-Based Access Control (Kubernetes RBAC). While both serve to regulate access, they operate at different scopes and are used for distinct purposes.

Scope and Purpose

FeatureAzure RBACKubernetes RBAC
ScopeManages access to Azure resources, including the AKS cluster itself.Manages access within the Kubernetes cluster, such as namespaces and resources.
Used forControlling who can perform actions like scaling or upgrading the AKS cluster.Controlling what users can do inside the AKS cluster, like accessing pods or services.
AuthenticationUses Microsoft Entra ID (formerly Azure Active Directory) for identity verification.Uses Kubernetes service accounts or integrates with Microsoft Entra ID for identity verification.
AuthorizationAssigns Azure roles to users/groups to define their permissions on Azure resources.Defines Kubernetes Roles and RoleBindings to specify permissions within the cluster.

In AKS, Azure RBAC controls access to the Kubernetes API, while Kubernetes RBAC controls what users can do inside the cluster.

Authentication mechanisms

  • Azure RBAC: Relies on Microsoft Entra ID to authenticate users attempting to access Azure resources, including AKS.
  • Kubernetes RBAC: Authenticates users through Kubernetes service accounts or integrates with Microsoft Entra ID for user identity verification within the cluster.

Authorization processes

  • Azure RBAC: Permissions are granted by assigning Azure roles to users or groups at a specific scope (subscription, resource group, or resource).
  • Kubernetes RBAC: Permissions are defined using Kubernetes Roles (within a namespace) or ClusterRoles (cluster-wide), and assigned to users or groups via RoleBindings or ClusterRoleBindings.

Integration and use cases

In an AKS environment, both Azure RBAC and Kubernetes RBAC can be used in tandem to provide a comprehensive access control strategy:

  • Azure RBAC: Manages access to the AKS cluster as an Azure resource, controlling actions like scaling, upgrading, or retrieving cluster configurations.
  • Kubernetes RBAC: Manages permissions within the AKS cluster, such as granting access to specific namespaces, pods, or other Kubernetes resources.

By understanding and appropriately configuring both Azure RBAC and Kubernetes RBAC, administrators can ensure secure and efficient access management for both the AKS cluster and its internal resources.

Practical example 1: Developer Access to AKS

Let’s say you want a developer to:

  • Access the AKS cluster (but not manage it).
  • Read deployments and logs inside a Kubernetes namespace.

Step 1: Grant Azure RBAC Permissions (Access to Cluster API)

First, assign the "Azure Kubernetes Service Cluster User" role to the developer in Azure RBAC:

az role assignment create                         \
  --assignee <User_ID>                            \
  --role "Azure Kubernetes Service Cluster User"  \
  --scope /subscriptions/<Subscription_ID>/resourceGroups/<Resource_Group>/providers/Microsoft.ContainerService/managedClusters/<AKS_Cluster>

This allows the developer to authenticate to the AKS API, but they still don’t have permissions inside Kubernetes.

Step 2: Grant Kubernetes RBAC Permissions (Inside the Cluster)
Now, inside the AKS cluster, create a RoleBinding to grant access to a specific namespace:

apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: developer-view
  namespace: dev-namespace
subjects:
- kind: Group
  name: "<Entra_ID_Group_ID>"  # Replace with the actual Microsoft Entra ID Group Object ID
  apiGroup: rbac.authorization.k8s.io
roleRef:
  kind: Role
  name: view
  apiGroup: rbac.authorization.k8s.io

Apply this RoleBinding:

kubectl apply -f role-binding.yaml

Now, the developer can log into AKS via Entra ID and view deployments/logs inside the dev-namespace.

Practical example 2: Admin Access to AKS

If you need to grant full Kubernetes admin access to an Entra ID group:

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: aks-admins
subjects:
- kind: Group
  name: "<Entra_ID_Admin_Group_ID>" # Microsoft Entra ID group for AKS admins
  apiGroup: rbac.authorization.k8s.io
roleRef:
  kind: ClusterRole
  name: cluster-admin
  apiGroup: rbac.authorization.k8s.io

This ensures that members of the Entra ID Admin Group have full cluster admin rights in Kubernetes.

3. Leveraging Azure RBAC for Kubernetes authorization

Integrating Azure Role-Based Access Control (RBAC) with your Azure Kubernetes Service (AKS) cluster allows for unified management of access permissions across both Azure resources and Kubernetes resources within the cluster. This integration streamlines the process of assigning and managing user permissions, enhancing security and operational efficiency.

Enabling Azure RBAC for Kubernetes authorization

To utilize Azure RBAC for Kubernetes authorization, ensure that your AKS cluster is configured with managed Microsoft Entra ID integration. This setup allows Azure to handle authentication and authorization for Kubernetes resources.

Creating a new AKS cluster with Azure RBAC enabled:

When creating a new AKS cluster, you can enable Azure RBAC for Kubernetes authorization using the following Azure CLI command:

az aks create                             \ 
  --resource-group <resource-group-name>  \ 
  --name <cluster-name>                   \ 
  --enable-aad                            \     
  --enable-azure-rbac                     \ 
  --generate-ssh-keys

In this command:

  • --enable-aad: Enables managed Microsoft Entra ID integration.
  • --enable-azure-rbac: Activates Azure RBAC for Kubernetes authorization.

Enabling Azure RBAC on an existing AKS cluster:

For existing AKS clusters with managed Microsoft Entra ID integration, enable Azure RBAC using:

az aks update                             \ 
  --resource-group <resource-group-name>  \ 
  --name <cluster-name>                   \ 
  --enable-azure-rbac

This command updates the cluster to use Azure RBAC for managing Kubernetes permissions.

Assigning Azure roles for Kubernetes access

With Azure RBAC enabled, you can assign Azure roles to users or groups, defining their permissions within the Kubernetes cluster. Azure provides several built-in roles tailored for Kubernetes authorization:

  • Azure Kubernetes Service RBAC Reader: Grants read-only access to most objects in a namespace.
  • Azure Kubernetes Service RBAC Writer: Allows read and write access to most objects in a namespace.
  • Azure Kubernetes Service RBAC Admin: Provides admin access within a namespace, including the ability to create roles and role bindings.
  • Azure Kubernetes Service RBAC Cluster Admin: Offers super-user access to perform any action on any resource within the cluster.

Assigning a role to a user or group:

To assign the "Azure Kubernetes Service RBAC Reader" role to a user for a specific namespace, use:

az role assignment create                         \
  --assignee <user-object-id>                     \
  --role "Azure Kubernetes Service RBAC Reader"   \
  --scope /subscriptions/<subscription-id>/resourceGroups/<resource-group-name>/providers/Microsoft.ContainerService/managedClusters/<cluster-name>/namespaces/<namespace-name>

Replace the placeholders with your specific details:

  • <user-object-id>: The Object ID of the user in Microsoft Entra ID.
  • <subscription-id>: Your Azure subscription ID.
  • <resource-group-name>: The name of the resource group containing your AKS cluster.
  • <cluster-name>: The name of your AKS cluster.
  • <namespace-name>: The Kubernetes namespace to which the role assignment applies.

This command assigns the specified role at the namespace level, controlling access within that specific namespace.

Benefits of using Azure RBAC for Kubernetes authorization

  • Centralized management: Manage all access permissions from the Azure portal, providing a single pane of glass for both Azure and Kubernetes resources.
  • Simplified access control: Utilize Azure's built-in roles to assign permissions, reducing the complexity of managing Kubernetes-specific roles and bindings.
  • Enhanced security: Ensure that only authorized users have access to Kubernetes resources, with all actions being auditable through Azure's monitoring tools.

By leveraging Azure RBAC for Kubernetes authorization, organizations can achieve a cohesive and secure access control strategy that spans their entire Azure ecosystem, including AKS clusters.

4. Assigning roles and permissions in AKS

Effectively managing access within an Azure Kubernetes Service (AKS) cluster requires a comprehensive understanding of both Azure Role-Based Access Control (Azure RBAC) and Kubernetes Role-Based Access Control (Kubernetes RBAC). While Azure RBAC manages access to Azure resources, Kubernetes RBAC governs permissions within the Kubernetes cluster itself. This section delves into the process of assigning roles and permissions in AKS using both systems.

Assigning roles with Azure RBAC

Azure RBAC allows administrators to control who can access Azure resources, including the AKS cluster, by assigning roles to users, groups, or service principals.

Built-in Azure roles for AKS:

Azure provides several built-in roles tailored for managing AKS resources:

  • Azure Kubernetes Service Contributor Role: Grants full access to manage all resources within the AKS cluster but does not allow role assignment in Azure RBAC.
  • Azure Kubernetes Service Cluster Admin Role: Provides permissions to list cluster admin credential actions only.
  • Azure Kubernetes Service RBAC Writer Role: Allows the user to create, read, update, and delete role assignments and role definitions within an AKS cluster.
  • Azure Kubernetes Service RBAC Reader Role: Grants read-only access to most objects in a namespace.

Assigning a role using Azure CLI:

To assign the "Azure Kubernetes Service RBAC Writer Role" to a user, execute the following command:

az role assignment create                             \ 
  --assignee <user-object-id>                         \ 
  --role "Azure Kubernetes Service RBAC Writer Role"  \ 
  --scope /subscriptions/<subscription-id>/resourceGroups/<resource-group-name>/providers/Microsoft.ContainerService/managedClusters/<aks-cluster-name>

Replace the placeholders with your specific details:

  • <user-object-id>: The Object ID of the user in Microsoft Entra ID.
  • <subscription-id>: Your Azure subscription ID.
  • <resource-group-name>: The name of the resource group containing your AKS cluster.
  • <aks-cluster-name>: The name of your AKS cluster.

This command assigns the specified role at the scope of the AKS cluster, granting the user permissions defined by the role.

Assigning permissions with Kubernetes RBAC

Within the AKS cluster, Kubernetes RBAC manages access to resources by defining roles and role bindings.

Key Components:

  • Role: Defines a set of permissions within a namespace.
  • ClusterRole: Defines a set of permissions cluster-wide.
  • RoleBinding: Associates a Role with a user or group within a namespace.
  • ClusterRoleBinding: Associates a ClusterRole with a user or group cluster-wide.

Creating a role and RoleBinding:

1. Define a role: Create a YAML file named pod-reader-role.yaml with the following content:

apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  namespace: <namespace>
  name: pod-reader
rules:
  - apiGroups: [""]
    resources: ["pods"]
    verbs: ["get", "list", "watch"]

Replace <namespace> with the desired namespace.

2. Apply the role:

kubectl apply -f pod-reader-role.yaml

3. Create a RoleBinding: Create a YAML file named pod-reader-binding.yaml:

apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: read-pods
  namespace: <namespace>
subjects:
  - kind: User
    name: <user-name>
    apiGroup: rbac.authorization.k8s.io
roleRef:
  kind: Role
  name: pod-reader
  apiGroup: rbac.authorization.k8s.io

Replace <namespace> with the desired namespace and <user-name> with the name of the user.

4. Apply the RoleBinding:

kubectl apply -f pod-reader-binding.yaml

This configuration grants the specified user read access to pods within the chosen namespace.

Important considerations:

  • Principle of least privilege: Assign users only the permissions they need to perform their tasks.
  • Regular auditing: Periodically review role assignments and bindings to ensure they align with current organizational needs.
  • Separation of duties: Use Azure RBAC for managing access to Azure resources and Kubernetes RBAC for in-cluster resource permissions.

By effectively utilizing both Azure RBAC and Kubernetes RBAC, organizations can establish a robust and secure access control framework for their AKS environments.

5. Impact of Microsoft Entra ID integration on local Kubernetes admin accounts

Integrating Microsoft Entra ID with your Azure Kubernetes Service (AKS) cluster enhances security by centralizing authentication and authorization. However, this integration affects the usage and management of local Kubernetes admin accounts. Understanding these impacts is crucial for maintaining appropriate access controls and ensuring cluster security.

Disabling Local Accounts

By default, AKS clusters have local accounts enabled, providing direct access to the cluster. Even with Microsoft Entra ID integration and Role-Based Access Control (RBAC) enabled, the --admin credential remains active, serving as a non-auditable backdoor. To enhance security, it's advisable to disable these local accounts, ensuring that all access is funneled through Microsoft Entra ID for centralized management and auditing.

Creating a new AKS cluster without local accounts:

To deploy a new AKS cluster with local accounts disabled, use the following Azure CLI command:

az aks create                                   \ 
  --resource-group <resource-group>             \ 
  --name <cluster-name>                         \ 
  --enable-aad                                  \ 
  --aad-admin-group-object-ids <aad-group-id>   \ 
  --disable-local-accounts                      \ 
  --generate-ssh-keys

In this command:

  • --enable-aad: Enables Microsoft Entra ID integration.
  • --aad-admin-group-object-ids: Specifies the Object ID(s) of the Microsoft Entra ID group(s) to be granted cluster admin rights.
  • --disable-local-accounts: Disables local Kubernetes accounts, including the --admin credential.

Disabling local accounts on an existing AKS cluster:

For existing clusters, disable local accounts using:

az aks update                         \ 
  --resource-group <resource-group>   \ 
  --name <cluster-name>               \ 
  --disable-local-accounts

After executing this command, attempts to retrieve admin credentials using az aks get-credentials --admin will result in an error, indicating that local accounts are disabled.

Important considerations:

After disabling local accounts on an existing Azure Kubernetes Service (AKS) cluster, it's crucial to rotate the cluster certificates to revoke any previously issued credentials that might have been compromised. This step ensures that any access previously granted through local accounts is effectively invalidated.

  • Automatic Certificate Rotation: Clusters with Azure role-based access control (Azure RBAC) created after March 2022 have certificate auto-rotation enabled by default. However, manual rotation is still necessary after disabling local accounts to immediately revoke existing credentials.
  • Downtime: Rotating certificates can cause up to 30 minutes of downtime for your AKS cluster. Plan accordingly to minimize impact on your applications.

Re-enabling local accounts

If there's a need to restore local account access, you can re-enable them:

az aks update                         \ 
  --resource-group <resource-group>   \ 
  --name <cluster-name>               \ 
  --enable-local-accounts

Once re-enabled, you can retrieve the admin credentials using:

az aks get-credentials                \ 
  --resource-group <resource-group>   \ 
  --name <cluster-name>               \ 
  --admin

This command merges the -admin context into your kubeconfig file, allowing direct access to the cluster using local credentials.

Security implications:

Re-enabling local accounts reintroduces non-auditable access paths to your cluster. It's crucial to assess the security implications and ensure that such access aligns with your organization's compliance and governance policies.

Best practices

  • Centralized Access Management: Prefer using Microsoft Entra ID for all user authentications to maintain centralized control and auditing capabilities.
  • Regular Audits: Periodically review and audit access controls to ensure that only authorized personnel have access to the cluster.
  • Minimal Privilege Principle: Assign roles and permissions that grant the least privilege necessary for users to perform their tasks, reducing potential security risks.

By understanding and managing the interplay between Microsoft Entra ID integration and local Kubernetes admin accounts, you can enhance your AKS cluster's security posture and maintain robust access controls.

For detailed guidance on managing local accounts with AKS-managed Microsoft Entra integration, refer to the official Azure documentation: Manage local accounts with AKS-managed Microsoft Entra integration

6. Implementing managed identities and workload identities in AKS

In Azure Kubernetes Service (AKS), securely managing access to Azure resources by your workloads is paramount. Managed Identities and Microsoft Entra Workload Identities offer robust solutions to handle this access without the need to manage credentials manually.

Comparison of Managed Identities and Microsoft Entra Workload Identities in Azure Kubernetes Service (AKS):

FeatureManaged IdentityWorkload Identity
ScopeAssigned to an Azure resource (VMs, AKS)Assigned to Kubernetes workloads (pods)
Credential ManagementAutomatic, managed by AzureUses federated authentication via OIDC
GranularityIdentity applies to an entire AKS clusterEach pod can have its own identity
SecurityNo credentials stored in codeNo secrets stored in pods, enhances security
Best forAKS interacting with Azure servicesPod-level authentication with Azure services
Used ForAKS cluster itself authenticating to Azure services (e.g., pulling container images)Kubernetes workloads (pods) authenticating to Azure services
AuthenticationAssigned to AKS during cluster creationUses OIDC federation between Kubernetes and Microsoft Entra ID
Ideal Use CaseAKS needs access to Azure resources like Key Vault, Storage, ACRA pod running in AKS needs access to Azure Key Vault or Database

Managed identities in AKS

Managed Identities are a feature of Microsoft Entra ID that provide Azure services with an automatically managed identity in Microsoft Entra ID. This identity can authenticate to any service that supports Microsoft Entra authentication without storing credentials in your code.

Types of managed identities:

  1. System-assigned managed identity:
    • Lifecycle: Tied to the lifecycle of the Azure resource, such as an AKS cluster. When the resource is deleted, the identity is also deleted.
    • Use Case: Ideal for scenarios where the identity is only needed for the lifespan of the resource.
  2. User-assigned managed identity:
    • Lifecycle: Created as a standalone Azure resource. It can be assigned to multiple Azure resources and persists independently of the resources it’s associated with.
    • Use Case: Suitable when you need a single identity to be shared across multiple resources or when the identity's lifecycle should be managed separately.

Benefits of using managed identities in AKS

The implementation of managed identities in AKS offers several benefits:

  • Simplified credential management: Eliminates the need to manually manage credentials, as Azure automatically handles their creation and rotation.
  • Enhanced security: Reduces the risk of credential exposure, as there is no need to store them in code or environment variables.
  • Granular access control: Allows for defining specific permissions for each identity, ensuring that resources are accessed only by authorized entities.

Implementing a system-assigned managed identity in AKS:

By default, a new AKS cluster is created with a system-assigned managed identity.

az aks create                             \ 
  --resource-group <resource-group-name>  \ 
  --name <aks-cluster-name>               \ 
  --generate-ssh-keys

This command creates an AKS cluster with a system-assigned managed identity, enabling the cluster to access Azure resources securely.

Implementing a user-assigned managed identity in AKS:

1. Create a User-Assigned Managed Identity:

az identity create                        \ 
  --resource-group <resource-group-name>  \
  --name <identity-name>

This command creates a user-assigned managed identity in the specified resource group.

2. Assign the managed identity to the AKS Cluster:

az aks create                               \ 
  --resource-group <resource-group-name>    \ 
  --name <aks-cluster-name>                 \ 
  --assign-identity <identity-resource-id>  \ 
  --generate-ssh-keys

Replace <identity-resource-id> with the resource ID of the user-assigned managed identity.

Assigning permissions to managed identities:

After creating the managed identity, assign it the necessary permissions to access Azure resources. For example, to grant access to an Azure Key Vault:

az role assignment create           \ 
  --assignee <identity-client-id>   \ 
  --role Reader                     \ 
  --scope /subscriptions/<subscription-id>/resourceGroups/<resource-group-name>/providers/Microsoft.KeyVault/vaults/<keyvault-name>

Replace <identity-client-id> with the client ID of the managed identity.

Microsoft Entra Workload Identities

Microsoft Entra Workload Identities integrate Kubernetes service accounts with Microsoft Entra ID, enabling pods to access Azure resources securely without managing secrets. This approach leverages Kubernetes' native capabilities to federate with external identity providers.

Implementing Microsoft Entra Workload Identity in AKS:

1. Enable OIDC Issuer on AKS Cluster:

Ensure your AKS cluster has the OpenID Connect (OIDC) issuer enabled.

az aks update                             \ 
  --resource-group <resource-group-name>  \ 
  --name <aks-cluster-name>               \ 
  --enable-oidc-issuer

2. Create a managed identity:

Similar to the user-assigned managed identity creation step above.

3. Configure federated identity credential:

Establish a federated identity credential between the managed identity and the Kubernetes service account.

az identity federated-credential create   \ 
  --name <federated-credential-name>      \ 
  --identity-name <identity-name>         \ 
  --resource-group <resource-group-name>  \ 
  --issuer <oidc-issuer-url>              \ 
  --subject <kubernetes-service-account-subject>
  • <oidc-issuer-url>: The OIDC issuer URL of your AKS cluster.
  • <kubernetes-service-account-subject>: The subject identifier for the Kubernetes service account.

4. Deploy the workload:

Create a Kubernetes service account annotated with the client ID of the managed identity and deploy your pods using this service account.

apiVersion: v1
kind: ServiceAccount
metadata:
  name: <service-account-name>
  annotations:
    azure.workload.identity/client-id: <identity-client-id>

This configuration allows the pod to acquire tokens from Microsoft Entra ID, facilitating secure access to Azure resources.

Benefits of Microsoft Entra Workload Identities:

  • Enhanced Security: Eliminates the need to store secrets within pods.
  • Simplified Management: Utilizes Kubernetes-native resources for identity management.
  • Scalability: Supports large-scale deployments with multiple identities.

For a detailed walkthrough on deploying and configuring AKS clusters with workload identities, refer to the official Azure documentation: Deploy and configure workload identity on an Azure Kubernetes Service (AKS) cluster

7. Practical exercise: Integrating Azure Kubernetes Service (AKS) with Microsoft Entra ID Using AKS-managed integration

Integrating Azure Kubernetes Service (AKS) with Microsoft Entra ID enhances cluster security by centralizing authentication and authorization. The AKS-managed Microsoft Entra ID integration simplifies this process by automating the configuration, eliminating the need to manually manage Microsoft Entra applications. This exercise provides a step-by-step guide to implementing this integration.

Prerequisites

Before proceeding, ensure you have:

  • Azure CLI: Version 2.29.0 or later installed and configured. Verify your version with:
az --version

If an upgrade is needed, follow the Azure CLI installation guide.

  • kubectl: Ensure kubectl is installed. For clusters running Kubernetes version 1.24 or newer, the kubelogin plugin is also required.
  • Microsoft Entra ID Group: An existing Microsoft Entra ID group to assign as cluster administrators. If you don't have one, create it using:
az ad group create --display-name <group-name> \
  --mail-nickname <group-nickname>

Replace <group-name> and <group-nickname> with your desired group name and alias, and note the Object ID of the group created, as it will be necessary in later steps.

Step 1: Create a resource Group

Organize your resources by creating a new resource group:

az group create --name MyResourceGroup --location eastus

Step 2: Deploy an AKS cluster with Microsoft Entra ID integration

Create an AKS cluster with Microsoft Entra ID integration enabled:

az aks create                                         \ 
  --resource-group MyResourceGroup                    \ 
  --name MyAKSCluster                                 \ 
  --enable-aad                                        \   
  --aad-admin-group-object-ids <aad-group-object-id>  \ 
  --generate-ssh-keys

In this command:

  • --enable-aad: Enables Microsoft Entra ID integration.
  • --aad-admin-group-object-ids: Specifies the Object ID of the Microsoft Entra ID group to grant cluster admin rights. Replace <aad-group-object-id> with your group's Object ID.

This setup ensures that members of the specified Microsoft Entra ID group have administrative access to the AKS cluster.

Step 3: Configure Kubernetes Role-Based Access Control (RBAC)

Define roles and bindings within Kubernetes to manage access:

1. Create a namespace:

kubectl create namespace mynamespace

2. Define a role:

Create a file named role.yaml with the following content:

apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  namespace: mynamespace
  name: pod-reader
rules:
  - apiGroups: [""]
    resources: ["pods"]
    verbs: ["get", "watch", "list"]

3. Apply the role:

kubectl apply -f role.yaml

4. Create a RoleBinding:

Create a file named rolebinding.yaml:

apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: read-pods
  namespace: <namespace>
subjects:
- kind: Group
  name: <aad-group-name>
  apiGroup: ""
roleRef:
  kind: Role
  name: pod-reader
  apiGroup: rbac.authorization.k8s.io

Replace <aad-group-name> with the name of your Microsoft Entra ID group.

5. Apply the RoleBinding:

kubectl apply -f rolebinding.yaml

This configuration grants members of the specified Microsoft Entra ID group read access to pods within the mynamespace namespace.

Step 4: Access the AKS cluster

Retrieve the Kubernetes configuration to access the cluster:

az aks get-credentials --resource-group MyResourceGroup \
  --name MyAKSCluster

This command configures kubectl to use your Microsoft Entra ID credentials for authentication.

For clusters running Kubernetes version 1.24 or newer, ensure the kubelogin plugin is installed and in your system's PATH. This plugin facilitates the authentication process with Microsoft Entra ID.

Verification

To verify the integration:

1. List pods in the namespace:

kubectl get pods -n mynamespace

If configured correctly, users in the specified Microsoft Entra ID group should see the list of pods.

Visualizing the authentication and authorization flow

To better understand the process of authenticating and authorizing users in an AKS cluster with Microsoft Entra ID, here's a diagram that illustrates the flow:

This diagram captures the process of secure authentication and authorization within an AKS cluster using Entra ID and RBAC.

Breakdown of the flow:

  1. User requests access to AKS cluster via kubectl: The user initiates a request to access the AKS cluster, typically using kubectl.
  2. Entra ID authenticates and issues JWT token: Entra ID authenticates the user and issues a JWT token for subsequent authentication to the Kubernetes API server.
  3. User sends request with JWT token to Kubernetes API server: The user includes the JWT token in the request to the Kubernetes API server.
  4. Kubernetes API server verifies JWT token validity: The Kubernetes API server verifies the JWT token's validity (e.g., signature, expiration).
  5. Valid token: If the token is valid, the Kubernetes API server checks the user's permissions using RBAC.
  6. Invalid token: If the token is invalid, the Kubernetes API server returns a failure response to the user.
  7. Authorization check: If the token is valid, the server checks the user's roles and permissions to determine if the requested action is authorized.
  8. Unauthorized access: If the user does not have sufficient permissions, the server returns an access denied response.
  9. Action execution: If the user is authorized, the Kubernetes cluster resources execute the action.
  10. Final response: If the action is successful, a success response is returned; otherwise, a failure response is returned.

8. Best practices for AKS authentication and authorization

Ensuring robust authentication and authorization mechanisms is crucial for maintaining the security and integrity of your Azure Kubernetes Service (AKS) clusters. Implementing best practices helps prevent unauthorized access and ensures that users have appropriate permissions for their roles. Below are key recommendations:

1. Integrate with Microsoft Entra ID

Utilizing Microsoft Entra ID centralizes identity management, allowing seamless control over user access to AKS resources.

  • Centralized identity management: Integrate AKS with Microsoft Entra ID to manage user identities and access from a single platform. This integration ensures that any changes in user accounts or group memberships are automatically reflected in AKS access permissions.
  • Granular access control: Define roles and permissions within Kubernetes and bind them to Microsoft Entra ID users or groups. This approach enforces the principle of least privilege, granting users only the access necessary for their responsibilities.

For detailed guidance, refer to Microsoft's best practices for authentication and authorization in AKS and the identity and access management considerations for AKS

2. Implement Kubernetes Role-Based Access Control (RBAC)

Kubernetes RBAC provides fine-grained control over user actions within the cluster.

  • Define roles and RoleBindings: Create specific roles that outline permissible actions on resources and bind them to users or groups. This setup ensures that only authorized personnel can perform sensitive operations.
  • Namespace isolation: Use namespaces to segment resources and apply RBAC policies accordingly, limiting user access to designated environments.

Refer to Microsoft's documentation on Kubernetes RBAC with Entra ID in AKS  for more information.

3. Utilize Azure RBAC for cluster resource management

Azure Role-Based Access Control (Azure RBAC) manages access to Azure resources, including AKS clusters.

  • Assign Azure roles: Grant users or groups specific roles at the subscription, resource group, or resource level to control actions like scaling or upgrading the cluster.
  • Control kubeconfig access: Restrict access to the Kubernetes configuration file (kubeconfig) to prevent unauthorized cluster interactions.

For comprehensive details, see Microsoft's reference for RBAC in AKS

4. Implement Workload Identities for pod-level access

Securely manage pod access to Azure resources by implementing workload identities.

  • Use managed identities: Assign managed identities to pods, enabling them to authenticate to Azure services without storing credentials within the code.
  • Adopt Microsoft Entra Workload Identity: Leverage the integration between Kubernetes and Microsoft Entra ID to provide pods with access to Azure resources using Kubernetes-native capabilities.

For more information, consult Microsoft's documentation for Workload ID with AKS

5. Regularly review and audit access controls

Continuous monitoring and auditing of access controls help maintain cluster security.

  • Periodic access reviews: Regularly assess user and group permissions to ensure they align with current roles and responsibilities.
  • Implement logging and ,onitoring: Enable logging of authentication and authorization activities to detect and respond to unauthorized access attempts promptly.

Refer to Microsoft's best practices for cluster security in AKS and AKS security concepts

Conclusion

Transitioning to Azure Kubernetes Service (AKS) introduces a paradigm where identity and access management are integral to cluster security. By integrating AKS with Microsoft Entra ID, implementing Kubernetes and Azure RBAC, and adopting workload identities, organizations can establish a robust framework for authentication and authorization. Regular reviews and audits further ensure that access controls remain aligned with organizational policies, safeguarding the cluster environment against unauthorized access and potential security threats.

Key takeaways:

  • Centralized identity management: By leveraging Microsoft Entra ID, organizations can manage user identities and group memberships centrally, ensuring that any changes are automatically reflected in AKS access permissions.
  • Granular access control: Utilizing Kubernetes Role-Based Access Control (RBAC) in conjunction with Microsoft Entra ID allows for precise permission assignments, ensuring users have the minimum required access to perform their tasks.
  • Enhanced security posture: Disabling local Kubernetes admin accounts in favor of Microsoft Entra ID authentication reduces potential attack vectors and ensures that all access is auditable and compliant with organizational policies.
  • Seamless Azure integration: The synergy between AKS and Azure services, facilitated by Microsoft Entra ID, enables secure and efficient interactions with other Azure resources, promoting a cohesive cloud ecosystem.

How are you managing authentication and access control in your AKS environments? Share your thoughts and experiences in the comments!

Updated Feb 27, 2025
Version 9.0
  • pinna's avatar
    pinna
    Copper Contributor

    That is very well explained! 
    Thanks for sharing