Skip to content

Commit 48a4df3

Browse files
committed
Updates to the cross-tenant workload identity doc
1 parent 6bec31b commit 48a4df3

File tree

1 file changed

+95
-25
lines changed

1 file changed

+95
-25
lines changed

articles/aks/workload-identity-cross-tenant.md

Lines changed: 95 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ description: Learn how to configure cross-tenant workload identity on Azure Kube
44
author: schaffererin
55
ms.topic: article
66
ms.subservice: aks-security
7-
ms.date: 06/11/2024
7+
ms.date: 07/02/2024
88
ms.author: schaffererin
99
---
1010

1111
# Configure cross-tenant workload identity on Azure Kubernetes Service (AKS)
1212

13-
In this article, you learn how to configure cross-tenant workload identity on Azure Kubernetes Service (AKS). Cross-tenant workload identity allows you to access resources in another tenant from your AKS cluster. In this example, you will create an Azure Service Bus in one tenant and send messages to it from a workload running in an AKS cluster in another tenant.
13+
In this article, you learn how to configure cross-tenant workload identity on Azure Kubernetes Service (AKS). Cross-tenant workload identity allows you to access resources in another tenant from your AKS cluster. In this example, you create an Azure Service Bus in one tenant and send messages to it from a workload running in an AKS cluster in another tenant.
1414

1515
For more information on workload identity, see the [Workload identity overview][workload-identity-overview].
1616

