mirror of https://github.com/citusdata/citus.git
Review changes for pg16 update GRANT and REVOKE
parent
816fb85333
commit
ff3cabb1cb
|
@ -878,8 +878,10 @@ GenerateGrantRoleStmtsOfRole(Oid roleid)
|
||||||
#if PG_VERSION_NUM >= PG_VERSION_16
|
#if PG_VERSION_NUM >= PG_VERSION_16
|
||||||
if (membership->admin_option)
|
if (membership->admin_option)
|
||||||
{
|
{
|
||||||
DefElem *opt = makeDefElem("admin", (Node *) makeBoolean(true), -1);
|
DefElem *opt = makeDefElem("admin", (Node *) makeBoolean(true), -1);
|
||||||
grantRoleStmt->opt = list_make1(opt);
|
DefElem *inherit_opt = makeDefElem("inherit", (Node *) makeBoolean(true), -1);
|
||||||
|
DefElem *set_opt = makeDefElem("set", (Node *) makeBoolean(true), -1);
|
||||||
|
grantRoleStmt->opt = list_make3(opt, inherit_opt, set_opt);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (membership->inherit_option)
|
if (membership->inherit_option)
|
||||||
|
|
|
@ -403,21 +403,33 @@ AppendRevokeAdminOptionFor(StringInfo buf, GrantRoleStmt *stmt)
|
||||||
if (!stmt->is_grant)
|
if (!stmt->is_grant)
|
||||||
{
|
{
|
||||||
DefElem *opt = NULL;
|
DefElem *opt = NULL;
|
||||||
|
int opt_count = 0 ;
|
||||||
foreach_ptr(opt, stmt->opt)
|
foreach_ptr(opt, stmt->opt)
|
||||||
{
|
{
|
||||||
|
switch (opt->defname)
|
||||||
|
{
|
||||||
|
case "admin":
|
||||||
|
appendStringInfo(buf, "ADMIN OPTION FOR ");
|
||||||
|
opt_count++;
|
||||||
|
break;
|
||||||
|
|
||||||
switch (opt->defname)
|
case "inherit":
|
||||||
{
|
if (opt_count > 0)
|
||||||
appendStringInfo(buf, "ADMIN OPTION FOR ");
|
{
|
||||||
}
|
appendStringInfo(buf, ", ");
|
||||||
else if (strcmp(opt->defname, "inherit") == 0);
|
}
|
||||||
{
|
appendStringInfo(buf, "INHERIT OPTION FOR ");
|
||||||
appendStringInfo(buf, "INHERIT TRUE");
|
opt_count++;
|
||||||
appendStringInfo(buf, "GRANT x TO y WITH INHERIT TRUE, SET TRUE;");
|
break;
|
||||||
}
|
|
||||||
else if (strcmp(opt->defname, "set") == 0)
|
case "set":
|
||||||
{
|
if (opt_count > 0)
|
||||||
appendStringInfo(buf, "SET TRUE");
|
{
|
||||||
|
appendStringInfo(buf, ", ");
|
||||||
|
}
|
||||||
|
appendStringInfo(buf, "SET OPTION FOR ");
|
||||||
|
opt_count++;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -440,13 +452,32 @@ AppendGrantWithAdminOption(StringInfo buf, GrantRoleStmt *stmt)
|
||||||
int opt_count = 0;
|
int opt_count = 0;
|
||||||
foreach_ptr(opt, stmt->opt)
|
foreach_ptr(opt, stmt->opt)
|
||||||
{
|
{
|
||||||
bool admin_option = false;
|
switch (opt->defname)
|
||||||
char *optval = defGetString(opt);
|
{
|
||||||
if (strcmp(opt->defname, "admin") == 0 &&
|
case "admin":
|
||||||
parse_bool(optval, &admin_option) && admin_option)
|
appendStringInfo(buf, " WITH ADMIN OPTION");
|
||||||
{
|
opt_count++;
|
||||||
appendStringInfo(buf, " WITH ADMIN OPTION");
|
break;
|
||||||
|
|
||||||
|
case "inherit":
|
||||||
|
if (opt_count > 0)
|
||||||
|
{
|
||||||
|
appendStringInfo(buf, ", ");
|
||||||
|
}
|
||||||
|
appendStringInfo(buf, "INHERIT OPTION ");
|
||||||
|
opt_count++;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
||||||
|
case "set":
|
||||||
|
if (opt_count > 0)
|
||||||
|
{
|
||||||
|
appendStringInfo(buf, ", ");
|
||||||
|
}
|
||||||
|
appendStringInfo(buf, "SET OPTION ");
|
||||||
|
opt_count++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
|
|
@ -658,3 +658,38 @@ DROP ROLE role3, role4, role5;
|
||||||
SET client_min_messages TO ERROR;
|
SET client_min_messages TO ERROR;
|
||||||
DROP EXTENSION postgres_fdw CASCADE;
|
DROP EXTENSION postgres_fdw CASCADE;
|
||||||
DROP SCHEMA pg16 CASCADE;
|
DROP SCHEMA pg16 CASCADE;
|
||||||
|
|
||||||
|
--
|
||||||
|
-- PG16 allows GRANT WITH ADMIN | INHERIT | SET
|
||||||
|
--
|
||||||
|
-- GRANT privileges to a role or roles
|
||||||
|
\c - - - :master_port
|
||||||
|
CREATE ROLE create_role;
|
||||||
|
CREATE ROLE create_role_2;
|
||||||
|
CREATE ROLE create_role_3;
|
||||||
|
CREATE ROLE create_role_4;
|
||||||
|
CREATE USER create_user;
|
||||||
|
CREATE USER create_user_2;
|
||||||
|
CREATE GROUP create_group;
|
||||||
|
CREATE GROUP create_group_2;
|
||||||
|
|
||||||
|
--test grant role
|
||||||
|
GRANT create_group TO create_role;
|
||||||
|
GRANT create_group TO create_role_2 WITH ADMIN OPTION;
|
||||||
|
GRANT create_group TO create_role_3 WITH INHERIT;
|
||||||
|
GRANT create_group TO create_role_4 WITH SET;
|
||||||
|
|
||||||
|
-- ADMIN role can perfom administrative tasks
|
||||||
|
-- role can now access the data and permissions of the table (owner of table)
|
||||||
|
-- role can change current user to any other user/role that has access
|
||||||
|
GRANT ADMIN TO joe;
|
||||||
|
GRANT INHERIT ON ROLE joe TO james;
|
||||||
|
|
||||||
|
GRANT SELECT ON companies TO joe WITH GRANT OPTION;
|
||||||
|
GRANT SET (SELECT) ON companies TO james;
|
||||||
|
|
||||||
|
|
||||||
|
\set VERBOSITY terse
|
||||||
|
SET client_min_messages TO ERROR;
|
||||||
|
DROP SCHEMA pg16 CASCADE;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue