Skip to content

Commit f2dbb84

Browse files
authored
Merge pull request #276060 from JnHs/jh-arckb-rbac2
updates
2 parents f617eaa + 6ca7ff9 commit f2dbb84

File tree

3 files changed

+28
-244
lines changed

3 files changed

+28
-244
lines changed

articles/azure-arc/kubernetes/azure-rbac.md

Lines changed: 20 additions & 234 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
---
2-
title: "Azure RBAC on Azure Arc-enabled Kubernetes clusters (preview)"
3-
ms.date: 05/04/2023
2+
title: "Azure RBAC on Azure Arc-enabled Kubernetes clusters"
3+
ms.date: 05/22/2024
44
ms.topic: how-to
55
ms.custom: devx-track-azurecli
66
description: "Use Azure RBAC for authorization checks on Azure Arc-enabled Kubernetes clusters."
77
---
88

9-
# Use Azure RBAC on Azure Arc-enabled Kubernetes clusters (preview)
9+
# Use Azure RBAC on Azure Arc-enabled Kubernetes clusters
1010

1111
Kubernetes [ClusterRoleBinding and RoleBinding](https://kubernetes.io/docs/reference/access-authn-authz/rbac/#rolebinding-and-clusterrolebinding) object types help to define authorization in Kubernetes natively. By using this feature, you can use Microsoft Entra ID and role assignments in Azure to control authorization checks on the cluster. Azure role assignments let you granularly control which users can read, write, and delete Kubernetes objects such as deployment, pod, and service.
1212

1313
For a conceptual overview of this feature, see [Azure RBAC on Azure Arc-enabled Kubernetes](conceptual-azure-rbac.md).
1414

15-
[!INCLUDE [preview features note](./includes/preview/preview-callout.md)]
16-
1715
## Prerequisites
1816

1917
- [Install or upgrade the Azure CLI](/cli/azure/install-azure-cli) to the latest version.
@@ -37,222 +35,31 @@ For a conceptual overview of this feature, see [Azure RBAC on Azure Arc-enabled
3735
> [!NOTE]
3836
> You can't set up this feature for Red Hat OpenShift, or for managed Kubernetes offerings of cloud providers like Elastic Kubernetes Service or Google Kubernetes Engine where the user doesn't have access to the API server of the cluster. For Azure Kubernetes Service (AKS) clusters, this [feature is available natively](../../aks/manage-azure-rbac.md) and doesn't require the AKS cluster to be connected to Azure Arc.
3937
40-
<a name='set-up-azure-ad-applications'></a>
41-
42-
## Set up Microsoft Entra applications
43-
44-
### [Azure CLI >= v2.3.7](#tab/AzureCLI)
45-
46-
#### Create a server application
47-
48-
1. Create a new Microsoft Entra application and get its `appId` value. This value is used in later steps as `serverApplicationId`.
49-
50-
```azurecli
51-
CLUSTER_NAME="<name-of-arc-connected-cluster>"
52-
TENANT_ID="<tenant>"
53-
SERVER_UNIQUE_SUFFIX="<identifier_suffix>"
54-
SERVER_APP_ID=$(az ad app create --display-name "${CLUSTER_NAME}Server" --identifier-uris "api://${TENANT_ID}/${SERVER_UNIQUE_SUFFIX}" --query appId -o tsv)
55-
echo $SERVER_APP_ID
56-
```
57-
58-
1. To grant "Sign in and read user profile" API permissions to the server application, copy this JSON and save it in a file called oauth2-permissions.json:
59-
60-
```json
61-
{
62-
"oauth2PermissionScopes": [
63-
{
64-
"adminConsentDescription": "Sign in and read user profile",
65-
"adminConsentDisplayName": "Sign in and read user profile",
66-
"id": "<paste_the_SERVER_APP_ID>",
67-
"isEnabled": true,
68-
"type": "User",
69-
"userConsentDescription": "Sign in and read user profile",
70-
"userConsentDisplayName": "Sign in and read user profile",
71-
"value": "User.Read"
72-
}
73-
]
74-
}
75-
```
76-
77-
1. Update the application's group membership claims. Run the commands in the same directory as the `oauth2-permissions.json` file. RBAC for Azure Arc-enabled Kubernetes requires [`signInAudience` to be set to **AzureADMyOrg**](../../active-directory/develop/supported-accounts-validation.md):
78-
79-
```azurecli
80-
az ad app update --id "${SERVER_APP_ID}" --set groupMembershipClaims=All
81-
az ad app update --id ${SERVER_APP_ID} --set [email protected]
82-
az ad app update --id ${SERVER_APP_ID} --set signInAudience=AzureADMyOrg
83-
SERVER_OBJECT_ID=$(az ad app show --id "${SERVER_APP_ID}" --query "id" -o tsv)
84-
az rest --method PATCH --headers "Content-Type=application/json" --uri https://graph.microsoft.com/v1.0/applications/${SERVER_OBJECT_ID}/ --body '{"api":{"requestedAccessTokenVersion": 1}}'
85-
```
86-
87-
1. Create a service principal and get its `password` field value. This value is required later as `serverApplicationSecret` when you're enabling this feature on the cluster. This secret is valid for one year by default and will need to be [rotated after that](#refresh-the-secret-of-the-server-application). To set a custom expiration duration, use [`az ad sp credential reset`](/cli/azure/ad/sp/credential?view=azure-cli-latest&preserve-view=true#az-ad-sp-credential-reset):
88-
89-
```azurecli
90-
az ad sp create --id "${SERVER_APP_ID}"
91-
SERVER_APP_SECRET=$(az ad sp credential reset --id "${SERVER_APP_ID}" --query password -o tsv)
92-
```
93-
94-
1. Grant "Sign in and read user profile" API permissions to the application by using [`az ad app permission`](/cli/azure/ad/app/permission?view=azure-cli-latest&preserve-view=true##az-ad-app-permission-add-examples):
95-
96-
```azurecli
97-
az ad app permission add --id "${SERVER_APP_ID}" --api 00000003-0000-0000-c000-000000000000 --api-permissions e1fe6dd8-ba31-4d61-89e7-88639da4683d=Scope
98-
az ad app permission grant --id "${SERVER_APP_ID}" --api 00000003-0000-0000-c000-000000000000 --scope User.Read
99-
```
100-
101-
> [!NOTE]
102-
> An Azure [application administrator](../../active-directory/roles/permissions-reference.md#application-administrator) has to run this step.
103-
>
104-
> For usage of this feature in production, we recommend that you create a different server application for every cluster.
105-
106-
#### Create a client application
107-
108-
1. Create a new Microsoft Entra application and get its `appId` value. This value is used in later steps as `clientApplicationId`.
109-
110-
```azurecli
111-
CLIENT_UNIQUE_SUFFIX="<identifier_suffix>"
112-
CLIENT_APP_ID=$(az ad app create --display-name "${CLUSTER_NAME}Client" --is-fallback-public-client --public-client-redirect-uris "api://${TENANT_ID}/${CLIENT_UNIQUE_SUFFIX}" --query appId -o tsv)
113-
echo $CLIENT_APP_ID
114-
```
115-
116-
2. Create a service principal for this client application:
117-
118-
```azurecli
119-
az ad sp create --id "${CLIENT_APP_ID}"
120-
```
121-
122-
3. Get the `oAuthPermissionId` value for the server application:
123-
124-
```azurecli
125-
az ad app show --id "${SERVER_APP_ID}" --query "api.oauth2PermissionScopes[0].id" -o tsv
126-
```
127-
128-
4. Grant the required permissions for the client application. RBAC for Azure Arc-enabled Kubernetes requires [`signInAudience` to be set to **AzureADMyOrg**](../../active-directory/develop/supported-accounts-validation.md):
129-
130-
```azurecli
131-
az ad app permission add --id "${CLIENT_APP_ID}" --api "${SERVER_APP_ID}" --api-permissions <oAuthPermissionId>=Scope
132-
RESOURCE_APP_ID=$(az ad app show --id "${CLIENT_APP_ID}" --query "requiredResourceAccess[0].resourceAppId" -o tsv)
133-
az ad app permission grant --id "${CLIENT_APP_ID}" --api "${RESOURCE_APP_ID}" --scope User.Read
134-
az ad app update --id ${CLIENT_APP_ID} --set signInAudience=AzureADMyOrg
135-
CLIENT_OBJECT_ID=$(az ad app show --id "${CLIENT_APP_ID}" --query "id" -o tsv)
136-
az rest --method PATCH --headers "Content-Type=application/json" --uri https://graph.microsoft.com/v1.0/applications/${CLIENT_OBJECT_ID}/ --body '{"api":{"requestedAccessTokenVersion": 1}}'
137-
```
138-
139-
### [Azure CLI < v2.3.7](#tab/AzureCLI236)
140-
141-
#### Create a server application
142-
143-
1. Create a new Microsoft Entra application and get its `appId` value. This value is used in later steps as `serverApplicationId`.
144-
145-
```azurecli
146-
CLUSTER_NAME="<name-of-arc-connected-cluster>"
147-
TENANT_ID="<tenant>"
148-
SERVER_UNIQUE_SUFFIX="<identifier_suffix>"
149-
SERVER_APP_ID=$(az ad app create --display-name "${CLUSTER_NAME}Server" --identifier-uris "api://${TENANT_ID}/${SERVER_UNIQUE_SUFFIX}" --query appId -o tsv)
150-
echo $SERVER_APP_ID
151-
```
152-
153-
1. Update the application's group membership claims:
154-
155-
```azurecli
156-
az ad app update --id "${SERVER_APP_ID}" --set groupMembershipClaims=All
157-
```
158-
159-
1. Create a service principal and get its `password` field value. This value is required later as `serverApplicationSecret` when you're enabling this feature on the cluster. This secret is valid for one year by default and will need to be [rotated after that](#refresh-the-secret-of-the-server-application). To set a custom expiration duration, use [`az ad sp credential reset`](/cli/azure/ad/sp/credential?view=azure-cli-latest&preserve-view=true#az-ad-sp-credential-reset):
160-
161-
```azurecli
162-
az ad sp create --id "${SERVER_APP_ID}"
163-
SERVER_APP_SECRET=$(az ad sp credential reset --name "${SERVER_APP_ID}" --credential-description "ArcSecret" --query password -o tsv)
164-
```
165-
166-
1. Grant "Sign in and read user profile" API permissions to the application by using [`az ad app permission`](/cli/azure/ad/app/permission?view=azure-cli-latest&preserve-view=true##az-ad-app-permission-add-examples):
167-
168-
```azurecli
169-
az ad app permission add --id "${SERVER_APP_ID}" --api 00000003-0000-0000-c000-000000000000 --api-permissions e1fe6dd8-ba31-4d61-89e7-88639da4683d=Scope
170-
az ad app permission grant --id "${SERVER_APP_ID}" --api 00000003-0000-0000-c000-000000000000
171-
```
172-
173-
> [!NOTE]
174-
> An Azure [application administrator](../../active-directory/roles/permissions-reference.md#application-administrator) has to run this step.
175-
>
176-
> For usage of this feature in production, we recommend that you create a different server application for every cluster.
177-
178-
#### Create a client application
38+
## Enable Azure RBAC on the cluster
17939
180-
1. Create a new Microsoft Entra application and get its `appId` value. This value is used in later steps as `clientApplicationId`.
40+
1. Get the cluster MSI identity by running the following command:
18141
18242
```azurecli
183-
CLIENT_UNIQUE_SUFFIX="<identifier_suffix>"
184-
CLIENT_APP_ID=$(az ad app create --display-name "${CLUSTER_NAME}Client" --native-app --reply-urls "api://${TENANT_ID}/${CLIENT_UNIQUE_SUFFIX}" --query appId -o tsv)
185-
echo $CLIENT_APP_ID
43+
az connectedk8s show -g <resource-group> -n <connected-cluster-name>
18644
```
18745

188-
2. Create a service principal for this client application:
46+
1. Get the ED (`identity.principalId`) from the output and run the following command to assign the **Connected Cluster Managed Identity CheckAccess Reader** role to the cluster MSI:
18947

19048
```azurecli
191-
az ad sp create --id "${CLIENT_APP_ID}"
49+
az role assignment create --role "Connected Cluster Managed Identity CheckAccess Reader" --assignee "<Cluster MSI ID>" --scope <cluster ARM ID>
19250
```
19351

194-
3. Get the `oAuthPermissionId` value for the server application:
19552

196-
```azurecli
197-
az ad app show --id "${SERVER_APP_ID}" --query "oauth2Permissions[0].id" -o tsv
198-
```
199-
200-
4. Grant the required permissions for the client application:
53+
1. Enable Azure role-based access control (RBAC) on your Azure Arc-enabled Kubernetes cluster by running the following command:
20154

20255
```azurecli
203-
az ad app permission add --id "${CLIENT_APP_ID}" --api "${SERVER_APP_ID}" --api-permissions <oAuthPermissionId>=Scope
204-
az ad app permission grant --id "${CLIENT_APP_ID}" --api "${SERVER_APP_ID}"
205-
```
206-
207-
---
208-
209-
## Create a role assignment for the server application
210-
211-
The server application needs the `Microsoft.Authorization/*/read` permissions so that it can confirm that the user making the request is authorized on the Kubernetes objects that are included in the request.
212-
213-
1. Create a file named *accessCheck.json* with the following contents:
214-
215-
```json
216-
{
217-
"Name": "Read authorization",
218-
"IsCustom": true,
219-
"Description": "Read authorization",
220-
"Actions": ["Microsoft.Authorization/*/read"],
221-
"NotActions": [],
222-
"DataActions": [],
223-
"NotDataActions": [],
224-
"AssignableScopes": [
225-
"/subscriptions/<subscription-id>"
226-
]
227-
}
56+
az connectedk8s enable-features -n <clusterName> -g <resourceGroupName> --features azure-rbac --app-id "${SERVER_APP_ID}" --app-secret "${SERVER_APP_SECRET}"
22857
```
22958

230-
Replace `<subscription-id>` with the actual subscription ID.
231-
232-
2. Run the following command to create the new custom role:
233-
234-
```azurecli
235-
ROLE_ID=$(az role definition create --role-definition ./accessCheck.json --query id -o tsv)
236-
```
237-
238-
3. Create a role assignment on the server application as `assignee` by using the role that you created:
239-
240-
```azurecli
241-
az role assignment create --role "${ROLE_ID}" --assignee "${SERVER_APP_ID}" --scope /subscriptions/<subscription-id>
242-
```
243-
244-
## Enable Azure RBAC on the cluster
245-
246-
Enable Azure role-based access control (RBAC) on your Azure Arc-enabled Kubernetes cluster by running the following command:
247-
248-
```azurecli
249-
az connectedk8s enable-features -n <clusterName> -g <resourceGroupName> --features azure-rbac --app-id "${SERVER_APP_ID}" --app-secret "${SERVER_APP_SECRET}"
250-
```
251-
252-
> [!NOTE]
253-
> Before you run the preceding command, ensure that the `kubeconfig` file on the machine is pointing to the cluster on which you'll enable the Azure RBAC feature.
254-
>
255-
> Use `--skip-azure-rbac-list` with the preceding command for a comma-separated list of usernames, emails, and OpenID connections undergoing authorization checks by using Kubernetes native `ClusterRoleBinding` and `RoleBinding` objects instead of Azure RBAC.
59+
> [!NOTE]
60+
> Before you run the preceding command, ensure that the `kubeconfig` file on the machine is pointing to the cluster on which you'll enable the Azure RBAC feature.
61+
>
62+
> Use `--skip-azure-rbac-list` with the preceding command for a comma-separated list of usernames, emails, and OpenID connections undergoing authorization checks by using Kubernetes native `ClusterRoleBinding` and `RoleBinding` objects instead of Azure RBAC.
25663
25764
### Generic cluster where no reconciler is running on the `apiserver` specification
25865

@@ -487,7 +294,7 @@ Using a shared kubeconfig requires slightly different steps depending on your Ku
487294

488295
### [Kubernetes version >= 1.26](#tab/kubernetes-latest)
489296

490-
1. Run the following command to set the credentials for the user:
297+
1. Run the following command to set the credentials for the user. Specify `serverApplicationId` as `6256c85f-0aad-4d50-b960-e6e9b21efe35` and `clientApplicationId` as `3f4439ff-e698-4d6d-84fe-09c9d574f06b`:
491298

492299
```console
493300
kubectl config set-credentials <testuser>@<mytenant.onmicrosoft.com> \
@@ -519,10 +326,10 @@ Using a shared kubeconfig requires slightly different steps depending on your Ku
519326
name: azure
520327
```
521328

522-
> [!NOTE]
523-
>[Exec plugin](https://kubernetes.io/docs/reference/access-authn-authz/authentication/#client-go-credential-plugins) is a Kubernetes authentication strategy that allows `kubectl` to execute an external command to receive user credentials to send to `apiserver`. Starting with Kubernetes version 1.26, the default Azure authorization plugin is no longer included in `client-go` and `kubectl`. With later versions, in order to use the exec plugin to receive user credentials you must use [Azure Kubelogin](https://azure.github.io/kubelogin/index.html), a `client-go` credential (exec) plugin that implements Azure authentication.
329+
> [!NOTE]
330+
>[Exec plugin](https://kubernetes.io/docs/reference/access-authn-authz/authentication/#client-go-credential-plugins) is a Kubernetes authentication strategy that allows `kubectl` to execute an external command to receive user credentials to send to `apiserver`. Starting with Kubernetes version 1.26, the default Azure authorization plugin is no longer included in `client-go` and `kubectl`. With later versions, in order to use the exec plugin to receive user credentials you must use [Azure Kubelogin](https://azure.github.io/kubelogin/index.html), a `client-go` credential (exec) plugin that implements Azure authentication.
524331

525-
4. Install Azure Kubelogin:
332+
1. Install Azure Kubelogin:
526333

527334
- For Windows or Mac, follow the [Azure Kubelogin installation instructions](https://azure.github.io/kubelogin/install.html#installation).
528335
- For Linux or Ubuntu, download the [latest version of kubelogin](https://github.com/Azure/kubelogin/releases), then run the following commands:
@@ -537,7 +344,7 @@ Using a shared kubeconfig requires slightly different steps depending on your Ku
537344
sudo chmod +x /usr/local/bin/kubelogin
538345
```
539346

540-
5. [Convert](https://azure.github.io/kubelogin/cli/convert-kubeconfig.html) the kubelogin to use the appropriate [login mode](https://azure.github.io/kubelogin/concepts/login-modes.html). For example, for [device code login](https://azure.github.io/kubelogin/concepts/login-modes/devicecode.html) with a Microsoft Entra user, the commands would be as follows:
347+
1. [Convert](https://azure.github.io/kubelogin/cli/convert-kubeconfig.html) the kubelogin to use the appropriate [login mode](https://azure.github.io/kubelogin/concepts/login-modes.html). For example, for [device code login](https://azure.github.io/kubelogin/concepts/login-modes/devicecode.html) with a Microsoft Entra user, the commands would be as follows:
541348

542349
```bash
543350
export KUBECONFIG=/path/to/kubeconfig
@@ -547,7 +354,7 @@ Using a shared kubeconfig requires slightly different steps depending on your Ku
547354

548355
### [Kubernetes < v1.26](#tab/Kubernetes-earlier)
549356

550-
1. Run the following command to set the credentials for the user:
357+
1. Run the following command to set the credentials for the user. Specify `serverApplicationId` as `6256c85f-0aad-4d50-b960-e6e9b21efe35` and `clientApplicationId` as `3f4439ff-e698-4d6d-84fe-09c9d574f06b`:
551358

552359
```console
553360
kubectl config set-credentials <testuser>@<mytenant.onmicrosoft.com> \
@@ -712,27 +519,6 @@ node-2 Ready agent 6m42s v1.18.14
712519
node-3 Ready agent 6m33s v1.18.14
713520
```
714521

715-
## Refresh the secret of the server application
716-
717-
If the secret for the server application's service principal has expired, you'll need to rotate it.
718-
719-
### [Azure CLI >= v2.3.7](#tab/AzureCLI)
720-
```azurecli
721-
SERVER_APP_SECRET=$(az ad sp credential reset --id "${SERVER_APP_ID}" --query password -o tsv)
722-
```
723-
### [Azure CLI < v2.3.7](#tab/AzureCLI236)
724-
```azurecli
725-
SERVER_APP_SECRET=$(az ad sp credential reset --name "${SERVER_APP_ID}" --credential-description "ArcSecret" --query password -o tsv)
726-
```
727-
---
728-
729-
Update the secret on the cluster. Include any optional parameters you configured when the command was originally run.
730-
731-
```azurecli
732-
az connectedk8s enable-features -n <clusterName> -g <resourceGroupName> --features azure-rbac --app-id "${SERVER_APP_ID}" --app-secret "${SERVER_APP_SECRET}"
733-
```
734-
735-
736522
## Next steps
737523

738524
- Securely connect to the cluster by using [Cluster Connect](cluster-connect.md).

articles/azure-arc/kubernetes/conceptual-azure-rbac.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
---
2-
title: "Azure RBAC on Azure Arc-enabled Kubernetes (preview)"
3-
ms.date: 02/28/2024
2+
title: "Azure RBAC on Azure Arc-enabled Kubernetes"
3+
ms.date: 05/22/2024
44
ms.topic: conceptual
55
description: "This article provides a conceptual overview of the Azure RBAC capability on Azure Arc-enabled Kubernetes."
66
---
77

8-
# Azure RBAC on Azure Arc-enabled Kubernetes clusters (preview)
8+
# Azure RBAC on Azure Arc-enabled Kubernetes clusters
99

1010
Kubernetes [ClusterRoleBinding and RoleBinding](https://kubernetes.io/docs/reference/access-authn-authz/rbac/#rolebinding-and-clusterrolebinding) object types help to define authorization in Kubernetes natively. With Azure role-based access control (Azure RBAC), you can use Microsoft Entra ID and role assignments in Azure to control authorization checks on the cluster. This allows the benefits of Azure role assignments, such as activity logs showing all Azure RBAC changes to an Azure resource, to be used with your Azure Arc-enabled Kubernetes cluster.
1111

12-
[!INCLUDE [preview features note](./includes/preview/preview-callout.md)]
13-
1412
## Architecture
1513

1614
:::image type="content" source="media/conceptual-azure-rbac.png" alt-text="Diagram showing Azure RBAC architecture.":::

0 commit comments

Comments
 (0)