Skip to content

Commit 309d6d8

Browse files
authored
Update container-instances-encrypt-data.md
1 parent 76b067a commit 309d6d8

File tree

1 file changed

+75
-40
lines changed

1 file changed

+75
-40
lines changed

articles/container-instances/container-instances-encrypt-data.md

Lines changed: 75 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ This article reviews two flows for encrypting data with a customer-managed key:
3636
1. Encrypt data with a customer-managed key stored in a standard Azure Key Vault
3737
2. Encrypt data with a customer-managed key stored in a network-proteted Azure Key Vault with [Trusted Services](../key-vault/general/network-security.md) enabled.
3838

39-
## Encrypt data with a customer-managed key in a network-proected Azure Key Vault with Trusted Services enabled
39+
## Encrypt data with a customer-managed key stored in a standard Azure Key Vault
4040

4141
### Create Service Principal for ACI
4242

@@ -243,31 +243,11 @@ az deployment group create --resource-group myResourceGroup --template-file depl
243243

244244
Within a few seconds, you should receive an initial response from Azure. Once the deployment completes, all data related to it persisted by the ACI service will be encrypted with the key you provided.
245245

246-
## Encrypt data with a customer-managed key in a standard Azure Key Vault
247-
248-
### Create Service Principal for ACI
249-
250-
The first step is to ensure that your [Azure tenant](../active-directory/develop/quickstart-create-new-tenant.md) has a service principal assigned for granting permissions to the Azure Container Instances service.
251-
252-
> [!IMPORTANT]
253-
> In order to run the following command and create a service principal successfully, confirm that you have permissions to create service principals in your tenant.
254-
>
255-
256-
The following CLI command will set up the ACI SP in your Azure environment:
257-
258-
```azurecli-interactive
259-
az ad sp create --id 6bb8e274-af5d-4df2-98a3-4fd78b4cafd9
260-
```
261-
262-
The output from running this command should show you a service principal that has been set up with "displayName": "Azure Container Instance Service."
263-
264-
In case you are unable to successfully create the service principal:
265-
* confirm that you have permissions to do so in your tenant
266-
* check to see if a service principal already exists in your tenant for deploying to ACI. You can do that by running `az ad sp show --id 6bb8e274-af5d-4df2-98a3-4fd78b4cafd9` and use that service principal instead
246+
## Encrypt data with a customer-managed key in a network protected Azure Key Vault with Trusted Services enabled
267247

268248
### Create a Key Vault resource
269249

270-
Create an Azure Key Vault using [Azure portal](../key-vault/general/quick-create-portal.md), [Azure CLI](../key-vault/general/quick-create-cli.md), or [Azure PowerShell](../key-vault/general/quick-create-powershell.md).
250+
Create an Azure Key Vault using [Azure portal](../key-vault/general/quick-create-portal.md), [Azure CLI](../key-vault/general/quick-create-cli.md), or [Azure PowerShell](../key-vault/general/quick-create-powershell.md). To start, do not apply any network-limitations so we can add necessary keys to the vault. In subsequent steps, we will add network-limitations and enable trusted services.
271251

272252
For the properties of your key vault, use the following guidelines:
273253
* Name: A unique name is required.
@@ -285,33 +265,74 @@ Once your key vault is created, navigate to the resource in Azure portal. On the
285265

286266
![Generate a new key](./media/container-instances-encrypt-data/generate-key.png)
287267

