Re: set role command

From: Álvaro Herrera <alvherre(at)kurilemu(dot)de>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, Calvin Guo <newoakllc2023(at)gmail(dot)com>, pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: set role command
Date: 2025-11-24 17:05:50
Message-ID: 202511241648.tw7dx3ga7rxk@alvherre.pgsql
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 2025-Nov-24, Tom Lane wrote:

> Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at> writes:
> > On Mon, 2025-11-24 at 16:15 +0800, Calvin Guo wrote:
> > I respect your feelings, but that is not how SET ROLE works.
> > The current behavior is intentional and documented in
> > https://stream.boxwatch.ru/docs/current/sql-set-role.html
>
> And it's also required by the SQL standard, which is very clear
> that "user identifier" and "role" are different things, and
> SET ROLE only changes the latter.

For what it's worth, I think we break the SQL standard's security model
by providing RESET ROLE and RESET SESSION AUTHORIZATION, neither of
which the standard has. This means that in the standard model you have
commands to lower your privilege, but once you've lowered them, you
cannot return (in the same connection) to what you had.

Section 4.42 "Basic security model" of the 2023 edition of the standard
explains this. There is a stack of authorizations -- but when you do
SET SESSION AUTHORIZATION, you don't add another cell of the stack.
Instead, the current session user is replaced. They provide no way to
return. The stack is used for
<routine invocation>,
<externally-invoked procedure>,
triggered action,
<execute statement>, or
<direct SQL statement>
and the stack cell so created is automatically removed when that
operation completes.

Of course, I may be misreading the standard.

--
Álvaro Herrera Breisgau, Deutschland — https://www.EnterpriseDB.com/
"No renuncies a nada. No te aferres a nada."

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2025-11-24 18:43:31 Re: set role command
Previous Message Tom Lane 2025-11-24 16:18:20 Re: set role command