Skip to content

Commit 4c70dd1

Browse files
committed
command line breaks
1 parent ba5fc3a commit 4c70dd1

File tree

1 file changed

+50
-12
lines changed

1 file changed

+50
-12
lines changed

articles/container-instances/container-instances-managed-identity.md

Lines changed: 50 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,19 @@ az group create --name myResourceGroup --location eastus
6262
Use the [az keyvault create](/cli/azure/keyvault?view=azure-cli-latest#az-keyvault-create) command to create a key vault. Be sure to specify a unique key vault name.
6363

6464
```azurecli-interactive
65-
az keyvault create --name mykeyvault --resource-group myResourceGroup --location eastus
65+
az keyvault create \
66+
--name mykeyvault \
67+
--resource-group myResourceGroup \
68+
--location eastus
6669
```
6770

6871
Store a sample secret in the key vault using the [az keyvault secret set](/cli/azure/keyvault/secret?view=azure-cli-latest#az-keyvault-secret-set) command:
6972

7073
```azurecli-interactive
71-
az keyvault secret set --name SampleSecret --value "Hello Container Instances" --description ACIsecret --vault-name mykeyvault
74+
az keyvault secret set \
75+
--name SampleSecret \
76+
--value "Hello Container Instances" \
77+
--description ACIsecret --vault-name mykeyvault
7278
```
7379

7480
Continue with the following examples to access the key vault using either a user-assigned or system-assigned managed identity in Azure Container Instances.
@@ -80,7 +86,9 @@ Continue with the following examples to access the key vault using either a user
8086
First create an identity in your subscription using the [az identity create](/cli/azure/identity?view=azure-cli-latest#az-identity-create) command. You can use the same resource group used to create the key vault, or use a different one.
8187

8288
```azurecli-interactive
83-
az identity create --resource-group myResourceGroup --name myACIId
89+
az identity create \
90+
--resource-group myResourceGroup \
91+
--name myACIId
8492
```
8593

8694
To use the identity in the following steps, use the [az identity show](/cli/azure/identity?view=azure-cli-latest#az-identity-show) command to store the identity's service principal ID and resource ID in variables.
@@ -100,13 +108,20 @@ Run the following [az container create](/cli/azure/container?view=azure-cli-late
100108
The `--assign-identity` parameter passes your user-assigned managed identity to the group. The long-running command keeps the container running. This example uses the same resource group used to create the key vault, but you could specify a different one.
101109

102110
```azurecli-interactive
103-
az container create --resource-group myResourceGroup --name mycontainer --image mcr.microsoft.com/azure-cli --assign-identity $resourceID --command-line "tail -f /dev/null"
111+
az container create \
112+
--resource-group myResourceGroup \
113+
--name mycontainer \
114+
--image mcr.microsoft.com/azure-cli \
115+
--assign-identity $resourceID \
116+
--command-line "tail -f /dev/null"
104117
```
105118

106119
Within a few seconds, you should get a response from the Azure CLI indicating that the deployment has completed. Check its status with the [az container show](/cli/azure/container?view=azure-cli-latest#az-container-show) command.
107120

108121
```azurecli-interactive
109-
az container show --resource-group myResourceGroup --name mycontainer
122+
az container show \
123+
--resource-group myResourceGroup \
124+
--name mycontainer
110125
```
111126

112127
The `identity` section in the output looks similar to the following, showing the identity is set in the container group. The `principalID` under `userAssignedIdentities` is the service principal of the identity you created in Azure Active Directory:
@@ -132,15 +147,22 @@ The `identity` section in the output looks similar to the following, showing the
132147
Run the following [az keyvault set-policy](/cli/azure/keyvault?view=azure-cli-latest) command to set an access policy on the key vault. The following example allows the user-assigned identity to get secrets from the key vault:
133148

134149
```azurecli-interactive
135-
az keyvault set-policy --name mykeyvault --resource-group myResourceGroup --object-id $spID --secret-permissions get
150+
az keyvault set-policy \
151+
--name mykeyvault \
152+
--resource-group myResourceGroup \
153+
--object-id $spID \
154+
--secret-permissions get
136155
```
137156

138157
### Use user-assigned identity to get secret from key vault
139158

140159
Now you can use the managed identity within the running container instance to access the key vault. First launch a bash shell in the container:
141160

142161
```azurecli-interactive
143-
az container exec --resource-group myResourceGroup --name mycontainer --exec-command "/bin/bash"
162+
az container exec \
163+
--resource-group myResourceGroup \
164+
--name mycontainer \
165+
--exec-command "/bin/bash"
144166
```
145167

146168
Run the following commands in the bash shell in the container. To get an access token to use Azure Active Directory to authenticate to key vault, run the following command:
@@ -187,13 +209,20 @@ The `--assign-identity` parameter with no additional value enables a system-assi
187209
rgID=$(az group show --name myResourceGroup --query id --output tsv)
188210
189211
# Create container group with system-managed identity
190-
az container create --resource-group myResourceGroup --name mycontainer --image mcr.microsoft.com/azure-cli --assign-identity --scope $rgID --command-line "tail -f /dev/null"
212+
az container create \
213+
--resource-group myResourceGroup \
214+
--name mycontainer \
215+
--image mcr.microsoft.com/azure-cli \
216+
--assign-identity --scope $rgID \
217+
--command-line "tail -f /dev/null"
191218
```
192219

193220
Within a few seconds, you should get a response from the Azure CLI indicating that the deployment has completed. Check its status with the [az container show](/cli/azure/container?view=azure-cli-latest#az-container-show) command.
194221

195222
```azurecli-interactive
196-
az container show --resource-group myResourceGroup --name mycontainer
223+
az container show \
224+
--resource-group myResourceGroup \
225+
--name mycontainer
197226
```
198227

199228
The `identity` section in the output looks similar to the following, showing that a system-assigned identity is created in Azure Active Directory:
@@ -220,15 +249,22 @@ spID=$(az container show --resource-group myResourceGroup --name mycontainer --q
220249
Run the following [az keyvault set-policy](/cli/azure/keyvault?view=azure-cli-latest) command to set an access policy on the key vault. The following example allows the system-managed identity to get secrets from the key vault:
221250

222251
```azurecli-interactive
223-
az keyvault set-policy --name mykeyvault --resource-group myResourceGroup --object-id $spID --secret-permissions get
252+
az keyvault set-policy \
253+
--name mykeyvault \
254+
--resource-group myResourceGroup \
255+
--object-id $spID \
256+
--secret-permissions get
224257
```
225258

226259
### Use container group identity to get secret from key vault
227260

228261
Now you can use the managed identity to access the key vault within the running container instance. First launch a bash shell in the container:
229262

230263
```azurecli-interactive
231-
az container exec --resource-group myResourceGroup --name mycontainer --exec-command "/bin/bash"
264+
az container exec \
265+
--resource-group myResourceGroup \
266+
--name mycontainer \
267+
--exec-command "/bin/bash"
232268
```
233269

234270
Run the following commands in the bash shell in the container. First log in to the Azure CLI using the managed identity:
@@ -240,7 +276,9 @@ az login --identity
240276
From the running container, retrieve the secret from the key vault:
241277

242278
```bash
243-
az keyvault secret show --name SampleSecret --vault-name mykeyvault --query value
279+
az keyvault secret show \
280+
--name SampleSecret \
281+
--vault-name mykeyvault --query value
244282
```
245283

246284
The value of the secret is retrieved:

0 commit comments

Comments
 (0)