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 <[email protected]> Author: ChangAo Chen <[email protected]> Reviewed-by: Chao Li <[email protected]> Reviewed-by: Pretham <[email protected]> Reviewed-by: Robert Haas <[email protected]> Reviewed-by: Jacob Champion <[email protected]> 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 ------ REL_16_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/dbda203fe95de429d238f3eb1b7847de34a53479 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(-)
