@@ -9,7 +9,7 @@ ms.custom:
9
9
- devx-track-azurepowershell
10
10
- ignite-2023
11
11
ms.topic : tutorial
12
- ms.date : 05/11/2022
12
+ ms.date : 12/10/2024
13
13
ms.author : cshoe
14
14
zone_pivot_groups : container-apps-image-build-type
15
15
---
@@ -145,25 +145,118 @@ cd code-to-cloud/src
145
145
146
146
## Create an Azure Container Registry
147
147
148
- After the album API container image is built, create an Azure Container Registry (ACR) instance in your resource group to store it.
148
+ 1 . After the album API container image is built, create an Azure Container Registry (ACR) instance in your resource group to store it.
149
149
150
- # [ Bash] ( #tab/bash )
150
+ # [ Bash] ( #tab/bash )
151
151
152
- ``` azurecli
153
- az acr create \
154
- --resource-group $RESOURCE_GROUP \
155
- --name $ACR_NAME \
156
- --sku Basic \
157
- --admin-enabled true
158
- ```
152
+ ``` azurecli
153
+ az acr create \
154
+ --resource-group $RESOURCE_GROUP \
155
+ --name $ACR_NAME \
156
+ --sku Basic
157
+ ```
159
158
160
159
# [Azure PowerShell](#tab/azure-powershell)
161
160
162
- ``` azurepowershell
163
- $acr = New-AzContainerRegistry -ResourceGroupName $ResourceGroup -Name $ACRName -Sku Basic -EnableAdminUser
164
- ```
161
+ ```azurepowershell
162
+ $acr = New-AzContainerRegistry `
163
+ -ResourceGroupName $ResourceGroup `
164
+ -Name $ACRName `
165
+ -Sku Basic
166
+ ```
165
167
166
- ---
168
+ ---
169
+
170
+ 1. Your container registry must allow Azure Resource Manager (ARM) audience tokens for authentication in order to use managed identity to pull images.
171
+
172
+ Use the following command to check if ARM tokens are allowed to access your Azure Container Registry (ACR).
173
+
174
+ # [Bash](#tab/bash)
175
+ ```azurecli
176
+ az acr config authentication-as-arm show --registry "$ACR_NAME"
177
+ ```
178
+
179
+ TODO1 Use PS command
180
+ # [Azure PowerShell](#tab/azure-powershell)
181
+ ```powershell
182
+ $acr = Get-AzContainerRegistry -Name $ACRName
183
+ $acr.Config.AuthenticationAsArm
184
+ ```
185
+
186
+ ---
187
+
188
+ If ARM tokens are allowed, the command outputs the following.
189
+
190
+ ```
191
+ {
192
+ "status": "enabled"
193
+ }
194
+ ```
195
+
196
+ If the `status` is `disabled`, allow ARM tokens with the following command.
197
+
198
+ # [Bash](#tab/bash)
199
+ ```azurecli
200
+ az acr config authentication-as-arm update --registry "$ACR_NAME" --status enabled
201
+ ```
202
+
203
+ TODO1 Use PS command
204
+ # [Azure PowerShell](#tab/azure-powershell)
205
+ ```powershell
206
+ $acr.Config.AuthenticationAsArm.Enabled = $true
207
+ Set-AzContainerRegistry -ResourceGroupName $acr.ResourceGroupName -Name $acr.Name -Registry $acr
208
+ ```
209
+
210
+ ---
211
+
212
+ ## Create a user-assigned managed identity
213
+
214
+ To avoid using administrative credentials, pull images from private repositories in Microsoft Azure Container Registry using managed identities for authentication. When possible, use a user-assigned managed identity to pull images.
215
+
216
+ 1. Create a user-assigned managed identity. Before you run the following commands, choose a name for your managed identity and replace the `\<PLACEHOLDER\>` with the name.
217
+
218
+ # [Bash](#tab/bash)
219
+
220
+ ```bash
221
+ IDENTITY="<YOUR_IDENTITY_NAME>"
222
+ ```
223
+
224
+ ```azurecli
225
+ az identity create \
226
+ --name $IDENTITY \
227
+ --resource-group $RESOURCE_GROUP
228
+ ```
229
+
230
+ # [Azure PowerShell](#tab/azure-powershell)
231
+
232
+ TODO1 Use PS command
233
+ ```powershell
234
+ $IdentityName="<YOUR_IDENTITY_NAME>"
235
+ $Identity = New-AzUserAssignedIdentity -ResourceGroupName $ResourceGroup -Name $IdentityName
236
+ ```
237
+
238
+ ---
239
+
240
+ 1. Get the identity's resource ID.
241
+
242
+ # [Bash](#tab/bash)
243
+
244
+ ```azurecli
245
+ IDENTITY_ID=$(az identity show \
246
+ --name $IDENTITY \
247
+ --resource-group $RESOURCE_GROUP \
248
+ --query id \
249
+ --output tsv)
250
+ ```
251
+
252
+ # [Azure PowerShell](#tab/azure-powershell)
253
+
254
+ TODO1 Use PS command
255
+ ```powershell
256
+ $IdentityId = $identity.Id
257
+ ```
258
+
259
+ ---
167
260
168
261
::: zone pivot="acr-remote"
169
262
@@ -183,8 +276,10 @@ az acr build --registry $ACR_NAME --image $API_NAME .
183
276
184
277
# [ Azure PowerShell] ( #tab/azure-powershell )
185
278
279
+ TODO1 Was this already in here? We think there is no PS equivalent for az acr build. If so, verify that. We think we say so elsewhere. Or maybe it's that there is no PS equivalent for az containerapp up.
186
280
``` azurepowershell
187
- az acr build --registry $ACRName --image $APIName .
281
+ New-AzAcrBuildTask -RegistryName $ACRName -ImageName $APIName -ContextPath "."
282
+
188
283
```
189
284
190
285
---
@@ -229,12 +324,14 @@ az acr login --name $ACR_NAME
229
324
230
325
# [ Azure PowerShell] ( #tab/azure-powershell )
231
326
327
+ TODO1 Use PS command
232
328
``` powershell
233
- az acr login --name $ACRName
329
+ Connect-AzContainerRegistry -Name $ACRName
234
330
```
235
331
236
332
---
237
333
334
+ TODO1 Shouldn't az acr build take care of this? Try skipping this.
238
335
Now, push the image to your registry.
239
336
240
337
# [ Bash] ( #tab/bash )
@@ -319,6 +416,8 @@ az containerapp create \
319
416
--target-port 8080 \
320
417
--ingress external \
321
418
--registry-server $ACR_NAME.azurecr.io \
419
+ --user-assigned "$IDENTITY_ID" \
420
+ --registry-identity "$IDENTITY_ID" \
322
421
--query properties.configuration.ingress.fqdn
323
422
```
324
423
@@ -342,6 +441,7 @@ $ImageParams = @{
342
441
$TemplateObj = New-AzContainerAppTemplateObject @ImageParams
343
442
```
344
443
444
+ TODO1 Remove?
345
445
Run the following command to get your registry credentials.
346
446
347
447
``` azurepowershell
@@ -353,11 +453,11 @@ Create a registry credential object to define your registry information, and a s
353
453
``` azurepowershell
354
454
$RegistryArgs = @{
355
455
Server = $ACRName + '.azurecr.io'
356
- PasswordSecretRef = 'registrysecret'
357
- Username = $RegistryCredentials.Username
456
+ Identity = $IdentityId
358
457
}
359
458
$RegistryObj = New-AzContainerAppRegistryCredentialObject @RegistryArgs
360
459
460
+ TODO1 Remove.
361
461
$SecretObj = New-AzContainerAppSecretObject -Name 'registrysecret' -Value $RegistryCredentials.Password
362
462
```
363
463
@@ -377,7 +477,6 @@ $AppArgs = @{
377
477
ManagedEnvironmentId = $EnvId
378
478
TemplateContainer = $TemplateObj
379
479
ConfigurationRegistry = $RegistryObj
380
- ConfigurationSecret = $SecretObj
381
480
IngressTargetPort = 8080
382
481
IngressExternal = $true
383
482
}
0 commit comments