60174 Commits

Author SHA1 Message Date
Anders Åstrand
65fa2e241b Rename KeyringProviderXLRecord
The new name, KeyringProviderRecordInFile, describes what it is rather
than what it's used for. But the real reason is that I want to use it
for other things than the WAL in future commits.
2025-04-23 10:31:30 +02:00
Anders Åstrand
d6eb31f59a Fix error message in keyring_file.c
The colon was on the wrong side of the space.
2025-04-23 10:31:30 +02:00
Anders Åstrand
ce63840ca9 Remove non-test
This regression file didn't really test anything. The tests it was
supposed to do was removed here e270322f72
So now it doesn't test anything that key_provider.sql doesn't already do
for us.
2025-04-23 10:31:30 +02:00
Anders Åstrand
043232e31e Change some keyring function to return void
No callers cared about the return value of these functions anyway.
2025-04-23 10:31:30 +02:00
Andreas Karlsson
14a2bd2849 Clean up a couple comments in pg_tde_tdemap.c 2025-04-23 09:23:20 +02:00
Andreas Karlsson
1885236fa9 Simplify error handling in pg_tde_write_map_keydata_file() 2025-04-23 09:23:20 +02:00
Andreas Karlsson
15ea8358f3 Do not switch between using prev_pos and curr_pos
Be consistent about always passing curr_pos when reading or writing the
map file. The code is easier to understand if only one variable is used
for positioning in the file.
2025-04-23 09:23:20 +02:00
Andreas Karlsson
0b2dbd2ccd Consistently update the position in a pointer passed to the function
This UX is not nice but let's at least be consistent about it.
2025-04-23 09:23:20 +02:00
Andreas Karlsson
676d637f51 Do not initialize local variables unnecessarily
By initializing them to something it makes it look like there is an
intent behind it which there in all of these cases is not.
2025-04-23 09:23:20 +02:00
Andreas Karlsson
332064b8bb Remove useless comments in pg_tde_tdemap.c 2025-04-23 09:23:20 +02:00
Andreas Karlsson
b2fb3ffb45 Rename pg_tde_xlog_encrypt.{c,h} to pg_tde_xlog_smgr.{c,h}
The new name makes it clearer what the files does plus matches our
naming conventions with the relation data storage manager.
2025-04-23 09:21:06 +02:00
Andreas Karlsson
0cc1d56681 Fix whitespace in pg_tde tools Makefile 2025-04-23 09:21:06 +02:00
Dragos Andriciuc
86a43fc484 Update a small fix to sequences
Fixed sequences from seqeunces
2025-04-22 18:22:48 +02:00
Andreas Karlsson
5ae34a248a PG-1366 Remove too detailed and incorrect comment from achitecture docs
The fucntions for lsiting keys do not look at inherit_global_providers
but even if they did it does not seem like something which would belong
in the architecture documentation.
2025-04-22 18:22:48 +02:00
Andreas Karlsson
2b417dad54 PG-1366 Clean up architecture documentation and make it up to date
The architecture documentation was outdated so this makes it up to date
plus improves various minor issues found while updating the
documentation.
2025-04-22 18:22:48 +02:00
Anders Åstrand
3095a6afe0 Add 71da1f03f2f0ff18ed11e4ba6b07b6bd56705a5d to .git-blame-ignore-revs 2025-04-22 18:20:50 +02:00
Artem Gavrilov
ecabb8b9c2 Do missing renamings in documentation 2025-04-22 17:47:13 +02:00
Andrew Pogrebnoy
0d86245ccd XLog a key rotation event rather than the result
Before this commit, we Xlogged the binary result of the _map file
content during key rotation. This led to issues:
1. Replicas would rewrite their own WAL keys with the primary's ones.
And WAL keys are different on replicas. The same would have happened
with SMGR keys since we're also planning to have them different across
replicas.
2. The crash recovery would rewrite the latest WAL key as it's being
created before redo.

This commit switches to rather Xlogging the event of rotation (to which
key should rotate) and lets redo/replicas perform the actual rotation.

Fixes PG-1468, PG-1541
2025-04-22 18:07:59 +03:00
Andreas Karlsson
f3719a73b4 Use restart TAP helper and do not assert result
There is a restart function so there is not and need to call first stop
and then start. And since by default a start, stop or restart call does
not return on error it is totally pointless to assert anything about the
return value. And since PostgreSQL's own tests also are fine with just
bailing out on error we do the same.

