Skip to content

This is the multi-page printable view of this section.

Return to the regular view of this page

Key management

Configure keyring files and external key management systems.

This is the Percona pg_tde 2.3.0 manual. For the paired build, backup tools and major upgrades, see PG TDE on Mimus.

PG.CENTER edition · Upstream source

1 - Key management overview

Choose a supported KMS and understand principal keys, provider scope, and deployment requirements.

This is the Percona pg_tde 2.3.0 manual. For the paired build, backup tools and major upgrades, see PG TDE on Mimus.

Editorial correction

This overview retains an older qualification of Vault KMIP. The 2.2.2 release notes explicitly announce Vault Enterprise KMIP support; consult those notes for the version-specific status. See site errata.

In production environments, storing encryption keys locally on the PostgreSQL server can introduce security risks. To enhance security, pg_tde supports integration with external Key Management Systems (KMS) through a Global Key Provider interface.

This section describes how you can configure pg_tde to use the local and external key providers.

To use an external KMS with pg_tde:

  1. Configure a Key Provider
  2. Set the Global Principal Key
Note

While key files may be acceptable for local or testing environments, KMS integration is the recommended approach for production deployments.

Important

When using HashiCorp Vault, KV v2 is the recommended and supported integration method.

The KMIP engine in Vault is not a validated configuration for pg_tde and is not recommended for production deployments.

Warning

Do not rotate encryption keys while a backup is running. This may result in an inconsistent backup and restore failure. This applies to all backup tools.

Schedule key rotations outside backup windows. After rotating keys, take a new full backup.

For more details, see Limitations of pg_tde.

pg_tde has been tested with the following key providers:

KMS ProviderDescriptionDocumentation
KMIPStandard Key Management Interoperability Protocol.Configure KMIP →
VaultHashiCorp Vault integration (KV v2 API).Configure Vault →
FortanixFortanix DSM key management.Configure Fortanix →
ThalesThales CipherTrust Manager and DSM.Configure Thales →
OpenBaoCommunity fork of Vault, supporting KV v2.Configure OpenBao →
AkeylessA cloud-based secrets management platform for securely storing and accessing credentials and encryption keys.Configure Akeyless →
Keyring file (not recommended)Local key file for dev/test only.Configure keyring file →

PG.CENTER edition · Upstream source

2 - Keyring file configuration

Configure a plaintext file keyring for local development and testing.

This is the Percona pg_tde 2.3.0 manual. For the paired build, backup tools and major upgrades, see PG TDE on Mimus.

Editorial correction

The inspection example now uses the table it creates and the current database key-info function. See site errata.

This setup is intended for development and stores the keys, unencrypted, in a data file you specify.

Note

While keyring files may be acceptable for local or testing environments, proper KMS providers are the recommended approach for production deployments.

You can configure key providers either at the database level (for development and testing) or at the global level (for production).

The steps below provide an example on how to add a database-scoped key provider:

  1. Create a database-scoped file key provider (file-keyring in this example) in the /tmp/pg_tde_test_local_keyring.per file:

    SELECT pg_tde_add_database_key_provider_file(
        'file-keyring',
        '/tmp/pg_tde_test_local_keyring.per'
    );
  2. Create a key (my_default_key in this example) inside the newly created file-keyring provider:

    SELECT pg_tde_create_key_using_database_key_provider(
        'my_default_key',
        'file-keyring'
    );
  3. Set the key (my_default_key) from the key provider (file-keyring):

    SELECT pg_tde_set_key_using_database_key_provider(
        'my_default_key',
        'file-keyring'
    );
    Tip

    You can check the current database key information (such as the date and time of creation). Run:

    SELECT pg_tde_key_info();
  4. Now, create a table using tde_heap:

    CREATE TABLE customer_table (a INT) USING tde_heap;

    The newly created table is encrypted with the database key you have set (my_default_key).

    Tip

    To check if your created table is encrypted with tde_heap, run:

    \d+ customer_table

    If Access method: tde_heap, then your table is encrypted.

    Example output

    postgres=# \d+ customer_table Table “public.customer_table” Column | Type | Collation | Nullable | Default | Storage | Compression | Stats target | Description ——–+———+———–+———-+———+———+————-+————–+————- a | integer | | | | plain | | | Access method: tde_heap

Further reading

Next, for production deployments, configure a global principal key using a proper KMS provider.

Alternatively, you can skip directly to validating encryption with pg_tde or configuring WAL encryption.

You can also review the available pg_tde functions in Functions.

PG.CENTER edition · Upstream source

3 - Vault configuration

