| From: | Fabien Roy <fabienlroy(at)yahoo(dot)com> |
|---|---|
| To: | pgsql-hackers(at)lists(dot)postgresql(dot)org |
| Subject: | [PROPOSAL] Extension: searchable encrypted column type with externally supplied crypto |
| Date: | 2026-12-01 19:32:39 |
| Message-ID: | 39F88560-473D-4112-BFB7-DF34A2D1F949@yahoo.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Hi all,
I would like feedback before writing code on an extension (and possibly a core type later) for personal data covered by GDPR.
Problem: a stolen dump or backup exposes everything. pgcrypto encrypts values but makes them unsearchable, and keys often end up next to the data.
Proposal: a column type, say rgpd_text, that stores and indexes data encrypted OUTSIDE the server. The extension has no crypto dependency. Any library can do the work (OpenSSL, libsodium, or ours).
Stored value: (hdr, ct, bi, tg)
- hdr: format version, key id, IV or nonce
- ct: ciphertext
- bi: HMAC blind index for equality (btree)
- tg: truncated HMAC trigram tokens for substring candidate search (GIN, @>); the client decrypts and verifies the match
The server never receives a key. The client computes ct, bi, and the tokens of the query.
Key handling, using AES-256-CBC as the example:
- The master key is never used directly. It lives in a KMS or HSM (the KEK). Data keys per tenant or column are derived with HKDF (RFC 5869) or wrapped, with separate keys for encryption, MAC and indexes.
- The key id in hdr allows rotation without rewriting everything at once.
- Keys stay in client memory only: not in postgresql.conf, not in SQL text, not in logs (log_statement, pg_stat_statements).
- IV: random, 16 bytes, unpredictable, one per value. It is stored in clear in hdr (it is not secret, but must never repeat or be predictable). Since search uses the separate blind index, ciphertext can stay randomized.
- CBC alone is malleable and exposed to padding oracles, so encrypt-then-MAC: HMAC-SHA256 over hdr||IV||ct, verified before decrypting. An AEAD mode (GCM, SIV) is preferable where available. Table, column and primary key go into the MAC or AAD so values cannot be moved between rows.
Leakage, stated openly: bi reveals equality; tg reveals substring structure and frequencies. Mitigations: truncated tokens (deliberate collisions), no trigrams on low-cardinality fields, length checks. A threat model section would be part of the docs.
Questions:
1. A true base type with operator classes, or a composite type plus index expressions?
2. Is contrib the right home, or should this stay on PGXN first?
3. Any overlap with the ongoing TDE or column-encryption discussions I should read first?
Thanks,
Fabien Roy
---
Nisi fractum, noli refeci
Or
Aint Broke! Don't Fix It!
|\ _,,,---,,_ _,,---,,,_ /|
/,`.-'`' -. ;-;;,_ _,;;-; ._ `'`-.',\
|,4- ) )-,_. ,\ ( `'-' `-'' ) /, ._,-( ( -7,|
'---''(_/--' `-'\_) (_/`-' `--\_)``---`
<fabienlroy(at)yahoo(dot)com>
Tel: +33 6 66 11 64 12
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Masahiko Sawada | 2026-12-01 19:41:25 | Re: Fix race between copying and dropping a replication slot |
| Previous Message | Daniel Gustafsson | 2026-12-01 19:23:41 | Re: passwordcheck: Make the user name check case-insensitive |