MSDN Documentation

Integrate Azure Kubernetes Service (AKS) with Azure Active Directory (AAD)

Published: October 26, 2023 | Last Updated: October 26, 2023

This tutorial demonstrates how to integrate your Azure Kubernetes Service (AKS) cluster with Azure Active Directory (AAD) for centralized identity and access management. This allows you to use your existing AAD identities to authenticate and authorize access to your Kubernetes cluster.

Why Integrate AKS with AAD?

Integrating AKS with AAD offers several benefits:

Prerequisites

Before you begin, ensure you have the following:

Steps to Integrate AAD with AKS

Follow these steps to enable AAD integration with your AKS cluster:

  1. Enable AAD Integration during AKS Cluster Creation (Recommended)

    The easiest way to integrate is to enable AAD integration when you create your AKS cluster. Use the following Azure CLI command:

    az aks create \
        --resource-group myResourceGroup \
        --name myAKSCluster \
        --node-count 1 \
        --enable-aad \
        --aad-admin-group-object-ids <your-group-object-id> \
        --enable-azure- polĂ­ticas \
        --location eastus

    Replace myResourceGroup, myAKSCluster, and <your-group-object-id> with your specific values. The aad-admin-group-object-ids flag assigns administrator roles to members of the specified AAD group.

  2. Enable AAD Integration on an Existing AKS Cluster

    If your AKS cluster already exists, you can enable AAD integration using the following command:

    az aks update \
        --resource-group myResourceGroup \
        --name myAKSCluster \
        --enable-aad \
        --aad-admin-group-object-ids <your-group-object-id>

    This command will update the existing cluster to enable AAD integration. You will need to restart your cluster nodes for the changes to take effect.

  3. Configure Kubernetes RBAC

    After enabling AAD integration, you need to configure Kubernetes Role-Based Access Control (RBAC) to grant permissions to your AAD users and groups. You can create Kubernetes ClusterRole and ClusterRoleBinding objects.

    Example ClusterRole:

    apiVersion: rbac.authorization.k8s.io/v1
    kind: ClusterRole
    metadata:
      name: aks-role-for-aad-users
    rules:
    - apiGroups: [""]
      resources: ["pods", "services", "deployments"]
      verbs: ["get", "list", "watch", "create", "update", "patch", "delete"]

    Example ClusterRoleBinding:

    apiVersion: rbac.authorization.k8s.io/v1
    kind: ClusterRoleBinding
    metadata:
      name: aks-rolebinding-for-aad-users
    subjects:
    - kind: Group
      name: "<your-aad-group-name>" # e.g., "Developers"
      apiGroup: rbac.authorization.k8s.io
    roleRef:
      kind: ClusterRole
      name: aks-role-for-aad-users
      apiGroup: rbac.authorization.k8s.io

    Replace <your-aad-group-name> with the actual name of your Azure AD group.

  4. Connect to your AKS cluster using kubectl

    Once configured, you can connect to your AKS cluster using kubectl. The authentication will be handled by AAD.

    az aks get-credentials --resource-group myResourceGroup --name myAKSCluster

    When you run kubectl commands, you will be prompted to authenticate with your AAD credentials through a web browser.

Managing Access

You can manage access to your AKS cluster by:

Troubleshooting

If you encounter issues, consider the following:

Conclusion

Integrating AKS with Azure AD provides a powerful and secure way to manage access to your Kubernetes clusters. By centralizing identity and leveraging RBAC, you can ensure that only authorized users and applications can interact with your cluster resources.

"AAD integration enhances the security posture of your AKS clusters by providing a unified approach to identity and access management."