60161 Commits

Author SHA1 Message Date
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
Andreas Karlsson
233305bbc4 Remove unused includes in TAP tests
Additionally we remove unnecessary copies if the generated config file.
2025-04-17 00:32:50 +02:00
Andreas Karlsson
945cbe436b Make global variable local in TAP tests 2025-04-17 00:32:50 +02:00
Andreas Karlsson
a4818a845f Clean up TAP test helpers
Checking for PostgreSQL versions can be done in a cleaner way plus we do
not need to run chmod.
2025-04-17 00:32:50 +02:00
Andrew Pogrebnoy
cc459df896 Always pfree tmp WAL key when allocated
We didn't pfree the key in case of `EncryptXLog == true && key == true`
2025-04-16 18:17:41 +03:00
Andreas Karlsson
033f7cae77 Make sure we have tests which fetch KMIP and Vault keys
Before this we had no coverage of the code path for successfully
fetching a KMIP key from the key provider.
2025-04-16 14:03:54 +02:00
Andreas Karlsson
44c3619f5e Stop pretending that we use autotools to build config.h
We have not been using autotools since commit
e0978a8be6c70b2fccc86ca1cb8fc5499dd83a88 so stop pretending that we do
related to config.h and instead directly have the necessary defines with
the right names in pg_tde.h.
2025-04-16 14:02:48 +02:00
Andreas Karlsson
c10665840e Remove dead code in pg_tde_defs.c 2025-04-16 14:02:48 +02:00
Andreas Karlsson
6aa4203eca Actually run the test of pg_tde_version()
The test was added in fb5658242eed71b645768ec35ec13d3e4c8cc1e4 but never
actually added to the lists of tests.
2025-04-16 14:02:31 +02:00
Anders Åstrand
a08ed99570 Modernize the way we call ereport() part 2
These were not updated in 725c34da520cca4597f6751d1d671c6191466200 and
we still want to use this way of calling ereport() everywhere.
2025-04-16 11:05:52 +02:00
Andreas Karlsson
20ab981941 PG-1440 Remove unnecesary query for test case
This query gave no extra coverage, either in qualitity or quality.
2025-04-16 08:40:49 +02:00
Andreas Karlsson
99ef6b20f9 PG-1440 Only let superusers modify the global key proviers
Since as soon as we have installed pg_tde the database owner can call
any function created by the extension so any database owner can meddle
with any global key provider. The only way to prevent the database owner
to do whatever they want add permissions checks to the C code and here
we keep that check simple by limiting modifying the global key provider
to only the super user.

Additionally we also protect the function for settting the WAL key, for
setting the default key and to be paranoid also the function for using a
global key provider to set the database key. The third is not obvious if
it is necessary or not but I chose to be paranoid and relax that
restirction later once we have demed it to be secure.
2025-04-16 08:40:49 +02:00
Naeem Akhter
dcdcebbf92
PG-1482, PG-1289 Add coverage to repo and percona server version check. (#212)
- Added code coverage to link repo to codecov.io for coverage stats on
PR and merge.
- Added coverage badge on the landing page (readme) of the repo. 
- Updated GH action to run on PUSH/MERGE, as this is required for code
coverage.
- Updated bash files in ci_scripts folder to accommodate tde
installcheck only.
- Added percona server version scheme verification TAP test case.
2025-04-15 19:42:57 +05:00
Artem Gavrilov
c8dd16849f PG-1458 Add default key info/verify funcions 2025-04-15 14:57:27 +02:00