Skip to content

Commit 16e42ba

Browse files
authored
Merge pull request #118842 from JoeyC-Dev/patch-1
Fix missing parts and refine in workload-identity-deploy-cluster.md
2 parents 1e753a9 + 2b8bb04 commit 16e42ba

File tree

1 file changed

+75
-25
lines changed

1 file changed

+75
-25
lines changed

articles/aks/workload-identity-deploy-cluster.md

Lines changed: 75 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,16 @@ az aks update -g "${RESOURCE_GROUP}" -n myAKSCluster --enable-oidc-issuer --enab
6666
To get the OIDC Issuer URL and save it to an environmental variable, run the following command. Replace the default value for the arguments `-n`, which is the name of the cluster:
6767

6868
```bash
69-
export AKS_OIDC_ISSUER="$(az aks show -n myAKSCluster -g "${RESOURCE_GROUP}" --query "oidcIssuerProfile.issuerUrl" -otsv)"
69+
export AKS_OIDC_ISSUER="$(az aks show -n myAKSCluster -g "${RESOURCE_GROUP}" --query "oidcIssuerProfile.issuerUrl" -o tsv)"
7070
```
7171

7272
The variable should contain the Issuer URL similar to the following example:
7373

7474
```output
75-
https://eastus.oic.prod-aks.azure.com/00000000-0000-0000-0000-000000000000/00000000-0000-0000-0000-000000000000/
75+
https://eastus.oic.prod-aks.azure.com/00000000-0000-0000-0000-000000000000/11111111-1111-1111-1111-111111111111/
7676
```
7777

78-
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.
78+
By default, the Issuer is set to use the base URL `https://{region}.oic.prod-aks.azure.com/{tenant_id}/{uuid}`, where the value for `{region}` matches the location the AKS cluster is deployed in. The value `{uuid}` represents the OIDC key.
7979

8080
## Create a managed identity
8181

@@ -88,7 +88,7 @@ az identity create --name "${USER_ASSIGNED_IDENTITY_NAME}" --resource-group "${R
8888
Next, let's create a variable for the managed identity ID.
8989

9090
```bash
91-
export USER_ASSIGNED_CLIENT_ID="$(az identity show --resource-group "${RESOURCE_GROUP}" --name "${USER_ASSIGNED_IDENTITY_NAME}" --query 'clientId' -otsv)"
91+
export USER_ASSIGNED_CLIENT_ID="$(az identity show --resource-group "${RESOURCE_GROUP}" --name "${USER_ASSIGNED_IDENTITY_NAME}" --query 'clientId' -o tsv)"
9292
```
9393

9494
## Create Kubernetes service account
@@ -116,7 +116,7 @@ EOF
116116
The following output resembles successful creation of the identity:
117117

118118
```output
119-
Serviceaccount/workload-identity-sa created
119+
serviceaccount/workload-identity-sa created
120120
```
121121

