pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andres Freund <andres@anarazel.de>
To: David G. Johnston <david.g.johnston@gmail.com>
Cc: Robert Haas <robertmhaas@gmail.com>
Cc: Tom Lane <tgl@sss.pgh.pa.us>
Cc: pgsql-hackers@postgresql.org <pgsql-hackers@postgresql.org>
Subject: Re: pgsql: Add new GUC createrole_self_grant.
Date: Fri, 13 Jan 2023 15:46:35 -0800
Message-ID: <20230113234635.kyelgvnnak6jxzlx@awork3.anarazel.de> (raw)
In-Reply-To: <CAKFQuwaMBdUkgMj=5ehyDBLb2UmPGUDmN9r5uY=fROXhkY30kw@mail.gmail.com>
References: <CA+TgmoZdOYxkPOWHD+3gG=DDccg9cDVYS8EtpO9EY85NNMaNtg@mail.gmail.com>
	<404209.1673404807@sss.pgh.pa.us>
	<CA+TgmoYzCt16YKRTZPQ-LYdWgkRAC7RuUxOkwBr_rhA3LoXg4g@mail.gmail.com>
	<408089.1673407504@sss.pgh.pa.us>
	<CA+Tgmob=67ghS9SQ8iEV5kMUQn_E4Bdp_=yvkdt8W74eu-v5tQ@mail.gmail.com>
	<668179.1673470826@sss.pgh.pa.us>
	<CA+TgmoYSh1Zi0UH77dre-+PHUyWkYcD2bbGBFcCeAEMsdDjcjw@mail.gmail.com>
	<CAKFQuwY7_W=JwPFb4ODw=9RTU+wbMEZUzKdCRsV28jU73c3LUg@mail.gmail.com>
	<CA+Tgmoauqd1cHQjsNEoxL5O-kEO4iC9dAPyCudSvmNqPJGmy9g@mail.gmail.com>
	<CAKFQuwaMBdUkgMj=5ehyDBLb2UmPGUDmN9r5uY=fROXhkY30kw@mail.gmail.com>

Hi,

On 2023-01-12 18:15:50 -0700, David G. Johnston wrote:
> On Thu, Jan 12, 2023 at 8:11 AM Robert Haas <robertmhaas@gmail.com> wrote:
> 
> > On Wed, Jan 11, 2023 at 7:53 PM David G. Johnston
> > <david.g.johnston@gmail.com> wrote:
> > > Justed wanted to chime in and say Robert has eloquently put into words
> > much of what I have been thinking here, and that I concur that guiding the
> > DBA to use care with the power they have been provided is a sane position
> > to take.
> > >
> > > +1, and thank you.
> >
> > Thanks!
> >
> > Here's a patch. In it I make three changes, only one of which is
> > directly relevant to the topic at hand:
> >
> > 1. Add a sentence to the documentation on writing SECURITY FUNCTIONS
> > safely concerning createrole_self_grant.
> > 2. Add a sentence to the documentation on SECURITY DEFINER referring
> > to the section about writing such functions safely.
> > 3. Remove a note discussing the fact that pre-8.3 versions did not
> > have SET clauses for functions.
> >
> > I can separate this into multiple patches if desired. And of course
> > you, Tom, or others may have suggestions on which of these changes
> > should be included at all or how to word them better.
> >
> >
> I'm still not really feeling how security definer is the problematic option
> here.  Security invoker scares me much more.

I don't really see what that has to do with the topic at hand, unless you want
to suggest removing the entire section about how to write secure security
definer functions?


> postgres=# create role unpriv login;
> CREATE ROLE
> postgres=# create role creator createrole login;
> CREATE ROLE
> postgres=# grant pg_read_all_data to creator with admin option;
> postgres=#
> create procedure makeunprivpowerful() LANGUAGE sql AS $$
> grant pg_read_all_data to unpriv;
> $$;
> CREATE PROCEDURE
> postgres=# alter procedure makeunprivpowerful() owner to unpriv;
> ALTER PROCEDURE
> 
> postgres=# \c postgres unpriv
> You are now connected to database "postgres" as user "unpriv".
> postgres=> call makeunprivpowerful();
> ERROR:  must have admin option on role "pg_read_all_data"
> CONTEXT:  SQL function "makeunprivpowerful" statement 1
> 
> postgres=# \c postgres creator
> You are now connected to database "postgres" as user "creator".
> postgres=> call makeunprivpowerful();
> CALL
> 
> Personally I think the best advice for a CREATEROLE granted user is to
> never call routines they themselves don't own; or at least only those have
> reviewed thoroughly and understand the consequences of.  Regardless of
> security definer/invoker.
> 
> In short, a low-privilege user can basically run anything without much fear
> because they can't do harm anyway.  Thus security invoker applies to them,
> and having security definer gives them the ability to do some things
> without needing to have permanent higher privileges.  These are useful,
> security related attributes with respect to them.
> 
> For a high-privilege I would argue that neither security invoker nor
> definer are relevant considerations from a security point-of-view.  If you
> have high-privilege you must know what it is you are executing before you
> execute it and anything bad it causes you to do using your privileges, or
> higher if you run a security definer function blindly, is an administrative
> failure, not a security hole.

The point of the security definer section is to explain how to safely write
security definer functions that you grant to less privileged users. It's not
about whether it's safe to call a security invoker / definer function -
indeed, if you don't trust the function author / owner, it's never safe to
call the function.


Greetings,

Andres Freund





view thread (20+ messages)  latest in thread

Message-ID: <20230113234635.kyelgvnnak6jxzlx@awork3.anarazel.de>
Permalink:  ../20230113234635.kyelgvnnak6jxzlx@awork3.anarazel.de/
Also on:    postgresql.org/message-id/20230113234635.kyelgvnnak6jxzlx@awork3.anarazel.de

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-committers@postgresql.org
  Cc: andres@anarazel.de, david.g.johnston@gmail.com, robertmhaas@gmail.com, tgl@sss.pgh.pa.us, pgsql-hackers@postgresql.org
  Subject: Re: pgsql: Add new GUC createrole_self_grant.
  In-Reply-To: <20230113234635.kyelgvnnak6jxzlx@awork3.anarazel.de>
  References: <CA+TgmoZdOYxkPOWHD+3gG=DDccg9cDVYS8EtpO9EY85NNMaNtg@mail.gmail.com> <404209.1673404807@sss.pgh.pa.us> <CA+TgmoYzCt16YKRTZPQ-LYdWgkRAC7RuUxOkwBr_rhA3LoXg4g@mail.gmail.com> <408089.1673407504@sss.pgh.pa.us> <CA+Tgmob=67ghS9SQ8iEV5kMUQn_E4Bdp_=yvkdt8W74eu-v5tQ@mail.gmail.com> <668179.1673470826@sss.pgh.pa.us> <CA+TgmoYSh1Zi0UH77dre-+PHUyWkYcD2bbGBFcCeAEMsdDjcjw@mail.gmail.com> <CAKFQuwY7_W=JwPFb4ODw=9RTU+wbMEZUzKdCRsV28jU73c3LUg@mail.gmail.com> <CA+Tgmoauqd1cHQjsNEoxL5O-kEO4iC9dAPyCudSvmNqPJGmy9g@mail.gmail.com> <CAKFQuwaMBdUkgMj=5ehyDBLb2UmPGUDmN9r5uY=fROXhkY30kw@mail.gmail.com> <20230113234635.kyelgvnnak6jxzlx@awork3.anarazel.de>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox