Vault configuration
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.
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)
2. Enable the KV v2 secrets engine
In the Vault container, enable a KV v2 storage engine for pg_tde:
This creates a tde/ mount for storing encrypted keys.
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:
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.
This allows pg_tde to:
- read, create, and update encryption keys
- list and access metadata for the
tde/path
If you encounter the following error:
Ensure your Vault policy includes the following path:
This allows pg_tde to read the mount metadata from Vault.
4. Create an Authentication Method and Token
Enable the AppRole authentication method:
Generate a token associated with the tde-policy:
Example output:
5. Share the token with PostgreSQL
Copy the generated token into the shared secrets directory (shared secrets volume) so PostgreSQL can use it:
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:
7. Create and set the global master key
Create the global master key:
Then set it:
8. Test encryption with a sample table
Create a sample table:
Then insert data into the table:
Query the table and confirm that the encryption is functioning:
Example global key provider usage
Parameter descriptions
provider-nameis the name to identify this key providersecret_token_pathis a path to the file that contains an access token with read and write access to the above mount pointurlis the URL of the Vault servermountis the mount point where the keyring should store the keys- [optional]
ca_pathis 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:
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
For more information on Vault permissions, see the following documentation.