aboutsummaryrefslogtreecommitdiff
path: root/src/backend/access/transam/parallel.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/access/transam/parallel.c')
-rw-r--r--src/backend/access/transam/parallel.c33
1 files changed, 24 insertions, 9 deletions
diff --git a/src/backend/access/transam/parallel.c b/src/backend/access/transam/parallel.c
index 8dcab485e0f..125a297e6ec 100644
--- a/src/backend/access/transam/parallel.c
+++ b/src/backend/access/transam/parallel.c
@@ -83,12 +83,14 @@ typedef struct FixedParallelState
/* Fixed-size state that workers must restore. */
Oid database_id;
Oid authenticated_user_id;
- Oid current_user_id;
+ Oid session_user_id;
Oid outer_user_id;
+ Oid current_user_id;
Oid temp_namespace_id;
Oid temp_toast_namespace_id;
int sec_context;
- bool is_superuser;
+ bool session_user_is_superuser;
+ bool role_is_superuser;
PGPROC *parallel_leader_pgproc;
pid_t parallel_leader_pid;
ProcNumber parallel_leader_proc_number;
@@ -336,9 +338,11 @@ InitializeParallelDSM(ParallelContext *pcxt)
shm_toc_allocate(pcxt->toc, sizeof(FixedParallelState));
fps->database_id = MyDatabaseId;
fps->authenticated_user_id = GetAuthenticatedUserId();
+ fps->session_user_id = GetSessionUserId();
fps->outer_user_id = GetCurrentRoleId();
- fps->is_superuser = current_role_is_superuser;
GetUserIdAndSecContext(&fps->current_user_id, &fps->sec_context);
+ fps->session_user_is_superuser = GetSessionUserIsSuperuser();
+ fps->role_is_superuser = current_role_is_superuser;
GetTempNamespaceState(&fps->temp_namespace_id,
&fps->temp_toast_namespace_id);
fps->parallel_leader_pgproc = MyProc;
@@ -1404,6 +1408,17 @@ ParallelWorkerMain(Datum main_arg)
entrypt = LookupParallelWorkerFunction(library_name, function_name);
+ /*
+ * Restore current session authorization and role id. No verification
+ * happens here, we just blindly adopt the leader's state. Note that this
+ * has to happen before InitPostgres, since InitializeSessionUserId will
+ * not set these variables.
+ */
+ SetAuthenticatedUserId(fps->authenticated_user_id);
+ SetSessionAuthorization(fps->session_user_id,
+ fps->session_user_is_superuser);
+ SetCurrentRoleId(fps->outer_user_id, fps->role_is_superuser);
+
/* Restore database connection. */
BackgroundWorkerInitializeConnectionByOid(fps->database_id,
fps->authenticated_user_id,
@@ -1469,13 +1484,13 @@ ParallelWorkerMain(Datum main_arg)
InvalidateSystemCaches();
/*
- * Restore current role id. Skip verifying whether session user is
- * allowed to become this role and blindly restore the leader's state for
- * current role.
+ * Restore current user ID and security context. No verification happens
+ * here, we just blindly adopt the leader's state. We can't do this till
+ * after restoring GUCs, else we'll get complaints about restoring
+ * session_authorization and role. (In effect, we're assuming that all
+ * the restored values are okay to set, even if we are now inside a
+ * restricted context.)
*/
- SetCurrentRoleId(fps->outer_user_id, fps->is_superuser);
-
- /* Restore user ID and security context. */
SetUserIdAndSecContext(fps->current_user_id, fps->sec_context);
/* Restore temp-namespace state to ensure search path matches leader's. */