Connect pg_tde to a HashiCorp Vault KV v2 secrets engine.

This is the Percona pg_tde 2.3.0 manual. For the paired build, backup tools and major upgrades, see PG TDE on Mimus.

You can configure pg_tde to use HashiCorp Vault as a global key provider for managing encryption keys securely. Both the open source and enterprise editions are supported.

Configure Vault with pg_tde in Docker

This example setup describes how to run HashiCorp Vault and Percona PostgreSQL with pg_tde side by side using Docker, configure Vault policies, and connect it as a global key provider for TDE encryption.

Note

For production deployments, follow your organization’s security standards.

1. Create the docker-compose.yaml file

The following docker-compose.yaml file is an example on how to run both Vault and PostgreSQL with a shared secrets volume:

docker-compose.yaml (example file)
version: '3.8'

services:
vault:
    image: hashicorp/vault:latest
    container_name: vault
    ports:
    - "8200:8200"
    volumes:
    - ./vault-config.hcl:/vault/config/vault-config.hcl
    - ./vault-data:/vault/data
    - shared-secrets:/vault/secrets
    environment:
    VAULT_ADDR: http://127.0.0.1:8200
    command: vault server -config=/vault/config/vault-config.hcl

pg:
    image: percona/percona-distribution-postgresql:17.5-2
    container_name: pg
    ports:
    - "5432:5432"
    environment:
    POSTGRES_PASSWORD: secret
    ENABLE_PG_TDE: "1"
    volumes:
    - ./pgdata:/var/lib/postgresql/data
    - shared-secrets:/etc/postgresql/secrets:ro
    depends_on:
    - vault

volumes:
shared-secrets:

2. Enable the KV v2 secrets engine

In the Vault container, enable a KV v2 storage engine for pg_tde:

vault secrets enable -path=tde -version=2 kv

This creates a tde/ mount for storing encrypted keys.

Vault namespaces (Enterprise) and mounts

If you are using Vault Enterprise namespaces, you don’t need a separate namespace parameter when configuring pg_tde.

You can include the namespace directly in the mount path. For example:

SELECT pg_tde_add_global_key_provider_vault_v2(
    'vault-ns',
    'https://127.0.0.1:8200',
    'pgns/tde/data/global-key',
    '/etc/postgresql/secrets/vault_token.txt',
    NULL
);

This is equivalent to configuring a namespace separately and works with both:

  • Vault OSS
  • Vault Enterprise (with namespaces)

3. Create a Vault policy for pg_tde

Define a Vault policy that grants pg_tde access to read, write, and list keys.

vault policy write tde-policy - <<EOF
path "tde/data/*" {
  capabilities = ["read", "create", "update", "list"]
}

path "tde/metadata/*" {
  capabilities = ["read", "list"]
}
EOF

This allows pg_tde to:

  • read, create, and update encryption keys
  • list and access metadata for the tde/ path
Tip

If you encounter the following error:

ERROR: failed to get mount info for "http://vault:8200" at mountpoint ...

Ensure your Vault policy includes the following path:

path "sys/mounts/*" {
  capabilities = ["read"]
}

This allows pg_tde to read the mount metadata from Vault.

4. Create an Authentication Method and Token

Enable the AppRole authentication method:

vault auth enable approle
vault write auth/approle/role/tde-role policies="tde-policy"

Generate a token associated with the tde-policy:

vault token create -policy="tde-policy"

Example output:

Key                  Value
token                hvs.{secret_code}
token_policies       ["default" "tde-policy"]

5. Share the token with PostgreSQL

Copy the generated token into the shared secrets directory (shared secrets volume) so PostgreSQL can use it:

echo "hvs.secret_code" > /vault/secrets/vault_token.txt
Tip

You can access this file in PostgreSQL at /etc/postgresql/secrets/vault_token.txt.

6. Register Vault as a global key provider in PostgreSQL

In the PostgreSQL container, connect pg_tde to Vault using:

SELECT pg_tde_add_global_key_provider_vault_v2(
  'vault-provider',
  'http://vault:8200',
  'tde/data/global-key',
  '/etc/postgresql/secrets/vault_token.txt',
  NULL
);

7. Create and set the global master key

Create the global master key:

SELECT pg_tde_create_key_using_global_key_provider(
  'global-master-key',
  'vault-provider'
);

Then set it:

SELECT pg_tde_set_default_key_using_global_key_provider(
  'global-master-key',
  'vault-provider'
);

8. Test encryption with a sample table

Create a sample table:

CREATE TABLE secure_data (
  id INTEGER GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
  name TEXT,
  amount NUMERIC(10,2),
  created_at DATE
) USING tde_heap;

