Skip to content

Commit 675eacd

Browse files
authored
Merge pull request #101181 from dlepow/acrmsi
[ACR] Tasks MSI updates
2 parents 9c117ea + b382798 commit 675eacd

File tree

3 files changed

+27
-20
lines changed

3 files changed

+27
-20
lines changed

articles/container-registry/container-registry-tasks-authentication-key-vault.md

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
---
22
title: External authentication from ACR task
3-
description: Enable a managed identity for Azure Resources in an Azure Container Registry (ACR) task to allow the task to read Docker Hub credentials stored in an Azure key vault.
3+
description: Configure an Azure Container Registry Task (ACR Task) to read Docker Hub credentials stored in an Azure key vault, by using a managed identity for Azure resources.
44
ms.topic: article
5-
ms.date: 07/12/2019
5+
ms.date: 01/14/2020
66
---
77

88
# External authentication in an ACR task using an Azure-managed identity
@@ -15,7 +15,7 @@ To create the Azure resources, this article requires that you run the Azure CLI
1515

1616
## Scenario overview
1717

18-
The example task reads Docker Hub credentials stored in an Azure key vault. The credentials are for a Docker Hub account with write (push) permissions to a private repository in Docker Hub. To read the credentials, you configure the task with a managed identity and assign appropriate permissions to it. The task associated with the identity builds an image, and signs into Docker Hub to push the image to the private repo.
18+
The example task reads Docker Hub credentials stored in an Azure key vault. The credentials are for a Docker Hub account with write (push) permissions to a private Docker Hub repository. To read the credentials, you configure the task with a managed identity and assign appropriate permissions to it. The task associated with the identity builds an image, and signs into Docker Hub to push the image to the private repo.
1919

2020
This example shows steps using either a user-assigned or system-assigned managed identity. Your choice of identity depends on your organization's needs.
2121

@@ -66,7 +66,7 @@ In a real-world scenario, secrets would likely be set and maintained in a separa
6666
The steps for this example task are defined in a [YAML file](container-registry-tasks-reference-yaml.md). Create a file named `dockerhubtask.yaml` in a local working directory and paste the following contents. Be sure to replace the key vault name in the file with the name of your key vault.
6767

