Skip to content

Commit

Permalink
The patch implements on disk "key map and data" structure. It replaces
Browse files Browse the repository at this point in the history
the old "tde" fork architecture.

This new architecture implements a two file pair with:
(1) Map File
(2) Key Data File

Both files contain a header that contains the name of the master key that
was to encrypt the data keys and a file version. The file version is set
to PG_TDE_FILEMAGIC at the moment and it can be used to differiate between
different file format versions in case we change the structure later on.

The map file is a list of relNumber, flags and key index.
- relNumber is the Oid of the associated relation.
- Flags define if the map entry is free or in use.
- Key index points to the starting position of the key in the key data file.

The flags play a pivotal role in avoiding the file to grow infinitely. When
a relation is either deleted or a transaction is aborted, the entry map entry
is marked as MAP_ENTRY_FREE. Any next transaction requiring to store its
relation key will pick the first entry with flag set to MAP_ENTRY_FREE.

The key data file is simply a list of keys. No flags are needed as the validity
is identified by the map file. Writing to the file is performed using FileWrite
function. This avoids any locking in the key data file.

Pending:
- Implementation of key rotation
- Locking of file during key rotation or map entry
- Review of fflush calls
- Review of the WAL
  • Loading branch information
Hamid Akhtar committed Feb 7, 2024
1 parent b6ccd6c commit 397221a
Show file tree
Hide file tree
Showing 11 changed files with 852 additions and 295 deletions.
5 changes: 5 additions & 0 deletions pg_tde--1.0.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ RETURNS boolean
AS $$ SELECT amname = 'pg_tde' FROM pg_class INNER JOIN pg_am ON pg_am.oid = pg_class.relam WHERE relname = table_name $$
LANGUAGE SQL;

CREATE FUNCTION pg_tde_rotate_key(key_name VARCHAR)
RETURNS boolean
AS 'MODULE_PATHNAME'
LANGUAGE C;

-- Access method
CREATE ACCESS METHOD pg_tde TYPE TABLE HANDLER pg_tdeam_handler;
COMMENT ON ACCESS METHOD pg_tde IS 'pg_tde table access method';
Expand Down
2 changes: 1 addition & 1 deletion src/access/pg_tde_ddl.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ static void
rel->rd_rel->relkind == RELKIND_MATVIEW) &&
(subId == 0) && is_pg_tde_rel(rel))
{
pg_tde_delete_key_fork(rel);
pg_tde_delete_key_map_entry(&rel->rd_locator);
}
relation_close(rel, AccessShareLock);
}
Expand Down
Loading

0 comments on commit 397221a

Please sign in to comment.