mirror of https://github.com/citusdata/citus.git
Merge pull request #1049 from citusdata/bugfix/schema_owner
Fix permissions for multi-user re-partition queriespull/912/head
commit
64c140e78e
|
@ -261,12 +261,8 @@ CreateJobSchema(StringInfo schemaName)
|
|||
|
||||
Oid savedUserId = InvalidOid;
|
||||
int savedSecurityContext = 0;
|
||||
|
||||
/* build a CREATE SCHEMA statement */
|
||||
CreateSchemaStmt *createSchemaStmt = makeNode(CreateSchemaStmt);
|
||||
createSchemaStmt->schemaname = schemaName->data;
|
||||
createSchemaStmt->authrole = NULL;
|
||||
createSchemaStmt->schemaElts = NIL;
|
||||
CreateSchemaStmt *createSchemaStmt = NULL;
|
||||
RoleSpec currentUserRole = { 0 };
|
||||
|
||||
/* allow schema names that start with pg_ */
|
||||
oldAllowSystemTableMods = allowSystemTableMods;
|
||||
|
@ -276,7 +272,18 @@ CreateJobSchema(StringInfo schemaName)
|
|||
GetUserIdAndSecContext(&savedUserId, &savedSecurityContext);
|
||||
SetUserIdAndSecContext(CitusExtensionOwner(), SECURITY_LOCAL_USERID_CHANGE);
|
||||
|
||||
/* actually create schema, and make it visible */
|
||||
/* build a CREATE SCHEMA statement */
|
||||
currentUserRole.type = T_RoleSpec;
|
||||
currentUserRole.roletype = ROLESPEC_CSTRING;
|
||||
currentUserRole.rolename = GetUserNameFromId(savedUserId, false);
|
||||
currentUserRole.location = -1;
|
||||
|
||||
createSchemaStmt = makeNode(CreateSchemaStmt);
|
||||
createSchemaStmt->schemaname = schemaName->data;
|
||||
createSchemaStmt->authrole = (Node *) ¤tUserRole;
|
||||
createSchemaStmt->schemaElts = NIL;
|
||||
|
||||
/* actually create schema with the current user as owner */
|
||||
CreateSchemaCommand(createSchemaStmt, queryString);
|
||||
CommandCounterIncrement();
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include "catalog/pg_namespace.h"
|
||||
#include "commands/copy.h"
|
||||
#include "commands/tablecmds.h"
|
||||
#include "distributed/metadata_cache.h"
|
||||
#include "distributed/worker_protocol.h"
|
||||
#include "executor/spi.h"
|
||||
#include "nodes/makefuncs.h"
|
||||
|
@ -74,6 +75,8 @@ worker_merge_files_into_table(PG_FUNCTION_ARGS)
|
|||
bool schemaExists = false;
|
||||
List *columnNameList = NIL;
|
||||
List *columnTypeList = NIL;
|
||||
Oid savedUserId = InvalidOid;
|
||||
int savedSecurityContext = 0;
|
||||
|
||||
/* we should have the same number of column names and types */
|
||||
int32 columnNameCount = ArrayObjectCount(columnNameObject);
|
||||
|
@ -101,8 +104,14 @@ worker_merge_files_into_table(PG_FUNCTION_ARGS)
|
|||
|
||||
CreateTaskTable(jobSchemaName, taskTableName, columnNameList, columnTypeList);
|
||||
|
||||
/* need superuser to copy from files */
|
||||
GetUserIdAndSecContext(&savedUserId, &savedSecurityContext);
|
||||
SetUserIdAndSecContext(CitusExtensionOwner(), SECURITY_LOCAL_USERID_CHANGE);
|
||||
|
||||
CopyTaskFilesFromDirectory(jobSchemaName, taskTableName, taskDirectoryName);
|
||||
|
||||
SetUserIdAndSecContext(savedUserId, savedSecurityContext);
|
||||
|
||||
PG_RETURN_VOID();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue