|
| 1 | +--- |
| 2 | +title: Create and manage Azure Database for PostgreSQL - Flexible Server with data encrypted by Customer Managed Keys using Azure REST API |
| 3 | +description: Create and manage Azure Database for PostgreSQL - Flexible Server with data encrypted by Customer Managed Keys using Azure REST API |
| 4 | +author: gennadNY |
| 5 | +ms.author: gennadyk |
| 6 | +ms.service: postgresql |
| 7 | +ms.subservice: flexible-server |
| 8 | +ms.topic: how-to |
| 9 | +ms.date: 04/13/2023 |
| 10 | +--- |
| 11 | +# Create and manage Azure Database for PostgreSQL - Flexible Server with data encrypted by Customer Managed Keys (CMK) using Azure REST API |
| 12 | + |
| 13 | +[!INCLUDE [applies-to-postgresql-flexible-server](../includes/applies-to-postgresql-flexible-server.md)] |
| 14 | + |
| 15 | +In this article, you learn how to create Azure Database for PostgreSQL with data encrypted by Customer Managed Keys (CMK) by using the Azure REST API. For more information on encryption with Customer Managed Keys (CMK), see [overview](../flexible-server/concepts-data-encryption.md). |
| 16 | + |
| 17 | +## Setup Customer Managed Key during Server Creation |
| 18 | + |
| 19 | +Prerequisites: |
| 20 | +- You must have an Azure subscription and be an administrator on that subscription. |
| 21 | +- Azure managed identity in region where Postgres Flex Server will be created. |
| 22 | +- 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. |
| 23 | + |
| 24 | +You can create a PostgreSQL Flexible Server encrypted with Customer Managed Key by using the [create API](https://learn.microsoft.com/rest/api/postgresql/flexibleserver/servers/create?tabs=HTTP): |
| 25 | +```rest |
| 26 | +PUT https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBForPostgreSql/flexibleServers/{serverName}?api-version=2022-12-01 |
| 27 | +
|
| 28 | +``` |
| 29 | +```json |
| 30 | +{ |
| 31 | + "location": "eastus", |
| 32 | + "identity": { |
| 33 | + "type": "UserAssigned", |
| 34 | + "UserAssignedIdentities": { |
| 35 | + "/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/Microsoft.ManagedIdentity/userAssignedIdentities/{userIdentity}": {} |
| 36 | + } |
| 37 | + }, |
| 38 | + "properties": { |
| 39 | + "CreateMode": "Create", |
| 40 | + "administratorLogin": "admin", |
| 41 | + "AdministratorLoginPassword": "p@ssw0rd", |
| 42 | + "version": "14", |
| 43 | + "dataencryption": { |
| 44 | + "type": "AzureKeyVault", |
| 45 | + "primaryUserAssignedIdentityId": "/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/Microsoft.ManagedIdentity/userAssignedIdentities/{userIdentity}", |
| 46 | + "primaryKeyUri": {keyVaultUri} |
| 47 | + } |
| 48 | + } |
| 49 | +} |
| 50 | +``` |
| 51 | +Key Vault Uri can be copied from key properties **Key Identifier** field in Azure Key Vault Portal UI, as shown in image below: |
| 52 | +:::image type="content" source="./media/how-to-create-server-customer-managed-key-azure-api/keyuri-portal.png" alt-text =" Key properties and URI on Azure Key Vault Portal page." ::: |
| 53 | +You can also programmatically fetch Key Vault Uri using [Azure REST API](https://learn.microsoft.com/en-us/rest/api/keyvault/keyvault/vaults/get?tabs=HTTP) |
| 54 | + |
| 55 | +## Next steps |
| 56 | + |
| 57 | +- [Flexible Server encryption with Customer Managed Key (CMK)](../flexible-server/concepts-data-encryption.md) |
| 58 | +- [Azure Active Directory](../../active-directory-domain-services/overview.md) |
0 commit comments