6868
```yml
69-
version: v1.0.0
69+
version: v1.1.0
7070
# Replace mykeyvault with the name of your key vault
7171
secrets:
7272
- id: username
@@ -75,12 +75,12 @@ secrets:
7575
keyvault: https://mykeyvault.vault.azure.net/secrets/Password
7676
steps:
7777
# Log in to Docker Hub
78-
- cmd: docker login --username '{{.Secrets.username}}' --password '{{.Secrets.password}}'
78+
- cmd: bash echo '{{.Secrets.password}}' | docker login --username '{{.Secrets.username}}' --password-stdin
7979
# Build image
80-
- build: -t {{.Values.PrivateRepo}}:{{.Run.ID}} https://github.com/Azure-Samples/acr-tasks.git -f hello-world.dockerfile
80+
- build: -t {{.Values.PrivateRepo}}:$ID https://github.com/Azure-Samples/acr-tasks.git -f hello-world.dockerfile
8181
# Push image to private repo in Docker Hub
8282
- push:
83-
- {{.Values.PrivateRepo}}:{{.Run.ID}}
83+
- {{.Values.PrivateRepo}}:$ID
8484
```
8585
8686
The task steps do the following:
@@ -90,6 +90,7 @@ The task steps do the following:
9090
* Build an image using a sample Dockerfile in the [Azure-Samples/acr-tasks](https://github.com/Azure-Samples/acr-tasks.git) repo.
9191
* Push the image to the private Docker Hub repository.
9292

93+
9394
## Option 1: Create task with user-assigned identity
9495

9596
The steps in this section create a task and enable a user-assigned identity. If you want to enable a system-assigned identity instead, see [Option 2: Create task with system-assigned identity](#option-2-create-task-with-system-assigned-identity).
@@ -135,15 +136,18 @@ az acr task create \
135136
Run the following [az keyvault set-policy][az-keyvault-set-policy] command to set an access policy on the key vault. The following example allows the identity to read secrets from the key vault.
136137

137138
```azurecli
138-
az keyvault set-policy --name mykeyvault --resource-group myResourceGroup --object-id $principalID --secret-permissions get
139+
az keyvault set-policy --name mykeyvault \
140+
--resource-group myResourceGroup \
141+
--object-id $principalID \
142+
--secret-permissions get
139143
```
140144

141145
## Manually run the task
142146

143147
To verify that the task in which you enabled a managed identity runs successfully, manually trigger the task with the [az acr task run][az-acr-task-run] command. The `--set` parameter is used to pass the private repo name to the task. In this example, the placeholder repo name is *hubuser/hubrepo*.
144148

145149
```azurecli
146-
az acr task run --name dockerhubtask --registry myregistry --set PrivateRepo=hubuser/hubrepo
150+
az acr task run --name dockerhubtask --registry myregistry --set PrivateRepo=hubuser/hubrepo
147151
```
148152

149153
When the task runs successfully, output shows successful authentication to Docker Hub, and the image is successfully built and pushed to the private repo:

articles/container-registry/container-registry-tasks-cross-registry-authentication.md

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
---
22
title: Cross-registry authentication from ACR task
3-
description: Configure an Azure Container Registry Task (ACR Task) to access another private Azure container registry by using a managed identity for Azure Resources
3+
description: Configure an Azure Container Registry Task (ACR Task) to access another private Azure container registry by using a managed identity for Azure resources
44
ms.topic: article
5-
ms.date: 07/12/2019
5+
ms.date: 01/14/2020
66
---
77

88
# Cross-registry authentication in an ACR task using an Azure-managed identity
99

1010
In an [ACR task](container-registry-tasks-overview.md), you can [enable a managed identity for Azure resources](container-registry-tasks-authentication-managed-identity.md). The task can use the identity to access other Azure resources, without needing to provide or manage credentials.
1111

12-
In this article, you learn how to enable a managed identity in a task that pulls an image from a registry different from the one used to run the task.
12+
In this article, you learn how to enable a managed identity in a task to pull an image from a registry different from the one used to run the task.
1313

1414
To create the Azure resources, this article requires that you run the Azure CLI version 2.0.68 or later. Run `az --version` to find the version. If you need to install or upgrade, see [Install Azure CLI][azure-cli].
1515

@@ -47,14 +47,14 @@ az acr build --image baseimages/node:9-alpine --registry mybaseregistry --file D
4747

4848
## Define task steps in YAML file
4949

50-
The steps for this example [multi-step task](container-registry-tasks-multi-step.md) are defined in a [YAML file](container-registry-tasks-reference-yaml.md). Create a file named `helloworldtask.yaml` in your local working directory and paste in the following contents. Update the value of `REGISTRY_NAME` in the build step with the server name of your base registry.
50+
The steps for this example [multi-step task](container-registry-tasks-multi-step.md) are defined in a [YAML file](container-registry-tasks-reference-yaml.md). Create a file named `helloworldtask.yaml` in your local working directory and paste the following contents. Update the value of `REGISTRY_NAME` in the build step with the server name of your base registry.
5151

5252
```yml
53-
version: v1.0.0
53+
version: v1.1.0
5454
steps:
5555
# Replace mybaseregistry with the name of your registry containing the base image
56-
- build: -t {{.Run.Registry}}/hello-world:{{.Run.ID}} https://github.com/Azure-Samples/acr-build-helloworld-node.git -f Dockerfile-app --build-arg REGISTRY_NAME=mybaseregistry.azurecr.io
57-
- push: ["{{.Run.Registry}}/hello-world:{{.Run.ID}}"]
56+
- build: -t $Registry/hello-world:$ID https://github.com/Azure-Samples/acr-build-helloworld-node.git -f Dockerfile-app --build-arg REGISTRY_NAME=mybaseregistry.azurecr.io
57+
- push: ["$Registry/hello-world:$ID"]
5858
```
5959
6060
The build step uses the `Dockerfile-app` file in the [Azure-Samples/acr-build-helloworld-node](https://github.com/Azure-Samples/acr-build-helloworld-node.git) repo to build an image. The `--build-arg` references the base registry to pull the base image. When successfully built, the image is pushed to the registry used to run the task.
@@ -111,12 +111,15 @@ baseregID=$(az acr show --name mybaseregistry --query id --output tsv)
111111
Use the [az role assignment create][az-role-assignment-create] command to assign the identity the `acrpull` role to the base registry. This role has permissions only to pull images from the registry.
112112

113113
```azurecli
114-
az role assignment create --assignee $principalID --scope $baseregID --role acrpull
114+
az role assignment create \
115+
--assignee $principalID \
116+
--scope $baseregID \
117+
--role acrpull
115118
```
116119

117120
## Add target registry credentials to task
118121

119-
Now use the [az acr task credential add][az-acr-task-credential-add] command to add the identity's credentials to the task so that it can authenticate with the base registry. Run the command corresponding to the type of managed identity you enabled in the task. If you enabled a user-assigned identity, pass `--use-identity` with the client ID of the identity. If you enabled a system-assigned identity, pass `--use-identity [system]`.
122+
Now use the [az acr task credential add][az-acr-task-credential-add] command to enable the task to authenticate with the base registry using the identity's credentials. Run the command corresponding to the type of managed identity you enabled in the task. If you enabled a user-assigned identity, pass `--use-identity` with the client ID of the identity. If you enabled a system-assigned identity, pass `--use-identity [system]`.
120123

121124
```azurecli
122125
# Add credentials for user-assigned identity to the task

includes/container-registry-tasks-system-id-properties.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ In the command output, the `identity` section shows an identity of type `SystemA
2323
"location": "eastus",
2424
[...]
2525
```
26-
Use the [az acr task show][az-acr-task-show] command to store the principalId in a variable, to use in later commands:
26+
Use the [az acr task show][az-acr-task-show] command to store the principalId in a variable, to use in later commands. Substitute the name of your task and your registry in the following command:
2727

2828
```azurecli
29-
principalID=$(az acr task show --name dockerhubtask --registry myregistry --query identity.principalId --output tsv)
29+
principalID=$(az acr task show --name mytask --registry myregistry --query identity.principalId --output tsv)
3030
```
3131

3232
<!-- LINKS - Internal -->

0 commit comments

Comments
 (0)