pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Nathan Bossart <nathan@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix authorization check for role membership changes.
Date: Thu, 13 Aug 2026 21:36:02 +0000
Message-ID: <E1wud5l-00000000Sdv-1QMH@gemulon.postgresql.org> (raw)

Fix authorization check for role membership changes.

Presently, check_role_membership_authorization() decides whether
the current user may grant or revoke membership in a role by
calling is_admin_of_role(), which recurses through all grants,
while it chooses the grantor to record for the resulting entry by
calling select_best_admin(), which recurses only through inherited
grants.  When the two disagree, the permission check passes and the
grantor lookup then comes up empty, so the user sees an internal
"no possible grantors" error.  ALTER GROUP ... ADD USER reaches the
same error through the separate check in AlterRole().

To fix, teach both checks to search the same way
select_best_admin() does via a new has_admin_privs_of_role().  The
new check passes exactly when the grantor lookup was going to
succeed, so nothing that works today starts failing; the internal
error simply becomes a proper permission error.  Note that this
leaves the other callers of is_admin_of_role() alone, so a role
reachable only through a non-inherited grant can still be dropped,
renamed, or altered.  Whether that ought to change as well is left
as a future exercise.

Oversight in commit ce6b672e44.

Reported-by: ChangAo Chen <cca5507@qq.com>
Author: ChangAo Chen <cca5507@qq.com>
Reviewed-by: Chao Li <li.evan.chao@gmail.com>
Reviewed-by: Pretham <prezza672@gmail.com>
Reviewed-by: Robert Haas <robertmhaas@gmail.com>
Reviewed-by: Jacob Champion <jacob.champion@enterprisedb.com>
Discussion: https://postgr.es/m/tencent_ADCE2B34B230A9B631854806104FEF40C105%40qq.com
Discussion: https://postgr.es/m/CAJUn_kN%2BMhbb8fYP5xxQCq1KEziOinM6HgYx4ts_pPDnQ2y1nQ%40mail.gmail.com
Backpatch-through: 16

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/a8261c766067f939aeea8e2dff821fed08dada79

Modified Files
--------------
src/backend/commands/user.c              |  4 ++--
src/backend/utils/adt/acl.c              | 27 +++++++++++++++++++++++++++
src/include/utils/acl.h                  |  1 +
src/test/regress/expected/privileges.out |  9 +++++++++
src/test/regress/sql/privileges.sql      |  5 +++++
5 files changed, 44 insertions(+), 2 deletions(-)



view thread (5+ messages)  latest in thread

Message-ID: <E1wud5l-00000000Sdv-1QMH@gemulon.postgresql.org>
Permalink:  ../E1wud5l-00000000Sdv-1QMH@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1wud5l-00000000Sdv-1QMH@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-committers@postgresql.org
  Cc: nathan@postgresql.org, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: Fix authorization check for role membership changes.
  In-Reply-To: <E1wud5l-00000000Sdv-1QMH@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox