Edit

Configure data encryption in Azure Database for PostgreSQL flexible server

This article provides step-by-step instructions to configure data encryption for an Azure Database for PostgreSQL flexible server.

Important

You can decide to use a system managed key or a customer managed key for data encryption only at server creation. After you make that decision and create the server, you can't switch between the two options.

In this article, you learn how to create a new server and configure its data encryption options. For existing servers that use customer managed encryption key for data encryption, you learn:

  • How to select a different user assigned managed identity for the service to access the encryption key.
  • How to specify a different encryption key or how to rotate the encryption key currently used for data encryption.

To learn about data encryption in the context of Azure Database for PostgreSQL, see data encryption.

Configure data encryption with system managed key during server provisioning

Use the Azure portal:

  1. During provisioning of a new Azure Database for PostgreSQL flexible server, configure data encryption in the Security tab. For Data encryption key, select the Service-managed key option.

    Screenshot that shows how to select the system managed encryption key during server provisioning.

  2. If you enable geo-redundant backup storage to be provisioned together with the server, the aspect of the Security tab changes slightly because the server uses two separate encryption keys. One key is for the primary region in which you're deploying your server, and one key is for the paired region to which the server backups are asynchronously replicated.

    Screenshot that shows how to select the system managed encryption key during server provisioning, when the server is enabled for geo-redundant backup storage.

Configure data encryption with customer managed key during server provisioning

Use the Azure portal:

  1. Create a user assigned managed identity, if you don't have one yet. If your server has geo-redundant backups enabled, you need to create two different identities. Each of those identities accesses each of the two data encryption keys.

Note

Although it's not required, to maintain regional resiliency, create the user managed identity in the same region as your server. If your server has geo-backup redundancy enabled, create the second user managed identity in the paired region of the server.

  1. Create an Azure Key Vault or create a Managed HSM, if you don't have a key store created yet. Make sure that you meet the requirements. Also, follow the recommendations before you configure the key store, and before you create the key and assign the required permissions to the user assigned managed identity. If your server has geo-redundant backups enabled, you need to create a second key store. That second key store keeps the data encryption key that encrypts your backups copied to the paired region of the server.

Note

You must deploy the key store that keeps the data encryption key in the same region as your server. If your server has geo-backup redundancy enabled, you must create the key store that keeps the data encryption key for geo-redundant backups in the paired region of the server.

  1. Create a key in your key store. If your server has geo-redundant backups enabled, you need one key on each of the key stores. By using one of these keys, you encrypt all your server's data (including all system and user databases, temporary files, server logs, write-ahead log segments, and backups). By using the second key, you encrypt the copies of the backups that are asynchronously copied over the paired region of your server.

  2. During provisioning of a new Azure Database for PostgreSQL flexible server, configure data encryption in the Security tab. For Data encryption key, select the Customer-managed key radio button.

    Screenshot that shows how to select the customer managed encryption key during server provisioning.

  3. If you enable geo-redundant backup storage to be provisioned together with the server, the aspect of the Security tab changes slightly because the server uses two separate encryption keys. One key is for the primary region in which you're deploying your server, and one key is for the paired region to which the server backups are asynchronously replicated.

    Screenshot that shows how to select the customer managed encryption key during server provisioning, when the server is enabled for geo-redundant backup storage.

  4. In User assigned managed identity, select Change identity.

    Screenshot that shows how to select the user assigned managed identity to access the data encryption key for the data of the server location.

  5. From the list of user assigned managed identities, select the one you want your server to use to access the data encryption key stored in an Azure Key Vault.

    Screenshot that shows how to select the user assigned managed identity with which the server accesses the data encryption key.

  6. Select Add.

    Screenshot that shows the location of the Add button to assign the identity with which the server accesses the data encryption key.

  7. Select Use automatic key version update, if you prefer to let the service automatically update the reference to the most current version of the chosen key, whenever the current version is rotated manually or automatically. To understand the benefits of using automatic key version updates, see automatic key version update.

    Screenshot that shows how to enable automatic key version updates.

  8. Select Select a key.

    Screenshot that shows how to select a data encryption key.

  9. Subscription is automatically populated with the name of the subscription on which your server is about to be created. The key store that keeps the data encryption key must exist in the same subscription as the server.

    Screenshot that shows how to select the subscription in which the key store should exist.

  10. In Key store type, select the radio button corresponding to the type of key store in which you plan to store the data encryption key. In this example, choose Key vault, but the experience is similar if you choose Managed HSM.

    Screenshot that shows how to select the type of store that keeps the data encryption key.

  11. Expand Key vault (or Managed HSM, if you selected that storage type), and select the instance where the data encryption key exists.

    Screenshot that shows how to select the key store that keeps the data encryption key.

    Note

    When you expand the dropdown box, it shows No available items. It takes a few seconds until it lists all the instances of key vault which are deployed in the same region as the server.

  12. Expand Key, and select the name of the key that you want to use for data encryption.

    Screenshot that shows how to select the data encryption key.

  13. If you didn't select Use automatic key version update, you must also select a specific version of the key. To do that, expand Version, and select the identifier of the version of the key that you want to use for data encryption.

    Screenshot that shows how to select the version to use of the data encryption key.

  14. Select Select.

    Screenshot that shows how to select the chose key.

  15. Configure all other settings of the new server and select Review + create.

    Screenshot that shows how to complete creation of server.

Configure data encryption with customer managed key on existing servers

