Skip to content
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

PG-952: Handle non existent principal key in tde_heap #287

Merged
merged 1 commit into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/access/pg_tde_tdemap.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ pg_tde_create_key_map_entry(const RelFileLocator *newrlocator)
if (principal_key == NULL)
{
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 @@ -873,7 +873,7 @@ pg_tde_get_key_from_file(const RelFileLocator *rlocator)
{
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.")));
}

/* 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 @@ -270,7 +270,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
Loading