Skip to content

Commit 6ef9ad1

Browse files
authored
Merge pull request #213927 from omkark95/main
Updated AzureCLI commands for Azure Arc K8s RBAC
2 parents f08b87f + 4523e11 commit 6ef9ad1

File tree

1 file changed

+121
-16
lines changed

1 file changed

+121
-16
lines changed

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

Lines changed: 121 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -40,49 +40,147 @@ A conceptual overview of this feature is available in the [Azure RBAC on Azure A
4040
4141
## Set up Azure AD applications
4242
43-
### Create a server application
4443
44+
### [AzureCLI >= v2.37](#tab/AzureCLI)
45+
#### Create a server application
4546
1. Create a new Azure AD application and get its `appId` value. This value is used in later steps as `serverApplicationId`.
4647
4748
```azurecli
4849
CLUSTER_NAME="<clusterName>"
4950
TENANT_ID="<tenant>"
50-
SERVER_APP_ID=$(az ad app create --display-name "${CLUSTER_NAME}Server" --identifier-uris "api://${TENANT_ID}/ClientAnyUniqueSuffix" --query appId -o tsv)
51+
SERVER_UNIQUE_SUFFIX="<identifier_suffix>"
52+
SERVER_APP_ID=$(az ad app create --display-name "${CLUSTER_NAME}Server" --identifier-uris "api://${TENANT_ID}/${SERVER_UNIQUE_SUFFIX}" --query appId -o tsv)
5153
echo $SERVER_APP_ID
5254
```
5355
54-
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:
5557
56-
```azurecli
57-
az ad app update --id "${SERVER_APP_ID}" --set groupMembershipClaims=All
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-enabled Kubernetes requires [`signInAudience` to be set to **AzureADMyOrg**](/azure/active-directory/develop/supported-accounts-validation):
76+
77+
```azurecli
78+
az ad app update --id "${SERVER_APP_ID}" --set groupMembershipClaims=All
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}}'
5883
```
5984
85+
6086
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.
6187
6288
```azurecli
63-
az ad sp create --id "${SERVER_APP_ID}"
64-
SERVER_APP_SECRET=$(az ad sp credential reset --name "${SERVER_APP_ID}" --credential-description "ArcSecret" --query password -o tsv)
89+
az ad sp create --id "${SERVER_APP_ID}"
90+
SERVER_APP_SECRET=$(az ad sp credential reset --id "${SERVER_APP_ID}" --query password -o tsv)
6591
```
6692
67-
1. Grant "Sign in and read user profile" API permissions to the application:
93+
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):
6894
6995
```azurecli
70-
az ad app permission add --id "${SERVER_APP_ID}" --api 00000003-0000-0000-c000-000000000000 --api-permissions e1fe6dd8-ba31-4d61-89e7-88639da4683d=Scope
71-
az ad app permission grant --id "${SERVER_APP_ID}" --api 00000003-0000-0000-c000-000000000000
96+
az ad app permission add --id "${SERVER_APP_ID}" --api 00000003-0000-0000-c000-000000000000 --api-permissions e1fe6dd8-ba31-4d61-89e7-88639da4683d=Scope
97+
az ad app permission grant --id "${SERVER_APP_ID}" --api 00000003-0000-0000-c000-000000000000 --scope User.Read
98+
```
99+
100+
> [!NOTE]
101+
> An Azure tenant administrator has to run this step.
102+
>
103+
> For usage of this feature in production, we recommend that you create a different server application for every cluster.
104+
105+
#### Create a client application
106+
107+
1. Create a new Azure AD application and get its `appId` value. This value is used in later steps as `clientApplicationId`.
108+
109+
```azurecli
110+
CLIENT_UNIQUE_SUFFIX="<identifier_suffix>"
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
113+
```
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**](/azure/active-directory/develop/supported-accounts-validation):
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+
140+
### [AzureCLI < v2.37](#tab/AzureCLI236)
141+
#### Create a server application
142+
1. Create a new Azure AD application and get its `appId` value. This value is used in later steps as `serverApplicationId`.
143+
144+
```azurecli
145+
CLUSTER_NAME="<clusterName>"
146+
TENANT_ID="<tenant>"
147+
SERVER_UNIQUE_SUFFIX="<identifier_suffix>"
148+
SERVER_APP_ID=$(az ad app create --display-name "${CLUSTER_NAME}Server" --identifier-uris "api://${TENANT_ID}/${SERVER_UNIQUE_SUFFIX}" --query appId -o tsv)
149+
echo $SERVER_APP_ID
150+
```
151+
152+
1. Update the application's group membership claims:
153+
```azurecli
154+
az ad app update --id "${SERVER_APP_ID}" --set groupMembershipClaims=All
155+
```
156+
157+
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](./azure-rbac.md#refresh-the-secret-of-the-server-application). You can also [set a custom expiration duration](/cli/azure/ad/sp/credential?view=azure-cli-latest&preserve-view=true#az-ad-sp-credential-reset).
158+
159+
```azurecli
160+
az ad sp create --id "${SERVER_APP_ID}"
161+
SERVER_APP_SECRET=$(az ad sp credential reset --name "${SERVER_APP_ID}" --credential-description "ArcSecret" --query password -o tsv)
162+
```
163+
164+
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):
165+
166+
```azurecli
167+
az ad app permission add --id "${SERVER_APP_ID}" --api 00000003-0000-0000-c000-000000000000 --api-permissions e1fe6dd8-ba31-4d61-89e7-88639da4683d=Scope
168+
az ad app permission grant --id "${SERVER_APP_ID}" --api 00000003-0000-0000-c000-000000000000
72169
```
73170
74171
> [!NOTE]
75172
> An Azure tenant administrator has to run this step.
76173
>
77174
> For usage of this feature in production, we recommend that you create a different server application for every cluster.
78175
79-
### Create a client application
176+
#### Create a client application
80177
81178
1. Create a new Azure AD application and get its `appId` value. This value is used in later steps as `clientApplicationId`.
82179
83180
```azurecli
84-
CLIENT_APP_ID=$(az ad app create --display-name "${CLUSTER_NAME}Client" --native-app --reply-urls "api://${TENANT_ID}/ServerAnyUniqueSuffix" --query appId -o tsv)
85-
echo $CLIENT_APP_ID
181+
CLIENT_UNIQUE_SUFFIX="<identifier_suffix>"
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
86184
```
87185
88186
2. Create a service principal for this client application:
@@ -94,15 +192,16 @@ A conceptual overview of this feature is available in the [Azure RBAC on Azure A
94192
3. Get the `oAuthPermissionId` value for the server application:
95193
96194
```azurecli
97-
az ad app show --id "${SERVER_APP_ID}" --query "oauth2Permissions[0].id" -o tsv
195+
az ad app show --id "${SERVER_APP_ID}" --query "oauth2Permissions[0].id" -o tsv
98196
```
99197
100198
4. Grant the required permissions for the client application:
101199
102200
```azurecli
103-
az ad app permission add --id "${CLIENT_APP_ID}" --api "${SERVER_APP_ID}" --api-permissions <oAuthPermissionId>=Scope
104-
az ad app permission grant --id "${CLIENT_APP_ID}" --api "${SERVER_APP_ID}"
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}"
105203
```
204+
---
106205
107206
## Create a role assignment for the server application
108207
@@ -160,6 +259,12 @@ az connectedk8s enable-features -n <clusterName> -g <resourceGroupName> --featur
160259

161260
1. The `azure-arc-guard-manifests` secret in the `kube-system` namespace contains two files `guard-authn-webhook.yaml` and `guard-authz-webhook.yaml`. Copy these files to the `/etc/guard` directory of the node.
162261

262+
```console
263+
sudo mkdir -p /etc/guard
264+
kubectl get secrets azure-arc-guard-manifests -n kube-system -o json | jq '.data."guard-authn-webhook.yaml"' | base64 -d > /etc/guard/guard-authn-webhook.yaml
265+
kubectl get secrets azure-arc-guard-manifests -n kube-system -o json | jq '.data."guard-authz-webhook.yaml"' | base64 -d > /etc/guard/guard-authz-webhook.yaml
266+
```
267+
163268
1. Open the `apiserver` manifest in edit mode:
164269
165270
```console

0 commit comments

Comments
 (0)