CYBERTEC PostgreSQL Blog· Christoph Berg·
CYBERTEC details pgee_key_manager: key management for PostgreSQL TDE across multiple vaults
One data key, many vaults: key management for PostgreSQL TDE
Key Takeaway
CYBERTEC describes pgee_key_manager, a helper in its PostgreSQL Enterprise Edition that supplies the TDE data encryption key to PostgreSQL via encryption_key_command at start-up, initdb and pg_upgrade.
Why It Matters
The tool fails closed with a non-zero exit when the key service is unreachable, so PostgreSQL refuses to start; backups must cover both tdekey.json and the referenced key-service state or the cluster cannot start.
Technical Breakdown · Distilled from the original source
Key delivery
- TDE needs the key at start-up, on
initdband during maintenance such aspg_upgrade; the hook isencryption_key_command, whose stdout is the key. - Three production rules: the key is printed only when launched by PostgreSQL or its utilities, never from an interactive shell; the tool fails closed (non-zero exit, empty stdout) if the key service is unreachable, slow or unexpected;
tdekey.jsonis written atomically with0600and holds only ciphertext and version numbers.
Two-level hierarchy and backends
- The DEK is a 128/192/256-bit AES key encrypting database files; a wrapping secret or key protects it, and
tdekey.jsonstores only the wrapped DEK. - Password stores (Vault/OpenBao, Azure Key Vault, CyberArk Conjur, built-in bootstrap) keep a random password and record its version; wrapping stores (AWS KMS, Google Cloud KMS, KMIP) never release the key.
- The built-in
localbackend uses a password compiled into the binary and is bootstrap-only. - Google Cloud KMS needs
useToEncrypt,useToDecryptandcloudkms.cryptoKeys.get; the predefined Encrypter/Decrypter role omits the last, breaking decryption. - KMIP requires server-side AES-GCM Encrypt/Decrypt; Vault Enterprise KMIP secrets engine and Infisical KMS only do lifecycle operations.
Operations
- Vault KV v2 retention and Conjur's 20-version limit can purge the recorded version and make the DEK unrecoverable; only the tool should write.
- Switching stores is one command in
$PGDATAwith the old backend reachable once;-rotatere-wraps the DEK without re-encrypting data. - The tool never exports an existing key; offline copies must be generated with
openssl rand -hex 32and imported via-import.
Source: CYBERTEC PostgreSQL Blog· cybertec-postgresql.com
PG Radar summarizes verified changes and impact. Read the original post for full technical details and code samples.