Skip to content

Commit 60fd6e0

Browse files
Merge pull request #291729 from craigshoemaker/aca/jason/ropc/jobs-mi
[Container Apps] Update: CI/CD Jobs tutorial -> add managed identity
2 parents 0395fcf + d6bf851 commit 60fd6e0

File tree

1 file changed

+113
-12
lines changed

1 file changed

+113
-12
lines changed

articles/container-apps/tutorial-ci-cd-runners-jobs.md

Lines changed: 113 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ author: craigshoemaker
66
ms.service: azure-container-apps
77
ms.custom: devx-track-azurecli
88
ms.topic: conceptual
9-
ms.date: 10/16/2024
9+
ms.date: 12/10/2024
1010
ms.author: cshoe
1111
zone_pivot_groups: container-apps-jobs-self-hosted-ci-cd
1212
---
@@ -288,8 +288,7 @@ To create a self-hosted runner, you need to build a container image that execute
288288
--name "$CONTAINER_REGISTRY_NAME" \
289289
--resource-group "$RESOURCE_GROUP" \
290290
--location "$LOCATION" \
291-
--sku Basic \
292-
--admin-enabled true
291+
--sku Basic
293292
```
294293

295294
# [Azure PowerShell](#tab/azure-powershell)
@@ -298,8 +297,45 @@ To create a self-hosted runner, you need to build a container image that execute
298297
--name "$CONTAINER_REGISTRY_NAME" `
299298
--resource-group "$RESOURCE_GROUP" `
300299
--location "$LOCATION" `
301-
--sku Basic `
302-
--admin-enabled true
300+
--sku Basic
301+
```
302+
303+
---
304+
305+
1. Your container registry must allow Azure Resource Manager (ARM) audience tokens for authentication in order to use managed identity to pull images.
306+
307+
Use the following command to check if ARM tokens are allowed to access your Azure Container Registry (ACR).
308+
309+
# [Bash](#tab/bash)
310+
```azurecli
311+
az acr config authentication-as-arm show --registry "$CONTAINER_REGISTRY_NAME"
312+
```
313+
314+
# [Azure PowerShell](#tab/azure-powershell)
315+
```powershell
316+
az acr config authentication-as-arm show --registry "$CONTAINER_REGISTRY_NAME"
317+
```
318+
319+
---
320+
321+
If ARM tokens are allowed, the command outputs the following.
322+
323+
```
324+
{
325+
"status": "enabled"
326+
}
327+
```
328+
329+
If the `status` is `disabled`, allow ARM tokens with the following command.
330+
331+
# [Bash](#tab/bash)
332+
```azurecli
333+
az acr config authentication-as-arm update --registry "$CONTAINER_REGISTRY_NAME" --status enabled
334+
```
335+
336+
# [Azure PowerShell](#tab/azure-powershell)
337+
```powershell
338+
az acr config authentication-as-arm update --registry "$CONTAINER_REGISTRY_NAME" --status enabled
303339
```
304340

305341
---
@@ -328,6 +364,59 @@ To create a self-hosted runner, you need to build a container image that execute
328364

329365
The image is now available in the container registry.
330366

