Skip to content

Commit 9a2c916

Browse files
committed
Added the following changes:
1. combined bash and azcli commands for the KeyVault operations 2. used easy to read variable assignements 3. fix spelling for resource group name 4. added variables for the service account and sa namespace 5. removed the need to replace the above mentioned variables in several places by setting them once and exporting
1 parent 0fa35f7 commit 9a2c916

File tree

1 file changed

+18
-25
lines changed

1 file changed

+18
-25
lines changed

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

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -96,35 +96,25 @@ You can retrieve this information using the Azure CLI command: [az keyvault list
9696

9797
1. Use the Azure CLI [az account set][az-account-set] command to set a specific subscription to be the current active subscription. Then use the [az identity create][az-identity-create] command to create a managed identity.
9898

99-
```bash
99+
```azurecli
100100
export SUBSCRIPTION_ID="$(az account show --query id --output tsv)"
101-
```
101+
export USER_ASSIGNED_IDENTITY_NAME="myIdentity"
102+
export RG_NAME="myResourceGroup"
103+
export LOCATION="eastus"
102104
103-
```azurecli
104105
az account set --subscription "${SUBSCRIPTION_ID}"
105-
```
106-
107-
```bash
108-
export USER_ASSIGNED_IDENTITY_NAME="${IDENTITY:-myIdentity}"
109-
export RG_NAME="${RESOURCE_GROUP:-myResourceGroup}"
110-
export LOCATION="${LOC:-eastus}"
111-
export SUBSCRIPTION_ID="$(az account show --query id --output tsv)"
112-
```
113106
114-
```azurecli
115107
az identity create --name "${USER_ASSIGNED_IDENTITY_NAME}" --resource-group "${RG_NAME}" --location "${LOCATION}" --subscription "${SUBSCRIPTION_ID}"
116108
```
117109
118110
2. Set an access policy for the managed identity to access secrets in your Key Vault by running the following commands:
119111
120-
```bash
121-
export RG_NAME="${RESOURCE_GROUP:-myResourceGroup}"
122-
export USER_ASSIGNED_IDENTITY_NAME="${IDENTITY:-myIdentity}"
123-
export KEYVAULT_NAME="${KEYVAULT:-myKeyVault}"
112+
```azurecli
113+
export RG_NAME="myResourceGroup"
114+
export USER_ASSIGNED_IDENTITY_NAME="myIdentity"
115+
export KEYVAULT_NAME="myKeyVault"
124116
export USER_ASSIGNED_CLIENT_ID="$(az identity show --resource-group "${RG_NAME}" --name "${USER_ASSIGNED_IDENTITY_NAME}" --query 'clientId' -otsv)"
125-
```
126117
127-
```azurecli
128118
az keyvault set-policy --name "${KEYVAULT_NAME}" --secret-permissions get --spn "${USER_ASSIGNED_CLIENT_ID}"
129119
```
130120
@@ -133,22 +123,25 @@ You can retrieve this information using the Azure CLI command: [az keyvault list
133123
Create a Kubernetes service account and annotate it with the client ID of the managed identity created in the previous step. Use the [az aks get-credentials][az-aks-get-credentials] command and replace the values for the cluster name and the resource group name.
134124
135125
```azurecli
136-
az aks get-credentials -n myAKSCluster -g MyResourceGroup
126+
az aks get-credentials -n myAKSCluster -g myResourceGroup
137127
```
138128

139-
Copy and paste the following multi-line input in the Azure CLI, and update the values for `serviceAccountName` and `serviceAccountNamespace` with the Kubernetes service account name and its namespace.
129+
Copy and paste the following multi-line input in the Azure CLI, and update the values for `SERVICE_ACCOUNT_NAME` and `SERVICE_ACCOUNT_NAMESPACE` with the Kubernetes service account name and its namespace.
140130

141131
```bash
132+
export SERVICE_ACCOUNT_NAME="workload-identity-sa"
133+
export SERVICE_ACCOUNT_NAMESPACE="my-namespace"
134+
142135
cat <<EOF | kubectl apply -f -
143136
apiVersion: v1
144137
kind: ServiceAccount
145138
metadata:
146139
annotations:
147-
azure.workload.identity/client-id: ${USER_ASSIGNED_CLIENT_ID}
140+
azure.workload.identity/client-id: "${USER_ASSIGNED_CLIENT_ID}"
148141
labels:
149142
azure.workload.identity/use: "true"
150-
name: serviceAccountName
151-
namespace: serviceAccountNamspace
143+
name: "${SERVICE_ACCOUNT_NAME}"
144+
namespace: "${SERVICE_ACCOUNT_NAMESPACE}"
152145
EOF
153146
```
154147

@@ -160,10 +153,10 @@ Serviceaccount/workload-identity-sa created
160153

161154
## Establish federated identity credential
162155

163-
Use the [az identity federated-credential create][az-identity-federated-credential-create] command to create the federated identity credential between the managed identity, the service account issuer, and the subject. Replace the values `resourceGroupName`, `userAssignedIdentityName`, `federatedIdentityName`, `serviceAccountNamespace`, and `serviceAccountName`.
156+
Use the [az identity federated-credential create][az-identity-federated-credential-create] command to create the federated identity credential between the managed identity, the service account issuer, and the subject.
164157

165158
```azurecli
166-
az identity federated-credential create --name federatedIdentityName --identity-name userAssignedIdentityName --resource-group resourceGroupName --issuer ${AKS_OIDC_ISSUER} --subject system:serviceaccount:serviceAccountNamespace:serviceAccountName
159+
az identity federated-credential create --name myfederatedIdentity --identity-name "${USER_ASSIGNED_IDENTITY_NAME}" --resource-group "${RG_NAME}" --issuer "${AKS_OIDC_ISSUER}" --subject system:serviceaccount:"${SERVICE_ACCOUNT_NAMESPACE}":"${SERVICE_ACCOUNT_NAME}"
167160
```
168161

169162
> [!NOTE]

0 commit comments

Comments
 (0)