Skip to content

Commit 0ff55c5

Browse files
Sasha Krassovskytristan957
Sasha Krassovsky
authored andcommitted
Support creating subscriptions as neon_superuser
1 parent 8d18a8d commit 0ff55c5

File tree

4 files changed

+18
-9
lines changed

4 files changed

+18
-9
lines changed

src/backend/commands/publicationcmds.c

-7
Original file line numberDiff line numberDiff line change
@@ -727,13 +727,6 @@ CheckPubRelationColumnList(char *pubname, List *tables,
727727
}
728728
}
729729

730-
static bool
731-
is_neon_superuser(void)
732-
{
733-
Oid neon_superuser_oid = get_role_oid("neon_superuser", true /*missing_ok*/);
734-
return neon_superuser_oid != InvalidOid && has_privs_of_role(GetUserId(), neon_superuser_oid);
735-
}
736-
737730
/*
738731
* Create new publication.
739732
*/

src/backend/commands/subscriptioncmds.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ CreateSubscription(ParseState *pstate, CreateSubscriptionStmt *stmt,
541541
if (opts.create_slot)
542542
PreventInTransactionBlock(isTopLevel, "CREATE SUBSCRIPTION ... WITH (create_slot = true)");
543543

544-
if (!superuser())
544+
if (!superuser() && !is_neon_superuser())
545545
ereport(ERROR,
546546
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
547547
errmsg("must be superuser to create subscriptions")));
@@ -1666,7 +1666,7 @@ AlterSubscriptionOwner_internal(Relation rel, HeapTuple tup, Oid newOwnerId)
16661666
NameStr(form->subname));
16671667

16681668
/* New owner must be a superuser */
1669-
if (!superuser_arg(newOwnerId))
1669+
if (!superuser_arg(newOwnerId) && !is_neon_superuser_arg(newOwnerId))
16701670
ereport(ERROR,
16711671
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
16721672
errmsg("permission denied to change owner of subscription \"%s\"",

src/backend/utils/adt/acl.c

+12
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,18 @@ static AclResult pg_role_aclcheck(Oid role_oid, Oid roleid, AclMode mode);
117117

118118
static void RoleMembershipCacheCallback(Datum arg, int cacheid, uint32 hashvalue);
119119

120+
bool
121+
is_neon_superuser(void)
122+
{
123+
return is_neon_superuser_arg(GetUserId());
124+
}
125+
126+
bool
127+
is_neon_superuser_arg(Oid roleid)
128+
{
129+
Oid neon_superuser_oid = get_role_oid("neon_superuser", true /*missing_ok*/);
130+
return neon_superuser_oid != InvalidOid && has_privs_of_role(roleid, neon_superuser_oid);
131+
}
120132

121133
/*
122134
* getid

src/include/miscadmin.h

+4
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,10 @@ extern void SetCurrentRoleId(Oid roleid, bool is_superuser);
373373
extern bool superuser(void); /* current user is superuser */
374374
extern bool superuser_arg(Oid roleid); /* given user is superuser */
375375

376+
/* in utils/adt/acl.c */
377+
extern bool is_neon_superuser(void); /* current user is neon_superuser */
378+
extern bool is_neon_superuser_arg(Oid roleid); /* given user is neon_superuser */
379+
376380

377381
/*****************************************************************************
378382
* pmod.h -- *

0 commit comments

Comments
 (0)