BUG #18622: Attempt to grant role in absence of INHERIT option fails with internal error - Mailing list pgsql-bugs

From PG Bug reporting form
Subject BUG #18622: Attempt to grant role in absence of INHERIT option fails with internal error
Date
Msg-id 18622-066b779aa707ab7a@postgresql.org
Whole thread Raw
List pgsql-bugs
The following bug has been logged on the website:

Bug reference:      18622
Logged by:          Alexander Lakhin
Email address:      exclusion@gmail.com
PostgreSQL version: 17rc1
Operating system:   Ubuntu 22.04
Description:

The last command of the following script:
CREATE ROLE role0;
CREATE ROLE role1 WITH CREATEROLE;
SET role role1;
CREATE ROLE role2 WITH CREATEROLE;
SET role role2;
CREATE ROLE role3;
CREATE ROLE role4;
SET role role1;
        
CREATE ROLE role5 IN ROLE role3;

fails with
ERROR:  XX000: no possible grantors
LOCATION:  check_role_grantor, user.c:2232

whilst:
CREATE ROLE role5 IN ROLE role0;
fails with
ERROR:  permission denied to grant role "role0"
DETAIL:  Only roles with the ADMIN option on role "role0" may grant this
role.

Another, simpler example:
GRANT role3 TO role4;
ERROR:  no possible grantors

Both "no possible grantors" errors go away after:
GRANT role2 TO role1 WITH INHERIT OPTION;

This error is raised at check_role_grantor() where it accompanied by the
comment:
We shouldn't fail to find a best grantor ...

This was added by ce6b672e44 and was true back then, until cf5eb37c5.

Now this error is raised due to a difference between:
check_role_membership_authorization() -> is_admin_of_role() ->
    roles_is_member_of(member, ROLERECURSE_MEMBERS, ...)
and
check_role_grantor() -> select_best_admin() -> 
    roles_is_member_of(member, ROLERECURSE_PRIVS, ...)


pgsql-bugs by date:

Previous
From: "David G. Johnston"
Date:
Subject: Re: INFORMATION_SCHEMA.routines column routine_definition does not show the source
Next
From: PG Bug reporting form
Date:
Subject: BUG #18623: postgresql v14.13.1 installation error