268+
### Create a user-assigned managed identity for your container group
269+
Create an identity in your subscription using the [az identity create](/cli/azure/identity#az-identity-create) command. You can use the same resource group used to create the key vault, or use a different one.
270+
271+
```azurecli-interactive
272+
az identity create \
273+
--resource-group myResourceGroup \
274+
--name myACIId
275+
```
276+
277+
To use the identity in the following steps, use the [az identity show](/cli/azure/identity#az-identity-show) command to store the identity's service principal ID and resource ID in variables.
278+
279+
```azurecli-interactive
280+
# Get service principal ID of the user-assigned identity
281+
spID=$(az identity show \
282+
--resource-group myResourceGroup \
283+
--name myACIId \
284+
--query principalId --output tsv)
285+
```
286+
288287
### Set access policy
289288

290-
Create a new access policy for allowing the ACI service to access your Key.
289+
Create a new access policy for allowing the user-assigned identity to access your Key.
291290

292-
* Once your key has been generated, back in your key vault resource blade, under Settings, click **Access Policies**.
293-
* On the "Access Policies" page for your key vault, click **Add Access Policy**.
294-
* Set the *Key Permissions* to include **Get** and **Unwrap Key**
295-
![Set key permissions](./media/container-instances-encrypt-data/set-key-permissions.png)
296-
* For *Select Principal*, select **Azure Container Instance Service**
297-
* Click **Add** at the bottom
291+
```azurecli-interactive
292+
az keyvault set-policy \
293+
--name mykeyvault \
294+
--resource-group myResourceGroup \
295+
--object-id $spID \
296+
--secret-permissions get unwrap
297+
```
298298

299299
The access policy should now show up in your key vault's access policies.
300300

301301
![New access policy](./media/container-instances-encrypt-data/access-policy.png)
302302

303+
### Modify Azure Key Vault's network permissions
304+
The following commands set up an Azure Firewall for your Azure Key Vault and allow Azure Trusted Services such as ACI access.
305+
306+
```azurecli-interactive
307+
az keyvault update \
308+
--name mykeyvault \
309+
--resource-group myResourceGroup \
310+
--default-action Deny
311+
```
312+
313+
```azurecli-interactive
314+
az keyvault update \
315+
--name mykeyvault \
316+
--resource-group myResourceGroup \
317+
--bypass AzureServices
318+
```
319+
303320
### Modify your JSON deployment template
304321

305322
> [!IMPORTANT]
306-
> Encrypting deployment data with a customer-managed key is available in the latest API version (2019-12-01) that is currently rolling out. Specify this API version in your deployment template. If you have any issues with this, please reach out to Azure Support.
323+
> Encrypting deployment data with a customer-managed key is available in the latest API version (2022-09-01) that is currently rolling out. This API version is only available via ARM or REST. If you have any issues with this, please reach out to Azure Support.
307324
308325
Once the key vault key and access policy are set up, add the following properties to your ACI deployment template. Learn more about deploying ACI resources with a template in the [Tutorial: Deploy a multi-container group using a Resource Manager template](./container-instances-multi-container-group.md).
309-
* Under `resources`, set `apiVersion` to `2019-12-01`.
326+
* Under `resources`, set `apiVersion` to `2022-09-01`.
310327
* Under the container group properties section of the deployment template, add an `encryptionProperties`, which contains the following values:
311328
* `vaultBaseUrl`: the DNS Name of your key vault, can be found on the overview blade of the key vault resource in Portal
312329
* `keyName`: the name of the key generated earlier
313330
* `keyVersion`: the current version of the key. This can be found by clicking into the key itself (under "Keys" in the Settings section of your key vault resource)
314-
* Under the container group properties, add a `sku` property with value `Standard`. The `sku` property is required in API version 2019-12-01.
331+
* `identity`: this is the resource URI of the Managed Identity instance created earlier
332+
* Under the container group properties, add a `sku` property with value `Standard`. The `sku` property is required in API version 2022-09-01.
333+
* Under resources, add the `identity` object required to use Managed Identity with ACI, whichcontainsthe following values:
334+
* `type`: the type of the identity being used (either user-assigned or system-assigned). This case will be set to "UserAssigned"
335+
* `userAssignedIdentities`: the resourceURI of the same user-assigned identity used above in the `encryptionProperties` object.
315336

316337
The following template snippet shows these additional properties to encrypt deployment data:
317338

@@ -323,11 +344,18 @@ The following template snippet shows these additional properties to encrypt depl
323344
"type": "Microsoft.ContainerInstance/containerGroups",
324345
"apiVersion": "2019-12-01",
325346
"location": "[resourceGroup().location]",
347+
"identity": {
348+
"type": "UserAssigned",
349+
"userAssignedIdentities": {
350+
"/subscriptions/XXXXXXXXXXXXXXXXXXXXXX/resourcegroups/XXXXXXXXXXXXXXXXXXXXXX/providers/Microsoft.ManagedIdentity/userAssignedIdentities/myACIId": {}
351+
}
352+
},
326353
"properties": {
327354
"encryptionProperties": {
328355
"vaultBaseUrl": "https://example.vault.azure.net",
329356
"keyName": "acikey",
330-
"keyVersion": "xxxxxxxxxxxxxxxx"
357+
"keyVersion": "xxxxxxxxxxxxxxxx",
358+
"identity": "/subscriptions/XXXXXXXXXXXXXXXXXXXXXX/resourcegroups/XXXXXXXXXXXXXXXXXXXXXX/providers/Microsoft.ManagedIdentity/userAssignedIdentities/myACIId"
331359
},
332360
"sku": "Standard",
333361
"containers": {
@@ -365,13 +393,20 @@ Following is a complete template, adapted from the template in [Tutorial: Deploy
365393
"type": "Microsoft.ContainerInstance/containerGroups",
366394
"apiVersion": "2019-12-01",
367395
"location": "[resourceGroup().location]",
396+
"identity": {
397+
"type": "UserAssigned",
398+
"userAssignedIdentities": {
399+
"/subscriptions/XXXXXXXXXXXXXXXXXXXXXX/resourcegroups/XXXXXXXXXXXXXXXXXXXXXX/providers/Microsoft.ManagedIdentity/userAssignedIdentities/myACIId": {}
400+
}
401+
},
368402
"properties": {
369403
"encryptionProperties": {
370-
"vaultBaseUrl": "https://example.vault.azure.net",
371-
"keyName": "acikey",
372-
"keyVersion": "xxxxxxxxxxxxxxxx"
404+
"vaultBaseUrl": "https://example.vault.azure.net",
405+
"keyName": "acikey",
406+
"keyVersion": "xxxxxxxxxxxxxxxx",
407+
"identity": "/subscriptions/XXXXXXXXXXXXXXXXXXXXXX/resourcegroups/XXXXXXXXXXXXXXXXXXXXXX/providers/Microsoft.ManagedIdentity/userAssignedIdentities/myACIId"
373408
},
374-
"sku": "Standard",
409+
"sku": "Standard",
375410
"containers": [
376411
{
377412
"name": "[variables('container1name')]",
@@ -415,8 +450,8 @@ Following is a complete template, adapted from the template in [Tutorial: Deploy
415450
"port": "80"
416451
},
417452
{
418-
"protocol": "tcp",
419-
"port": "8080"
453+
"protocol": "tcp",
454+
"port": "8080"
420455
}
421456
]
422457
}

0 commit comments

Comments
 (0)