Skip to content

Commit bb16bf6

Browse files
committed
updated the cli commands and reordered ver in tabs
1 parent fdfb298 commit bb16bf6

File tree

1 file changed

+56
-57
lines changed

1 file changed

+56
-57
lines changed

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

Lines changed: 56 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ A conceptual overview of this feature is available in the [Azure RBAC on Azure A
4141
## Set up Azure AD applications
4242
4343
44-
### [AzureCLI < v2.37](#tab/AzureCLI)
44+
### [AzureCLI >= v2.37](#tab/AzureCLI237)
4545
#### Create a server application
4646
1. Create a new Azure AD application and get its `appId` value. This value is used in later steps as `serverApplicationId`.
4747
@@ -53,40 +53,66 @@ A conceptual overview of this feature is available in the [Azure RBAC on Azure A
5353
echo $SERVER_APP_ID
5454
```
5555
56-
1. Update the application's group membership claims:
56+
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:
57+
58+
```json
59+
{
60+
"oauth2PermissionScopes": [
61+
{
62+
"adminConsentDescription": "Sign in and read user profile",
63+
"adminConsentDisplayName": "Sign in and read user profile",
64+
"id": "<unique_guid>",
65+
"isEnabled": true,
66+
"type": "User",
67+
"userConsentDescription": "Sign in and read user profile",
68+
"userConsentDisplayName": "Sign in and read user profile",
69+
"value": "User.Read"
70+
}
71+
]
72+
}
73+
```
74+
75+
1. Update the application's group membership claims. Run the commands in the same directory as `oauth2-permissions.json` file. RBAC for Azure Arc for kuberentes requires scope `AzureADMyOrg` [Additional Information](/azure/active-directory/develop/supported-accounts-validation):
76+
5777
```azurecli
5878
az ad app update --id "${SERVER_APP_ID}" --set groupMembershipClaims=All
59-
```
79+
az ad app update --id ${SERVER_APP_ID} --set [email protected]
80+
az ad app update --id ${SERVER_APP_ID} --set signInAudience=AzureADMyOrg
81+
SERVER_OBJECT_ID=$(az ad app show --id "${SERVER_APP_ID}" --query "id" -o tsv)
82+
az rest --method PATCH --headers "Content-Type=application/json" --uri https://graph.microsoft.com/v1.0/applications/${SERVER_OBJECT_ID}/ --body '{"api":{"requestedAccessTokenVersion": 1}}'
83+
```
84+
6085
6186
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. Please note that this secret is valid for 1 year by default and will need to be [rotated after that](./azure-rbac.md#refresh-the-secret-of-the-server-application). Please refer to [this](/cli/azure/ad/sp/credential?view=azure-cli-latest&preserve-view=true#az-ad-sp-credential-reset) to set a custom expiry duration.
6287
6388
```azurecli
6489
az ad sp create --id "${SERVER_APP_ID}"
65-
SERVER_APP_SECRET=$(az ad sp credential reset --name "${SERVER_APP_ID}" --credential-description "ArcSecret" --query password -o tsv)
90+
SERVER_APP_SECRET=$(az ad sp credential reset --id "${SERVER_APP_ID}" --query password -o tsv)
6691
```
6792
6893
1. Grant "Sign in and read user profile" API permissions to the application. [Additional information](/cli/azure/ad/app/permission?view=azure-cli-latest#az-ad-app-permission-add-examples):
6994
70-
```azurecli
95+
```azurecli
7196
az ad app permission add --id "${SERVER_APP_ID}" --api 00000003-0000-0000-c000-000000000000 --api-permissions e1fe6dd8-ba31-4d61-89e7-88639da4683d=Scope
72-
az ad app permission grant --id "${SERVER_APP_ID}" --api 00000003-0000-0000-c000-000000000000
97+
az ad app permission grant --id "${SERVER_APP_ID}" --api 00000003-0000-0000-c000-000000000000 --scope User.Read
7398
```
7499
75100
> [!NOTE]
76101
> An Azure tenant administrator has to run this step.
77102
>
78-
> For usage of this feature in production, we recommend that you create a different server application for every cluster.
103+
> For usage of this feature in production, we recommend that you create a different server application for every cluster.
79104
80105
#### Create a client application
81106
82107
1. Create a new Azure AD application and get its `appId` value. This value is used in later steps as `clientApplicationId`.
83108
84109
```azurecli
85110
CLIENT_UNIQUE_SUFFIX="<identifier_suffix>"
86-
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)
87-
echo $CLIENT_APP_ID
111+
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)
112+
echo $CLIENT_APP_ID
88113
```
89114
115+
90116
2. Create a service principal for this client application:
91117
92118
```azurecli
@@ -96,17 +122,22 @@ A conceptual overview of this feature is available in the [Azure RBAC on Azure A
96122
3. Get the `oAuthPermissionId` value for the server application:
97123
98124
```azurecli
99-
az ad app show --id "${SERVER_APP_ID}" --query "oauth2Permissions[0].id" -o tsv
125+
az ad app show --id "${SERVER_APP_ID}" --query "api.oauth2PermissionScopes[0].id" -o tsv
100126
```
101127
102-
4. Grant the required permissions for the client application:
128+
4. Grant the required permissions for the client application. RBAC for Azure Arc for kuberentes requires scope `AzureADMyOrg` [Additional Information](/azure/active-directory/develop/supported-accounts-validation):
103129
104130
```azurecli
105131
az ad app permission add --id "${CLIENT_APP_ID}" --api "${SERVER_APP_ID}" --api-permissions <oAuthPermissionId>=Scope
106-
az ad app permission grant --id "${CLIENT_APP_ID}" --api "${SERVER_APP_ID}"
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}}'
107137
```
108138
109-
### [AzureCLI >= v2.37](#tab/AzureCLI237)
139+
140+
### [AzureCLI < v2.37](#tab/AzureCLI)
110141
#### Create a server application
111142
1. Create a new Azure AD application and get its `appId` value. This value is used in later steps as `serverApplicationId`.
112143
@@ -118,66 +149,40 @@ A conceptual overview of this feature is available in the [Azure RBAC on Azure A
118149
echo $SERVER_APP_ID
119150
```
120151
121-
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:
122-
123-
```json
124-
{
125-
"oauth2PermissionScopes": [
126-
{
127-
"adminConsentDescription": "Sign in and read user profile",
128-
"adminConsentDisplayName": "Sign in and read user profile",
129-
"id": "<oauth_app_ID>",
130-
"isEnabled": true,
131-
"type": "User",
132-
"userConsentDescription": "Sign in and read user profile",
133-
"userConsentDisplayName": "Sign in and read user profile",
134-
"value": "User.Read"
135-
}
136-
]
137-
}
138-
```
139-
140-
1. Update the application's group membership claims. RBAC for Azure Arc for kuberentes requires scope `AzureADMyOrg` [Additional Information](/azure/active-directory/develop/supported-accounts-validation):
141-
152+
1. Update the application's group membership claims:
142153
```azurecli
143154
az ad app update --id "${SERVER_APP_ID}" --set groupMembershipClaims=All
144-
az ad app update --id ${SERVER_APP_ID} --set [email protected]
145-
az ad app update --id ${SERVER_APP_ID} --set signInAudience=AzureADMyOrg
146-
SERVER_OBJECT_ID=$(az ad app show --id "${SERVER_APP_ID}" --query "id" -o tsv)
147-
az rest --method PATCH --headers "Content-Type=application/json" --uri https://graph.microsoft.com/v1.0/applications/${SERVER_OBJECT_ID}/ --body '{"api":{"requestedAccessTokenVersion": 1}}'
148-
```
149-
155+
```
150156
151157
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. Please note that this secret is valid for 1 year by default and will need to be [rotated after that](./azure-rbac.md#refresh-the-secret-of-the-server-application). Please refer to [this](/cli/azure/ad/sp/credential?view=azure-cli-latest&preserve-view=true#az-ad-sp-credential-reset) to set a custom expiry duration.
152158
153159
```azurecli
154160
az ad sp create --id "${SERVER_APP_ID}"
155-
SERVER_APP_SECRET=$(az ad sp credential reset --id "${SERVER_APP_ID}" --query password -o tsv)
161+
SERVER_APP_SECRET=$(az ad sp credential reset --name "${SERVER_APP_ID}" --credential-description "ArcSecret" --query password -o tsv)
156162
```
157163
158164
1. Grant "Sign in and read user profile" API permissions to the application. [Additional information](/cli/azure/ad/app/permission?view=azure-cli-latest#az-ad-app-permission-add-examples):
159165
160-
```azurecli
166+
```azurecli
161167
az ad app permission add --id "${SERVER_APP_ID}" --api 00000003-0000-0000-c000-000000000000 --api-permissions e1fe6dd8-ba31-4d61-89e7-88639da4683d=Scope
162-
az ad app permission grant --id "${SERVER_APP_ID}" --api 00000003-0000-0000-c000-000000000000 --scope User.Read
168+
az ad app permission grant --id "${SERVER_APP_ID}" --api 00000003-0000-0000-c000-000000000000
163169
```
164170
165171
> [!NOTE]
166172
> An Azure tenant administrator has to run this step.
167173
>
168-
> For usage of this feature in production, we recommend that you create a different server application for every cluster.
174+
> For usage of this feature in production, we recommend that you create a different server application for every cluster.
169175
170176
#### Create a client application
171177
172178
1. Create a new Azure AD application and get its `appId` value. This value is used in later steps as `clientApplicationId`.
173179
174180
```azurecli
175181
CLIENT_UNIQUE_SUFFIX="<identifier_suffix>"
176-
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)
177-
echo $CLIENT_APP_ID
182+
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)
183+
echo $CLIENT_APP_ID
178184
```
179185
180-
181186
2. Create a service principal for this client application:
182187
183188
```azurecli
@@ -187,23 +192,17 @@ A conceptual overview of this feature is available in the [Azure RBAC on Azure A
187192
3. Get the `oAuthPermissionId` value for the server application:
188193
189194
```azurecli
190-
az ad app show --id "${SERVER_APP_ID}" --query "api.oauth2PermissionScopes[0].id" -o tsv
195+
az ad app show --id "${SERVER_APP_ID}" --query "oauth2Permissions[0].id" -o tsv
191196
```
192197
193-
4. Grant the required permissions for the client application. RBAC for Azure Arc for kuberentes requires scope `AzureADMyOrg` [Additional Information](/azure/active-directory/develop/supported-accounts-validation):
198+
4. Grant the required permissions for the client application:
194199
195200
```azurecli
196-
az ad app permission add --id "${CLIENT_APP_ID}" --api "$ENV:SERVER_APP_ID" --api-permissions <oAuthPermissionId>=Scope
197-
az ad app permission grant --id "${CLIENT_APP_ID}" --api <oAuthPermissionId> --scope User.Read
198-
#
199-
az ad app update --id ${SERVER_APP_ID} --set signInAudience=AzureADMyOrg
200-
CLIENT_OBJECT_ID=$(az ad app show --id "${CLIENT_APP_ID}" --query "id" -o tsv)
201-
az rest --method PATCH --headers "Content-Type=application/json" --uri https://graph.microsoft.com/v1.0/applications/${CLIENT_OBJECT_ID}/ --body '{"api":{"requestedAccessTokenVersion": 1}}'
201+
az ad app permission add --id "${CLIENT_APP_ID}" --api "${SERVER_APP_ID}" --api-permissions <oAuthPermissionId>=Scope
202+
az ad app permission grant --id "${CLIENT_APP_ID}" --api "${SERVER_APP_ID}"
202203
```
203-
204204
---
205205
206-
207206
## Create a role assignment for the server application
208207
209208
The server application needs the `Microsoft.Authorization/*/read` permissions to check if the user making the request is authorized on the Kubernetes objects that are a part of the request.

0 commit comments

Comments
 (0)