Skip to content

Commit

Permalink
Merge pull request #287 from dutow/pg952
Browse files Browse the repository at this point in the history
PG-952: Handle non existent principal key in tde_heap
  • Loading branch information
dutow authored Sep 30, 2024
2 parents cb7557f + 6d02b5e commit d715cb1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/access/pg_tde_tdemap.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ pg_tde_create_key_map_entry(const RelFileLocator *newrlocator)
{
LWLockRelease(lock_pk);
ereport(ERROR,
(errmsg("failed to retrieve principal key")));
(errmsg("failed to retrieve principal key. Create one using pg_tde_set_principal_key before using encrypted tables.")));

return NULL;
}
Expand Down Expand Up @@ -870,7 +870,7 @@ pg_tde_get_key_from_file(const RelFileLocator *rlocator)
{
LWLockRelease(lock_pk);
ereport(ERROR,
(errmsg("failed to retrieve principal key")));
(errmsg("failed to retrieve principal key. Create one using pg_tde_set_principal_key before using encrypted tables.")));
}

/* Get the file paths */
Expand Down
2 changes: 1 addition & 1 deletion src/catalog/tde_principal_key.c
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ set_principal_key_with_keyring(const char *key_name, GenericKeyring *keyring,
LWLockRelease(lock_files);

ereport(ERROR,
(errmsg("failed to retrieve principal key")));
(errmsg("failed to retrieve principal key. Create one using pg_tde_set_principal_key before using encrypted tables.")));
}

principalKey->keyLength = keyInfo->data.len;
Expand Down
16 changes: 16 additions & 0 deletions src/pg_tde_event_capture.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
#include "commands/event_trigger.h"
#include "common/pg_tde_utils.h"
#include "pg_tde_event_capture.h"
#include "commands/tablespace.h"
#include "catalog/tde_principal_key.h"
#include "miscadmin.h"

/* Global variable that gets set at ddl start and cleard out at ddl end*/
TdeCreateEvent tdeCurrentCreateEvent = {.relation = NULL};
Expand Down Expand Up @@ -97,6 +100,8 @@ pg_tde_ddl_command_start_capture(PG_FUNCTION_ARGS)
else if (IsA(parsetree, CreateStmt))
{
CreateStmt *stmt = (CreateStmt *) parsetree;
TDEPrincipalKey * principal_key;
Oid tablespace_oid;

tdeCurrentCreateEvent.eventType = TDE_TABLE_CREATE_EVENT;
tdeCurrentCreateEvent.relation = stmt->relation;
Expand All @@ -105,6 +110,17 @@ pg_tde_ddl_command_start_capture(PG_FUNCTION_ARGS)
{
tdeCurrentCreateEvent.encryptMode = true;
}

tablespace_oid = stmt->tablespacename != NULL ? get_tablespace_oid(stmt->tablespacename, false)
: MyDatabaseTableSpace;
principal_key = GetPrincipalKey(MyDatabaseId, tablespace_oid);
if (principal_key == NULL)
{
ereport(ERROR,
(errmsg("failed to retrieve principal key. Create one using pg_tde_set_principal_key before using encrypted tables.")));

}

}
#endif
PG_RETURN_NULL();
Expand Down

0 comments on commit d715cb1

Please sign in to comment.