How does TDE encrypt data?

TDE prevents unauthorized viewing of data in operating system files on the database server and on backup storage. Data becomes unintelligible for unauthorized users if it's stolen or misplaced.

Data encryption and decryption are managed by the database and don't require application changes or updated client drivers.

Enterprise Postgres (Oracle Compatible), formerly EDB Postgres Advanced Server, and Enterprise Postgres, formerly EDB Postgres Extended Server, provide hooks to key management that's external to the database. These hooks allow for simple passphrase encrypt/decrypt or integration with enterprise key management solutions.

Protecting the data encryption key

When you initialize a database cluster with data encryption enabled, TDE generates a data encryption key and stores it in a file on disk. Because that file is in plaintext by default, TDE wraps (encrypts) the key using a mechanism you choose, so the key itself is unreadable without an unwrap (decrypt) step. You choose this mechanism when you create the cluster, so decide on a mechanism before you enable TDE. Your options are:

  • Passphrase. A wrapping key derived from a passphrase, using the OpenSSL command-line utility. It's the simplest to set up, but the key custodian and the data custodian are the same person or process, which most compliance frameworks (PCI, HIPAA, FedRAMP) don't accept. There's also no recovery path: losing the passphrase makes the data unrecoverable, and leaking it voids the encryption. Use a passphrase for development and testing only.

  • Key store. A wrapping key managed by an external key management system (KMS) or hardware security module, such as AWS KMS, Azure Key Vault, HashiCorp Vault, Entrust KeyControl, Fortanix Data Security Manager, Google Cloud KMS, or Thales CipherTrust Manager. This mechanism separates key custody from data custody, supports audit trails and key rotation, and is the recommended option for production environments.

  • No protection (disabled). You can skip key wrapping entirely, leaving the generated key in plaintext on disk. This mechanism removes any protection for the key itself and should only be used for testing or demonstration purposes.

See Choosing a key protection mechanism to implement whichever mechanism you choose.

Encryption algorithms and key lengths

TDE uses OpenSSL to encrypt data files with the AES encryption algorithm. See TDE compatibility for which OpenSSL version TDE uses on each platform.

When you initialize the Postgres cluster, you choose a key length: AES-128 or AES-256. The choice hinges on balancing performance and security requirements:

  • AES-128 is commonly advised for environments where performance efficiency and lower power consumption are pivotal, making it suitable for most applications.
  • AES-256 is recommended for scenarios demanding the highest level of security, often driven by regulatory mandates.

See initdb TDE options for supported values and defaults.

Beyond the key length you choose, TDE automatically applies a mode of operation that depends on what it's encrypting.

  • Data files use AES-128-XTS or AES-256-XTS, matching your chosen key length. XTS uses a second value, known as the tweak value, to enhance the encryption. The XTS tweak value with TDE uses the database OID, the relfilenode, and the block number.
  • Write-ahead log (WAL) files use AES-128-CTR or AES-256-CTR, incorporating the WAL's log sequence number (LSN) as the counter component.
  • Temporary files that are accessed by block also use AES-128-XTS or AES-256-XTS. Other temporary files use AES-128-CBC or AES-256-CBC.

FIPS 140 compliance

TDE decides what to encrypt and when, but calls OpenSSL to perform the actual encryption and decryption of data files, WAL, and temporary files. TDE itself isn't FIPS-140 certified: FIPS certification applies to the cryptographic module that performs the encryption, and that module is OpenSSL's.

If the OpenSSL module TDE uses is FIPS-140-3 validated and running in FIPS mode, TDE's data encryption runs on that validated module. Every cipher TDE uses is FIPS-approved: AES-XTS for data files and block-accessed temporary files (NIST SP 800-38E), and AES-CTR for WAL files and AES-CBC for other temporary files (NIST SP 800-38A).

To confirm FIPS compliance for a deployment, check whether the OpenSSL module TDE uses on your platform — see TDE compatibility — has its own FIPS-140-3 validation certificate from NIST's Cryptographic Module Validation Program, and that it's running in FIPS mode.

How does TDE affect performance?

The performance impact of TDE is low. For benchmark details from Enterprise Postgres (Oracle Compatible) 15, see the Transparent Data Encryption Impacts on EDB Postgres Advanced Server 15 blog.

How is data stored on disk with TDE?

In this example, the data in the tbfoo table is encrypted. The pg_relation_filepath function locates the data file corresponding to the tbfoo table.

INSERT INTO tbfoo VALUES ('abc','123');
INSERT 0 1
SELECT pg_relation_filepath('tbfoo');
Output
 pg_relation_filepath
----------------------
 base/5/16416

Grepping the data looking for characters doesn't return anything:

hexdump -C 16416 | grep abc

Viewing the last five lines returns the encrypted data:

hexdump -C 16416 | tail -5
Output
00001fc0  c8 0f 1d c8 9a 63 3d dc  7d 4e 68 98 b8 f2 5e 0a  |.....c=.}Nh...^.|
00001fd0  9a eb 20 1d 59 ad be 94  6e fd d5 6e ed 0a 72 8c  |.. .Y...n..n..r.|
00001fe0  7b 14 7f de 5b 63 e3 84  ba 6c e7 b0 a3 86 aa b9  |{...[c...l......|
00001ff0  fe 4f 07 50 06 b7 ef 6a  cd f9 84 96 b2 4b 25 12  |.O.P...j.....K%.|
00002000

Could this page be better? Report a problem or suggest an addition!