Skip to content
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 initdb and during maintenance such as pg_upgrade; the hook is encryption_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.json is written atomically with 0600 and 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.json stores 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 local backend uses a password compiled into the binary and is bootstrap-only.
  • Google Cloud KMS needs useToEncrypt, useToDecrypt and cloudkms.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 $PGDATA with the old backend reachable once; -rotate re-wraps the DEK without re-encrypting data.
  • The tool never exports an existing key; offline copies must be generated with openssl rand -hex 32 and 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.

Read Official Source

Related PostgreSQL Reference