-
Notifications
You must be signed in to change notification settings - Fork 8
PG-1447 Test and fix support for template databases #270
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: TDE_REL_17_STABLE
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
❌ Your project status has failed because the head coverage (79.03%) is below the target coverage (90.00%). You can increase the head coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## TDE_REL_17_STABLE #270 +/- ##
=====================================================
+ Coverage 78.93% 79.03% +0.10%
=====================================================
Files 22 22
Lines 2464 2533 +69
Branches 385 397 +12
=====================================================
+ Hits 1945 2002 +57
- Misses 444 452 +8
- Partials 75 79 +4
🚀 New features to boost your workflow:
|
7ea8a82
to
c3c8917
Compare
(1 row) | ||
|
||
CREATE DATABASE new_db TEMPLATE template_db; | ||
ERROR: database "new_db" already exists |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something seems to be wrong in this testcase - this database already exists.
The description also said it only works if we have a default key, but we didn't have one during the previous create db.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems possibly like a bug unrelated to the PR. And since it only happens when when TDE is enabled for the whole test suite it will not directly be an issue now that that has been changed but I think we should take a look and try to figure out if I accidentally found a bug here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, the bug was in my test script. Doh. The issue is that we cannot delete the current default principal key. These tests used to run before the default key provider tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed by adding a comment and commenting out the code.
d2b6a47
to
33509c4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment in Makefile and meson.build should probably be clearer.
contrib/pg_tde/Makefile
Outdated
@@ -8,7 +8,7 @@ DATA = pg_tde--1.0-rc.sql | |||
# Since meson supports skipping test suites this is a make only feature | |||
ifndef TDE_MODE | |||
REGRESS_OPTS = --temp-config $(top_srcdir)/contrib/pg_tde/pg_tde.conf | |||
# default_principal_key needs to run after key_provider. | |||
# default_principal_key needs and create_database to run after key_provider. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This sentence makes no sense to me, but looking at the code it seems like you want to say that default_principal_key
needs to run after key_provider
, and create_database
needs to run after default_principal_key
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I was lazy when writing it. Should fix it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The issue is that there is currently no way to delete default principal keys so these tests becom order dependent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
Using a database with encrypted relations as template works works with the WAL_LOG strateg as long as you have configured a default principal key. It is a bit hackish but works and since encrypted objects in a template database is likely to be an uncommon use case this is fine for now. The test file is put last in the test run order since there is still no good way to clean up default principal keys.
The FILE_COPY strategy of CREATE DATABASE does not use the SMGR so it cannot properly copy and re-encrypt encrypted relations. So we check for such relations and error out if any are found. We look for encrypted relations simply by counting the number of keys in the key map file of the database. This simple approach is fine even with the risk of a left-over key from a crash or a bug due to the FILE_COPY method being rare and that we therefore want to keep this code minimal.
Using a database with encrypted relations as template works with the
WAL_LOG
strategy as long as you have configured a default principal key. It is a bit hackish but works and since encrypted objects in a template database is likely to be an uncommon use case this is fine for now.The test file is put last in the test run order since there is still no good way to clean up default principal keys.
Additionally we assert there are no encrypted relations when using
FILE_COPY
.The
FILE_COPY
strategy ofCREATE DATABASE
does not use the SMGR so it cannot properly copy and re-encrypt encrypted relations. So we check for such relations and error out if any are found.We look for encrypted relations simply by counting the number of keys in the key map file of the database. This simple approach is fine even with the risk of a left-over key from a crash or a bug due to the
FILE_COPY
strategy being rare and that we therefore want to keep this code minimal.