You decide whether to use a system managed key or a customer managed key for data encryption at server creation. After you make that decision and create the server, you can't switch between the two options. The only alternative, if you want to change from one to the other, requires restoring any of the backups available of server onto a new server. While configuring the restore, you can change the data encryption configuration of the new server.

For existing servers that you deployed with data encryption by using a customer managed key, you can make several configuration changes. You can change the references to the keys used for encryption, and references to the user assigned managed identities that the service uses to access the keys kept in the key stores.

You must update references that your Azure Database for PostgreSQL flexible server has to a key:

  • When the key stored in the key store is rotated, either manually or automatically, and your Azure Database for PostgreSQL flexible server is pointing to a specific version of the key. If you're pointing to a key, but not to a specific version of the key (that's when you have Use automatic key version update enabled), the service automatically references the most current version of the key whenever the key is manually or automatically rotated.
  • When you want to use the same or a different key stored in a different key store.

You must update the user assigned managed identities that your Azure Database for PostgreSQL flexible server uses to access the encryption keys whenever you want to use a different identity.

Use the Azure portal:

  1. Select your Azure Database for PostgreSQL flexible server.

  2. In the resource menu, under the Security section, select Data encryption.

    Screenshot that shows how to get to the Data encryption for an existing server.

  3. To change the user assigned managed identity that the server uses to access the key store, expand the User assigned managed identity dropdown, and select any of the available identities.

    Screenshot that shows how to select one of the user assigned managed identities associated to the server.

    Note

    The combo box shows only the identities that your Azure Database for PostgreSQL flexible server assigned. Although it's not required, to maintain regional resiliency, select user managed identities in the same region as your server. If your server has geo-backup redundancy enabled, the second user managed identity, used to access the data encryption key for geo-redundant backups, should exist in the paired region of the server.

  4. If the user assigned managed identity that you want to use to access the data encryption key isn't assigned to your Azure Database for PostgreSQL flexible server, and it doesn't exist as an Azure resource with its corresponding object in Microsoft Entra ID, create it by selecting Create.

    Screenshot that shows how to create a new user assigned managed identities in Azure and Microsoft Entra ID, automatically assign it to your Azure Database for PostgreSQL flexible server, and use it to access the data encryption key.

  5. In the Create User Assigned Managed Identity panel, enter the details of the user assigned managed identity that you want to create, and automatically assign it to your Azure Database for PostgreSQL flexible server to access the data encryption key.

    Screenshot that shows how to provide the details for the new user assigned managed identity.

  6. If the user assigned managed identity that you want to use to access the data encryption key isn't assigned to your Azure Database for PostgreSQL flexible server, but it exists as an Azure resource with its corresponding object in Microsoft Entra ID, assign it by selecting Select.

    Screenshot that shows how to select an existing user assigned managed identity in Azure and Microsoft Entra ID, automatically assign it to your Azure Database for PostgreSQL flexible server, and use it to access the data encryption key.

  7. From the list of user assigned managed identities, select the one you want your server to use to access the data encryption key stored in an Azure Key Vault.

    Screenshot that shows how to select an existing user assigned managed identity to assign it to your Azure Database for PostgreSQL flexible server, and use it to access the data encryption key.

  8. Select Add.

    Screenshot that shows how to add the selected user assigned managed identity.

  9. Select Use automatic key version update if you want the service to automatically update the reference to the most current version of the chosen key whenever the current version is rotated manually or automatically. To understand the benefits of using automatic key version updates, see [automatic key version update](../security/security-data-encryption.md##CMK key version updates).

    Screenshot that shows how to enable automatic key version updates.

  10. If you rotate the key and don't enable Use automatic key version update. Or if you want to use a different key, update your Azure Database for PostgreSQL flexible server so that it points to the new key version or new key. To do that, copy the resource identifier of the key, and paste it in the Key identifier box.

    Screenshot that shows where to paste the resource identifier of the new key or new key version that the server must use for data encryption.

  11. If the user accessing Azure portal has permissions to access the key stored in the key store, you can use an alternative approach to choose the new key or new key version. To do that, in Key selection method, select the Select a key radio button.

    Screenshot that shows how to enable the user friendlier method to choose the data encryption key to use for data encryption.

  12. Select Select key.

    Screenshot that shows how to select a data encryption key.

  13. Subscription is automatically populated with the name of the subscription on which your server is about to be created. The key store that keeps the data encryption key must exist in the same subscription as the server.

    Screenshot that shows how to select the subscription in which the key store should exist.

  14. In Key store type, select the radio button corresponding to the type of key store in which you plan to store the data encryption key. In this example, choose Key vault, but the experience is similar if you choose Managed HSM.

    Screenshot that shows how to select the type of store that keeps the data encryption key.

  15. Expand Key vault (or Managed HSM, if you selected that storage type), and select the instance where the data encryption key exists.

    Screenshot that shows how to select the key store that keeps the data encryption key.

    Note

    When you expand the dropdown box, it shows No available items. It takes a few seconds until it lists all the instances of key vault which are deployed in the same region as the server.

  16. Expand Key, and select the name of the key that you want to use for data encryption.

    Screenshot that shows how to select the data encryption key.

  17. If you didn't select Use automatic key version update, you must also select a specific version of the key. To do that, expand Version, and select the identifier of the version of the key that you want to use for data encryption.

    Screenshot that shows how to select the version to use of the data encryption key.

  18. Select Select.

    Screenshot that shows how to select the chose key.

  19. When you're satisfied with the changes, select Save.

    Screenshot that shows how to save the changes made to data encryption configuration.