While at it we also always call these three functions without
parentheses to be consistent.
2025-04-22 16:05:00 +02:00
Andreas Karlsson
6f1bb54ac5 Simplify pg_tde_find_map_entry() now that reading is simpler
Now that pg_tde_read_one_map_entry() is simpler it makes sense to also
simplify the pg_tde_find_map_entry() function.
2025-04-22 16:04:37 +02:00
Andreas Karlsson
5f279ad13b Fix broken reuse of deleted entries in key map file
Since we tried to check if flags & MAP_ENTRY_EMPTY was true when
searching for empty entries the code was broken since x & 0 always is
false. We fix this by refactoring pg_tde_read_one_map_entry() so the
filtering of the entries is done outside the function. This make
implementing search for empty entries much easier.
2025-04-22 16:04:37 +02:00
Andreas Karlsson
a6f774e57e PG-1444 Move relation key deleteion to smgr_unlink()
Replaces the old way we deleted keys which was built for tde_heap_basic
with deleting the the relation key when smgr_unlink() is called on the
main fork. This function is always called after commit/abort when a
relation deletion has been registered, even if no main fork would exist.

This approach means we do not need to WAL log any event for deleting
relation keys, the normal SMGR unlink also handles that which fits well
into the current approach of doing most of the encryption at the SMGR
layer.

We also remove the subtransaction test which is no longer useful since
it tested things very specific to the old key deleteion.
2025-04-22 11:59:49 +02:00
Andreas Karlsson
ec51d0895a PG-1444 Remove dead code for relation key deletion redo
This code is dead and there is no plan to re-use it any time soon.
2025-04-22 11:59:49 +02:00
Anders Åstrand
681b9ff1cd Run pgperltidy in github actions
Just as we use pgindent to validate that our c files conform to postgres
coding standards, we also run pgperltidy to do the same for perl files.
We only run it on our own code in contrib/pg_tde/

This doesn't actually run pgperltidy as we need to inject some options
in a way that didn't seem possible in that script. Instead it does the
same thing with some slight changes.

