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-instances/container-instances-managed-identity.md
+40-36Lines changed: 40 additions & 36 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
title: Enable managed identity in container group
3
3
description: Learn how to enable a managed identity in Azure Container Instances that can authenticate with other Azure services
4
4
ms.topic: article
5
-
ms.date: 01/29/2020
5
+
ms.date: 04/15/2020
6
6
---
7
7
8
8
# How to use managed identities with Azure Container Instances
@@ -17,33 +17,28 @@ In this article, you learn more about managed identities in Azure Container Inst
17
17
> * Use the managed identity to access a key vault from a running container
18
18
19
19
Adapt the examples to enable and use identities in Azure Container Instances to access other Azure services. These examples are interactive. However, in practice your container images would run code to access Azure services.
20
-
21
-
> [!NOTE]
22
-
> Currently you cannot use a managed identity in a container group deployed to a virtual network.
20
+
21
+
> [!IMPORTANT]
22
+
> This feature is currently in preview. Previews are made available to you on the condition that you agree to the [supplemental terms of use](https://azure.microsoft.com/support/legal/preview-supplemental-terms/). Some aspects of this feature may change prior to general availability (GA). Currently, managed identities on Azure Container Instances, are only supported with Linux containers and not yet with Windows containers.
23
23
24
24
## Why use a managed identity?
25
25
26
26
Use a managed identity in a running container to authenticate to any [service that supports Azure AD authentication](../active-directory/managed-identities-azure-resources/services-support-managed-identities.md#azure-services-that-support-azure-ad-authentication) without managing credentials in your container code. For services that don't support AD authentication, you can store secrets in an Azure key vault and use the managed identity to access the key vault to retrieve credentials. For more information about using a managed identity, see [What is managed identities for Azure resources?](../active-directory/managed-identities-azure-resources/overview.md)
27
27
28
-
> [!IMPORTANT]
29
-
> This feature is currently in preview. Previews are made available to you on the condition that you agree to the [supplemental terms of use](https://azure.microsoft.com/support/legal/preview-supplemental-terms/). Some aspects of this feature may change prior to general availability (GA). Currently, managed identities on Azure Container Instances, are only supported with Linux containers and not yet with Windows containers.
30
-
>
31
-
32
28
### Enable a managed identity
33
29
34
-
In Azure Container Instances, managed identities for Azure resources are supported as of REST API version 2018-10-01 and corresponding SDKs and tools. When you create a container group, enable one or more managed identities by setting a [ContainerGroupIdentity](/rest/api/container-instances/containergroups/createorupdate#containergroupidentity) property. You can also enable or update managed identities after a container group is running - either action causes the container group to restart. To set the identities on a new or existing container group, use the Azure CLI, a Resource Manager template, or a YAML file.
35
-
36
-
Azure Container Instances supports both types of managed Azure identities: user-assigned and system-assigned. On a container group, you can enable a system-assigned identity, one or more user-assigned identities, or both types of identities.
37
-
38
-
* A **user-assigned** managed identity is created as a standalone Azure resource in the Azure AD tenant that's trusted by the subscription in use. After the identity is created, the identity can be assigned to one or more Azure resources (in Azure Container Instances or other Azure services). The lifecycle of a user-assigned identity is managed separately from the lifecycle of the container groups or other service resources to which it's assigned. This behavior is especially useful in Azure Container Instances. Because the identity extends beyond the lifetime of a container group, you can reuse it along with other standard settings to make your container group deployments highly repeatable.
30
+
When you create a container group, enable one or more managed identities by setting a [ContainerGroupIdentity](/rest/api/container-instances/containergroups/createorupdate#containergroupidentity) property. You can also enable or update managed identities after a container group is running - either action causes the container group to restart. To set the identities on a new or existing container group, use the Azure CLI, a Resource Manager template, a YAML file, or another Azure tool.
39
31
40
-
* A **system-assigned** managed identity is enabled directly on a container group in Azure Container Instances. When it's enabled, Azure creates an identity for the group in the Azure AD tenant that's trusted by the subscription of the instance. After the identity is created, the credentials are provisioned in each container in the container group. The lifecycle of a system-assigned identity is directly tied to the container group that it's enabled on. When the group is deleted, Azure automatically cleans up the credentials and the identity in Azure AD.
32
+
Azure Container Instances supports both types of managed Azure identities: user-assigned and system-assigned. On a container group, you can enable a system-assigned identity, one or more user-assigned identities, or both types of identities. If you're unfamiliar with managed identities for Azure resources, see the [overview](../active-directory/managed-identities-azure-resources/overview.md).
41
33
42
34
### Use a managed identity
43
35
44
-
To use a managed identity, the identity must initially be granted access to one or more Azure service resources (such as a web app, a key vault, or a storage account) in the subscription. To access the Azure resources from a running container, your code must acquire an *access token* from an Azure AD endpoint. Then, your code sends the access token on a call to a service that supports Azure AD authentication.
36
+
To use a managed identity, the identity must be granted access to one or more Azure service resources (such as a web app, a key vault, or a storage account) in the subscription. Using a managed identity in a running container is similar to using an identity in an Azure VM. See the VM guidance for using a [token](../active-directory/managed-identities-azure-resources/how-to-use-vm-token.md), [Azure PowerShell or Azure CLI](../active-directory/managed-identities-azure-resources/how-to-use-vm-sign-in.md), or the [Azure SDKs](../active-directory/managed-identities-azure-resources/how-to-use-vm-sdk.md).
45
37
46
-
Using a managed identity in a running container is essentially the same as using an identity in an Azure VM. See the VM guidance for using a [token](../active-directory/managed-identities-azure-resources/how-to-use-vm-token.md), [Azure PowerShell or Azure CLI](../active-directory/managed-identities-azure-resources/how-to-use-vm-sign-in.md), or the [Azure SDKs](../active-directory/managed-identities-azure-resources/how-to-use-vm-sdk.md).
38
+
### Limitations
39
+
40
+
* Currently you can't use a managed identity in a container group deployed to a virtual network.
41
+
* You can't use a managed identity to pull an image from Azure Container Registry when creating a container group. The identity is only available within a running container.
resourceID=$(az identity show --resource-group myResourceGroup --name myACIId --query id --output tsv)
99
+
resourceID=$(az identity show \
100
+
--resource-group myResourceGroup \
101
+
--name myACIId \
102
+
--query id --output tsv)
103
+
```
104
+
105
+
### Grant user-assigned identity access to the key vault
106
+
107
+
Run the following [az keyvault set-policy](/cli/azure/keyvault?view=azure-cli-latest) command to set an access policy on the key vault. The following example allows the user-assigned identity to get secrets from the key vault:
108
+
109
+
```azurecli-interactive
110
+
az keyvault set-policy \
111
+
--name mykeyvault \
112
+
--resource-group myResourceGroup \
113
+
--object-id $spID \
114
+
--secret-permissions get
102
115
```
103
116
104
-
### Enable a user-assigned identity on a container group
117
+
### Enable user-assigned identity on a container group
105
118
106
-
Run the following [az container create](/cli/azure/container?view=azure-cli-latest#az-container-create) command to create a container instance based on Microsoft's `azure-cli` image. This example provides a single-container group that you can use interactively to run the Azure CLI to access other Azure services. In this section, only the base Ubuntu operating system is used.
119
+
Run the following [az container create](/cli/azure/container?view=azure-cli-latest#az-container-create) command to create a container instance based on Microsoft's `azure-cli` image. This example provides a single-container group that you can use interactively to run the Azure CLI to access other Azure services. In this section, only the base operating system is used. For an example to use the Azure CLI in the container, see [Enable system-assigned identity on a container group](#enable-system-assigned-identity-on-a-container-group).
107
120
108
121
The `--assign-identity` parameter passes your user-assigned managed identity to the group. The long-running command keeps the container running. This example uses the same resource group used to create the key vault, but you could specify a different one.
109
122
@@ -142,18 +155,6 @@ The `identity` section in the output looks similar to the following, showing the
142
155
[...]
143
156
```
144
157
145
-
### Grant user-assigned identity access to the key vault
146
-
147
-
Run the following [az keyvault set-policy](/cli/azure/keyvault?view=azure-cli-latest) command to set an access policy on the key vault. The following example allows the user-assigned identity to get secrets from the key vault:
148
-
149
-
```azurecli-interactive
150
-
az keyvault set-policy \
151
-
--name mykeyvault \
152
-
--resource-group myResourceGroup \
153
-
--object-id $spID \
154
-
--secret-permissions get
155
-
```
156
-
157
158
### Use user-assigned identity to get secret from key vault
158
159
159
160
Now you can use the managed identity within the running container instance to access the key vault. First launch a bash shell in the container:
@@ -198,11 +199,11 @@ The response looks similar to the following, showing the secret. In your code, y
198
199
199
200
## Example 2: Use a system-assigned identity to access Azure key vault
200
201
201
-
### Enable a system-assigned identity on a container group
202
+
### Enable system-assigned identity on a container group
202
203
203
204
Run the following [az container create](/cli/azure/container?view=azure-cli-latest#az-container-create) command to create a container instance based on Microsoft's `azure-cli` image. This example provides a single-container group that you can use interactively to run the Azure CLI to access other Azure services.
204
205
205
-
The `--assign-identity` parameter with no additional value enables a system-assigned managed identity on the group. The identity is scoped to the resource group of the container group. The long-running command keeps the container running. This example uses the same resource group used to create the key vault, but you could specify a different one.
206
+
The `--assign-identity` parameter with no additional value enables a system-assigned managed identity on the group. The identity is scoped to the resource group of the container group. The long-running command keeps the container running. This example uses the same resource group used to create the key vault, which is in the scope of the identity.
206
207
207
208
```azurecli-interactive
208
209
# Get the resource ID of the resource group
@@ -217,7 +218,7 @@ az container create \
217
218
--command-line "tail -f /dev/null"
218
219
```
219
220
220
-
Within a few seconds, you should get a response from the Azure CLI indicating that the deployment has completed. Check its status with the [az container show](/cli/azure/container?view=azure-cli-latest#az-container-show) command.
221
+
Within a few seconds, you should get a response from the Azure CLI indicating that the deployment has completed. Check its status with the [az container show](/cli/azure/container#az-container-show) command.
221
222
222
223
```azurecli-interactive
223
224
az container show \
@@ -241,7 +242,10 @@ The `identity` section in the output looks similar to the following, showing tha
241
242
Set a variable to the value of `principalId` (the service principal ID) of the identity, to use in later steps.
0 commit comments