Re: pgsql: Add new GUC createrole_self_grant.

From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
Cc: Andres Freund <andres(at)anarazel(dot)de>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: pgsql: Add new GUC createrole_self_grant.
Date: 2023-01-15 00:31:30
Message-ID: CA+TgmobVQNWi92ijBUNHDc9Zt-K04=pruA-2MsQShv9bNnuQWQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers pgsql-hackers

On Fri, Jan 13, 2023 at 8:29 PM David G. Johnston
<david(dot)g(dot)johnston(at)gmail(dot)com> wrote:
>> The point of the security definer section is to explain how to safely write
>> security definer functions that you grant to less privileged users
>
> Yeah, we are really good at "how".
>
> + If the security definer function intends to create roles, and if it
> + is running as a non-superuser, <varname>createrole_self_grant</varname>
> + should also be set to a known value using the <literal>SET</literal>
> + clause.
>
> I'd like to know "why". Without knowing why we are adding this I can't give it a +1. I want the patch to include the why.

What don't you understand about the "why"? If your security-definer
function relies on some GUC having some particular value for some
security-critical purpose, and the caller can substitute some other
value, they might be able to create a security compromise. Since this
GUC has some connection to security, there is at least some distant
possibility of that happening. Reasonable people can, perhaps, differ
about how likely that is, but I don't really see what's confusing
about the theory. As a general statement about the human condition, if
you know that someone may be untrustworthy, you should be careful
about letting them influence your decisions. If you aren't, something
bad may happen to you.

The whole thing about SECURITY INVOKER functions is really a separate
issue. You can tell people how to write SECURITY DEFINER functions
more safely, and we do. You cannot tell them how to write SECURITY
INVOKER functions more safely, because the direction of the attack is
reversed. In the case of SECURITY DEFINER, the caller of the function
can attack the owner of the function. In the case of a SECURITY
INVOKER function, the owner of the function can attack the caller of
the function. We can't document how to write security invoker
functions safely because the author of the function is the one
potentially making an attack, and therefore would do the opposite of
whatever advice we gave. We *could* add whole new sections to the
documentation telling people to be careful about calling security
invoker functions, and that's a fine thing to discuss, but what I'm
doing here is following up an already-committed patch by adjusting
parts of the existing documentation to account for the changes.
Inventing whole new sections of the documentation would be a job for a
new patch on a new thread, not a follow-up patch on an existing
thread.

--
Robert Haas
EDB: http://www.enterprisedb.com

In response to

Responses

Browse pgsql-committers by date

  From Date Subject
Next Message David G. Johnston 2023-01-15 01:12:24 Re: pgsql: Add new GUC createrole_self_grant.
Previous Message Tatsuo Ishii 2023-01-14 09:18:10 pgsql: Doc: fix typo in backup.sgml.

Browse pgsql-hackers by date

  From Date Subject
Next Message Robert Haas 2023-01-15 00:32:20 Re: fixing CREATEROLE
Previous Message Tomas Vondra 2023-01-14 23:39:06 Re: logical decoding and replication of sequences, take 2