Skip to content

Commit

Permalink
Support creating subscriptions as neon_superuser
Browse files Browse the repository at this point in the history
  • Loading branch information
save-buffer authored and tristan957 committed Feb 6, 2024
1 parent 8d18a8d commit 0ff55c5
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
7 changes: 0 additions & 7 deletions src/backend/commands/publicationcmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -727,13 +727,6 @@ CheckPubRelationColumnList(char *pubname, List *tables,
}
}

static bool
is_neon_superuser(void)
{
Oid neon_superuser_oid = get_role_oid("neon_superuser", true /*missing_ok*/);
return neon_superuser_oid != InvalidOid && has_privs_of_role(GetUserId(), neon_superuser_oid);
}

/*
* Create new publication.
*/
Expand Down
4 changes: 2 additions & 2 deletions src/backend/commands/subscriptioncmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ CreateSubscription(ParseState *pstate, CreateSubscriptionStmt *stmt,
if (opts.create_slot)
PreventInTransactionBlock(isTopLevel, "CREATE SUBSCRIPTION ... WITH (create_slot = true)");

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

/* New owner must be a superuser */
if (!superuser_arg(newOwnerId))
if (!superuser_arg(newOwnerId) && !is_neon_superuser_arg(newOwnerId))
ereport(ERROR,
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
errmsg("permission denied to change owner of subscription \"%s\"",
Expand Down
12 changes: 12 additions & 0 deletions src/backend/utils/adt/acl.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,18 @@ static AclResult pg_role_aclcheck(Oid role_oid, Oid roleid, AclMode mode);

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

bool
is_neon_superuser(void)
{
return is_neon_superuser_arg(GetUserId());
}

bool
is_neon_superuser_arg(Oid roleid)
{
Oid neon_superuser_oid = get_role_oid("neon_superuser", true /*missing_ok*/);
return neon_superuser_oid != InvalidOid && has_privs_of_role(roleid, neon_superuser_oid);
}

/*
* getid
Expand Down
4 changes: 4 additions & 0 deletions src/include/miscadmin.h
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,10 @@ extern void SetCurrentRoleId(Oid roleid, bool is_superuser);
extern bool superuser(void); /* current user is superuser */
extern bool superuser_arg(Oid roleid); /* given user is superuser */

/* in utils/adt/acl.c */
extern bool is_neon_superuser(void); /* current user is neon_superuser */
extern bool is_neon_superuser_arg(Oid roleid); /* given user is neon_superuser */


/*****************************************************************************
* pmod.h -- *
Expand Down

0 comments on commit 0ff55c5

Please sign in to comment.