Skip to content

Commit 76b067a

Browse files
authored
Inital commit
1 parent f0fc1e0 commit 76b067a

File tree

1 file changed

+211
-1
lines changed

1 file changed

+211
-1
lines changed

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

Lines changed: 211 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@ The rest of the document covers the steps required to encrypt your ACI deploymen
3232

3333
[!INCLUDE [azure-cli-prepare-your-environment.md](../../includes/azure-cli-prepare-your-environment.md)]
3434

35-
## Encrypt data with a customer-managed key
35+
This article reviews two flows for encrypting data with a customer-managed key:
36+
1. Encrypt data with a customer-managed key stored in a standard Azure Key Vault
37+
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.
38+
39+
## Encrypt data with a customer-managed key in a network-proected Azure Key Vault with Trusted Services enabled
3640

3741
### Create Service Principal for ACI
3842

@@ -239,6 +243,212 @@ az deployment group create --resource-group myResourceGroup --template-file depl
239243

240244
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.
241245

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
267+
268+
### Create a Key Vault resource
269+
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).
271+
272+
For the properties of your key vault, use the following guidelines:
273+
* Name: A unique name is required.
274+
* Subscription: Choose a subscription.
275+
* Under Resource Group, either choose an existing resource group, or create new and enter a resource group name.
276+
* In the Location pull-down menu, choose a location.
277+
* You can leave the other options to their defaults or pick based on additional requirements.
278+
279+
> [!IMPORTANT]
280+
> When using customer-managed keys to encrypt an ACI deployment template, it is recommended that the following two properties be set on the key vault, Soft Delete and Do Not Purge. These properties are not enabled by default, but can be enabled using either PowerShell or Azure CLI on a new or existing key vault.
281+
282+
### Generate a new key
283+
284+
Once your key vault is created, navigate to the resource in Azure portal. On the left navigation menu of the resource blade, under Settings, click **Keys**. On the view for "Keys," click "Generate/Import" to generate a new key. Use any unique Name for this key, and any other preferences based on your requirements.
285+
286+
![Generate a new key](./media/container-instances-encrypt-data/generate-key.png)
287+
288+
### Set access policy
289+
290+
Create a new access policy for allowing the ACI service to access your Key.
291+
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
298+
299+
The access policy should now show up in your key vault's access policies.
300+
301+
![New access policy](./media/container-instances-encrypt-data/access-policy.png)
302+
303+
### Modify your JSON deployment template
304+
305+
> [!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.
307+
308+
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`.
310+
* Under the container group properties section of the deployment template, add an `encryptionProperties`, which contains the following values:
311+
* `vaultBaseUrl`: the DNS Name of your key vault, can be found on the overview blade of the key vault resource in Portal
312+
* `keyName`: the name of the key generated earlier
313+
* `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.
315+
316+
The following template snippet shows these additional properties to encrypt deployment data:
317+
318+
```json
319+
[...]
320+
"resources": [
321+
{
322+
"name": "[parameters('containerGroupName')]",
323+
"type": "Microsoft.ContainerInstance/containerGroups",
324+
"apiVersion": "2019-12-01",
325+
"location": "[resourceGroup().location]",
326+
"properties": {
327+
"encryptionProperties": {
328+
"vaultBaseUrl": "https://example.vault.azure.net",
329+
"keyName": "acikey",
330+
"keyVersion": "xxxxxxxxxxxxxxxx"
331+
},
332+
"sku": "Standard",
333+
"containers": {
334+
[...]
335+
}
336+
}
337+
}
338+
]
339+
```
340+
341+
Following is a complete template, adapted from the template in [Tutorial: Deploy a multi-container group using a Resource Manager template](./container-instances-multi-container-group.md).
342+
343+
```json
344+
{
345+
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
346+
"contentVersion": "1.0.0.0",
347+
"parameters": {
348+
"containerGroupName": {
349+
"type": "string",
350+
"defaultValue": "myContainerGroup",
351+
"metadata": {
352+
"description": "Container Group name."
353+
}
354+
}
355+
},
356+
"variables": {
357+
"container1name": "aci-tutorial-app",
358+
"container1image": "mcr.microsoft.com/azuredocs/aci-helloworld:latest",
359+
"container2name": "aci-tutorial-sidecar",
360+
"container2image": "mcr.microsoft.com/azuredocs/aci-tutorial-sidecar"
361+
},
362+
"resources": [
363+
{
364+
"name": "[parameters('containerGroupName')]",
365+
"type": "Microsoft.ContainerInstance/containerGroups",
366+
"apiVersion": "2019-12-01",
367+
"location": "[resourceGroup().location]",
368+
"properties": {
369+
"encryptionProperties": {
370+
"vaultBaseUrl": "https://example.vault.azure.net",
371+
"keyName": "acikey",
372+
"keyVersion": "xxxxxxxxxxxxxxxx"
373+
},
374+
"sku": "Standard",
375+
"containers": [
376+
{
377+
"name": "[variables('container1name')]",
378+
"properties": {
379+
"image": "[variables('container1image')]",
380+
"resources": {
381+
"requests": {
382+
"cpu": 1,
383+
"memoryInGb": 1.5
384+
}
385+
},
386+
"ports": [
387+
{
388+
"port": 80
389+
},
390+
{
391+
"port": 8080
392+
}
393+
]
394+
}
395+
},
396+
{
397+
"name": "[variables('container2name')]",
398+
"properties": {
399+
"image": "[variables('container2image')]",
400+
"resources": {
401+
"requests": {
402+
"cpu": 1,
403+
"memoryInGb": 1.5
404+
}
405+
}
406+
}
407+
}
408+
],
409+
"osType": "Linux",
410+
"ipAddress": {
411+
"type": "Public",
412+
"ports": [
413+
{
414+
"protocol": "tcp",
415+
"port": "80"
416+
},
417+
{
418+
"protocol": "tcp",
419+
"port": "8080"
420+
}
421+
]
422+
}
423+
}
424+
}
425+
],
426+
"outputs": {
427+
"containerIPv4Address": {
428+
"type": "string",
429+
"value": "[reference(resourceId('Microsoft.ContainerInstance/containerGroups/', parameters('containerGroupName'))).ipAddress.ip]"
430+
}
431+
}
432+
}
433+
```
434+
435+
### Deploy your resources
436+
437+
If you created and edited the template file on your desktop, you can upload it to your Cloud Shell directory by dragging the file into it.
438+
439+
Create a resource group with the [az group create][az-group-create] command.
440+
441+
```azurecli-interactive
442+
az group create --name myResourceGroup --location eastus
443+
```
444+
445+
Deploy the template with the [az deployment group create][az-deployment-group-create] command.
446+
447+
```azurecli-interactive
448+
az deployment group create --resource-group myResourceGroup --template-file deployment-template.json
449+
```
450+
451+
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.
242452
<!-- LINKS - Internal -->
243453
[az-group-create]: /cli/azure/group#az_group_create
244454
[az-deployment-group-create]: /cli/azure/deployment/group/#az_deployment_group_create

0 commit comments

Comments
 (0)