Skip to content

Commit 16cde81

Browse files
authored
Merge pull request #221183 from GennadNY/gennadyk897
Gennadyk897
2 parents 0438778 + da4a764 commit 16cde81

File tree

3 files changed

+75
-8
lines changed

3 files changed

+75
-8
lines changed

articles/postgresql/TOC.yml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,10 @@
576576
href: flexible-server/how-to-manage-server-cli.md
577577
- name: Connect and query guide
578578
href: flexible-server/how-to-connect-query-guide.md
579+
- name: Encryption with CMK
580+
items:
581+
- name: Azure CLI
582+
href: flexible-server/how-to-create-server-customer-managed-key-cli.md
579583
- name: Database deployment
580584
items:
581585
- name: GitHub Actions
@@ -600,12 +604,6 @@
600604
href: flexible-server/how-to-manage-firewall-portal.md
601605
- name: Azure CLI
602606
href: flexible-server/how-to-manage-firewall-cli.md
603-
- name: Security (TLS/SSL/SCRAM)
604-
items:
605-
- name: Connect using TLS/SSL
606-
href: flexible-server/how-to-connect-tls-ssl.md
607-
- name: Connect using SCRAM
608-
href: flexible-server/how-to-connect-scram.md
609607
- name: Configure server parameters
610608
items:
611609
- name: Azure portal

