Re: psql: Add role's membership options to the \du+ command - Mailing list pgsql-hackers

From Pavel Luzanov
Subject Re: psql: Add role's membership options to the \du+ command
Date
Msg-id 20824093-d94f-e5d6-b611-8cec7fc6e95e@postgrespro.ru
Whole thread Raw
In response to Re: psql: Add role's membership options to the \du+ command  ("David G. Johnston" <david.g.johnston@gmail.com>)
Responses Re: psql: Add role's membership options to the \du+ command
List pgsql-hackers
Hello,

On 22.02.2023 00:34, David G. Johnston wrote:
I didn't even know this function existed. But I see that it was changed in 3d14e171 with updated documentation:

I think that should probably have ADMIN as one of the options as well.  Also curious what it reports for an empty membership.

I've been experimenting for a few days and I want to admit that this is a very difficult and not obvious topic.
I'll try to summarize what I think.

1.
About ADMIN value for pg_has_role.
Implementation of ADMIN value will be different from USAGE and SET.
To be True, USAGE value requires the full chain of memberships to have INHERIT option.
Similar with SET: the full chain of memberships must have SET option.
But for ADMIN, only last member in the chain must have ADMIN option and all previous members
must have INHERIT (to administer directly) or SET option (to switch to role, last in the chain).
Therefore, it is not obvious to me that the function needs the ADMIN value.

2.
pg_has_role function description starts with: Does user have privilege for role?
    - This is not exact: function works not only with users, but with NOLOGIN roles too.
    - Term "privilege": this term used for ACL columns, such usage may be confusing,
      especially after adding INHERIT and SET in addition to ADMIN option.

    
3.
It is possible to grant membership with all three options turned off:
    grant a to b with admin false, inherit false, set false;

But such membership is completely useless (if i didn't miss something).
May be such grants must be prohibited. At least this may be documented in the GRANT command.


4.
Since v16 it is possible to grant membership from one role to another several times with different grantors.
And only grantor can revoke membership.

    - This is not documented anywhere.
    - Current behavior of \du command with duplicated roles in "Member of" column strongly confusing.
      This is one of the goals of the discussion patch.

    
I think to write about this to pgsql-docs additionally to this topic.
-- 
Pavel Luzanov
Postgres Professional: https://postgrespro.com

pgsql-hackers by date:

Previous
From: Alvaro Herrera
Date:
Subject: Re: cataloguing NOT NULL constraints
Next
From: John Naylor
Date:
Subject: Re: [PoC] Improve dead tuple storage for lazy vacuum