Then insert data into the table:

INSERT INTO secure_data (name, amount, created_at) VALUES
('Alice', 1234.56, '2025-08-01'),
('Bob', 7890.12, '2025-08-10'),
('Charlie', 345.67, '2025-08-19');

Query the table and confirm that the encryption is functioning:

select * from secure_data;
 id |  name   | amount  | created_at
----+---------+---------+------------
  1 | Alice   | 1234.56 | 2025-08-01
  2 | Bob     | 7890.12 | 2025-08-10
  3 | Charlie |  345.67 | 2025-08-19
(3 rows)

Example global key provider usage

SELECT pg_tde_add_global_key_provider_vault_v2(
    'provider-name',
    'url',
    'mount',
    'secret_token_path',
    'ca_path'
);

Parameter descriptions

  • provider-name is the name to identify this key provider
  • secret_token_path is a path to the file that contains an access token with read and write access to the above mount point
  • url is the URL of the Vault server
  • mount is the mount point where the keyring should store the keys
  • [optional] ca_path is the path of the CA file used for SSL verification

The following example is for testing purposes only. Use secure tokens and proper SSL validation in production environments:

SELECT pg_tde_add_global_key_provider_vault_v2(
    'my-vault',
    'https://vault.vault.svc.cluster.local:8200',
    'secret/data',
    '/path/to/token_file',
    '/path/to/ca_cert.pem'
);

For more information on related functions, see Function Reference.

Required permissions

