You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Migrate from pod managed-identity to workload identity
13
13
14
-
This article focuses on migrating from a pod-managed identity to Microsoft Entra Workload ID for your Azure Kubernetes Service (AKS) cluster. It also provides guidance depending on the version of the [Azure Identity][azure-identity-supported-versions] client library used by your container-based application.
14
+
## Create resource group
15
+
Set your subscription to be the current active subscription using the `az account set` command. Then, create a random suffix to ensure unique resource names.
15
16
16
-
If you aren't familiar with Microsoft Entra Workload ID, see the [Overview][workload-identity-overview] article.
17
-
18
-
## Before you begin
19
-
20
-
Ensure you have the Azure CLI version 2.47.0 or later installed. Run the `az --version` command to find the version
21
-
22
-
If you need to install or upgrade, see [Install Azure CLI][install-azure-cli].
23
-
24
-
## Migration scenarios
25
-
26
-
This section explains the migration options available depending on what version of the Azure Identity SDK is installed.
27
-
28
-
For either scenario, you need to have the federated trust set up before you update your application to use the workload identity. The following are the minimum steps required:
29
-
30
-
- Create a managed identity credential.
31
-
- Associate the managed identity with the Kubernetes service account already used for the pod-managed identity or create a new Kubernetes service account and then associate it with the managed identity.
32
-
- Establish a federated trust relationship between the managed identity and Microsoft Entra ID.
33
-
34
-
### Migrate from latest version
35
-
36
-
If your application is already using the latest version of the Azure Identity SDK, perform the following steps to complete the authentication configuration:
37
-
38
-
- Deploy workload identity in parallel with pod-managed identity. You can restart your application deployment to begin using the workload identity, where it injects the OIDC annotations into the application automatically.
39
-
- After verifying the application is able to authenticate successfully, you can remove the pod-managed identity annotations from your application and then remove the pod-managed identity add-on.
40
-
41
-
### Migrate from older version
42
-
43
-
If your application isn't using the latest version of the Azure Identity SDK, you have two options:
44
-
45
-
- Use a migration sidecar that we provide within your Linux applications, which proxies the IMDS transactions your application makes over to [OpenID Connect][openid-connect-overview] (OIDC). The migration sidecar isn't intended to be a long-term solution, but a way to get up and running quickly on workload identity. Perform the following steps:
46
-
47
-
- Deploy the workload with migration sidecar to proxy the application IMDS transactions.
48
-
- Verify the authentication transactions are completing successfully.
49
-
- Schedule the work for the applications to update their SDKs to a supported version.
50
-
- Once the SDKs are updated to the supported version, you can remove the proxy sidecar and redeploy the application.
51
-
52
-
> [!NOTE]
53
-
> The migration sidecar is **not supported for production use**. This feature is meant to give you time to migrate your application SDKs to a supported version, and not meant or intended to be a long-term solution.
54
-
> The migration sidecar is only available for Linux containers, due to only providing pod-managed identities with Linux node pools.
55
-
56
-
- Rewrite your application to support the latest version of the [Azure Identity][azure-identity-supported-versions] client library. Afterwards, perform the following steps:
57
-
58
-
- Restart your application deployment to begin authenticating using the workload identity.
59
-
- Once you verify the authentication transactions are completing successfully, you can remove the pod-managed identity annotations from your application and then remove the pod-managed identity add-on.
60
-
61
-
## Create a managed identity
62
-
63
-
If you don't have a managed identity created and assigned to your pod, perform the following steps to create and grant the necessary permissions to storage, Key Vault, or whatever resources your application needs to authenticate with in Azure.
64
-
65
-
1. Set your subscription to be the current active subscription using the `az account set` command. Then, create a random suffix to ensure unique resource names.
6. Grant the managed identity the permissions required to access the resources in Azure it requires. For information on how to do this, see [Assign a managed identity access to a resource][assign-rbac-managed-identity].
128
-
129
-
7. Get the OIDC Issuer URL and save it to an environment variable. Replace the default values for the cluster name and the resource group name.
Save the client ID of the managed identity to an environment variable.
150
69
151
-
By default, the Issuer is set to use the base URL `https://{region}.oic.prod-aks.azure.com/{uuid}`, where the value for `{region}` matches the location the AKS cluster is deployed in. The value `{uuid}` represents the OIDC key.
Get the OIDC Issuer URL and save it to an environment variable.By default, the Issuer is set to use the base URL `https://{region}.oic.prod-aks.azure.com/{uuid}`, where the value for `{region}` matches the location the AKS cluster is deployed in. The value `{uuid}` represents the OIDC key.
154
76
155
-
If you don't have a dedicated Kubernetes service account created for this application, perform the following steps to create and then annotate it with the client ID of the managed identity created in the previous step.
77
+
```bash
78
+
export AKS_CLUSTER_NAME=$MY_AKS_CLUSTER_NAME
79
+
export AKS_RESOURCE_GROUP=$MY_AKS_RESOURCE_GROUP
80
+
export AKS_OIDC_ISSUER="$(az aks show --name "$AKS_CLUSTER_NAME" --resource-group "$AKS_RESOURCE_GROUP" --query "oidcIssuerProfile.issuerUrl" -o tsv)"
81
+
```
156
82
157
-
1. Get the Kubernetes credentials for your cluster.
83
+
## Load credentials
158
84
159
-
```bash
160
-
az aks get-credentials --name "$AKS_CLUSTER_NAME" --resource-group "$AKS_RESOURCE_GROUP"
161
-
```
85
+
Get the Kubernetes credentials for your cluster.
162
86
163
-
2. Create a namespace if you don't have one.
87
+
```bash
88
+
az aks get-credentials --name "$AKS_CLUSTER_NAME" --resource-group "$AKS_RESOURCE_GROUP"
> It takes a few seconds for the federated identity credential to be propagated after being initially added. If a token request is made immediately after adding the federated identity credential, it might lead to failure for a couple of minutes as the cache is populated in the directory with old data. To avoid this issue, you can add a slight delay after adding the federated identity credential.
If your application is using managed identity and still relies on IMDS to get an access token, you can use the workload identity migration sidecar to start migrating to workload identity. This sidecar is a migration solution and in the long-term, applications should modify their code to use the latest Azure Identity SDKs that support client assertion.
201
-
202
-
To update or deploy the workload, add the following pod annotations to use the migration sidecar in your pod specification:
203
-
204
-
-`azure.workload.identity/inject-proxy-sidecar` - value is `"true"` or `"false"`
205
-
-`azure.workload.identity/proxy-sidecar-port` - value is the desired port for the proxy sidecar. The default value is `"8000"`.
206
-
207
-
When a pod with the above annotations is created, the Azure Workload Identity mutating webhook automatically injects the init-container and proxy sidecar to the pod spec.
208
-
209
-
Here's an example of the mutated pod spec:
210
-
211
120
```bash
212
121
export POD_NAME="httpbin-pod"
213
-
```
214
122
215
-
```bash
216
123
cat <<EOF > pod.yaml
217
124
apiVersion: v1
218
125
kind: Pod
@@ -237,44 +144,19 @@ spec:
237
144
- name: IMDS_ENDPOINT
238
145
value: "http://169.254.169.254"
239
146
EOF
240
-
```
241
-
242
-
After updating or deploying your application, verify the pod is in a running state using the [kubectl describe pod][kubectl-describe] command. Replace `$POD_NAME` with the name of your deployed pod.
The following log output resembles successful communication through the proxy sidecar. Verify that the logs show a token is successfully acquired and the GET operation is successful.
After you've completed your testing and the application is successfully able to get a token using the proxy sidecar, you can remove the Microsoft Entra pod-managed identity mapping for the pod from your cluster, and then remove the identity.
274
156
275
-
1. Remove the identity from your pod. This should only be done after all pods in the namespace using the pod-managed identity mapping have migrated to use the sidecar.
276
-
277
-
Use the `az aks pod-identity delete` command to delete the pod-managed identity. Ensure you replace `<pod-managed-identity-name>` with the name of the pod-managed identity you wish to delete.
0 commit comments