367+
## Create a user-assigned managed identity
368+
369+
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.
370+
371+
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.
372+
373+
# [Bash](#tab/bash)
374+
375+
```bash
376+
IDENTITY="<YOUR_IDENTITY_NAME>"
377+
```
378+
379+
```azurecli
380+
az identity create \
381+
--name $IDENTITY \
382+
--resource-group $RESOURCE_GROUP
383+
```
384+
385+
# [Azure PowerShell](#tab/azure-powershell)
386+
387+
```powershell
388+
$IDENTITY="<YOUR_IDENTITY_NAME>"
389+
az identity create `
390+
--name $IDENTITY `
391+
--resource-group $RESOURCE_GROUP
392+
```
393+
394+
---
395+
396+
1. Get the identity's resource ID.
397+
398+
# [Bash](#tab/bash)
399+
400+
```azurecli
401+
IDENTITY_ID=$(az identity show \
402+
--name $IDENTITY \
403+
--resource-group $RESOURCE_GROUP \
404+
--query id \
405+
--output tsv)
406+
```
407+
408+
# [Azure PowerShell](#tab/azure-powershell)
409+
410+
```powershell
411+
IDENTITY_ID=$(az identity show `
412+
--name $IDENTITY `
413+
--resource-group $RESOURCE_GROUP `
414+
--query id `
415+
--output tsv)
416+
```
417+
418+
---
419+
331420
## Deploy a self-hosted runner as a job
332421
333422
You can now create a job that uses to use the container image. In this section, you create a job that executes the self-hosted runner and authenticates with GitHub using the PAT you generated earlier. The job uses the [`github-runner` scale rule](https://keda.sh/docs/latest/scalers/github-runner/) to create job executions based on the number of pending workflow runs.
@@ -336,7 +425,10 @@ You can now create a job that uses to use the container image. In this section,
336425
337426
# [Bash](#tab/bash)
338427
```bash
339-
az containerapp job create -n "$JOB_NAME" -g "$RESOURCE_GROUP" --environment "$ENVIRONMENT" \
428+
az containerapp job create \
429+
--name "$JOB_NAME" \
430+
--resource-group "$RESOURCE_GROUP" \
431+
--environment "$ENVIRONMENT" \
340432
--trigger-type Event \
341433
--replica-timeout 1800 \
342434
--replica-retry-limit 0 \
@@ -354,12 +446,17 @@ You can now create a job that uses to use the container image. In this section,
354446
--memory "4Gi" \
355447
--secrets "personal-access-token=$GITHUB_PAT" \
356448
--env-vars "GITHUB_PAT=secretref:personal-access-token" "GH_URL=https://github.com/$REPO_OWNER/$REPO_NAME" "REGISTRATION_TOKEN_API_URL=https://api.github.com/repos/$REPO_OWNER/$REPO_NAME/actions/runners/registration-token" \
357-
--registry-server "$CONTAINER_REGISTRY_NAME.azurecr.io"
449+
--registry-server "$CONTAINER_REGISTRY_NAME.azurecr.io" \
450+
--mi-user-assigned "$IDENTITY_ID" \
451+
--registry-identity "$IDENTITY_ID"
358452
```
359453
360454
# [Azure PowerShell](#tab/azure-powershell)
361455
```powershell
362-
az containerapp job create -n "$JOB_NAME" -g "$RESOURCE_GROUP" --environment "$ENVIRONMENT" `
456+
az containerapp job create `
457+
--name "$JOB_NAME" `
458+
--resource-group "$RESOURCE_GROUP" `
459+
--environment "$ENVIRONMENT" `
363460
--trigger-type Event `
364461
--replica-timeout 1800 `
365462
--replica-retry-limit 0 `
@@ -377,7 +474,9 @@ You can now create a job that uses to use the container image. In this section,
377474
--memory "4Gi" `
378475
--secrets "personal-access-token=$GITHUB_PAT" `
379476
--env-vars "GITHUB_PAT=secretref:personal-access-token" "GH_URL=https://github.com/$REPO_OWNER/$REPO_NAME" "REGISTRATION_TOKEN_API_URL=https://api.github.com/repos/$REPO_OWNER/$REPO_NAME/actions/runners/registration-token" `
380-
--registry-server "$CONTAINER_REGISTRY_NAME.azurecr.io"
477+
--registry-server "$CONTAINER_REGISTRY_NAME.azurecr.io" `
478+
--mi-user-assigned "$IDENTITY_ID" `
479+
--registry-identity "$IDENTITY_ID"
381480
```
382481
383482
---
@@ -400,8 +499,10 @@ You can now create a job that uses to use the container image. In this section,
400499
| `--secrets` | The secrets to use for the job. |
401500
| `--env-vars` | The environment variables to use for the job. |
402501
| `--registry-server` | The container registry server to use for the job. For an Azure Container Registry, the command automatically configures authentication. |
502+
| `--mi-user-assigned` | The resource ID of the user-assigned managed identity to assign to the job. |
503+
| `--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. |
403504

404-
The scale rule configuration defines the event source to monitor. It's evaluated on each polling interval and determines how many job executions to trigger. To learn more, see [Set scaling rules](scale-app.md).
505+
The scale rule configuration defines the event source to monitor. Rules are evaluated on each polling interval to determine how many job executions to trigger. To learn more, see [Set scaling rules](scale-app.md).
405506

406507
The event-driven job is now created in the Container Apps environment.
407508

@@ -811,13 +912,13 @@ The following table describes the scale rule parameters used in the command.
811912
| `--scale-rule-metadata` | The metadata for the scale rule. |
812913
| `--scale-rule-auth` | The authentication for the scale rule. |
813914
814-
The scale rule configuration defines the event source to monitor. It's evaluated on each polling interval and determines how many job executions to trigger. To learn more, see [Set scaling rules](scale-app.md).
915+
The scale rule configuration defines the event source to monitor. Rules are evaluated on each polling interval to determine how many job executions to trigger. To learn more, see [Set scaling rules](scale-app.md).
815916
816917
The event-driven job is now created in the Container Apps environment.
817918
818919
## Run a pipeline and verify the job
819920
820-
Now that you've configured a self-hosted agent job, you can run a pipeline and verify it's working correctly.
921+
Once a self-hosted agent job is configured, you can run a pipeline and verify it's working correctly.
821922
822923
1. In the left-hand navigation of your Azure DevOps project, navigate to **Pipelines**.
823924

0 commit comments

Comments
 (0)