You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/container-registry/container-registry-tasks-authentication-managed-identity.md
+22-12Lines changed: 22 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,7 +7,7 @@ manager: gwallace
7
7
8
8
ms.service: container-registry
9
9
ms.topic: article
10
-
ms.date: 07/11/2019
10
+
ms.date: 01/14/2020
11
11
ms.author: danlep
12
12
---
13
13
@@ -17,14 +17,14 @@ Enable a [managed identity for Azure resources](../active-directory/managed-iden
17
17
18
18
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].
19
19
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:
*[Access external resources with secrets stored in Azure Key Vault](container-registry-tasks-authentication-key-vault.md)
24
24
25
25
## Why use a managed identity?
26
26
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.
28
28
29
29
Managed identities are of two types:
30
30
@@ -40,37 +40,39 @@ Follow these high-level steps to use a managed identity with an ACR task.
40
40
41
41
### 1. (Optional) Create a user-assigned identity
42
42
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.
44
44
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.
46
46
47
47
### 2. Enable identity on an ACR task
48
48
49
49
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.
50
50
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:
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:
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:
@@ -83,20 +85,23 @@ Depending on the requirements of your task, grant the identity permissions to ac
83
85
* 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).
84
86
* Assign the managed identity a role to read secrets in an Azure key vault.
85
87
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.
87
89
88
90
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.
89
91
90
92
91
93
```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
93
98
```
94
99
95
100
### 4. (Optional) Add credentials to the task
96
101
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.
98
103
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]`:
100
105
101
106
```azurecli
102
107
az acr task credential add \
@@ -118,6 +123,10 @@ az acr task credential add \
118
123
119
124
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`.
120
125
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
+
121
130
## Next steps
122
131
123
132
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
0 commit comments