|
| 1 | +--- |
| 2 | +title: Cluster access control with AKS-managed Azure Active Directory integration |
| 3 | +description: Learn how to access clusters when integrating Azure AD in your Azure Kubernetes Service (AKS) clusters. |
| 4 | +ms.topic: article |
| 5 | +ms.date: 04/20/2023 |
| 6 | +ms.custom: devx-track-azurecli |
| 7 | +--- |
| 8 | + |
| 9 | +# Cluster access control with AKS-managed Azure Active Directory integration |
| 10 | + |
| 11 | +When you integrate Azure AD with your AKS cluster, you can use [Conditional Access][aad-conditional-access] or Privileged Identity Management (PIM) for just-in-time requests to control access to your cluster. This article shows you how to enable Conditional Access and PIM on your AKS clusters. |
| 12 | + |
| 13 | +> [!NOTE] |
| 14 | +> Azure AD Conditional Access and Privileged Identity Management are Azure AD Premium capabilities requiring a Premium P2 SKU. For more on Azure AD SKUs, see the [pricing guide][aad-pricing]. |
| 15 | +
|
| 16 | +## Before you begin |
| 17 | + |
| 18 | +* See [AKS-managed Azure Active Directory integration](./managed-azure-ad.md) for an overview and setup instructions. |
| 19 | + |
| 20 | +## Use Conditional Access with Azure AD and AKS |
| 21 | + |
| 22 | +1. In the Azure portal, go to the **Azure Active Directory** page and select **Enterprise applications**. |
| 23 | +2. Select **Conditional Access** > **Policies** > **New policy**. |
| 24 | + |
| 25 | + :::image type="content" source="./media/managed-aad/conditional-access-new-policy.png" alt-text="Screenshot of adding a Conditional Access policy." lightbox="./media/managed-aad/conditional-access-new-policy.png"::: |
| 26 | + |
| 27 | +3. Enter a name for the policy, such as *aks-policy*. |
| 28 | + |
| 29 | +4. Under **Assignments**, select **Users and groups**. Choose the users and groups you want to apply the policy to. In this example, choose the same Azure AD group that has administrator access to your cluster. |
| 30 | + |
| 31 | + :::image type="content" source="./media/managed-aad/conditional-access-users-groups.png" alt-text="Screenshot of selecting users or groups to apply the Conditional Access policy." lightbox="./media/managed-aad/conditional-access-users-groups.png"::: |
| 32 | + |
| 33 | +5. Under **Cloud apps or actions** > **Include**, select **Select apps**. Search for **Azure Kubernetes Service** and select **Azure Kubernetes Service AAD Server**. |
| 34 | + |
| 35 | + :::image type="content" source="./media/managed-aad/conditional-access-apps.png" alt-text="Screenshot of selecting Azure Kubernetes Service AD Server for applying the Conditional Access policy." lightbox="./media/managed-aad/conditional-access-apps.png"::: |
| 36 | + |
| 37 | +6. Under **Access controls** > **Grant**, select **Grant access**, **Require device to be marked as compliant**, and **Require all the selected controls**. |
| 38 | + |
| 39 | + :::image type="content" source="./media/managed-aad/conditional-access-grant-compliant.png" alt-text="Screenshot of selecting to only allow compliant devices for the Conditional Access policy." lightbox="./media/managed-aad/conditional-access-grant-compliant.png" ::: |
| 40 | + |
| 41 | +7. Confirm your settings, set **Enable policy** to **On**, and then select **Create**. |
| 42 | + |
| 43 | + :::image type="content" source="./media/managed-aad/conditional-access-enable-policy.png" alt-text="Screenshot of enabling the Conditional Access policy." lightbox="./media/managed-aad/conditional-access-enable-policy.png"::: |
| 44 | + |
| 45 | +### Verify your Conditional Access policy has been successfully listed |
| 46 | + |
| 47 | +1. Get the user credentials to access the cluster using the [`az aks get-credentials`][az-aks-get-credentials] command. |
| 48 | + |
| 49 | + ```azurecli-interactive |
| 50 | + az aks get-credentials --resource-group myResourceGroup --name myManagedCluster |
| 51 | + ``` |
| 52 | +
|
| 53 | +2. Follow the instructions to sign in. |
| 54 | +
|
| 55 | +3. View the nodes in the cluster using the `kubectl get nodes` command. |
| 56 | +
|
| 57 | + ```azurecli-interactive |
| 58 | + kubectl get nodes |
| 59 | + ``` |
| 60 | +
|
| 61 | +4. In the Azure portal, navigate to **Azure Active Directory** and select **Enterprise applications** > **Activity** > **Sign-ins**. |
| 62 | +
|
| 63 | +5. Under the **Conditional Access** column you should see a status of *Success*. Select the event and then select the **Conditional Access** tab. Your Conditional Access policy will be listed. |
| 64 | +
|
| 65 | + :::image type="content" source="./media/managed-aad/conditional-access-sign-in-activity.png" alt-text="Screenshot that shows failed sign-in entry due to Conditional Access policy." lightbox="./media/managed-aad/conditional-access-sign-in-activity.png"::: |
| 66 | +
|
| 67 | +## Configure just-in-time cluster access with Azure AD and AKS |
| 68 | +
|
| 69 | +1. In the Azure portal, go to **Azure Active Directory** and select **Properties**. |
| 70 | +
|
| 71 | +2. Note the value listed under **Tenant ID**. It will be referenced in a later step as `<tenant-id>`. |
| 72 | +
|
| 73 | + :::image type="content" source="./media/managed-aad/jit-get-tenant-id.png" alt-text="Screenshot of the Azure portal screen for Azure Active Directory with the tenant's ID highlighted." lightbox="./media/managed-aad/jit-get-tenant-id.png"::: |
| 74 | +
|
| 75 | +3. Select **Groups** > **New group**. |
| 76 | +
|
| 77 | + :::image type="content" source="./media/managed-aad/jit-create-new-group.png" alt-text="Screenshot of the Azure portal Active Directory groups screen with the New Group option highlighted." lightbox="./media/managed-aad/jit-create-new-group.png"::: |
| 78 | +
|
| 79 | +4. Verify the group type **Security** is selected and specify a group name, such as *myJITGroup*. Under the option **Azure AD roles can be assigned to this group (Preview)**, select **Yes** and then select **Create**. |
| 80 | +
|
| 81 | + :::image type="content" source="./media/managed-aad/jit-new-group-created.png" alt-text="Screenshot of the new group creation screen in the Azure portal." lightbox="./media/managed-aad/jit-new-group-created.png"::: |
| 82 | +
|
| 83 | +5. On the **Groups** page, select the group you just created and note the Object ID. It will be referenced in a later step as `<object-id>`. |
| 84 | +
|
| 85 | + :::image type="content" source="./media/managed-aad/jit-get-object-id.png" alt-text="Screenshot of the Azure portal screen for the just-created group with the Object ID highlighted." lightbox="./media/managed-aad/jit-get-object-id.png"::: |
| 86 | +
|
| 87 | +6. Create the AKS cluster with AKS-managed Azure AD integration using the [`az aks create`][az-aks-create] command with the `--aad-admin-group-objects-ids` and `--aad-tenant-id parameters` and include the values noted in the steps earlier. |
| 88 | +
|
| 89 | + ```azurecli-interactive |
| 90 | + az aks create -g myResourceGroup -n myManagedCluster --enable-aad --aad-admin-group-object-ids <object-id> --aad-tenant-id <tenant-id> |
| 91 | + ``` |
| 92 | +
|
| 93 | +7. In the Azure portal, select **Activity** > **Privileged Access (Preview)** > **Enable Privileged Access**. |
| 94 | +
|
| 95 | + :::image type="content" source="./media/managed-aad/jit-enabling-priv-access.png" alt-text="Screenshot of the Privileged access (Preview) page in the Azure portal with Enable privileged access highlighted." lightbox="./media/managed-aad/jit-enabling-priv-access.png"::: |
| 96 | +
|
| 97 | +8. To grant access, select **Add assignments**. |
| 98 | +
|
| 99 | + :::image type="content" source="./media/managed-aad/jit-add-active-assignment.png" alt-text="Screenshot of the Privileged access (Preview) screen in the Azure portal after enabling. The option to Add assignments is highlighted." lightbox="./media/managed-aad/jit-add-active-assignment.png"::: |
| 100 | +
|
| 101 | +9. From the **Select role** drop-down list, select the users and groups you want to grant cluster access. These assignments can be modified at any time by a group administrator. Then select **Next**. |
| 102 | +
|
| 103 | + :::image type="content" source="./media/managed-aad/jit-adding-assignment.png" alt-text="Screenshot of the Add assignments Membership screen in the Azure portal with a sample user selected to be added as a member. The Next option is highlighted." lightbox="./media/managed-aad/jit-adding-assignment.png"::: |
| 104 | +
|
| 105 | +10. Under **Assignment type**, select **Active** and then specify the desired duration. Provide a justification and then select **Assign**. |
| 106 | +
|
| 107 | + :::image type="content" source="./media/managed-aad/jit-set-active-assignment-details.png" alt-text="Screenshot of the Add assignments Setting screen in the Azure portal. An assignment type of Active is selected and a sample justification has been given. The Assign option is highlighted." lightbox="./media/managed-aad/jit-set-active-assignment-details.png"::: |
| 108 | +
|
| 109 | +For more information about assignment types, see [Assign eligibility for a privileged access group (preview) in Privileged Identity Management][aad-assignments]. |
| 110 | +
|
| 111 | +### Verify just-in-time access is working by accessing the cluster |
| 112 | +
|
| 113 | +1. Get the user credentials to access the cluster using the [`az aks get-credentials`][az-aks-get-credentials] command. |
| 114 | +
|
| 115 | + ```azurecli-interactive |
| 116 | + az aks get-credentials --resource-group myResourceGroup --name myManagedCluster |
| 117 | + ``` |
| 118 | +
|
| 119 | +2. Follow the steps to sign in. |
| 120 | +
|
| 121 | +3. Use the `kubectl get nodes` command to view the nodes in the cluster. |
| 122 | +
|
| 123 | + ```azurecli-interactive |
| 124 | + kubectl get nodes |
| 125 | + ``` |
| 126 | +
|
| 127 | +4. Note the authentication requirement and follow the steps to authenticate. If successful, you should see an output similar to the following example output: |
| 128 | +
|
| 129 | + ```output |
| 130 | + To sign in, use a web browser to open the page https://microsoft.com/devicelogin and enter the code AAAAAAAAA to authenticate. |
| 131 | + NAME STATUS ROLES AGE VERSION |
| 132 | + aks-nodepool1-61156405-vmss000000 Ready agent 6m36s v1.18.14 |
| 133 | + aks-nodepool1-61156405-vmss000001 Ready agent 6m42s v1.18.14 |
| 134 | + aks-nodepool1-61156405-vmss000002 Ready agent 6m33s v1.18.14 |
| 135 | + ``` |
| 136 | +
|
| 137 | +### Apply just-in-time access at the namespace level |
| 138 | +
|
| 139 | +1. Integrate your AKS cluster with [Azure RBAC](manage-azure-rbac.md). |
| 140 | +
|
| 141 | +2. Associate the group you want to integrate with just-in-time access with a namespace in the cluster using the [`az role assignment create`][az-role-assignment-create] command. |
| 142 | +
|
| 143 | + ```azurecli-interactive |
| 144 | + az role assignment create --role "Azure Kubernetes Service RBAC Reader" --assignee <AAD-ENTITY-ID> --scope $AKS_ID/namespaces/<namespace-name> |
| 145 | + ``` |
| 146 | +
|
| 147 | +3. Associate the group you configured at the namespace level with PIM to complete the configuration. |
| 148 | +
|
| 149 | +## Troubleshooting |
| 150 | +
|
| 151 | +If `kubectl get nodes` returns an error similar to the following: |
| 152 | +
|
| 153 | +```output |
| 154 | +Error from server (Forbidden): nodes is forbidden: User "aaaa11111-11aa-aa11-a1a1-111111aaaaa" cannot list resource "nodes" in API group "" at the cluster scope |
| 155 | +``` |
| 156 | + |
| 157 | +Make sure the admin of the security group has given your account an *Active* assignment. |
| 158 | + |
| 159 | +## Next steps |
| 160 | + |
| 161 | +* Use [kubelogin](https://github.com/Azure/kubelogin) to access features for Azure authentication that aren't available in kubectl. |
| 162 | + |
| 163 | +<!-- LINKS - External --> |
| 164 | +[aad-pricing]: https://azure.microsoft.com/pricing/details/active-directory/ |
| 165 | + |
| 166 | +<!-- LINKS - Internal --> |
| 167 | +[aad-conditional-access]: ../active-directory/conditional-access/overview.md |
| 168 | +[az-aks-get-credentials]: /cli/azure/aks#az_aks_get_credentials |
| 169 | +[az-role-assignment-create]: /cli/azure/role/assignment#az_role_assignment_create |
| 170 | +[aad-assignments]: ../active-directory/privileged-identity-management/groups-assign-member-owner.md#assign-an-owner-or-member-of-a-group |
| 171 | +[az-aks-create]: /cli/azure/aks#az_aks_create |
0 commit comments