Re: psql: Add role's membership options to the \du+ command

From: Pavel Luzanov <p(dot)luzanov(at)postgrespro(dot)ru>
To: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
Cc: David Zhang <david(dot)zhang(at)highgo(dot)ca>, "pgsql-hackers(at)lists(dot)postgresql(dot)org" <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: psql: Add role's membership options to the \du+ command
Date: 2023-03-03 11:01:59
Message-ID: 20824093-d94f-e5d6-b611-8cec7fc6e95e@postgrespro.ru
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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:
> https://www.postgresql.org/docs/devel/functions-info.html#FUNCTIONS-INFO-ACCESS
> Maybe that's enough.
>
>
> 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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message John Naylor 2023-03-03 11:03:53 Re: [PoC] Improve dead tuple storage for lazy vacuum
Previous Message Alvaro Herrera 2023-03-03 10:47:28 Re: cataloguing NOT NULL constraints