Skip to content

Commit 1f717b2

Browse files
authored
Merge pull request #100713 from ThomasWeiss/thweiss-cosmosdb-cmk
Added Cosmos DB CMK setup page
2 parents 2615e9d + 11c4189 commit 1f717b2

13 files changed

+218
-0
lines changed

articles/cosmos-db/TOC.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -978,6 +978,8 @@
978978
href: certificate-based-authentication.md
979979
- name: Restrict user access to data operations only
980980
href: how-to-restrict-user-data.md
981+
- name: Configure customer-managed keys
982+
href: how-to-setup-cmk.md
981983
- name: Enterprise readiness
982984
items:
983985
- name: Restore data from a backup
Lines changed: 216 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,216 @@
1+
---
2+
title: Configure customer-managed keys for your Azure Cosmos DB account
3+
description: Learn how to configure customer-managed keys for your Azure Cosmos DB account
4+
author: ThomasWeiss
5+
ms.service: cosmos-db
6+
ms.topic: conceptual
7+
ms.date: 01/09/2020
8+
ms.author: thweiss
9+
---
10+
11+
# Configure customer-managed keys for your Azure Cosmos DB account
12+
13+
> [!NOTE]
14+
> At this time, you must request access to use this capability. To do so, please contact [[email protected]](mailto:[email protected]).
15+
16+
Data stored in your Azure Cosmos DB account is automatically and seamlessly encrypted. Azure Cosmos DB offers two options for managing the keys used to encrypt your data at rest:
17+
- **Service-managed keys**. By default, Microsoft manages the keys used to encrypt your Azure Cosmos DB account.
18+
- **Customer-managed keys (CMK)**. You can optionally choose to add a second layer of encryption with keys you manage.
19+
20+
Customer-managed keys must be stored in [Azure Key Vault](../key-vault/key-vault-overview.md). A key must be provided for each CMK-enabled account and is used to encrypt all the data stored in that account.
21+
22+
## Setup
23+
24+
Currently, customer-managed keys are only available for new accounts and need to be set up during account creation.
25+
26+
### 1. Make sure the Azure Cosmos DB resource provider is registered for your Azure subscription
27+
28+
From the Azure portal, go to your Azure subscription and select "Resource providers" from the left menu:
29+
30+
!["Resource providers" entry from the left menu](./media/how-to-setup-cmk/portal-rp.png)
31+
32+
Search for the "Microsoft.DocumentDB" resource provider.
33+
- If the resource provider is already marked as registered, nothing needs to be done.
34+
- If not, select it and click on "Register":
35+
36+
![Registering the Microsoft.DocumentDB resource provider](./media/how-to-setup-cmk/portal-rp-register.png)
37+
38+
### 2. Configure your Azure Key Vault instance
39+
40+
Using customer-managed keys with Azure Cosmos DB requires two properties to be set on the Azure Key Vault instance you plan to use to host your encryption keys: **Soft Delete** and **Do Not Purge**. These properties aren't enabled by default but can be enabled using either PowerShell or the Azure CLI.
41+
42+
To learn how to enable these properties on an existing Azure Key Vault instance, see the sections titled Enabling soft-delete and Enabling Purge Protection in one of the following articles:
43+
- [How to use soft-delete with PowerShell](../key-vault/key-vault-soft-delete-powershell.md)
44+
- [How to use soft-delete with Azure CLI](../key-vault/key-vault-soft-delete-cli.md)
45+
46+
### 3. Add an access policy to your Azure Key Vault instance
47+
48+
From the Azure portal, go to the Azure Key Vault instance you plan to use to host your encryption keys. Then, select "Access Policies" from the left menu:
49+
50+
!["Access policies" from the left menu](./media/how-to-setup-cmk/portal-akv-ap.png)
51+
52+
- Click on "+ Add Access Policy"
53+
- Under the "Key permissions" dropdown menu, select "Get", "Unwrap Key" and "Wrap Key":
54+
55+
![Selecting the right permissions](./media/how-to-setup-cmk/portal-akv-add-ap-perm2.png)
56+
57+
- Under "Select principal", click on "None selected", search for and select the "Azure Cosmos DB" principal, then click "Select" at the bottom (if the "Azure Cosmos DB" principal can't be found, you may need to re-register the "Microsoft.DocumentDB" resource provider at step 2):
58+
59+
![Selecting the Azure Cosmos DB principal](./media/how-to-setup-cmk/portal-akv-add-ap.png)
60+
61+
- Click "Add" to add the new access policy
62+
63+
### 4. Generate a key in Azure Key Vault
64+
65+
From the Azure portal, go the Azure Key Vault instance you plan to use to host your encryption keys. Then, select "Keys" from the left menu:
66+
67+
!["Keys" entry from the left menu](./media/how-to-setup-cmk/portal-akv-keys.png)
68+
69+
- Click on "Generate/Import"
70+
- Provide a name for the new key, select an RSA key size (a minimum of 3072 is recommended for best security) and click "Create":
71+
72+
![Creating a new key](./media/how-to-setup-cmk/portal-akv-gen.png)
73+
74+
- Once the key is created, click on the newly created key, then on its current version
75+
- Copy the key’s "Key Identifier" except the part after the last forward slash:
76+
77+
![Copying the key's key identifier](./media/how-to-setup-cmk/portal-akv-keyid.png)
78+
79+
### 5. Create a new Azure Cosmos DB account
80+
81+
#### Using the Azure portal
82+
83+
When creating a new Azure Cosmos DB account from the Azure portal, choose "Customer-managed key" at the "Encryption" step. In the "Key URI" field, pass the URI of the Azure Key Vault key copied from step 4:
84+
85+
![Setting CMK parameters in the Azure portal](./media/how-to-setup-cmk/portal-cosmos-enc.png)
86+
87+
#### Using PowerShell
88+
89+
When creating a new Azure Cosmos DB account with PowerShell,
90+
- pass the URI of the Azure Key Vault key copied from step 4 under the "keyVaultKeyUri" property in the "PropertyObject",
91+
- make sure to use "2019-12-12" as the API version.
92+
93+
```powershell
94+
$resourceGroupName = "myResourceGroup"
95+
$accountLocation = "West US 2"
96+
$accountName = "mycosmosaccount"
97+
98+
$failoverLocations = @(
99+
@{ "locationName"="West US 2"; "failoverPriority"=0 }
100+
)
101+
102+
$CosmosDBProperties = @{
103+
"databaseAccountOfferType"="Standard";
104+
"locations"=$failoverLocations;
105+
"keyVaultKeyUri" = "https://<my-vault>.vault.azure.net/keys/<my-key>";
106+
}
107+
108+
New-AzResource -ResourceType "Microsoft.DocumentDb/databaseAccounts" `
109+
-ApiVersion "2019-12-12" -ResourceGroupName $resourceGroupName `
110+
-Location $accountLocation -Name $accountName -PropertyObject $CosmosDBProperties
111+
```
112+
113+
#### Using Azure Resource Manager templates
114+
115+
When creating a new Azure Cosmos DB account through an Azure Resource Manager template:
116+
- pass the URI of the Azure Key Vault key copied from step 4 under the "keyVaultKeyUri" property in the "properties" object
117+
- make sure to use "2019-12-12" as the API version
118+
119+
```
120+
{
121+
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
122+
"contentVersion": "1.0.0.0",
123+
"parameters": {
124+
"accountName": {
125+
"type": "string"
126+
},
127+
"location": {
128+
"type": "string"
129+
},
130+
"keyVaultKeyUri": {
131+
"type": "string"
132+
}
133+
},
134+
"resources":
135+
[
136+
{
137+
"type": "Microsoft.DocumentDB/databaseAccounts",
138+
"name": "[parameters('accountName')]",
139+
"apiVersion": "2019-12-12",
140+
"kind": "GlobalDocumentDB",
141+
"location": "[parameters('location')]",
142+
"properties": {
143+
"locations": [
144+
{
145+
"locationName": "[parameters('location')]",
146+
"failoverPriority": 0,
147+
"isZoneRedundant": false
148+
}
149+
],
150+
"databaseAccountOfferType": "Standard",
151+
"keyVaultKeyUri": "[parameters('keyVaultKeyUri')]"
152+
}
153+
}
154+
]
155+
}
156+
157+
```
158+
159+
```powershell
160+
$resourceGroupName = "myResourceGroup"
161+
$accountName = "mycosmosaccount"
162+
$accountLocation = "West US 2"
163+
$keyVaultKeyUri = "https://<my-vault>.vault.azure.net/keys/<my-key>"
164+
165+
New-AzResourceGroupDeployment `
166+
-ResourceGroupName $resourceGroupName `
167+
-TemplateFile "deploy.json" `
168+
-accountName $accountName `
169+
-location $accountLocation `
170+
-keyVaultKeyUri $keyVaultKeyUri
171+
```
172+
173+
## Frequently asked questions
174+
175+
### Is there any additional charge when using customer-managed keys?
176+
177+
Yes. To account for the additional compute load that is required to manage data encryption and decryption with customer-managed keys, all operations executed against the Azure Cosmos DB account get a 25% increase in [Request Units](./request-units.md) consumed.
178+
179+
### What data gets encrypted with the CMK?
180+
181+
All the data stored in your Azure Cosmos DB account gets encrypted with the CMK, except for the following meta-data:
182+
- the names of your Azure Cosmos DB [accounts, databases and containers](./account-overview.md#elements-in-an-azure-cosmos-account),
183+
- the names of your [stored procedures](./stored-procedures-triggers-udfs.md),
184+
- the property paths declared in your [indexing policies](./index-policy.md),
185+
- the values of your containers' [partition key](./partitioning-overview.md).
186+
187+
### Will customer-managed keys be supported for existing accounts?
188+
189+
This feature is currently available for new accounts only.
190+
191+
### Is there a plan to support finer granularity than account-level keys?
192+
193+
Not currently, however container-level keys are being considered.
194+
195+
### How does customer-managed keys affect backups?
196+
197+
Azure Cosmos DB takes [regular and automatic backups](./online-backup-and-restore.md) of the data stored in your account. This operation backs up the encrypted data. For a restored backup to be usable, the encryption key used at the time of the backup must still be available. This means that no revocation shall have been made and the version of the key that was used at the time of the backup shall still be enabled.
198+
199+
### How do I revoke an encryption key?
200+
201+
Key revocation is done by disabling the latest version of the key:
202+
203+
![Disabling a key's version](./media/how-to-setup-cmk/portal-akv-rev2.png)
204+
205+
Alternatively, to revoke all keys from an Azure Key Vault instance, you can delete the access policy granted to the Azure Cosmos DB principal:
206+
207+
![Deleting the access policy for the Azure Cosmos DB principal](./media/how-to-setup-cmk/portal-akv-rev.png)
208+
209+
### What operations are available after a customer-managed key is revoked?
210+
211+
The only operation possible when the encryption key has been revoked is account deletion.
212+
213+
## Next steps
214+
215+
- Learn more about [data encryption in Azure Cosmos DB](./database-encryption-at-rest.md)
216+
- Get an overview of [secure access to data in Cosmos DB](secure-access-to-data.md)
12.8 KB
Loading
41.9 KB
Loading
2.88 KB
Loading
20.7 KB
Loading
4.81 KB
Loading
3.41 KB
Loading
12.9 KB
Loading
42.4 KB
Loading

0 commit comments

Comments
 (0)