The PostgreSQL instance requires the following Vault API capabilities to manage and read encryption keys:

  • sys/mounts/<mount>/* - read permissions
  • <mount>/data/* - create, read permissions
  • <mount>/metadata/* - list permissions
Note

For more information on Vault permissions, see the following documentation.

Next steps

Global Principal Key Configuration

PG.CENTER edition · Upstream source

4 - Using OpenBao as a key provider

Configure an OpenBao secrets engine, token, and pg_tde key provider.

This is the Percona pg_tde 2.3.0 manual. For the paired build, backup tools and major upgrades, see PG TDE on Mimus.

You can configure pg_tde to use OpenBao as a global key provider for managing encryption keys securely.

Note

This guide assumes that your OpenBao server is already set up and accessible. OpenBao configuration is outside the scope of this document, see OpenBao’s official documentation for more information.

Example usage

To register an OpenBao server as a global key provider:

SELECT pg_tde_add_global_key_provider_vault_v2(
    'provider-name',
    'url',
    'mount',
    'secret_token_path',
    'ca_path',
    'namespace'
);

Parameter descriptions

  • provider-name is the name to identify this key provider
  • secret_token_path is a path to the file that contains an access token with read and write access to the above mount point
  • url is the URL of the OpenBao server
  • mount is the mount point where the keyring should store the keys
  • [optional] ca_path is the path of the CA file used for SSL verification
  • [optional] namespace is the namespace within the OpenBao server. Read more about the namespace support in OpenBao` (NOTE: You can use a namespace without ca_path. In this case, specify NULL as the ca_path value)

The following example is for testing purposes only. Use secure tokens and proper SSL validation in production environments:

SELECT pg_tde_add_global_key_provider_vault_v2(
    'my-openbao-provider',
    'https://openbao.example.com:8200',
    'secret/data',
    '/path/to/token_file',
    '/path/to/ca_cert.pem'
);

For more information on related functions, see the link below:

Percona pg_tde Function Reference

Next steps

Global Principal Key Configuration

PG.CENTER edition · Upstream source

5 - KMIP configuration

Configure a KMIP endpoint, client credentials, and key provider.

This is the Percona pg_tde 2.3.0 manual. For the paired build, backup tools and major upgrades, see PG TDE on Mimus.

Editorial correction

This overview retains an older qualification of Vault KMIP. The 2.2.2 release notes explicitly announce Vault Enterprise KMIP support; consult those notes for the version-specific status. See site errata.

To use a Key Management Interoperability Protocol (KMIP) server with pg_tde, you must configure it as a global key provider. This setup enables pg_tde to securely fetch and manage encryption keys from a centralized key management appliance.

Important

When using HashiCorp Vault as a KMIP server, this configuration is not a validated deployment model for pg_tde and is not recommended for production use.

For Vault-based key management, use the KV v2 integration instead.

Note

You need the root certificate of the KMIP server and a client key/certificate pair with permissions to create and read keys on the server.

For testing purposes, you can use a Eviden KMS server, which enables easy certificate generation and basic KMIP behavior. If you’re using a production-grade KMIP server, ensure you obtain valid, trusted certificates from the key management appliance.

Example usage

SELECT pg_tde_add_global_key_provider_kmip(
    'provider-name',
    'kmip-IP', 
    `port`,
    '/path_to/server_certificate.pem', 
    '/path_to/client_cert.pem',
    '/path_to/client_key.pem'
);

Parameter descriptions

  • provider-name is the name of the provider. You can specify any name, it’s for you to identify the provider
  • kmip-IP is the IP address of a domain name of the KMIP server
  • port is the port to communicate with the KMIP server. Typically used port is 5696
  • server-certificate is the path to the certificate file for the KMIP server
  • client_cert is the path to the client certificate.
  • client_key is the path to the client key.

The following example is for testing purposes only.

SELECT pg_tde_add_global_key_provider_kmip(
    'kmip','127.0.0.1', 
    5696, 
    '/tmp/server_certificate.pem', 
    '/tmp/client_cert_jane_doe.pem',
    '/tmp/client_key_jane_doe.pem'
);

For more information on related functions, see the link below:

Percona pg_tde Function Reference

Next steps

Global Principal Key Configuration

PG.CENTER edition · Upstream source

6 - Thales KMIP server configuration

Connect pg_tde to Thales CipherTrust Manager through KMIP.

This is the Percona pg_tde 2.3.0 manual. For the paired build, backup tools and major upgrades, see PG TDE on Mimus.

pg_tde is compatible with the Thales CipherTrust Manager via the KMIP protocol. For a full setup guide, see the Thales documentation.

For more information on adding or modifying the provider, see the Adding or modifying KMIP providers topic.

PG.CENTER edition · Upstream source

7 - Fortanix KMIP server configuration

Prepare a Fortanix DSM security object, certificate, and KMIP endpoint.

This is the Percona pg_tde 2.3.0 manual. For the paired build, backup tools and major upgrades, see PG TDE on Mimus.

pg_tde is compatible with Fortanix Data Security Manager (DSM) via the KMIP protocol. For a full setup guide, see the Fortanix KMIP documentation here.

For more information on adding or modifying the provider, see the Adding or modifying KMIP providers topic.

PG.CENTER edition · Upstream source

8 - Akeyless KMIP server configuration

Create Akeyless KMIP credentials and connect a pg_tde key provider.

This is the Percona pg_tde 2.3.0 manual. For the paired build, backup tools and major upgrades, see PG TDE on Mimus.

pg_tde is compatible with the Akeyless CipherTrust Manager via the KMIP protocol. For a full setup guide, see the Akeyless documentation .

For more information on adding or modifying the provider, see the Add or modify KMIP providers topic.

Next steps

Global Principal Key Configuration

PG.CENTER edition · Upstream source

9 - Default principal key configuration

Assign a default principal key to databases without their own configured key.

This is the Percona pg_tde 2.3.0 manual. For the paired build, backup tools and major upgrades, see PG TDE on Mimus.

You can configure a default principal key for the server using a global key provider. This key is used by all databases that do not have their own encryption keys configured.

Configuring the default principal key is a multi-step process that uses the following functions:

Add a global key provider

To add a global key provider, see the Key provider management topic.

Create a default principal key

Note

The sample output below is for demonstration purposes only. Be sure to replace the key name and provider with your actual values.

To create a global principal key, run:

SELECT pg_tde_create_key_using_global_key_provider(
    'key-name',
    'global_vault_provider'
);
Sample output
    postgres=# SELECT pg_tde_create_key_using_global_key_provider(
        'keytest1',
        'file-keyring'
    );
    pg_tde_create_key_using_global_key_provider
    ---------------------------------------------

    (1 row)

Set a default principal key

To set a default principal key, run:

SELECT pg_tde_set_default_key_using_global_key_provider(
    'key-name',
    'global_vault_provider'
);
Sample output
    postgres=# SELECT pg_tde_set_default_key_using_global_key_provider(
        'keytest1',
        'file-keyring'
    );
    pg_tde_set_default_key_using_global_key_provider 
    --------------------------------------------------

    (1 row)

Parameter description

  • key-name is the name under which the principal key is stored in the provider.
  • global_vault_provider is the name of the global key provider you previously configured.
Note

If no error is reported, the action completed successfully.

How key generation works

The key material (actual cryptographic key) is auto-generated by pg_tde and stored securely by the configured provider.

Note

This process sets the default principal key for the entire server. Any database without a key explicitly configured will fall back to this key.

Next steps

To confirm that encryption is working as expected, follow the validation steps:

Validate Encryption with pg_tde

PG.CENTER edition · Upstream source