Skip to content

Commit c9494cd

Browse files
authored
Merge pull request #111551 from dlepow/acimifix
[ACI] Managed identity updates
2 parents 475a4af + b2db584 commit c9494cd

File tree

1 file changed

+40
-36
lines changed

1 file changed

+40
-36
lines changed

articles/container-instances/container-instances-managed-identity.md

Lines changed: 40 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: Enable managed identity in container group
33
description: Learn how to enable a managed identity in Azure Container Instances that can authenticate with other Azure services
44
ms.topic: article
5-
ms.date: 01/29/2020
5+
ms.date: 04/15/2020
66
---
77

88
# 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
1717
> * Use the managed identity to access a key vault from a running container
1818
1919
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.
2323
2424
## Why use a managed identity?
2525

2626
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)
2727

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-
3228
### Enable a managed identity
3329

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.
3931

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).
4133

4234
### Use a managed identity
4335

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).
4537

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.
4742

4843
[!INCLUDE [cloud-shell-try-it.md](../../includes/cloud-shell-try-it.md)]
4944

@@ -95,15 +90,33 @@ To use the identity in the following steps, use the [az identity show](/cli/azur
9590

9691
```azurecli-interactive
9792
# Get service principal ID of the user-assigned identity
98-
spID=$(az identity show --resource-group myResourceGroup --name myACIId --query principalId --output tsv)
93+
spID=$(az identity show \
94+
--resource-group myResourceGroup \
95+
--name myACIId \
96+
--query principalId --output tsv)
9997
10098
# Get resource ID of the user-assigned identity
101-
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
102115
```
103116

104-
### Enable a user-assigned identity on a container group
117+
### Enable user-assigned identity on a container group
105118

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).
107120

108121
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.
109122

@@ -142,18 +155,6 @@ The `identity` section in the output looks similar to the following, showing the
142155
[...]
143156
```
144157

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-
157158
### Use user-assigned identity to get secret from key vault
158159

159160
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
198199

199200
## Example 2: Use a system-assigned identity to access Azure key vault
200201

201-
### Enable a system-assigned identity on a container group
202+
### Enable system-assigned identity on a container group
202203

203204
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.
204205

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.
206207

207208
```azurecli-interactive
208209
# Get the resource ID of the resource group
@@ -217,7 +218,7 @@ az container create \
217218
--command-line "tail -f /dev/null"
218219
```
219220

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.
221222

222223
```azurecli-interactive
223224
az container show \
@@ -241,7 +242,10 @@ The `identity` section in the output looks similar to the following, showing tha
241242
Set a variable to the value of `principalId` (the service principal ID) of the identity, to use in later steps.
242243

243244
```azurecli-interactive
244-
spID=$(az container show --resource-group myResourceGroup --name mycontainer --query identity.principalId --out tsv)
245+
spID=$(az container show \
246+
--resource-group myResourceGroup \
247+
--name mycontainer \
248+
--query identity.principalId --out tsv)
245249
```
246250

247251
### Grant container group access to the key vault

0 commit comments

Comments
 (0)