Skip to content

Commit 8de764e

Browse files
ololobusMMeent
andauthored
Parametrize neon_superuser via privileged_role_name var (#677)
neondatabase/neon#12539 Co-authored-by: Matthias van de Meent <[email protected]>
1 parent 353c725 commit 8de764e

File tree

3 files changed

+22
-9
lines changed

3 files changed

+22
-9
lines changed

src/backend/commands/publicationcmds.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,7 @@ CreatePublication(ParseState *pstate, CreatePublicationStmt *stmt)
748748
get_database_name(MyDatabaseId));
749749

750750
/* FOR ALL TABLES requires superuser */
751-
if (stmt->for_all_tables && !superuser() && !is_neon_superuser())
751+
if (stmt->for_all_tables && !superuser() && !is_privileged_role())
752752
ereport(ERROR,
753753
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
754754
errmsg("must be superuser to create FOR ALL TABLES publication")));
@@ -819,7 +819,7 @@ CreatePublication(ParseState *pstate, CreatePublicationStmt *stmt)
819819
&schemaidlist);
820820

821821
/* FOR TABLES IN SCHEMA requires superuser */
822-
if (schemaidlist != NIL && !superuser() && !is_neon_superuser())
822+
if (schemaidlist != NIL && !superuser() && !is_privileged_role())
823823
ereport(ERROR,
824824
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
825825
errmsg("must be superuser to create FOR TABLES IN SCHEMA publication"));

src/backend/utils/adt/acl.c

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,17 +129,29 @@ static AclResult pg_role_aclcheck(Oid role_oid, Oid roleid, AclMode mode);
129129

130130
static void RoleMembershipCacheCallback(Datum arg, int cacheid, uint32 hashvalue);
131131

132+
/*
133+
* Name of the user-accessible privileged role in this system.
134+
* Generally neon_superuser on neon.com
135+
*/
136+
char *privileged_role_name = NULL;
137+
132138
bool
133-
is_neon_superuser(void)
139+
is_privileged_role(void)
134140
{
135-
return is_neon_superuser_arg(GetUserId());
141+
return is_privileged_role_arg(GetUserId());
136142
}
137143

138144
bool
139-
is_neon_superuser_arg(Oid roleid)
145+
is_privileged_role_arg(Oid roleid)
140146
{
141-
Oid neon_superuser_oid = get_role_oid("neon_superuser", true /*missing_ok*/);
142-
return neon_superuser_oid != InvalidOid && has_privs_of_role(roleid, neon_superuser_oid);
147+
Oid privileged_role_oid;
148+
149+
if (privileged_role_name == NULL)
150+
return false;
151+
152+
privileged_role_oid = get_role_oid(privileged_role_name, true /* missing_ok */);
153+
154+
return privileged_role_oid != InvalidOid && has_privs_of_role(roleid, privileged_role_oid);
143155
}
144156

145157
/*

src/include/miscadmin.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -430,8 +430,9 @@ extern bool superuser(void); /* current user is superuser */
430430
extern bool superuser_arg(Oid roleid); /* given user is superuser */
431431

432432
/* in utils/adt/acl.c */
433-
extern bool is_neon_superuser(void); /* current user is neon_superuser */
434-
extern bool is_neon_superuser_arg(Oid roleid); /* given user is neon_superuser */
433+
extern PGDLLIMPORT char *privileged_role_name;
434+
extern bool is_privileged_role(void); /* current user is a privileged role */
435+
extern bool is_privileged_role_arg(Oid roleid); /* given user is a privileged role */
435436

436437
/*****************************************************************************
437438
* pmod.h -- *

0 commit comments

Comments
 (0)