@@ -19,26 +19,32 @@ For more information on workload identity, see the [Workload identity overview][
1919
* ***Two Azure subscriptions***, each in a separate tenant. In this article, we refer to these as *Tenant A* and *Tenant B*.
2020
* Azure CLI installed on your local machine. If you don't have the Azure CLI installed, see [Install the Azure CLI][install-azure-cli].
2121
* Bash shell environment. This article uses Bash shell syntax.
22+
* You need to have the following subscription details:
2223

23-
In order to complete the steps in this article, you need to have the following information:
24+
* *Tenant A* tenant ID
25+
* *Tenant A* subscription ID
26+
* *Tenant B* tenant ID
27+
* *Tenant B* subscription ID
2428

25-
* *Tenant A* tenant ID
26-
* *Tenant A* subscription ID
27-
* *Tenant B* tenant ID
28-
* *Tenant B* subscription ID
29+
> [!IMPORTANT]
30+
> Make sure you stay within the same terminal window for the duration of this article to retain the environment variables you set. If you close the terminal window, you need to set the environment variables again.
2931
3032
## Configure resources in Tenant A
3133

3234
In *Tenant A*, you create an AKS cluster with workload identity and OIDC issuer enabled. You use this cluster to deploy an application that attempts to access resources in *Tenant B*.
3335

34-
1. Log into your *Tenant A* subscription using the [`az login`][az-login-interactively] command and pass in the tenant ID of *Tenant A*.
36+
### Log in to Tenant A
37+
38+
1. Log in to your *Tenant A* subscription using the [`az login`][az-login-interactively] command.
3539

3640
```azurecli-interactive
41+
# Set environment variable
3742
TENANT_A_ID=<tenant-id>
43+
3844
az login --tenant $TENANT_A_ID
3945
```
4046
41-
1. Ensure you are working with the correct subscription in *Tenant A* by using the [`az account set`][az-account-set] command.
47+
1. Ensure you're working with the correct subscription in *Tenant A* using the [`az account set`][az-account-set] command.
4248
4349
```azurecli-interactive
4450
# Set environment variable
@@ -48,6 +54,8 @@ In *Tenant A*, you create an AKS cluster with workload identity and OIDC issuer
4854
az account set --subscription $TENANT_A_SUBSCRIPTION_ID
4955
```
5056
57+
### Create resources in Tenant A
58+
5159
1. Create a resource group in *Tenant A* to host the AKS cluster using the [`az group create`][az-group-create] command.
5260
5361
```azurecli-interactive
@@ -62,7 +70,7 @@ In *Tenant A*, you create an AKS cluster with workload identity and OIDC issuer
6270
1. Create an AKS cluster in *Tenant A* with workload identity and OIDC issuer enabled using the [`az aks create`][az-aks-create] command.
6371
6472
```azurecli-interactive
65-
# Set environment variables
73+
# Set environment variable
6674
CLUSTER_NAME=<cluster-name>
6775
6876
# Create an AKS cluster
@@ -74,7 +82,9 @@ In *Tenant A*, you create an AKS cluster with workload identity and OIDC issuer
7482
--generate-ssh-keys
7583
```
7684
77-
1. Get the OIDC issuer URL from the cluster in *Tenant A* using the [`az aks show`][az-aks-show] command.
85+
### Get OIDC issuer URL from AKS cluster
86+
87+
* Get the OIDC issuer URL from the cluster in *Tenant A* using the [`az aks show`][az-aks-show] command.
7888
7989
```azurecli-interactive
8090
OIDC_ISSUER_URL=$(az aks show --resource-group $RESOURCE_GROUP --name $CLUSTER_NAME --query "oidcIssuerProfile.issuerUrl" --output tsv)
@@ -84,20 +94,24 @@ In *Tenant A*, you create an AKS cluster with workload identity and OIDC issuer
8494
8595
In *Tenant B*, you create an Azure Service Bus, a managed identity and assign it permissions to read and write messages to the service bus, and establish the trust between the managed identity and the AKS cluster in *Tenant A*.
8696
97+
### Log in to Tenant B
98+
8799
1. Log out of your *Tenant A* subscription using the [`az logout`][az-logout] command.
88100
89101
```azurecli-interactive
90102
az logout
91103
```
92104
93-
1. Log into your *Tenant B* subscription using the [`az login`][az-login-interactively] command and pass in the tenant ID of *Tenant B*.
105+
1. Log in to your *Tenant B* subscription using the [`az login`][az-login-interactively] command.
94106
95107
```azurecli-interactive
108+
# Set environment variable
96109
TENANT_B_ID=<tenant-id>
110+
97111
az login --tenant $TENANT_B_ID
98112
```
99113
100-
1. Ensure you are working with the correct subscription in *Tenant A* by using the [`az account set`][az-account-set] command.
114+
1. Ensure you're working with the correct subscription in *Tenant B* using the [`az account set`][az-account-set] command.
101115
102116
```azurecli-interactive
103117
# Set environment variable
@@ -107,6 +121,8 @@ In *Tenant B*, you create an Azure Service Bus, a managed identity and assign it
107121
az account set --subscription $TENANT_B_SUBSCRIPTION_ID
108122
```
109123
124+
### Create resources in Tenant B
125+
110126
1. Create a resource group in *Tenant B* to host the managed identity using the [`az group create`][az-group-create] command.
111127
112128
```azurecli-interactive
@@ -117,10 +133,11 @@ In *Tenant B*, you create an Azure Service Bus, a managed identity and assign it
117133
# Create a resource group
118134
az group create --name $RESOURCE_GROUP --location $LOCATION
119135
```
136+
120137
1. Create a service bus and queue in *Tenant B* using the [`az servicebus namespace create`][az-servicebus-namespace-create] and [`az servicebus queue create`][az-servicebus-queue-create] commands.
121138
122139
```azurecli-interactive
123-
# Set a unique name for the servicebus
140+
# Set environment variable
124141
SERVICEBUS_NAME=sb-crosstenantdemo-$RANDOM
125142
126143
# Create a new service bus namespace and and return the service bus hostname
@@ -141,12 +158,15 @@ In *Tenant B*, you create an Azure Service Bus, a managed identity and assign it
141158
1. Create a user-assigned managed identity in *Tenant B* using the [`az identity create`][az-identity-create] command.
142159
143160
```azurecli-interactive
144-
# Set user-assigned managed identity name
161+
# Set environment variable
145162
IDENTITY_NAME=${SERVICEBUS_NAME}-identity
146163
147164
# Create a user-assigned managed identity
148165
az identity create --resource-group $RESOURCE_GROUP --name $IDENTITY_NAME
149166
```
167+
168+
### Get resource IDs and assign permissions in Tenant B
169+
150170
1. Get the principal ID of the managed identity in *Tenant B* using the [`az identity show`][az-identity-show] command.
151171
152172
```azurecli-interactive
@@ -178,7 +198,7 @@ In *Tenant B*, you create an Azure Service Bus, a managed identity and assign it
178198
--output tsv)
179199
```
180200
181-
6. Assign the managed identity in *Tenant B* permissions to read and write service bus messages using the [`az role assignment create`][az-role-assignment-create] command.
201+
1. Assign the managed identity in *Tenant B* permissions to read and write service bus messages using the [`az role assignment create`][az-role-assignment-create] command.
182202
183203
```azurecli-interactive
184204
az role assignment create \
@@ -203,36 +223,40 @@ In this section, you create the federated identity credential needed to establis
203223
--subject system:serviceaccount:default:myserviceaccount
204224
```
205225
206-
`--subject system:serviceaccount:default:myserviceaccount` is the name of the Kubernetes service account that you will create later in *Tenant A*. When your application pod makes authentication requests, this value is sent to Microsoft Entra ID as the `subject` in the authorization request. Microsoft Entra ID determines eligibility based on whether this value matches what you set when you created the federated identity credential, so it's important to ensure the value matches.
226+
`--subject system:serviceaccount:default:myserviceaccount` is the name of the Kubernetes service account that you create in *Tenant A* later in the article. When your application pod makes authentication requests, this value is sent to Microsoft Entra ID as the `subject` in the authorization request. Microsoft Entra ID determines eligibility based on whether this value matches what you set when you created the federated identity credential, so it's important to ensure the value matches.
207227
208228
## Deploy application to send messages to Azure Service Bus queue
209229
210230
In this section, you deploy an application to your AKS cluster in *Tenant A* that sends messages to the Azure Service Bus queue in *Tenant B*.
211231
232+
### Log in to Tenant A and get AKS credentials
233+
212234
1. Log out of your *Tenant B* subscription using the [`az logout`][az-logout] command.
213235
214236
```azurecli-interactive
215237
az logout
216238
```
217239
218-
1. Log into your *Tenant A* subscription using the [`az login`][az-login-interactively] command and pass in the tenant ID of *Tenant A*.
240+
1. Log in to your *Tenant A* subscription using the [`az login`][az-login-interactively] command.
219241
220242
```azurecli-interactive
221243
az login --tenant $TENANT_A_ID
222244
```
223245
224-
1. Ensure you are working with the correct subscription in *Tenant A* by using the [`az account set`][az-account-set] command.
246+
1. Ensure you're working with the correct subscription in *Tenant A* using the [`az account set`][az-account-set] command.
225247
226248
```azurecli-interactive
227249
az account set --subscription $TENANT_A_SUBSCRIPTION_ID
228250
```
229251
230-
1. Get the cluster credentials for the AKS cluster in *Tenant A* using the [`az aks get-credentials`][az-aks-get-credentials] command.
252+
1. Get the credentials for the AKS cluster in *Tenant A* using the [`az aks get-credentials`][az-aks-get-credentials] command.
231253
232254
```azurecli-interactive
233255
az aks get-credentials --resource-group $RESOURCE_GROUP --name $CLUSTER_NAME
234256
```
235257
258+
### Create Kubernetes resources to send messages to Azure Service Bus queue
259+
236260
1. Create a new Kubernetes ServiceAccount in the `default` namespace and pass in the client ID of your managed identity in *Tenant B* to the `kubectl apply` command. The client ID is used to authenticate the pod to the Azure Service Bus.
237261
238262
```azurecli-interactive
@@ -246,7 +270,7 @@ In this section, you deploy an application to your AKS cluster in *Tenant A* tha
246270
EOF
247271
```
248272
249-
4. Create a new Kubernetes Job in the `default` namespace to send 100 messages to your Azure Service Bus queue. The Pod template is configured to use workload identity and the service account you created in the previous step. Also note that the `AZURE_TENANT_ID` environment variable is set to the tenant ID of *Tenant B*. This is required as workload identity defaults to the tenant of the AKS cluster, so you need to explicitly set the tenant ID of *Tenant B*.
273+
1. Create a new Kubernetes Job in the `default` namespace to send 100 messages to your Azure Service Bus queue. The Pod template is configured to use workload identity and the service account you created in the previous step. Also note that the `AZURE_TENANT_ID` environment variable is set to the tenant ID of *Tenant B*. This is required as workload identity defaults to the tenant of the AKS cluster, so you need to explicitly set the tenant ID of *Tenant B*.
250274
251275
```azurecli-interactive
252276
kubectl apply -f - <<EOF
@@ -280,7 +304,9 @@ In this section, you deploy an application to your AKS cluster in *Tenant A* tha
280304
EOF
281305
```
282306
283-
5. Verify that the pod is configured correctly to interact with the Azure Service Bus queue in *Tenant B* by checking the status of the pod using the `kubectl describe pod` command.
307+
## Verify the deployment
308+
309+
1. Verify that the pod is correctly configured to interact with the Azure Service Bus queue in *Tenant B* by checking the status of the pod using the `kubectl describe pod` command.
284310
285311
```azurecli-interactive
286312
# Get the dynamically generated pod name
@@ -290,7 +316,7 @@ In this section, you deploy an application to your AKS cluster in *Tenant A* tha
290316
kubectl describe pod $POD_NAME | grep AZURE_TENANT_ID
291317
```
292318
293-
6. Check the logs of the pod to see if the application was able to send messages across tenants using the `kubectl logs` command.
319+
1. Check the logs of the pod to see if the application was able to send messages across tenants using the `kubectl logs` command.
294320
295321
```azurecli-interactive
296322
kubectl logs $POD_NAME
@@ -306,6 +332,50 @@ In this section, you deploy an application to your AKS cluster in *Tenant A* tha
306332
Sent 100 messages
307333
```
308334
335+
## Clean up resources
336+
337+
After you verify that the deployment is successful, you can clean up the resources to avoid incurring Azure costs.
338+
339+
### Delete resources in Tenant A
340+
341+
1. Log in to your *Tenant A* subscription using the [`az login`][az-login-interactively] command.
342+
343+
```azurecli-interactive
344+
az login --tenant $TENANT_A_ID
345+
```
346+
347+
1. Ensure you're working with the correct subscription in *Tenant A* using the [`az account set`][az-account-set] command.
348+
349+
```azurecli-interactive
350+
az account set --subscription $TENANT_A_SUBSCRIPTION_ID
351+
```
352+
353+
1. Delete the Azure resource group and all resources in it using the [`az group delete`][az-group-delete] command.
354+
355+
```azurecli-interactive
356+
az group delete --name $RESOURCE_GROUP --yes --no-wait
357+
```
358+
359+
### Delete resources in Tenant B
360+
361+
1. Log in to your *Tenant B* subscription using the [`az login`][az-login-interactively] command.
362+
363+
```azurecli-interactive
364+
az login --tenant $TENANT_B_ID
365+
```
366+
367+
1. Ensure you're working with the correct subscription in *Tenant B* using the [`az account set`][az-account-set] command.
368+
369+
```azurecli-interactive
370+
az account set --subscription $TENANT_B_SUBSCRIPTION_ID
371+
```
372+
373+
1. Delete the Azure resource group and all resources in it using the [`az group delete`][az-group-delete] command.
374+
375+
```azurecli-interactive
376+
az group delete --name $RESOURCE_GROUP --yes --no-wait
377+
```
378+
309379
## Next steps
310380
311381
In this article, you learned how to configure cross-tenant workload identity on Azure Kubernetes Service (AKS). To learn more about workload identity, see the following articles:
@@ -327,9 +397,9 @@ In this article, you learned how to configure cross-tenant workload identity on
327397
[az-identity-show]: /cli/azure/identity#az_identity_show
328398
[az-role-assignment-create]: /cli/azure/role/assignment#az_role_assignment_create
329399
[az-aks-federated-identity-add]: /cli/azure/aks/federated-identity#az_aks_federated_identity_add
330-
[az-provider-show]: /cli/azure/provider#az_provider_show
331-
[az-provider-register]: /cli/azure/provider#az_provider_register
332400
[az-aks-get-credentials]: /cli/azure/aks#az_aks_get_credentials
333401
[az-servicebus-namespace-create]: cli/azure/servicebus/namespace?view=azure-cli-latest#az-servicebus-namespace-create
334402
[az-servicebus-namespace-show]: cli/azure/servicebus/namespace?view=azure-cli-latest#az-servicebus-namespace-show
335403
[az-servicebus-queue-create]: cli/azure/servicebus/queue?view=azure-cli-latest#az-servicebus-queue-create
404+
[az-group-delete]: /cli/azure/group#az_group_delete
405+

0 commit comments

Comments
 (0)