Load the `pg_tde` at the start time. The extension requires additional shared memory; therefore, add the `pg_tde` value for the `shared_preload_libraries` parameter and restart the `postgresql` instance.
1. Use the [ALTER SYSTEM](https://www.postgresql.org/docs/current/sql-altersystem.html) command from `psql` terminal to modify the `shared_preload_libraries` parameter.
1. Use the [ALTER SYSTEM](https://www.postgresql.org/docs/current/sql-altersystem.html) command from `psql` terminal to modify the `shared_preload_libraries` parameter. This requires superuser privileges.
```
ALTER SYSTEM SET shared_preload_libraries = 'pg_tde';
@ -14,14 +14,14 @@ Load the `pg_tde` at the start time. The extension requires additional shared me
* On Debian and Ubuntu:
```{.bash data-prompt="$"}
$ sudo systemctl restart postgresql.service
```sh
sudo systemctl restart postgresql.service
```
* On RHEL and derivatives
```{.bash data-prompt="$"}
$ sudo systemctl restart postgresql-17
```sh
sudo systemctl restart postgresql-17
```
3. Create the extension using the [CREATE EXTENSION](https://www.postgresql.org/docs/current/sql-createextension.html) command. You must have the privileges of a superuser or a database owner to use this command. Connect to `psql` as a superuser for a database and run the following command:
@ -36,7 +36,7 @@ Load the `pg_tde` at the start time. The extension requires additional shared me
You can have the `pg_tde` extension automatically enabled for every newly created database. Modify the template `template1` database as follows:
```
```sh
psql -d template1 -c 'CREATE EXTENSION pg_tde;'
```
@ -44,65 +44,95 @@ Load the `pg_tde` at the start time. The extension requires additional shared me
1. Set up a key provider for the database where you have enabled the extension.
=== "With HashiCorp Vault"
=== "With KMIP server"
Make sure you have obtained the root certificate for the KMIP server and the keypair for the client. The client key needs permissions to create / read keys on the server. Find the [configuration guidelines for the HashiCorp Vault Enterprise KMIP Secrets Engine](https://developer.hashicorp.com/vault/tutorials/enterprise/kmip-engine).
For testing purposes, you can use the PyKMIP server which enables you to set up required certificates. To use a real KMIP server, make sure to obtain the valid certificates issued by the key management appliance.
<iinfo>:material-information: Info:</i> The key provider configuration is stored in the database catalog in an unencrypted table. See [how to use external reference to parameters](external-parameters.md) to add an extra security layer to your setup.
<iinfo>:material-information: Info:</i> The key provider configuration is stored in the database catalog in an unencrypted table. See [how to use external reference to parameters](external-parameters.md) to add an extra security layer to your setup.
## WAL encryption configuration (tech preview)
After you [enabled `pg_tde`](#enable-extension) and started the Percona Server for PostgreSQL, a principal key and internal keys for WAL encryption are created. They are stored in the data directory so that after WAL encryption is enabled, any process that requires access to WAL (a recovery or a checkpointer) can use them for decryption.
## WAL encryption configuration
Now you need to instruct `pg_tde ` to encrypt WAL files by configuring WAL encryption. Here's how to do it:
After you [enabled `pg_tde`](#enable-extension) and started the Percona Server for PostgreSQL, a principal key and a keyring for WAL are created. Now you need to instruct `pg_tde ` to encrypt WAL files by configuring WAL encryption.
### Enable WAL level encryption
Here's how to do it:
1. Use the `ALTER SYSTEM SET` command. You need the privileges of the superuser to run this command:
1. Enable WAL level encryption using the `ALTER SYSTEM SET` command. You need the privileges of the superuser to run this command:
```
```sql
ALTER SYSTEM set pg_tde.wal_encrypt = on;
```
@ -110,29 +140,23 @@ Now you need to instruct `pg_tde ` to encrypt WAL files by configuring WAL encry
* On Debian and Ubuntu:
```{.bash data-prompt="$"}
$ sudo systemctl restart postgresql.service
```sh
sudo systemctl restart postgresql.service
```
* On RHEL and derivatives
```{.bash data-prompt="$"}
$ sudo systemctl restart postgresql-17
```sh
sudo systemctl restart postgresql-17
```
On the server start
3. We highly recommend you to create your own keyring and rotate the principal key. This is because the default principal key is created from the local keyfile and is stored unencrypted.
### Rotate the principal key
We highly recommend you to create your own keyring and rotate the principal key. This is because the default principal key is created from the local keyfile and is stored unencrypted.
Rotating the principal key means re-encrypting internal keys used for WAL encryption with the new principal key. This process doesn't stop the database operation meaning that reads and writes can take place as usual during key rotation.
@ -6,10 +6,13 @@ Transparent Data Encryption is a technology to protect data at rest. The encrypt
To encrypt the data, two types of keys are used:
* Table encryption keys (TEK) to encrypt user data. These keys are stored internally, near the data that they encrypt.
* The principal key to encrypt table keys. It is kept separately from the table keys and is managed externally.
* Internal encryption keys to encrypt user data. They are stored internally, near the data that they encrypt.
* The principal key to encrypt database keys. It is kept separately from the database keys and is managed externally in the key management store.
`pg_tde` is integrated with HashiCorp Vault server to store and manage principal keys. Only the back end KV Secrets Engine - Version 2 (API) is supported.
You have the following options to store and manage principal keys externally:
* Use the HashiCorp Vault server. Only the back end KV Secrets Engine - Version 2 (API) is supported.
* Use the KMIP-compatible server. `pg_tde` has been tested with the [PyKMIP](https://pykmip.readthedocs.io/en/latest/server.html) server and [the HashiCorp Vault Enterprise KMIP Secrets Engine](https://www.vaultproject.io/docs/secrets/kmip).
The encryption process is the following:
@ -17,7 +20,7 @@ The encryption process is the following:
When a user creates an encrypted table using `pg_tde`, a new random key is generated for that table using the AES128 (AES-ECB) cipher algorithm. This key is used to encrypt all data the user inserts in that table. Eventually the encrypted data gets stored in the underlying storage.
The table itself is encrypted using the principal key. The principal key is stored externally in the Vault key management store.
The table itself is encrypted using the principal key. The principal key is stored externally in the key management store.
Similarly when the user queries the encrypted table, the principal key is retrieved from the key store to decrypt the table. Then the same unique internal key for that table is used to decrypt the data, and unencrypted data gets returned to the user. So, effectively, every TDE table has a unique key, and each table key is encrypted using the principal key.