Skip to content

Commit 5fd3d4e

Browse files
authored
Merge pull request #109472 from kummanish/byok
CLI documentation for Data encryption
2 parents 2d77276 + dfb8fe7 commit 5fd3d4e

File tree

6 files changed

+494
-254
lines changed

6 files changed

+494
-254
lines changed

articles/mysql/TOC.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,8 @@
246246
items:
247247
- name: Azure portal
248248
href: howto-data-encryption-portal.md
249+
- name: Azure CLI
250+
href: howto-data-encryption-cli.md
249251
- name: Azure AD Integration
250252
items:
251253
- name: Configure Azure AD integration
Lines changed: 245 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,245 @@
1+
---
2+
title: Data encryption - Azure CLI - Azure Database for MySQL
3+
description: Learn how to set up and manage data encryption for your Azure Database for MySQL by using the Azure CLI.
4+
author: kummanish
5+
ms.author: manishku
6+
ms.service: mysql
7+
ms.topic: conceptual
8+
ms.date: 03/30/2020
9+
---
10+
11+
# Data encryption for Azure Database for MySQL by using the Azure CLI
12+
13+
Learn how to use the Azure CLI to set up and manage data encryption for your Azure Database for MySQL.
14+
15+
## Prerequisites for Azure CLI
16+
17+
* You must have an Azure subscription and be an administrator on that subscription.
18+
* Create a key vault and a key to use for a customer-managed key. Also enable purge protection and soft delete on the key vault.
19+
20+
```azurecli-interactive
21+
az keyvault create -g <resource_group> -n <vault_name> --enable-soft-delete true --enable-purge-protection true
22+
```
23+
24+
* In the created Azure Key Vault, create the key that will be used for the data encryption of the Azure Database for MySQL.
25+
26+
```azurecli-interactive
27+
az keyvault key create --name <key_name> -p software --vault-name <vault_name>
28+
```
29+
30+
* In order to use an existing key vault, it must have the following properties to use as a customer-managed key:
31+
* [Soft delete](../key-vault/key-vault-ovw-soft-delete.md)
32+
33+
```azurecli-interactive
34+
az resource update --id $(az keyvault show --name \ <key_vault_name> -o tsv | awk '{print $1}') --set \ properties.enableSoftDelete=true
35+
```
36+
37+
* [Purge protected](../key-vault/key-vault-ovw-soft-delete.md#purge-protection)
38+
39+
```azurecli-interactive
40+
az keyvault update --name <key_vault_name> --resource-group <resource_group_name> --enable-purge-protection true
41+
```
42+
43+
* The key must have the following attributes to use as a customer-managed key:
44+
* No expiration date
45+
* Not disabled
46+
* Perform **get**, **wrap**, **unwrap** operations
47+
48+
## Set the right permissions for key operations
49+
50+
1. There are two ways of getting the managed identity for your Azure Database for MySQL.
51+
52+
### Create an new Azure Database for MySQL server with a managed identity.
53+
54+
```azurecli-interactive
55+
az mysql server create --name -g <resource_group> --location <locations> --storage-size <size> -u <user>-p <pwd> --backup-retention <7> --sku-name <sku name> --geo-redundant-backup <Enabled/Disabled> --assign-identity
56+
```
57+
58+
### Update an existing the Azure Database for MySQL server to get a managed identity.
59+
60+
```azurecli-interactive
61+
az mysql server update --name <server name> -g <resource_group> --assign-identity
62+
```
63+
64+
2. Set the **Key permissions** (**Get**, **Wrap**, **Unwrap**) for the **Principal**, which is the name of the MySQL server.
65+
66+
```azurecli-interactive
67+
az keyvault set-policy --name -g <resource_group> --key-permissions get unwrapKey wrapKey --object-id <principal id of the server>
68+
```
69+
70+
## Set data encryption for Azure Database for MySQL
71+
72+
1. Enable Data encryption for the Azure Database for MySQL using the key created in the Azure Key Vault.
73+
74+
```azurecli-interactive
75+
az mysql server key create –name <server name> -g <resource_group> --kid <key url>
76+
```
77+
78+
Key url: https://YourVaultName.vault.azure.net/keys/YourKeyName/01234567890123456789012345678901>
79+
80+
## Using Data encryption for restore or replica servers
81+
82+
After Azure Database for MySQL is encrypted with a customer's managed key stored in Key Vault, any newly created copy of the server is also encrypted. You can make this new copy either through a local or geo-restore operation, or through a replica (local/cross-region) operation. So for an encrypted MySQL server, you can use the following steps to create an encrypted restored server.
83+
84+
### Creating a restored/replica server
85+
86+
* [Create a restore server](howto-restore-server-cli.md)
87+
* [Create a read replica server](howto-read-replicas-cli.md)
88+
89+
### Once the server is restored, revalidate data encryption the restored server
90+
91+
```azurecli-interactive
92+
az mysql server key create –name <server name> -g <resource_group> --kid <key url>
93+
```
94+
95+
## Additional capability for the key being used for the Azure Database for MySQL
96+
97+
### Get the Key used
98+
99+
```azurecli-interactive
100+
az mysql server key show --name <server name> -g <resource_group> --kid <key url>
101+
```
102+
103+
Key url: https://YourVaultName.vault.azure.net/keys/YourKeyName/01234567890123456789012345678901>
104+
105+
### List the Key used
106+
107+
```azurecli-interactive
108+
az mysql server key list --name <server name> -g <resource_group>
109+
```
110+
111+
### Drop the key being used
112+
113+
```azurecli-interactive
114+
az mysql server key delete -g <resource_group> --kid <key url>
115+
```
116+
117+
## Using an Azure Resource Manager template to enable data encryption
118+
119+
Apart from the Azure portal, you can also enable data encryption on your Azure Database for MySQL server using Azure Resource Manager templates for new and existing servers.
120+
121+
### For a new server
122+
123+
Use one of the pre-created Azure Resource Manager templates to provision the server with data encryption enabled:
124+
[Example with Data encryption](https://github.com/Azure/azure-mysql/tree/master/arm-templates/ExampleWithDataEncryption)
125+
126+
This Azure Resource Manager template creates an Azure Database for MySQL server and uses the **KeyVault** and **Key** passed as parameters to enable data encryption on the server.
127+
128+
### For an existing server
129+
Additionally, you can use Azure Resource Manager templates to enable data encryption on your existing Azure Database for MySQL servers.
130+
131+
* Pass the Resource ID of the Azure Key Vault key that you copied earlier under the `Uri` property in the properties object.
132+
133+
* Use *2020-01-01-preview* as the API version.
134+
135+
```json
136+
{
137+
"$schema": "http://schema.management.azure.com/schemas/2014-04-01-preview/deploymentTemplate.json#",
138+
"contentVersion": "1.0.0.0",
139+
"parameters": {
140+
"location": {
141+
"type": "string"
142+
},
143+
"serverName": {
144+
"type": "string"
145+
},
146+
"keyVaultName": {
147+
"type": "string",
148+
"metadata": {
149+
"description": "Key vault name where the key to use is stored"
150+
}
151+
},
152+
"keyVaultResourceGroupName": {
153+
"type": "string",
154+
"metadata": {
155+
"description": "Key vault resource group name where it is stored"
156+
}
157+
},
158+
"keyName": {
159+
"type": "string",
160+
"metadata": {
161+
"description": "Key name in the key vault to use as encryption protector"
162+
}
163+
},
164+
"keyVersion": {
165+
"type": "string",
166+
"metadata": {
167+
"description": "Version of the key in the key vault to use as encryption protector"
168+
}
169+
}
170+
},
171+
"variables": {
172+
"serverKeyName": "[concat(parameters('keyVaultName'), '_', parameters('keyName'), '_', parameters('keyVersion'))]"
173+
},
174+
"resources": [
175+
{
176+
"type": "Microsoft.DBforMySQL/servers",
177+
"apiVersion": "2017-12-01",
178+
"kind": "",
179+
"location": "[parameters('location')]",
180+
"identity": {
181+
"type": "SystemAssigned"
182+
},
183+
"name": "[parameters('serverName')]",
184+
"properties": {
185+
}
186+
},
187+
{
188+
"type": "Microsoft.Resources/deployments",
189+
"apiVersion": "2019-05-01",
190+
"name": "addAccessPolicy",
191+
"resourceGroup": "[parameters('keyVaultResourceGroupName')]",
192+
"dependsOn": [
193+
"[resourceId('Microsoft.DBforMySQL/servers', parameters('serverName'))]"
194+
],
195+
"properties": {
196+
"mode": "Incremental",
197+
"template": {
198+
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
199+
"contentVersion": "1.0.0.0",
200+
"resources": [
201+
{
202+
"type": "Microsoft.KeyVault/vaults/accessPolicies",
203+
"name": "[concat(parameters('keyVaultName'), '/add')]",
204+
"apiVersion": "2018-02-14-preview",
205+
"properties": {
206+
"accessPolicies": [
207+
{
208+
"tenantId": "[subscription().tenantId]",
209+
"objectId": "[reference(resourceId('Microsoft.DBforMySQL/servers/', parameters('serverName')), '2017-12-01', 'Full').identity.principalId]",
210+
"permissions": {
211+
"keys": [
212+
"get",
213+
"wrapKey",
214+
"unwrapKey"
215+
]
216+
}
217+
}
218+
]
219+
}
220+
}
221+
]
222+
}
223+
}
224+
},
225+
{
226+
"name": "[concat(parameters('serverName'), '/', variables('serverKeyName'))]",
227+
"type": "Microsoft.DBforMySQL/servers/keys",
228+
"apiVersion": "2020-01-01-preview",
229+
"dependsOn": [
230+
"addAccessPolicy",
231+
"[resourceId('Microsoft.DBforMySQL/servers', parameters('serverName'))]"
232+
],
233+
"properties": {
234+
"serverKeyType": "AzureKeyVault",
235+
"uri": "[concat(reference(resourceId(parameters('keyVaultResourceGroupName'), 'Microsoft.KeyVault/vaults/', parameters('keyVaultName')), '2018-02-14-preview', 'Full').properties.vaultUri, 'keys/', parameters('keyName'), '/', parameters('keyVersion'))]"
236+
}
237+
}
238+
]
239+
}
240+
241+
```
242+
243+
## Next steps
244+
245+
To learn more about data encryption, see [Azure Database for MySQL data encryption with customer-managed key](concepts-data-encryption-mysql.md).

articles/mysql/howto-data-encryption-portal.md

Lines changed: 1 addition & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ Learn how to use the Azure portal to set up and manage data encryption for your
6060
6161
4. To ensure all files (including temp files) are fully encrypted, restart the server.
6262
63-
## Restore or create a replica of the server
63+
## Using Data encryption for restore or replica servers
6464
6565
After Azure Database for MySQL is encrypted with a customer's managed key stored in Key Vault, any newly created copy of the server is also encrypted. You can make this new copy either through a local or geo-restore operation, or through a replica (local/cross-region) operation. So for an encrypted MySQL server, you can use the following steps to create an encrypted restored server.
6666
@@ -89,133 +89,6 @@ After Azure Database for MySQL is encrypted with a customer's managed key stored
8989
9090
![Screenshot of Azure Database for MySQL, showing restored functionality](media/concepts-data-access-and-security-data-encryption/restore-successful.png)
9191
92-
93-
## Using an Azure Resource Manager template to enable data encryption
94-
95-
Apart from the Azure portal, you can also enable data encryption on your Azure Database for MySQL server using Azure Resource Manager templates for new and existing servers.
96-
97-
### For a new server
98-
99-
Use one of the pre-created Azure Resource Manager templates to provision the server with data encryption enabled:
100-
[Example with Data encryption](https://github.com/Azure/azure-mysql/tree/master/arm-templates/ExampleWithDataEncryption)
101-
102-
This Azure Resource Manager template creates a Azure Database for MySQL server and uses the **KeyVault** and **Key** passed as parameters to enable data encryption on the server.
103-
104-
### For an existing server
105-
Additionally, you can use Azure Resource Manager templates to enable data encryption on your existing Azure Database for MySQL servers.
106-
107-
* Pass the URI of the Azure Key Vault key that you copied earlier under the `keyVaultKeyUri` property in the properties object.
108-
109-
* Use *2020-01-01-preview* as the API version.
110-
111-
```json
112-
{
113-
"$schema": "http://schema.management.azure.com/schemas/2014-04-01-preview/deploymentTemplate.json#",
114-
"contentVersion": "1.0.0.0",
115-
"parameters": {
116-
"location": {
117-
"type": "string"
118-
},
119-
"serverName": {
120-
"type": "string"
121-
},
122-
"keyVaultName": {
123-
"type": "string",
124-
"metadata": {
125-
"description": "Key vault name where the key to use is stored"
126-
}
127-
},
128-
"keyVaultResourceGroupName": {
129-
"type": "string",
130-
"metadata": {
131-
"description": "Key vault resource group name where it is stored"
132-
}
133-
},
134-
"keyName": {
135-
"type": "string",
136-
"metadata": {
137-
"description": "Key name in the key vault to use as encryption protector"
138-
}
139-
},
140-
"keyVersion": {
141-
"type": "string",
142-
"metadata": {
143-
"description": "Version of the key in the key vault to use as encryption protector"
144-
}
145-
}
146-
},
147-
"variables": {
148-
"serverKeyName": "[concat(parameters('keyVaultName'), '_', parameters('keyName'), '_', parameters('keyVersion'))]"
149-
},
150-
"resources": [
151-
{
152-
"type": "Microsoft.DBforMySQL/servers",
153-
"apiVersion": "2017-12-01",
154-
"kind": "",
155-
"location": "[parameters('location')]",
156-
"identity": {
157-
"type": "SystemAssigned"
158-
},
159-
"name": "[parameters('serverName')]",
160-
"properties": {
161-
}
162-
},
163-
{
164-
"type": "Microsoft.Resources/deployments",
165-
"apiVersion": "2019-05-01",
166-
"name": "addAccessPolicy",
167-
"resourceGroup": "[parameters('keyVaultResourceGroupName')]",
168-
"dependsOn": [
169-
"[resourceId('Microsoft.DBforMySQL/servers', parameters('serverName'))]"
170-
],
171-
"properties": {
172-
"mode": "Incremental",
173-
"template": {
174-
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
175-
"contentVersion": "1.0.0.0",
176-
"resources": [
177-
{
178-
"type": "Microsoft.KeyVault/vaults/accessPolicies",
179-
"name": "[concat(parameters('keyVaultName'), '/add')]",
180-
"apiVersion": "2018-02-14-preview",
181-
"properties": {
182-
"accessPolicies": [
183-
{
184-
"tenantId": "[subscription().tenantId]",
185-
"objectId": "[reference(resourceId('Microsoft.DBforMySQL/servers/', parameters('serverName')), '2017-12-01', 'Full').identity.principalId]",
186-
"permissions": {
187-
"keys": [
188-
"get",
189-
"wrapKey",
190-
"unwrapKey"
191-
]
192-
}
193-
}
194-
]
195-
}
196-
}
197-
]
198-
}
199-
}
200-
},
201-
{
202-
"name": "[concat(parameters('serverName'), '/', variables('serverKeyName'))]",
203-
"type": "Microsoft.DBforMySQL/servers/keys",
204-
"apiVersion": "2020-01-01-preview",
205-
"dependsOn": [
206-
"addAccessPolicy",
207-
"[resourceId('Microsoft.DBforMySQL/servers', parameters('serverName'))]"
208-
],
209-
"properties": {
210-
"serverKeyType": "AzureKeyVault",
211-
"uri": "[concat(reference(resourceId(parameters('keyVaultResourceGroupName'), 'Microsoft.KeyVault/vaults/', parameters('keyVaultName')), '2018-02-14-preview', 'Full').properties.vaultUri, 'keys/', parameters('keyName'), '/', parameters('keyVersion'))]"
212-
}
213-
}
214-
]
215-
}
216-
217-
```
218-
21992
## Next steps
22093
22194
To learn more about data encryption, see [Azure Database for MySQL data encryption with customer-managed key](concepts-data-encryption-mysql.md).

0 commit comments

Comments
 (0)