We also bump the ubuntu version for this google actions job to the
newest LTS as the older ubuntu version seems to have a version of
perltidy that doesn't support the options used by pgperltidy.
2025-04-22 11:40:24 +02:00
Anders Åstrand
71da1f03f2 Run pgperltidy
Just as we use pgindent we should probably use pgperltidy. This is an
initial run of it using the following command:
src/tools/pgindent/pgperltidy contrib/pg_tde
2025-04-22 11:40:24 +02:00
Mohit Joshi
54cd79c81e
PG-1517 - Automate testcase for (#243)
PG-1473 - Executing pg_tde_verify_principal_key() must require key
viewer permission.
2025-04-22 14:49:45 +05:30
Anders Åstrand
607cf9397d Remove unused tests
These were not present in meson.build or Makefile, and as such are just
extra maintenance cost for no value.
2025-04-22 10:33:23 +02:00
Andreas Karlsson
eed26578cc Remove pgtde_init_pg() TAP helper
This helper mostly added confusion by making it seem like it did more
work than is actually did. And especially since we will want to call
init in the future with different parameters for some tests or
initialize from a backup.
2025-04-22 09:02:40 +02:00
Andreas Karlsson
ca37d73e9d Remove dead code for scanning key providers by type
This code has never been used.
2025-04-19 03:07:04 +02:00
Mohit Joshi
eb8b307b4c
PG-1491 Add SQL test cases for pg_tde_is_encrypted() for partitioned tables (#207)
PG-1491 pg_tde_is_encrypted() is broken for partitioned tables

Following new tescases added:
partition_table.sql
2025-04-18 15:15:57 +03:00
Andreas Karlsson
cf2806d9f3 Simplify setup_files_dir() in pgtde.pm 2025-04-18 09:59:59 +02:00
Andreas Karlsson
5fb92917f7 Drop support for PostgreSQL <15 in pgtde.pm
Since until we actually have CI for older versions the code is likely
broken anyway we might as well not try to support versions we do not
actually support. It is easy to re-add this once we want to add support
for PostgreSQL 14.
2025-04-18 09:59:59 +02:00
Andreas Karlsson
1df4ff5110 Remove unnecesary comments and code in pgtde.pm
None of this is useful or used.
2025-04-18 09:59:59 +02:00
Andreas Karlsson
3b6d3d46dd Use append_conf() helper in TAP tests
This is what PostgreSQL has been using since 9.6 so we can safely use it
too in our tests.
2025-04-18 01:51:40 +02:00
Anders Åstrand
1390dd0cef PG-1535 Do not delete global key provider in use
The code wrongly assumed that the databaseId set in the keyInfo returned
from GetPrincipalKeyNoDefault() would be the Oid of the key provider
owner, while in reality it is the Oid of the database using it as a
principal key.
2025-04-17 20:25:47 +02:00
Shahid Ullah
40c32b2de2
[PG-1545] - Remove pg_tde_revoke_global_key_management_from_role refe… (#228)
…rence
2025-04-17 18:43:55 +05:00
Andreas Karlsson
14a3d36ae1 Only check pg_tde with the combined typedefs
The reason to do this is that the old approach created an unnecessary
diff against upstream where they had forgot SinglePartitionSpec in
typedefs.list.

Additionally add two new structs from our SMGR patch to the list.
2025-04-17 11:04:54 +02:00
Andreas Karlsson
2131faf17d Use PostgreSQL's find_typedef script instead of our own
Since the PostgreSQL repo already contains a script extracting typedefs
from object files let's use it.
2025-04-17 11:04:54 +02:00
Andreas Karlsson
ee3279b9b4 PG-1441 Sort resource manager record types
Since we are breaking backwards compatbility anyway we might as well
have them in a bit nicer order.
2025-04-17 11:02:17 +02:00
Andreas Karlsson
ac53512847 PG-1441 Further improve resource manager type names
The type names were a a mess with diffeent naming convetions, e.g. KEY
vs PRINCIPAL_KEY, so try to standardize on something sane.
2025-04-17 11:02:17 +02:00
Andreas Karlsson
33d78260c5 PG-1441 Add record type names and descriptions for all types
Some resource manager record types were missing the name or the
description.
2025-04-17 11:02:17 +02:00
Andreas Karlsson
35ff2fdca8 PG-1441 Improve pg_tde resource manager record types and decriptions
While there is a quite big variation already among PostgreSQL's own
record types and decriptions at least try not to invent something
totally different.
2025-04-17 11:02:17 +02:00
Andreas Karlsson
ee8c285ce6 PG-1441 Change the name of the WAL resource manager
Seems like we used a plaholder name so instead picked pg_tde since that
is more than clear enough.
2025-04-17 11:02:17 +02:00
Andreas Karlsson
8a7fc7acb5 PG-1441 Clean up code formatting of pg_tde WAL resource manager 2025-04-17 11:02:17 +02:00
Andrew Pogrebnoy
cb80b20a43 pfree tmp key when set principal key
Pushing a principal key to the cache, we copy it to the shared mem.
Hence, the palloced tmp version can be freed.
2025-04-17 09:38:10 +03:00
Andreas Karlsson
832cbb4f4d Convert output of TAP tests to be more like pg_regress
This improves readbility of diffs a lot.
2025-04-17 00:32:50 +02:00
Andreas Karlsson
908d0776ba Rename test helper append_to_file() to append_to_result_file()
This way we can also import PostgreSQL's test utilities into the
current namespace.
2025-04-17 00:32:50 +02:00
Andreas Karlsson
b190cd0985 Add test helper to TAP tests which runs psql and appends
This simplifies working with tests a lot since now we will also always
get the errors from failed queries directly in the test output instead
of it being truncated when the TAP tests aborts due to the query
failing.

There is still a good case for why we should instead write idiomatic TAP
tests but this at least does a lot to improve the expereince of people
who have to work with these tests without changing the way the tests
work. Plus that the code is cleaner now so it should be easier to move
away from this way of testing in the future.
2025-04-17 00:32:50 +02:00
Andreas Karlsson
891adb150c Always restart the server in the same way in our TAP tests
It is hard to keep track when every place does it differently.
2025-04-17 00:32:50 +02:00
Andreas Karlsson
3bb5edf7b9 Remove pointless white space and comments from TAP tests
It removed readability rather than improved it.
2025-04-17 00:32:50 +02:00