Skip to content

Commit 99042d3

Browse files
authored
Merge pull request #125109 from v-jaswel/aca/v-jaswel_work_item_310519_20241209
[ACA] [310519] Convert tutorial-event-driven-jobs to use managed identity.
2 parents 91d8ce7 + e0e07c5 commit 99042d3

File tree

3 files changed

+75
-8
lines changed

3 files changed

+75
-8
lines changed

articles/container-apps/managed-identity-image-pull.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -381,13 +381,14 @@ New-AzUserAssignedIdentity -Name $IdentityName -ResourceGroupName $ResourceGroup
381381

382382
# [Bash](#tab/bash)
383383

384-
Get identity's resource ID.
384+
Get the identity's resource ID.
385385

386386
```azurecli
387387
IDENTITY_ID=$(az identity show \
388388
--name $IDENTITY \
389389
--resource-group $RESOURCE_GROUP \
390-
--query id)
390+
--query id \
391+
--output tsv)
391392
```
392393

393394
# [Azure PowerShell](#tab/azure-powershell)

articles/container-apps/tutorial-event-driven-jobs.md

Lines changed: 70 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ author: craigshoemaker
66
ms.service: azure-container-apps
77
ms.custom: build-2023, devx-track-azurecli
88
ms.topic: conceptual
9-
ms.date: 05/05/2023
9+
ms.date: 12/09/2024
1010
ms.author: cshoe
1111
---
1212

@@ -61,10 +61,24 @@ The job uses an Azure Storage queue to receive messages. In this section, you cr
6161
--kind StorageV2
6262
```
6363

64+
If this command returns the error:
65+
66+
```
67+
(SubscriptionNotFound) Subscription <SUBSCRIPTION_ID> was not found.
68+
Code: SubscriptionNotFound
69+
Message: Subscription <SUBSCRIPTION_ID> was not found.
70+
```
71+
72+
Be sure you have registered the `Microsoft.Storage` namespace in your Azure subscription.
73+
74+
```azurecli
75+
az provider register --namespace Microsoft.Storage
76+
```
77+
6478
1. Save the queue's connection string into a variable.
6579
6680
```bash
67-
QUEUE_CONNECTION_STRING=`az storage account show-connection-string -g $RESOURCE_GROUP --name $STORAGE_ACCOUNT_NAME --query connectionString --output tsv`
81+
QUEUE_CONNECTION_STRING=$(az storage account show-connection-string -g $RESOURCE_GROUP --name $STORAGE_ACCOUNT_NAME --query connectionString --output tsv)
6882
```
6983
7084
1. Create the message queue.
@@ -76,6 +90,32 @@ The job uses an Azure Storage queue to receive messages. In this section, you cr
7690
--connection-string "$QUEUE_CONNECTION_STRING"
7791
```
7892
93+
## Create a user-assigned managed identity
94+
95+
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.
96+
97+
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.
98+
99+
```bash
100+
IDENTITY="<YOUR_IDENTITY_NAME>"
101+
```
102+
103+
```azurecli
104+
az identity create \
105+
--name $IDENTITY \
106+
--resource-group $RESOURCE_GROUP
107+
```
108+
109+
1. Get the identity's resource ID.
110+
111+
```azurecli
112+
IDENTITY_ID=$(az identity show \
113+
--name $IDENTITY \
114+
--resource-group $RESOURCE_GROUP \
115+
--query id \
116+
--output tsv)
117+
```
118+
79119
## Build and deploy the job
80120

