|
| 1 | +--- |
| 2 | +title: Encrypt deployment data |
| 3 | +description: Learn about encryption of data persisted for your container instance resources and how to encrypt the data with a customer-managed key |
| 4 | +ms.topic: article |
| 5 | +ms.date: 01/10/2020 |
| 6 | +ms.author: danlep |
| 7 | +--- |
| 8 | + |
| 9 | +# Encrypt deployment data |
| 10 | + |
| 11 | +When running Azure Container Instances (ACI) resources in the cloud, the ACI service collects and persists data related to your containers. ACI automatically encrypts this data when it is persisted in the cloud. This encryption protects your data to help meet your organization's security and compliance commitments. ACI also gives you the option to encrypt this data with your own key, giving you greater control over the data related to your ACI deployments. |
| 12 | + |
| 13 | +## About ACI data encryption |
| 14 | + |
| 15 | +Data in ACI is encrypted and decrypted using 256-bit AES encryption. It is enabled for all ACI deployments, and you don't need to modify your deployment or containers to take advantage of this encryption. This includes metadata about the deployment, environment variables, keys being passed into your containers, and logs persisted after your containers are stopped so you can still see them. Encryption does not affect your container group performance, and there is no additional cost for encryption. |
| 16 | + |
| 17 | +## Encryption key management |
| 18 | + |
| 19 | +You can rely on Microsoft-managed keys for the encryption of your container data, or you can manage the encryption with your own keys. The following table compares these options: |
| 20 | + |
| 21 | +| | Microsoft-managed keys | Customer-managed keys | |
| 22 | +|----|----|----| |
| 23 | +| Encryption/decryption operations | Azure | Azure | |
| 24 | +| Key storage | Microsoft key store | Azure Key Vault | |
| 25 | +| Key rotation responsibility | Microsoft | Customer | |
| 26 | +| Key access | Microsoft only | Microsoft, Customer | |
| 27 | + |
| 28 | +The rest of the document covers the steps required to encrypt your ACI deployment data with your key (customer-managed key). |
| 29 | + |
| 30 | +[!INCLUDE [cloud-shell-try-it.md](../../includes/cloud-shell-try-it.md)] |
| 31 | + |
| 32 | +## Encrypt data with a customer-managed key |
| 33 | + |
| 34 | +### Create Service Principal for ACI |
| 35 | + |
| 36 | +The first step is to ensure that your [Azure tenant](https://docs.microsoft.com/azure/active-directory/develop/quickstart-create-new-tenant) has a service principal assigned for granting permissions to the Azure Container Instances service. |
| 37 | + |
| 38 | +The following CLI command will set up the ACI SP in your Azure environment: |
| 39 | + |
| 40 | +```azurecli-interactive |
| 41 | +az ad sp create --id 6bb8e274-af5d-4df2-98a3-4fd78b4cafd9 |
| 42 | +``` |
| 43 | + |
| 44 | +The output from running this command should show you a service principal that has been set up with "displayName": "Azure Container Instance Service." |
| 45 | + |
| 46 | +### Create a Key Vault resource |
| 47 | + |
| 48 | +Create an Azure Key Vault using [Azure portal](https://docs.microsoft.com/azure/key-vault/quick-create-portal#create-a-vault), [CLI](https://docs.microsoft.com/azure/key-vault/quick-create-cli), or [PowerShell](https://docs.microsoft.com/azure/key-vault/quick-create-powershell). |
| 49 | + |
| 50 | +For the properties of your key vault, use the following guidelines: |
| 51 | +* Name: A unique name is required. |
| 52 | +* Subscription: Choose a subscription. |
| 53 | +* Under Resource Group, either choose an existing resource group, or create new and enter a resource group name. |
| 54 | +* In the Location pull-down menu, choose a location. |
| 55 | +* You can leave the other options to their defaults or pick based on additional requirements. |
| 56 | + |
| 57 | +> [!IMPORTANT] |
| 58 | +> 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. |
| 59 | +
|
| 60 | +### Generate a new key |
| 61 | + |
| 62 | +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. |
| 63 | + |
| 64 | + |
| 65 | + |
| 66 | +### Set access policy |
| 67 | + |
| 68 | +Create a new access policy for allowing the ACI service to access your Key. |
| 69 | + |
| 70 | +* Once your key has been generated, back in your key vault resource blade, under Settings, click **Access Policies**. |
| 71 | +* On the "Access Policies" page for your key vault, click **Add Access Policy**. |
| 72 | +* Set the *Key Permissions* to include **Get** and **Unwrap Key** |
| 73 | +  |
| 74 | +* For *Select Principal*, select **Azure Container Instance Service** |
| 75 | +* Click **Add** at the bottom |
| 76 | + |
| 77 | +The access policy should now show up in your key vault's access policies. |
| 78 | + |
| 79 | + |
| 80 | + |
| 81 | +### Modify your JSON deployment template |
| 82 | + |
| 83 | +> [!IMPORTANT] |
| 84 | +> 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. |
| 85 | +
|
| 86 | +Once the key vault key and access policy are set up, add the following property to your ACI deployment template. You can learn more about deploying ACI resources with a template in the [Tutorial: Deploy a multi-container group using a Resource Manager template](https://docs.microsoft.com/azure/container-instances/container-instances-multi-container-group). |
| 87 | + |
| 88 | +Specifically, under the container group properties section of the deployment template, add an "encryptionProperties", which contains the following values: |
| 89 | +* vaultBaseUrl: the DNS Name of your key vault, can be found on the overview blade of the key vault resource in Portal |
| 90 | +* keyName: the name of the key generated earlier |
| 91 | +* 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) |
| 92 | + |
| 93 | + |
| 94 | +```json |
| 95 | +"resources": [ |
| 96 | + { |
| 97 | + "name": "[parameters('containerGroupName')]", |
| 98 | + "type": "Microsoft.ContainerInstance/containerGroups", |
| 99 | + "apiVersion": "2019-12-01", |
| 100 | + "location": "[resourceGroup().location]", |
| 101 | + "properties": { |
| 102 | + "encryptionProperties": { |
| 103 | + "vaultBaseUrl": "https://example.vault.azure.net", |
| 104 | + "keyName": "acikey", |
| 105 | + "keyVersion": "xxxxxxxxxxxxxxxx" |
| 106 | + }, |
| 107 | + "containers": { |
| 108 | + [...] |
| 109 | + } |
| 110 | + } |
| 111 | + } |
| 112 | +] |
| 113 | +``` |
| 114 | + |
| 115 | +### Deploy your resources |
| 116 | + |
| 117 | +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. |
| 118 | + |
| 119 | +Create a resource group with the [az group create][az-group-create] command. |
| 120 | + |
| 121 | +```azurecli-interactive |
| 122 | +az group create --name myResourceGroup --location eastus |
| 123 | +``` |
| 124 | + |
| 125 | +Deploy the template with the [az group deployment create][az-group-deployment-create] command. |
| 126 | + |
| 127 | +```azurecli-interactive |
| 128 | +az group deployment create --resource-group myResourceGroup --template-file deployment-template.json |
| 129 | +``` |
| 130 | + |
| 131 | +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. |
| 132 | + |
| 133 | +<!-- LINKS - Internal --> |
| 134 | +[az-group-create]: /cli/azure/group#az-group-create |
| 135 | +[az-group-deployment-create]: /cli/azure/group/deployment#az-group-deployment-create |
0 commit comments