Skip to content

Commit dd783e4

Browse files
committed
[ACR] Fix task managed identity auth
1 parent c929d5c commit dd783e4

File tree

1 file changed

+22
-12
lines changed

1 file changed

+22
-12
lines changed

articles/container-registry/container-registry-tasks-authentication-managed-identity.md

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ manager: gwallace
77

88
ms.service: container-registry
99
ms.topic: article
10-
ms.date: 07/11/2019
10+
ms.date: 01/14/2020
1111
ms.author: danlep
1212
---
1313

@@ -17,14 +17,14 @@ Enable a [managed identity for Azure resources](../active-directory/managed-iden
1717

1818
In this article, you learn how to use the Azure CLI to enable a user-assigned or system-assigned managed identity on an ACR task. You can use the Azure Cloud Shell or a local installation of the Azure CLI. If you'd like to use it locally, version 2.0.68 or later is required. Run `az --version` to find the version. If you need to install or upgrade, see [Install Azure CLI][azure-cli-install].
1919

20-
For scenarios to access secured resources from an ACR task using a managed identity, see:
20+
For illustration purposes, the example commands in this article use [az acr task create][az-acr-task-create] to create a basic image build task that enables a managed identity. For sample scenarios to access secured resources from an ACR task using a managed identity, see:
2121

2222
* [Cross-registry authentication](container-registry-tasks-cross-registry-authentication.md)
2323
* [Access external resources with secrets stored in Azure Key Vault](container-registry-tasks-authentication-key-vault.md)
2424

2525
## Why use a managed identity?
2626

27-
A managed identity for Azure resources provides selected Azure services with an automatically managed identity in Azure Active Directory (Azure AD). You can configure an ACR task with a managed identity so that the task can access other secured Azure resources, without passing credentials in the task steps.
27+
A managed identity for Azure resources provides selected Azure services with an automatically managed identity in Azure Active Directory. You can configure an ACR task with a managed identity so that the task can access other secured Azure resources, without passing credentials in the task steps.
2828

2929
Managed identities are of two types:
3030

@@ -40,37 +40,39 @@ Follow these high-level steps to use a managed identity with an ACR task.
4040

4141
### 1. (Optional) Create a user-assigned identity
4242

43-
If you plan to use a user-assigned identity, you can use an existing identity. Or, create the identity using the Azure CLI or other Azure tools. For example, use the [az identity create][az-identity-create] command.
43+
If you plan to use a user-assigned identity, use an existing identity., or create the identity using the Azure CLI or other Azure tools. For example, use the [az identity create][az-identity-create] command.
4444

45-
If you plan to use only a system-assigned identity, skip this step. You can create a system-assigned identity when you create the ACR task.
45+
If you plan to use only a system-assigned identity, skip this step. You create a system-assigned identity when you create the ACR task.
4646

4747
### 2. Enable identity on an ACR task
4848

4949
When you create an ACR task, optionally enable a user-assigned identity, a system-assigned identity, or both. For example, pass the `--assign-identity` parameter when you run the [az acr task create][az-acr-task-create] command in the Azure CLI.
5050

51-
To enable a system-assigned identity, pass `--assign-identity` with no value or `assign-identity [system]`. The following command creates a Linux task from a public GitHub repository which builds the `hello-world` image with a Git commit trigger and with a system-assigned managed identity:
51+
To enable a system-assigned identity, pass `--assign-identity` with no value or `assign-identity [system]`. The following example command creates a Linux task from a public GitHub repository which builds the `hello-world` image and enables a system-assigned managed identity:
5252

5353
```azurecli
5454
az acr task create \
5555
--image hello-world:{{.Run.ID}} \
5656
--name hello-world --registry MyRegistry \
5757
--context https://github.com/Azure-Samples/acr-build-helloworld-node.git \
5858
--file Dockerfile \
59+
--commit-trigger-enabled false \
5960
--assign-identity
6061
```
6162

62-
To enable a user-assigned identity, pass `--assign-identity` with a value of the *resource ID* of the identity. The following command creates a Linux task from a public GitHub repository which builds the `hello-world` image with a Git commit trigger and with a user-assigned managed identity:
63+
To enable a user-assigned identity, pass `--assign-identity` with a value of the *resource ID* of the identity. The following example command creates a Linux task from a public GitHub repository which builds the `hello-world` image and enables a user-assigned managed identity:
6364

6465
```azurecli
6566
az acr task create \
6667
--image hello-world:{{.Run.ID}} \
6768
--name hello-world --registry MyRegistry \
6869
--context https://github.com/Azure-Samples/acr-build-helloworld-node.git \
6970
--file Dockerfile \
71+
--commit-trigger-enabled false
7072
--assign-identity <resourceID>
7173
```
7274

73-
You can get the resource ID of the identity by running the [az identity show][az-identity-show] command. The resource ID for the ID *myUserAssignedIdentity* in resource group *myResourceGroup* is of the form.
75+
You can get the resource ID of the identity by running the [az identity show][az-identity-show] command. The resource ID for the ID *myUserAssignedIdentity* in resource group *myResourceGroup* is of the form:
7476

7577
```
7678
"/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourcegroups/myResourceGroup/providers/Microsoft.ManagedIdentity/userAssignedIdentities/myUserAssignedIdentity"
@@ -83,20 +85,23 @@ Depending on the requirements of your task, grant the identity permissions to ac
8385
* Assign the managed identity a role with pull, push and pull, or other permissions to a target container registry in Azure. For a complete list of registry roles, see [Azure Container Registry roles and permissions](container-registry-roles.md).
8486
* Assign the managed identity a role to read secrets in an Azure key vault.
8587

86-
Use the [Azure CLI](../role-based-access-control/role-assignments-cli.md) or other Azure tools to manage role-based access to resources. For example, run the [az role assignment create][az-role-assignment-create] command to assign the identity a role to the identity.
88+
Use the [Azure CLI](../role-based-access-control/role-assignments-cli.md) or other Azure tools to manage role-based access to resources. For example, run the [az role assignment create][az-role-assignment-create] command to assign the identity a role to the resource.
8789

8890
The following example assigns a managed identity the permissions to pull from a container registry. The command specifies the *service principal ID* of the identity and the *resource ID* of the target registry.
8991

9092

9193
```azurecli
92-
az role assignment create --assignee <servicePrincipalID> --scope <registryID> --role acrpull
94+
az role assignment create \
95+
--assignee <servicePrincipalID> \
96+
--scope <registryID> \
97+
--role acrpull
9398
```
9499

95100
### 4. (Optional) Add credentials to the task
96101

97-
If your task pulls or pushes images to another Azure container registry, add credentials to the task for the identity to authenticate. Run the [az acr task credential add][az-acr-task-credential-add] command and pass the `--use-identity` parameter to add the identity's credentials to the task.
102+
If your task pulls or pushes images to another custom registry, add credentials to the task for the identity to authenticate. For example, run the [az acr task credential add][az-acr-task-credential-add] command and pass the `--use-identity` parameter to add the identity's credentials to the task.
98103

99-
For example, to add credentials for a system-assigned identity to authenticate with the registry *targetregistry*, pass `use-identity [system]`:
104+
To add credentials for a system-assigned identity to authenticate with the Azure container registry *targetregistry*, pass `use-identity [system]`:
100105

101106
```azurecli
102107
az acr task credential add \
@@ -118,6 +123,10 @@ az acr task credential add \
118123

119124
You can get the client ID of the identity by running the [az identity show][az-identity-show] command. The client ID is a GUID of the form `xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx`.
120125

126+
## 5. Run the task
127+
128+
After configuring a task with a managed identity, run the task. For example, to test one of the tasks created in this article, manually trigger it using the [az acr task run][az-acr-task-run] command. If you configured additional, automated task triggers, the task runs when automatically triggered.
129+
121130
## Next steps
122131

123132
In this article, you learned how to enable and use a user-assigned or system-assigned managed identity on an ACR task. For scenarios to access secured resources from an ACR task using a managed identity, see:
@@ -131,5 +140,6 @@ In this article, you learned how to enable and use a user-assigned or system-ass
131140
[az-identity-create]: /cli/azure/identity#az-identity-create
132141
[az-identity-show]: /cli/azure/identity#az-identity-show
133142
[az-acr-task-create]: /cli/azure/acr/task#az-acr-task-create
143+
[az-acr-task-run]: /cli/azure/acr/task#az-acr-task-run
134144
[az-acr-task-credential-add]: /cli/azure/acr/task/credential#az-acr-task-credential-add
135145
[azure-cli-install]: /cli/azure/install-azure-cli

0 commit comments

Comments
 (0)