Re: set role command

From: Dominique Devienne <ddevienne(at)gmail(dot)com>
To: Calvin Guo <newoakllc2023(at)gmail(dot)com>
Cc: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: set role command
Date: 2025-11-24 13:46:20
Message-ID: CAFCRh-_evpaOaSNYqVNV7V2Fpibce4U4X11b3ZPj_HOqCPjseQ@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Mon, Nov 24, 2025 at 9:15 AM Calvin Guo <newoakllc2023(at)gmail(dot)com> wrote:
> I really feel, once you "set role usera", you should behave like usera, you should NOT have the power say:
> hi, I can assume my super user power whenever I want. As this make the "set role usera" pretty much useless.

SET ROLE is only about switching between USAGE and MEMBER of other ROLEs.
Since v16, one can control individual ROLE-to-ROLE GRANTs, for INHERIT'ance.
You can be GRANT'ed a ROLE, yet the permissions (ACLs on objects) associated to
that ROLE may not be "active", unless you INHERIT that ROLE. W/o INHERIT true,
you must explicit SET ROLE to that role, to activate that role and its
permissions.

I thought like you initially that after a SET ROLE, that restricted
which ROLE I could endorsed.
But no, of course. Restricting SET ROLE on ROLEs from the subgraph
makes no sense, when
you can RESET ROLE to "get back up" to your "root" role (your LOGIN
role, or SESSION_ROLE),
and then SET ROLE to a different subgraph role.

Any ROLE you are a MEMBER of, you can SET ROLE to, whatever the current_role.
But by playing with INHERIT'ance, you CAN control what's
active/effective, for a given current role.
One can always SET ROLE to some other ROLE, of course.

What really matters is who CONNECT'ed / logged-IN to the DB. I.e. who
is authenticated.
If you start as a SUPERUSER, then you can always become SUPERUSER again, as
Laurenz pointed out. Changing ROLE is only about activate this or that set of
permissions / privileges, on DB objects. Nothing more. --DD

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Rob Sargent 2025-11-24 15:43:07 Re: Schema design: user account deletion vs. keeping family tree data
Previous Message Bernice Southey 2025-11-24 13:17:53 Re: Schema design: user account deletion vs. keeping family tree data