articles/postgresql/flexible-server/concepts-data-encryption.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ Some of the reasons why server state can become *Inaccessible* are:
155155
- If you delete the key from the KeyVault, the Azure Database for PostgreSQL- Flexible Server will be unable to access the key and will move to *Inaccessible* state. [Recover the Key](../../key-vault/general/key-vault-recovery.md) and revalidate the data encryption to make the server *Available*.
156156
- If you delete [managed identity](../../active-directory/managed-identities-azure-resources/how-manage-user-assigned-managed-identities.md) from Azure AD that is used to retrieve a key from KeyVault, the Azure Database for PostgreSQL- Flexible Server will be unable to access the key and will move to *Inaccessible* state.[Recover the identity](../../active-directory/fundamentals/recover-from-deletions.md) and revalidate data encryption to make server *Available*.
157157
- If you revoke the Key Vault's list, get, wrapKey, and unwrapKey access policies from the [managed identity](../../active-directory/managed-identities-azure-resources/how-manage-user-assigned-managed-identities.md) that is used to retrieve a key from KeyVault, the Azure Database for PostgreSQL- Flexible Server will be unable to access the key and will move to *Inaccessible* state. [Add required access policies](../../key-vault/general/assign-access-policy.md) to the identity in KeyVault.
158-
- If you setup overly restrictive Azure KeyVault firewall rules that cause Azure Database for PostgreSQL- Flexible Server inability to communicate with Azure KeyVault to retrieve keys. If you enable [KeyVault firewall](../../key-vault/general/overview-vnet-service-endpoints.md#trusted-services), make sure you check an option to *'Allow Trusted Microsoft Services to bypass this firewall.'*
158+
- If you set up overly restrictive Azure KeyVault firewall rules that cause Azure Database for PostgreSQL- Flexible Server inability to communicate with Azure KeyVault to retrieve keys. If you enable [KeyVault firewall](../../key-vault/general/overview-vnet-service-endpoints.md#trusted-services), make sure you check an option to *'Allow Trusted Microsoft Services to bypass this firewall.'*
159159

160160

161161
> [!NOTE]
@@ -250,7 +250,7 @@ Follow the steps below to change\rotate key or identity after creation of server
250250
```
251251
2. Update server with new key and\or identity
252252
```azurecli-interactive
253-
<!-- az postgres flexible-server update --resource-group <resource_group> --name <server_name> --key $newKeyIdentifier --identity <identity_name> -->
253+
az postgres flexible-server update --resource-group <resource_group> --name <server_name> --key $newKeyIdentifier --identity <identity_name>
254254
```
255255
## Limitations
256256

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
---
2+
title: Create and manage Azure Database for PostgreSQL - Flexible Server with data encrypted by Customer Managed Keys using the Azure CLI
3+
description: Create and manage Azure Database for PostgreSQL - Flexible Server with data encrypted by Customer Managed Keys using the Azure CLI
4+
author: gennadNY
5+
ms.author: gennadyk
6+
ms.service: postgresql
7+
ms.subservice: flexible-server
8+
ms.topic: how-to
9+
ms.date: 12/10/2022
10+
---
11+
# Create and manage Azure Database for PostgreSQL - Flexible Server with data encrypted by Customer Managed Keys (CMK) using the Azure CLI
12+
13+
[!INCLUDE [applies-to-postgresql-flexible-server](../includes/applies-to-postgresql-flexible-server.md)]
14+
15+
> [!NOTE]
16+
> CLI examples below are based on 2.43.0 version of Azure Database for PostgreSQL - Flexible Server CLI libraries, which are in preview and may be subject to changes.
17+
18+
In this article, you learn how to create and manage Azure Database for PostgreSQL - Flexible Server with data encrypted by Customer Managed Keys using the Azure CLI. To learn more about Customer Managed Keys (CMK) feature with Azure Database for PostgreSQL - Flexible Server, see the [overview](concepts-data-encryption.md).
19+
20+
## Setup Customer Managed Key during Server Creation
21+
22+
Prerequisites:
23+
24+
- You must have an Azure subscription and be an administrator on that subscription.
25+
26+
Follow the steps below to enable CMK while creating Postgres Flexible Server using Azure CLI.
27+
28+
1. 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.
29+
30+
```azurecli-interactive
31+
az keyvault create -g <resource_group> -n <vault_name> --location <azure_region> --enable-purge-protection true
32+
```
33+
34+
2. In the created Azure Key Vault, create the key that will be used for the data encryption of the Azure Database for PostgreSQL - Flexible server.
35+
36+
```azurecli-interactive
37+
keyIdentifier=$(az keyvault key create --name <key_name> -p software --vault-name <vault_name> --query key.kid -o tsv)
38+
```
39+
3. Create Managed Identity which will be used to retrieve key from Azure Key Vault
40+
```azurecli-interactive
41+
identityPrincipalId=$(az identity create -g <resource_group> --name <identity_name> --location <azure_region> --query principalId -o tsv)
42+
```
43+
44+
4. Add access policy with key permissions of *wrapKey*,*unwrapKey*, *get*, *list* in Azure KeyVault to the managed identity we created above
45+
```azurecli-interactive
46+
az keyvault set-policy -g <resource_group> -n <vault_name> --object-id $identityPrincipalId --key-permissions wrapKey unwrapKey get list
47+
```
48+
5. Finally, lets create Azure Database for PostgreSQL - Flexible Server with CMK based encryption enabled
49+
```azurecli-interactive
50+
az postgres flexible-server create -g <resource_group> -n <postgres_server_name> --location <azure_region> --key $keyIdentifier --identity <identity_name>
51+
```
52+
## Update Customer Managed Key on the CMK enabled Flexible Server
53+
54+
Prerequisites:
55+
- You must have an Azure subscription and be an administrator on that subscription.
56+
- Key Vault with key in region where Postgres Flex Server will be created. Follow this [tutorial](../../key-vault/general/quick-create-portal.md) to create Key Vault and generate key.
57+
58+
Follow the steps below to change\rotate key or identity after creation of server with data encryption.
59+
1. Change key/identity for data encryption for existing server, first lets get new key identifier
60+
```azurecli-interactive
61+
newKeyIdentifier=$(az keyvault key show --vault-name <vault_name> --name <key_name> --query key.kid -o tsv)
62+
```
63+
2. Update server with new key and\or identity
64+
```azurecli-interactive
65+
az postgres flexible-server update --resource-group <resource_group> --name <server_name> --key $newKeyIdentifier --identity <identity_name>
66+
```
67+
## Next steps
68+
69+
- [Manage an Azure Database for PostgreSQL - Flexible Server by using the Azure CLI](how-to-manage-server-cli.md)

0 commit comments

Comments
 (0)