81121
To deploy the job, you must first build a container image for the job and push it to a registry. Then, you can deploy the job to the Container Apps environment.
@@ -96,8 +136,29 @@ To deploy the job, you must first build a container image for the job and push i
96136
--name "$CONTAINER_REGISTRY_NAME" \
97137
--resource-group "$RESOURCE_GROUP" \
98138
--location "$LOCATION" \
99-
--sku Basic \
100-
--admin-enabled true
139+
--sku Basic
140+
```
141+
142+
1. Your container registry must allow Azure Resource Manager (ARM) audience tokens for authentication in order to use managed identity to pull images.
143+
144+
Use the following command to check if ARM tokens are allowed to access your Azure Container Registry (ACR).
145+
146+
```azurecli
147+
az acr config authentication-as-arm show --registry "$CONTAINER_REGISTRY_NAME"
148+
```
149+
150+
If ARM tokens are allowed, the command outputs the following.
151+
152+
```
153+
{
154+
"status": "enabled"
155+
}
156+
```
157+
158+
If the `status` is `disabled`, allow ARM tokens with the following command.
159+
160+
```azurecli
161+
az acr config authentication-as-arm update --registry "$CONTAINER_REGISTRY_NAME" --status enabled
101162
```
102163

103164
1. The source code for the job is available on [GitHub](https://github.com/Azure-Samples/container-apps-event-driven-jobs-tutorial). Run the following command to clone the repository and build the container image in the cloud using the `az acr build` command.
@@ -132,6 +193,8 @@ To deploy the job, you must first build a container image for the job and push i
132193
--memory "1Gi" \
133194
--secrets "connection-string-secret=$QUEUE_CONNECTION_STRING" \
134195
--registry-server "$CONTAINER_REGISTRY_NAME.azurecr.io" \
196+
--mi-user-assigned "$IDENTITY_ID" \
197+
--registry-identity "$IDENTITY_ID" \
135198
--env-vars "AZURE_STORAGE_QUEUE_NAME=$QUEUE_NAME" "AZURE_STORAGE_CONNECTION_STRING=secretref:connection-string-secret"
136199
```
137200

@@ -149,6 +212,8 @@ To deploy the job, you must first build a container image for the job and push i
149212
| `--scale-rule-auth` | The authentication for the scale rule. |
150213
| `--secrets` | The secrets to use for the job. |
151214
| `--registry-server` | The container registry server to use for the job. For an Azure Container Registry, the command automatically configures authentication. |
215+
| `--mi-user-assigned` | The resource ID of the user-assigned managed identity to assign to the job. |
216+
| `--registry-identity` | The resource ID of a managed identity to authenticate with the registry server instead of using a username and password. If possible, an 'acrpull' role assignment is created for the identity automatically. |
152217
| `--env-vars` | The environment variables to use for the job. |
153218

154219
The scale rule configuration defines the event source to monitor. It is evaluated on each polling interval and determines how many job executions to trigger. To learn more, see [Set scaling rules](scale-app.md).
@@ -184,7 +249,7 @@ To verify the job was configured correctly, you can send some messages to the qu
184249
1. Run the following commands to see logged messages. These commands require the Log analytics extension, so accept the prompt to install extension when requested.
185250

186251
```azurecli
187-
LOG_ANALYTICS_WORKSPACE_ID=`az containerapp env show --name $ENVIRONMENT --resource-group $RESOURCE_GROUP --query properties.appLogsConfiguration.logAnalyticsConfiguration.customerId --out tsv`
252+
LOG_ANALYTICS_WORKSPACE_ID=$(az containerapp env show --name $ENVIRONMENT --resource-group $RESOURCE_GROUP --query properties.appLogsConfiguration.logAnalyticsConfiguration.customerId --output tsv)
188253
189254
az monitor log-analytics query \
190255
--workspace "$LOG_ANALYTICS_WORKSPACE_ID" \

includes/container-apps-create-cli-steps-jobs.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,12 @@ ms.custom: references_regions
3434
az extension add --name containerapp --upgrade
3535
```
3636
37-
1. Register the `Microsoft.App` and `Microsoft.OperationalInsights` namespaces if you haven't already registered them in your Azure subscription.
37+
1. Register the `Microsoft.App`, `Microsoft.OperationalInsights`, and `Microsoft.Storage` namespaces if you haven't already registered them in your Azure subscription.
3838
3939
```azurecli
4040
az provider register --namespace Microsoft.App
4141
az provider register --namespace Microsoft.OperationalInsights
42+
az provider register --namespace Microsoft.Storage
4243
```
4344
4445
1. Now that your Azure CLI setup is complete, you can define the environment variables that are used throughout this article.

0 commit comments

Comments
 (0)