122122
## Establish federated identity credential
@@ -139,33 +139,21 @@ cat <<EOF | kubectl apply -f -
139139
apiVersion: v1
140140
kind: Pod
141141
metadata:
142-
name: quick-start
142+
name: your-pod
143143
namespace: "${SERVICE_ACCOUNT_NAMESPACE}"
144144
labels:
145145
azure.workload.identity/use: "true"
146146
spec:
147147
serviceAccountName: "${SERVICE_ACCOUNT_NAME}"
148+
containers:
149+
- image: <your image>
150+
name: <containerName>
148151
EOF
149152
```
150153

151154
> [!IMPORTANT]
152155
> Ensure your application pods using workload identity have added the following label `azure.workload.identity/use: "true"` to your pod spec, otherwise the pods fail after their restarted.
153156
154-
```bash
155-
kubectl apply -f <your application>
156-
```
157-
158-
To check whether all properties are injected properly by the webhook, use the [kubectl describe][kubectl-describe] command:
159-
160-
```bash
161-
kubectl describe pod containerName
162-
```
163-
164-
To verify that pod is able to get a token and access the resource, use the kubectl logs command:
165-
166-
```bash
167-
kubectl logs containerName
168-
```
169157

170158
## Optional - Grant permissions to access Azure Key Vault
171159

@@ -181,20 +169,82 @@ You can retrieve this information using the Azure CLI command: [az keyvault list
181169
1. Set an access policy for the managed identity to access secrets in your Key Vault by running the following commands:
182170

183171
```azurecli-interactive
184-
export RESOURCE_GROUP="myResourceGroup"
185-
export USER_ASSIGNED_IDENTITY_NAME="myIdentity"
172+
export KEYVAULT_RESOURCE_GROUP="myResourceGroup"
186173
export KEYVAULT_NAME="myKeyVault"
187-
export USER_ASSIGNED_CLIENT_ID="$(az identity show --resource-group "${RESOURCE_GROUP}" --name "${USER_ASSIGNED_IDENTITY_NAME}" --query 'clientId' -otsv)"
174+
export USER_ASSIGNED_CLIENT_ID="$(az identity show --resource-group "${RESOURCE_GROUP}" --name "${USER_ASSIGNED_IDENTITY_NAME}" --query 'clientId' -o tsv)"
188175
189176
az keyvault set-policy --name "${KEYVAULT_NAME}" --secret-permissions get --spn "${USER_ASSIGNED_CLIENT_ID}"
190177
```
191178
179+
2. Create a secret in Key Vault:
180+
181+
```azurecli-interactive
182+
export KEYVAULT_SECRET_NAME="my-secret"
183+
184+
az keyvault secret set --vault-name "${KEYVAULT_NAME}" \
185+
--name "${KEYVAULT_SECRET_NAME}" \
186+
--value "Hello\!"
187+
```
188+
189+
3. Export Key Vault URL:
190+
```azurecli-interactive
191+
export KEYVAULT_URL="$(az keyvault show -g ${KEYVAULT_RESOURCE_GROUP} -n ${KEYVAULT_NAME} --query properties.vaultUri -o tsv)"
192+
```
193+
194+
4. Deploy a pod that references the service account and Key Vault URL above:
195+
196+
```yml
197+
cat <<EOF | kubectl apply -f -
198+
apiVersion: v1
199+
kind: Pod
200+
metadata:
201+
name: quick-start
202+
namespace: ${SERVICE_ACCOUNT_NAMESPACE}
203+
labels:
204+
azure.workload.identity/use: "true"
205+
spec:
206+
serviceAccountName: ${SERVICE_ACCOUNT_NAME}
207+
containers:
208+
- image: ghcr.io/azure/azure-workload-identity/msal-go
209+
name: oidc
210+
env:
211+
- name: KEYVAULT_URL
212+
value: ${KEYVAULT_URL}
213+
- name: SECRET_NAME
214+
value: ${KEYVAULT_SECRET_NAME}
215+
nodeSelector:
216+
kubernetes.io/os: linux
217+
EOF
218+
```
219+
220+
To check whether all properties are injected properly by the webhook, use the [kubectl describe][kubectl-describe] command:
221+
222+
```bash
223+
kubectl describe pod quick-start | grep "SECRET_NAME:"
224+
```
225+
226+
If successful, the output should be similar to the following:
227+
```bash
228+
SECRET_NAME: ${KEYVAULT_SECRET_NAME}
229+
```
230+
231+
To verify that pod is able to get a token and access the resource, use the kubectl logs command:
232+
233+
```bash
234+
kubectl logs quick-start
235+
```
236+
237+
If successful, the output should be similar to the following:
238+
```bash
239+
I0114 10:35:09.795900 1 main.go:63] "successfully got secret" secret="Hello\\!"
240+
```
241+
192242
## Disable workload identity
193243

194244
To disable the Microsoft Entra Workload ID on the AKS cluster where it's been enabled and configured, you can run the following command:
195245

196246
```azurecli-interactive
197-
az aks update --resource-group myResourceGroup --name myAKSCluster --disable-workload-identity
247+
az aks update --resource-group "${RESOURCE_GROUP}" --name myAKSCluster --disable-workload-identity
198248
```
199249

200250
## Next steps

0 commit comments

Comments
 (0)