Re: Additional role attributes && superuser review

Lists: pgsql-hackers
From: Stephen Frost <sfrost(at)snowman(dot)net>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Additional role attributes && superuser review
Date: 2014-10-15 05:22:59
Message-ID: 20141015052259.GG28859@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Greetings,

The attached patch for review implements a few additional role
attributes (all requested by users or clients in various forums) for
common operations which currently require superuser privileges. This
is not a complete solution for all of the superuser-only privileges we
have but it's certainly good progress and along the correct path, as
shown below in a review of the existing superuser checks in the
backend.

First though, the new privileges, about which the bikeshedding can
begin, short-and-sweet format:

BACKUP:
pg_start_backup()
pg_stop_backup()
pg_switch_xlog()
pg_create_restore_point()

LOGROTATE:
pg_rotate_logfile()

MONITOR:
View detailed information regarding other processes.
pg_stat_get_wal_senders()
pg_stat_get_activity()

PROCSIGNAL:
pg_signal_backend()
(not allowed to signal superuser-owned backends)

Before you ask, yes, this patch also does a bit of rework and cleanup.

Yes, that could be done as an independent patch- just ask, but the
changes are relatively minor. One curious item to note is that the
current if(!superuser()) {} block approach has masked an inconsistency
in at least the FDW code which required a change to the regression
tests- namely, we normally force FDW owners to have USAGE rights on
the FDW, but that was being bypassed when a superuser makes the call.
I seriously doubt that was intentional. I won't push back if someone
really wants it to stay that way though.

This also includes the previously discussed changes for pgstat and
friends to use role membership instead of GetUserId() == backend_role.

Full documentation is not included but will be forthcoming, of course.

As part of working through what the best solution is regarding the
existing superuser-only checks, I did a review of more-or-less all of
the ones which exist in the backend. From that review, I came to the
conclusion (certainly one which can be debated, but still) that most
cases of superuser() checks that should be possible for non-superusers
to do are yes/no privileges, except for when it comes to server-side
COPY and CREATE TABLESPACE operations, which need a form of
directory-level access control also (patch for that will be showing up
shortly..).

For posterity's sake, here's my review and comments on the various
existing superuser checks in the backend (those not addressed above):

CREATE EXTENSION
This could be a role attribute as the others above, but I didn't
want to try and include it in this patch as it has a lot of hairy
parts, I expect.

Connect using 'reserved' slots
This is another one which we might add as another role attribute.

Only needed during recovery, where it's fine to require superuser:
pg_xlog_replay_pause()
pg_xlog_replay_resume()

Directory / File access (addressed independently):
libpq/be/fsstubs.c
lo_import()
lo_export()

commands/tablespace.c - create tablespace
commands/copy.c - server-side COPY TO/FROM

utils/adt/genfile.c
pg_read_file() / pg_read_text_file() / pg_read_binary_file()
pg_stat_file()
pg_ls_dir()

Lots of things depend on being able to create C functions. These, in
my view, should either be done through extensions or should remain the
purview of the superuser. Below are the ones which I identified as
falling into this category:

commands/tsearchcmd.c
Create text search parser
Create text search template

tcop/utility.c
LOAD (load shared library)

commands/foreigncmds.c
Create FDW, Alter FDW
FDW ownership

commands/functioncmds.c
create binary-compatible casts
create untrusted-language functions

command/proclang.c
Create procedural languages (unless PL exists in pg_pltemplate)
Create custom procedural language

commands/opclasscmds.c
Create operator class
Create operator family
Alter operator family

commands/aggregatecmds.c
Create aggregates which use 'internal' types

commands/functioncmds.c
create leakproof functions
alter function to be leakproof

command/event_trigger.c
create event trigger

Other cases which I don't think would make sense to change (and some I
wonder if we should prevent the superuser from doing, unless they have
rolcatupdate or similar...):

commands/alter.c
rename objects (for objects which don't have an 'owner')
change object schema (ditto)

commands/trigger.c
enable or disable internal triggers

commands/functioncmds.c
execute DO blocks with untrusted languages

commands/dbcommands.c
allow encoding/locale to be different

commands/user.c
set 'superuser' on a role
alter superuser roles (other options)
drop superuser roles
alter role membership for superusers
force 'granted by' on a role grant
alter global settings
rename superuser roles

utils/misc/guc.c
set superuser-only GUCs
use ALTER SYSTEM
show ALL GUCs
get superuser-only GUC info
define custom placeholder GUC

utils/adt/misc.c
reload database configuration

utils/init/postinit.c
connect in binary upgrade mode
connect while database is shutting down

Another discussion could be had regarding the superuser-only GUCs.

Thanks!

Stephen

Attachment Content-Type Size
role-attributes.patch text/x-diff 51.1 KB

From: Jim Nasby <Jim(dot)Nasby(at)BlueTreble(dot)com>
To: Stephen Frost <sfrost(at)snowman(dot)net>, <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2014-10-16 06:27:08
Message-ID: 543F653C.9080605@BlueTreble.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 10/15/14, 12:22 AM, Stephen Frost wrote:
> BACKUP:
> pg_start_backup()
> pg_stop_backup()
> pg_switch_xlog()
> pg_create_restore_point()

It seems odd to me that this (presumably) supports PITR but not pg_dump*. I realize that most folks probably don't use pg_dump for actual backups, but I think it is very common to use it to produce schema-only (maybe with data from a few tables as well) dumps for developers. I've certainly wished I could offer that ability without going full-blown super-user.
--
Jim Nasby, Data Architect, Blue Treble Consulting
Data in Trouble? Get it in Treble! http://BlueTreble.com


From: Simon Riggs <simon(at)2ndQuadrant(dot)com>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2014-10-16 10:44:43
Message-ID: CA+U5nM+JxVvQ_07774Ty6KMChsNPTmS1v7JtqeA=TD8uTnv7Ww@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 15 October 2014 06:22, Stephen Frost <sfrost(at)snowman(dot)net> wrote:

> BACKUP:
> pg_start_backup()
> pg_stop_backup()
> pg_switch_xlog()
> pg_create_restore_point()

Yes, but its more complex. As Jim says, you need to include pg_dump,
plus you need to include the streaming utilities, e.g. pg_basebackup.

> LOGROTATE:
> pg_rotate_logfile()

Do we need one just for that?

> MONITOR:
> View detailed information regarding other processes.
> pg_stat_get_wal_senders()
> pg_stat_get_activity()

+1

> Connect using 'reserved' slots
> This is another one which we might add as another role attribute.

RESERVED?

Perhaps we need a few others also - BASHFUL, HAPPY, GRUMPY etc

--
Simon Riggs http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services


From: Petr Jelinek <petr(at)2ndquadrant(dot)com>
To: Stephen Frost <sfrost(at)snowman(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Additional role attributes && superuser review
Date: 2014-10-16 11:22:13
Message-ID: 543FAA65.3070905@2ndquadrant.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 15/10/14 07:22, Stephen Frost wrote:
>
> First though, the new privileges, about which the bikeshedding can
> begin, short-and-sweet format:
>
> BACKUP:
> pg_start_backup()
> pg_stop_backup()
> pg_switch_xlog()
> pg_create_restore_point()

As others have commented, I too think this should support pg_dump.

>
> For posterity's sake, here's my review and comments on the various
> existing superuser checks in the backend (those not addressed above):
>
> CREATE EXTENSION
> This could be a role attribute as the others above, but I didn't
> want to try and include it in this patch as it has a lot of hairy
> parts, I expect.

Yeah it will, mainly because extensions can load modules and can have
untrusted functions, we might want to limit which extensions are
possible to create without being superuser.

>
> tcop/utility.c
> LOAD (load shared library)
>

This already somewhat handles non-superuser access. You can do LOAD as
normal user as long as the library is in $libdir/plugins directory so it
probably does not need separate role attribute (might be somehow useful
in combination with CREATE EXTENSION though).

>
> commands/functioncmds.c
> create untrusted-language functions
>

I often needed more granularity there (plproxy).

>
> commands/functioncmds.c
> execute DO blocks with untrusted languages
>

I am not sure if this is significantly different from untrusted-language
functions.

--
Petr Jelinek http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Petr Jelinek <petr(at)2ndquadrant(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Additional role attributes && superuser review
Date: 2014-10-16 11:44:48
Message-ID: 20141016114448.GP28859@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

* Petr Jelinek (petr(at)2ndquadrant(dot)com) wrote:
> On 15/10/14 07:22, Stephen Frost wrote:
> > First though, the new privileges, about which the bikeshedding can
> > begin, short-and-sweet format:
> >
> > BACKUP:
> > pg_start_backup()
> > pg_stop_backup()
> > pg_switch_xlog()
> > pg_create_restore_point()
>
> As others have commented, I too think this should support pg_dump.

I'm uttly mystified as to what that *means*. Everyone asking for it is
great but until someone can define what "support pg_dump" means, there's
not much progress I can make towards it..

pg_dump doesn't require superuser rights today. If you're looking for a
role which allows a user to arbitrairly read all data, fine, but that's
a different consideration and would be a different role attribute, imv.
If you'd like the role attribute renamed to avoid confusion, I'm all for
that, just suggest something.

> > For posterity's sake, here's my review and comments on the various
> > existing superuser checks in the backend (those not addressed above):
> >
> > CREATE EXTENSION
> > This could be a role attribute as the others above, but I didn't
> > want to try and include it in this patch as it has a lot of hairy
> > parts, I expect.
>
> Yeah it will, mainly because extensions can load modules and can
> have untrusted functions, we might want to limit which extensions
> are possible to create without being superuser.

The extension has to be available on the filesystem before it can be
created, of course. I'm not against providing some kind of whitelist or
similar which a superuser could control.. That's similar to how PLs
work wrt pltemplate, no?

> > tcop/utility.c
> > LOAD (load shared library)
>
> This already somewhat handles non-superuser access. You can do LOAD
> as normal user as long as the library is in $libdir/plugins
> directory so it probably does not need separate role attribute
> (might be somehow useful in combination with CREATE EXTENSION
> though).

Ah, fair enough. Note that I wasn't suggesting this be changed, just
noting it in my overall review.

> > commands/functioncmds.c
> > create untrusted-language functions
>
> I often needed more granularity there (plproxy).

Not sure what you're getting at..? Is there a level of 'granularity'
for this which would make it safe for non-superusers to create
untrusted-language functions? I would think that'd be handled mainly
through extensions, but certainly curious what others think.

> > commands/functioncmds.c
> > execute DO blocks with untrusted languages
>
> I am not sure if this is significantly different from
> untrusted-language functions.

Nope, just another case where we're doing a superuser() check.

Thanks!

Stephen


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Simon Riggs <simon(at)2ndQuadrant(dot)com>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2014-10-16 11:59:14
Message-ID: 20141016115914.GQ28859@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

* Simon Riggs (simon(at)2ndQuadrant(dot)com) wrote:
> On 15 October 2014 06:22, Stephen Frost <sfrost(at)snowman(dot)net> wrote:
> > BACKUP:
> > pg_start_backup()
> > pg_stop_backup()
> > pg_switch_xlog()
> > pg_create_restore_point()
>
> Yes, but its more complex. As Jim says, you need to include pg_dump,
> plus you need to include the streaming utilities, e.g. pg_basebackup.

I'd rather have more, simpler, role attributes than one 'catch-all'.

Once I understand what "include pg_dump" and "include pg_basebackup"
mean, I'd be happy to work on adding those.

> > LOGROTATE:
> > pg_rotate_logfile()
>
> Do we need one just for that?

It didn't seem to "belong" to any others and it's currently limited to
superuser but useful for non-superusers, so I would argue 'yes'. Now,
another option (actually, for many of these...) would be to trust in our
authorization system (GRANT EXECUTE) and remove the explicit superuser
check inside the functions, revoke EXECUTE from public, and tell users
to GRANT EXECUTE to the roles which should be allowed.

> > MONITOR:
> > View detailed information regarding other processes.
> > pg_stat_get_wal_senders()
> > pg_stat_get_activity()
>
> +1
>
> > Connect using 'reserved' slots
> > This is another one which we might add as another role attribute.
>
> RESERVED?

Seems reasonable, but do we need another GUC for how many connections
are reserved for 'RESERVED' roles? Or are we happy to allow those with
the RESERVED role attribute to contend for the same slots as superusers?

For my 2c- I'm happy to continue to have just one 'pool' of reserved
connections and just allow roles with RESERVED to connect using those
slots also.

> Perhaps we need a few others also - BASHFUL, HAPPY, GRUMPY etc

Hah. :)

There was a suggestion raised (by Robert, I believe) that we store these
additional role attributes as a bitmask instead of individual columns.
I'm fine with either way, but it'd be a backwards-incompatible change
for anyone who looks at pg_authid. This would be across a major version
change, of course, so we are certainly within rights to do so, but I'm
also not sure how much we need to worry about a few bytes per pg_authid
row; we still have other issues if we want to try and support millions
of roles, starting with the inability to partition catalogs..

Thanks!

Stephen


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Jim Nasby <Jim(dot)Nasby(at)BlueTreble(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Additional role attributes && superuser review
Date: 2014-10-16 12:21:53
Message-ID: 20141016122152.GT28859@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Jim,

* Jim Nasby (Jim(dot)Nasby(at)BlueTreble(dot)com) wrote:
> On 10/15/14, 12:22 AM, Stephen Frost wrote:
> > BACKUP:
> > pg_start_backup()
> > pg_stop_backup()
> > pg_switch_xlog()
> > pg_create_restore_point()
>
> It seems odd to me that this (presumably) supports PITR but not pg_dump*. I realize that most folks probably don't use pg_dump for actual backups, but I think it is very common to use it to produce schema-only (maybe with data from a few tables as well) dumps for developers. I've certainly wished I could offer that ability without going full-blown super-user.

Can you clarify what you mean by "supports PITR but not pg_dump"?

The role attribute specifically allows a user to execute those
functions. Further, yes, this capability could be given to a role which
is used by, say, barman, to backup the database, or by other backup
solutions which do filesystem backups, but what do you mean by "does not
support pg_dump"?

What I think you're getting at here is a role attribute which can read
all data, which could certainly be done (as, say, a "READONLY"
attribute), but I view that a bit differently, as it could be used for
auditing and other purposes besides just non-superuser pg_dump support.

Thanks!

Stephen


From: Magnus Hagander <magnus(at)hagander(dot)net>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>, Simon Riggs <simon(at)2ndquadrant(dot)com>
Subject: Re: Additional role attributes && superuser review
Date: 2014-10-16 12:29:51
Message-ID: CABUevEyxdJE3kh5b0s7hjLd0VyG4B9ksmpX9PVzeD13t3Fh=uA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Oct 16, 2014 1:59 PM, "Stephen Frost" <sfrost(at)snowman(dot)net> wrote:
>
> * Simon Riggs (simon(at)2ndQuadrant(dot)com) wrote:
> > On 15 October 2014 06:22, Stephen Frost <sfrost(at)snowman(dot)net> wrote:
> > > BACKUP:
> > > pg_start_backup()
> > > pg_stop_backup()
> > > pg_switch_xlog()
> > > pg_create_restore_point()
> >
> > Yes, but its more complex. As Jim says, you need to include pg_dump,
> > plus you need to include the streaming utilities, e.g. pg_basebackup.
>
> I'd rather have more, simpler, role attributes than one 'catch-all'.
>
> Once I understand what "include pg_dump" and "include pg_basebackup"
> mean, I'd be happy to work on adding those.
>

Include pg_basebackup would mean the replication protocol methods for base
backup and streaming. Which is already covered by the REPLICATION flag.

But in think it's somewhat useful to separate these. Being able to execute
pg_stop_backup allows you to break somebody else's backup currently
running, which pg_basebackup is safe against. So being able to call those
functions is clearly a higher privilege than being able to use
pg_basebackup.

/Magnus


From: Petr Jelinek <petr(at)2ndquadrant(dot)com>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Additional role attributes && superuser review
Date: 2014-10-16 12:46:25
Message-ID: 543FBE21.5060501@2ndquadrant.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 16/10/14 13:44, Stephen Frost wrote:
> * Petr Jelinek (petr(at)2ndquadrant(dot)com) wrote:
>> On 15/10/14 07:22, Stephen Frost wrote:
>>> First though, the new privileges, about which the bikeshedding can
>>> begin, short-and-sweet format:
>>>
>>> BACKUP:
>>> pg_start_backup()
>>> pg_stop_backup()
>>> pg_switch_xlog()
>>> pg_create_restore_point()
>>
>> As others have commented, I too think this should support pg_dump.
>
> I'm uttly mystified as to what that *means*. Everyone asking for it is
> great but until someone can define what "support pg_dump" means, there's
> not much progress I can make towards it..

The explanation you wrote to Jim makes sense, plus given the comment
from Magnus about REPLICATION flag I guess I am happy enough with it (I
might have liked to have REPLICATION flag to somehow be part of BACKUP
flag but that's very minor thing).

>>>
>>> CREATE EXTENSION
>>> This could be a role attribute as the others above, but I didn't
>>> want to try and include it in this patch as it has a lot of hairy
>>> parts, I expect.
>>
>> Yeah it will, mainly because extensions can load modules and can
>> have untrusted functions, we might want to limit which extensions
>> are possible to create without being superuser.
>
> The extension has to be available on the filesystem before it can be
> created, of course. I'm not against providing some kind of whitelist or
> similar which a superuser could control.. That's similar to how PLs
> work wrt pltemplate, no?
>

Makes sense, there is actually extension called pgextwlist which does this.

>>> commands/functioncmds.c
>>> create untrusted-language functions
>>
>> I often needed more granularity there (plproxy).
>
> Not sure what you're getting at..? Is there a level of 'granularity'
> for this which would make it safe for non-superusers to create
> untrusted-language functions? I would think that'd be handled mainly
> through extensions, but certainly curious what others think.
>

I've been in situation where I wanted to give access to *some* untrusted
languages to non-superuser (as not every untrusted language can do same
kind of damage) and had to solve it via scripting outside of pg.

--
Petr Jelinek http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services


From: Simon Riggs <simon(at)2ndQuadrant(dot)com>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2014-10-16 13:06:56
Message-ID: CA+U5nMJGVdz6jX_YBJk99Nj7mWfGfVEmxtdc44LVHq64gkN8qg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 16 October 2014 12:59, Stephen Frost <sfrost(at)snowman(dot)net> wrote:

>> > LOGROTATE:
>> > pg_rotate_logfile()
>>
>> Do we need one just for that?
>
> It didn't seem to "belong" to any others and it's currently limited to
> superuser but useful for non-superusers, so I would argue 'yes'. Now,
> another option (actually, for many of these...) would be to trust in our
> authorization system (GRANT EXECUTE) and remove the explicit superuser
> check inside the functions, revoke EXECUTE from public, and tell users
> to GRANT EXECUTE to the roles which should be allowed.

Seems like OPERATOR would be a general description that could be
useful elsewhere.

> There was a suggestion raised (by Robert, I believe) that we store these
> additional role attributes as a bitmask instead of individual columns.
> I'm fine with either way, but it'd be a backwards-incompatible change
> for anyone who looks at pg_authid. This would be across a major version
> change, of course, so we are certainly within rights to do so, but I'm
> also not sure how much we need to worry about a few bytes per pg_authid
> row; we still have other issues if we want to try and support millions
> of roles, starting with the inability to partition catalogs..

I assumed that was an internal change for fast access.

An array of role attributes would be extensible and more databasey.

--
Simon Riggs http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Magnus Hagander <magnus(at)hagander(dot)net>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>, Simon Riggs <simon(at)2ndquadrant(dot)com>
Subject: Re: Additional role attributes && superuser review
Date: 2014-10-16 13:18:15
Message-ID: 20141016131815.GU28859@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

* Magnus Hagander (magnus(at)hagander(dot)net) wrote:
> On Oct 16, 2014 1:59 PM, "Stephen Frost" <sfrost(at)snowman(dot)net> wrote:
> > Once I understand what "include pg_dump" and "include pg_basebackup"
> > mean, I'd be happy to work on adding those.
>
> Include pg_basebackup would mean the replication protocol methods for base
> backup and streaming. Which is already covered by the REPLICATION flag.

Well, right. I had the impression there was some distinction that I
just wasn't getting.

> But in think it's somewhat useful to separate these. Being able to execute
> pg_stop_backup allows you to break somebody else's backup currently
> running, which pg_basebackup is safe against. So being able to call those
> functions is clearly a higher privilege than being able to use
> pg_basebackup.

Agreed.

Thanks!

Stephen


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Petr Jelinek <petr(at)2ndquadrant(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Additional role attributes && superuser review
Date: 2014-10-16 13:21:47
Message-ID: 20141016132147.GV28859@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

* Petr Jelinek (petr(at)2ndquadrant(dot)com) wrote:
> The explanation you wrote to Jim makes sense, plus given the comment
> from Magnus about REPLICATION flag I guess I am happy enough with it
> (I might have liked to have REPLICATION flag to somehow be part of
> BACKUP flag but that's very minor thing).

k. :)

> >The extension has to be available on the filesystem before it can be
> >created, of course. I'm not against providing some kind of whitelist or
> >similar which a superuser could control.. That's similar to how PLs
> >work wrt pltemplate, no?
> >
>
> Makes sense, there is actually extension called pgextwlist which does this.

Yeah. Not sure if that should only exist as an extension, but that's
really a conversation for a different thread.

> >Not sure what you're getting at..? Is there a level of 'granularity'
> >for this which would make it safe for non-superusers to create
> >untrusted-language functions? I would think that'd be handled mainly
> >through extensions, but certainly curious what others think.
>
> I've been in situation where I wanted to give access to *some*
> untrusted languages to non-superuser (as not every untrusted
> language can do same kind of damage) and had to solve it via
> scripting outside of pg.

Really curious what untrusted language you're referring to which isn't
as risky as others..? Any kind of filesystem or network access, or the
ability to run external commands, is dangerous to give non-superusers.

Perhaps more to the point- what would the more granular solution look
like..? Though, this is still getting a bit off-topic for this thread.

Thanks!

Stephen


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Simon Riggs <simon(at)2ndQuadrant(dot)com>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2014-10-16 13:32:18
Message-ID: 20141016133218.GW28859@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

* Simon Riggs (simon(at)2ndQuadrant(dot)com) wrote:
> On 16 October 2014 12:59, Stephen Frost <sfrost(at)snowman(dot)net> wrote:
> >> > LOGROTATE:
> >> > pg_rotate_logfile()
> >>
> >> Do we need one just for that?
> >
> > It didn't seem to "belong" to any others and it's currently limited to
> > superuser but useful for non-superusers, so I would argue 'yes'. Now,
> > another option (actually, for many of these...) would be to trust in our
> > authorization system (GRANT EXECUTE) and remove the explicit superuser
> > check inside the functions, revoke EXECUTE from public, and tell users
> > to GRANT EXECUTE to the roles which should be allowed.
>
> Seems like OPERATOR would be a general description that could be
> useful elsewhere.

Ok.. but what else? Are there specific functions which aren't covered
by these role attributes which should be and could fall into this
category? I'm not against the idea of an 'operator' role, but I don't
like the idea that it means 'logrotate, until we figure out some other
thing which makes sense to put into this category'. For one thing, this
approach would mean that future version which add more rights to the
'operator' role attribute would mean that upgrades are granting rights
which didn't previously exist..

> > There was a suggestion raised (by Robert, I believe) that we store these
> > additional role attributes as a bitmask instead of individual columns.
> > I'm fine with either way, but it'd be a backwards-incompatible change
> > for anyone who looks at pg_authid. This would be across a major version
> > change, of course, so we are certainly within rights to do so, but I'm
> > also not sure how much we need to worry about a few bytes per pg_authid
> > row; we still have other issues if we want to try and support millions
> > of roles, starting with the inability to partition catalogs..
>
> I assumed that was an internal change for fast access.

We could make it that way by turning pg_authid into a view and using a
new catalog table for roles instead (similar to what we did with
pg_user ages ago when we added roles), but that feels like overkill to
me.

> An array of role attributes would be extensible and more databasey.

Hrm. Agreed, and it would save a bit of space for the common case where
the user hasn't got any of these attributes, though it wouldn't be as
efficient as a bitmap.

For my part, I'm not really wedded to any particular catalog
representation. Having reviewed the various superuser checks, I think
there's a few more role attributes which could/should be added beyond
the ones listed, but I don't think we'll ever get to 64 of them, so a
single int64 would work if we want the most compact solution.

Thanks!

Stephen


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: Petr Jelinek <petr(at)2ndquadrant(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Additional role attributes && superuser review
Date: 2014-10-16 13:59:36
Message-ID: 6607.1413467976@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Stephen Frost <sfrost(at)snowman(dot)net> writes:
> * Petr Jelinek (petr(at)2ndquadrant(dot)com) wrote:
>> Yeah it will, mainly because extensions can load modules and can
>> have untrusted functions, we might want to limit which extensions
>> are possible to create without being superuser.

> The extension has to be available on the filesystem before it can be
> created, of course. I'm not against providing some kind of whitelist or
> similar which a superuser could control.. That's similar to how PLs
> work wrt pltemplate, no?

The existing behavior is "you can create an extension if you can execute
all the commands contained in its script". I'm not sure that messing
with that rule is a good idea; in any case it seems well out of scope
for this patch.

regards, tom lane


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Petr Jelinek <petr(at)2ndquadrant(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Additional role attributes && superuser review
Date: 2014-10-16 14:02:38
Message-ID: 20141016140238.GC28859@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

* Tom Lane (tgl(at)sss(dot)pgh(dot)pa(dot)us) wrote:
> Stephen Frost <sfrost(at)snowman(dot)net> writes:
> > * Petr Jelinek (petr(at)2ndquadrant(dot)com) wrote:
> >> Yeah it will, mainly because extensions can load modules and can
> >> have untrusted functions, we might want to limit which extensions
> >> are possible to create without being superuser.
>
> > The extension has to be available on the filesystem before it can be
> > created, of course. I'm not against providing some kind of whitelist or
> > similar which a superuser could control.. That's similar to how PLs
> > work wrt pltemplate, no?
>
> The existing behavior is "you can create an extension if you can execute
> all the commands contained in its script". I'm not sure that messing
> with that rule is a good idea; in any case it seems well out of scope
> for this patch.

Right, that's the normal rule. I still like the idea of letting
non-superusers create "safe" extensions, but I completely agree- beyond
the scope of this patch (as I noted in my initial post).

Thanks!

Stephen


From: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: Petr Jelinek <petr(at)2ndquadrant(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Additional role attributes && superuser review
Date: 2014-10-16 15:24:21
Message-ID: 20141016152421.GR7043@eldon.alvh.no-ip.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Stephen Frost wrote:
> * Petr Jelinek (petr(at)2ndquadrant(dot)com) wrote:
> > On 15/10/14 07:22, Stephen Frost wrote:
> > > First though, the new privileges, about which the bikeshedding can
> > > begin, short-and-sweet format:
> > >
> > > BACKUP:
> > > pg_start_backup()
> > > pg_stop_backup()
> > > pg_switch_xlog()
> > > pg_create_restore_point()
> >
> > As others have commented, I too think this should support pg_dump.
>
> I'm uttly mystified as to what that *means*. Everyone asking for it is
> great but until someone can define what "support pg_dump" means, there's
> not much progress I can make towards it..

To me, what this repeated discussion on this particular BACKUP point
says, is that the ability to run pg_start/stop_backend and the xlog
related functions should be a different privilege, i.e. something other
than BACKUP; because later we will want the ability to grant someone the
ability to run pg_dump on the whole database without being superuser,
and we will want to use the name BACKUP for that. So I'm inclined to
propose something more specific for this like WAL_CONTROL or
XLOG_OPERATOR, say.

> pg_dump doesn't require superuser rights today. If you're looking for a
> role which allows a user to arbitrairly read all data, fine, but that's
> a different consideration and would be a different role attribute, imv.
> If you'd like the role attribute renamed to avoid confusion, I'm all for
> that, just suggest something.

There.

(Along the same lines, perhaps the log rotate thingy that's being
mentioned elsewhere could be LOG_OPERATOR instead of just OPERATOR, to
avoid privilege "upgrades" as later releases include more capabilities
to the hypothetical OPERATOR capability.)

--
Álvaro Herrera http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
Cc: Petr Jelinek <petr(at)2ndquadrant(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Additional role attributes && superuser review
Date: 2014-10-16 15:47:51
Message-ID: 20141016154751.GE28859@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Alvaro,

* Alvaro Herrera (alvherre(at)2ndquadrant(dot)com) wrote:
> Stephen Frost wrote:
> > * Petr Jelinek (petr(at)2ndquadrant(dot)com) wrote:
> > > On 15/10/14 07:22, Stephen Frost wrote:
> > > > First though, the new privileges, about which the bikeshedding can
> > > > begin, short-and-sweet format:
> > > >
> > > > BACKUP:
> > > > pg_start_backup()
> > > > pg_stop_backup()
> > > > pg_switch_xlog()
> > > > pg_create_restore_point()
> > >
> > > As others have commented, I too think this should support pg_dump.
> >
> > I'm uttly mystified as to what that *means*. Everyone asking for it is
> > great but until someone can define what "support pg_dump" means, there's
> > not much progress I can make towards it..
>
> To me, what this repeated discussion on this particular BACKUP point
> says, is that the ability to run pg_start/stop_backend and the xlog
> related functions should be a different privilege, i.e. something other
> than BACKUP; because later we will want the ability to grant someone the
> ability to run pg_dump on the whole database without being superuser,
> and we will want to use the name BACKUP for that. So I'm inclined to
> propose something more specific for this like WAL_CONTROL or
> XLOG_OPERATOR, say.

Ok. Not sure that I see 'XLOG_OPERATOR' as making sense for
'pg_start_backup' though, and I see the need to support pg_dump'ing the
whole database as a non-superuser being more like a 'READONLY' kind of
role.

We've actually already looked at the notion of a 'READONLY' or 'READALL'
role attribute and, well, it's quite simple to implement.. We're
talking about a few lines of code to implicitly allow 'USAGE' on all
schemas, plus a minor change in ExecCheckRTEPerms to always (or perhaps
*only*) include SELECT rights. As there's so much interest in that
capability, perhaps we should add it..

One of the big question is- do we take steps to try and prevent a role
with this attribute from being able to modify the database in any way?
Or would this role attribute only ever increase your rights?

> > pg_dump doesn't require superuser rights today. If you're looking for a
> > role which allows a user to arbitrairly read all data, fine, but that's
> > a different consideration and would be a different role attribute, imv.
> > If you'd like the role attribute renamed to avoid confusion, I'm all for
> > that, just suggest something.
>
> There.

Fair enough, just don't like the specific suggestions. :) In the docs,
we talk about pg_start_backup being for 'on-line' backups, perhaps we
use ONLINE_BACKUP ? Or PITR_BACKUP ?

> (Along the same lines, perhaps the log rotate thingy that's being
> mentioned elsewhere could be LOG_OPERATOR instead of just OPERATOR, to
> avoid privilege "upgrades" as later releases include more capabilities
> to the hypothetical OPERATOR capability.)

I'd be fine calling it LOG_OPERATOR instead, sure.

Thanks!

Stephen


From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
Cc: Stephen Frost <sfrost(at)snowman(dot)net>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2014-10-16 18:43:36
Message-ID: CA+TgmoYrQV_QnfGJPbZFJ03fGA5ydpm=Aa+Mw=n0+rmjq19xbw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Thu, Oct 16, 2014 at 11:24 AM, Alvaro Herrera
<alvherre(at)2ndquadrant(dot)com> wrote:
> Stephen Frost wrote:
>> * Petr Jelinek (petr(at)2ndquadrant(dot)com) wrote:
>> > On 15/10/14 07:22, Stephen Frost wrote:
>> > > First though, the new privileges, about which the bikeshedding can
>> > > begin, short-and-sweet format:
>> > >
>> > > BACKUP:
>> > > pg_start_backup()
>> > > pg_stop_backup()
>> > > pg_switch_xlog()
>> > > pg_create_restore_point()
>> >
>> > As others have commented, I too think this should support pg_dump.
>>
>> I'm uttly mystified as to what that *means*. Everyone asking for it is
>> great but until someone can define what "support pg_dump" means, there's
>> not much progress I can make towards it..
>
> To me, what this repeated discussion on this particular BACKUP point
> says, is that the ability to run pg_start/stop_backend and the xlog
> related functions should be a different privilege, i.e. something other
> than BACKUP; because later we will want the ability to grant someone the
> ability to run pg_dump on the whole database without being superuser,
> and we will want to use the name BACKUP for that. So I'm inclined to
> propose something more specific for this like WAL_CONTROL or
> XLOG_OPERATOR, say.

I'm a little nervous that we're going to end up with a whole bunch of
things with names like X_control, Y_operator, and Z_admin, which I
think is particularly bad if we end up with a mix of styles and also
bad (though less so) if we end up just tacking the word "operator"
onto the end of everything.

I'd suggest calling these capabilities, and allow:

GRANT CAPABILITY whatever TO somebody;

...but keep extraneous words like "control" or "operator" out of the
capabilities names themselves. So just wal, xlog, logfile, etc.
rather than wal_operator, xlog_operator, logfile_operator and so on.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2014-10-16 18:59:35
Message-ID: 20141016185935.GG28859@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

* Robert Haas (robertmhaas(at)gmail(dot)com) wrote:
> On Thu, Oct 16, 2014 at 11:24 AM, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com> wrote:
> > To me, what this repeated discussion on this particular BACKUP point
> > says, is that the ability to run pg_start/stop_backend and the xlog
> > related functions should be a different privilege, i.e. something other
> > than BACKUP; because later we will want the ability to grant someone the
> > ability to run pg_dump on the whole database without being superuser,
> > and we will want to use the name BACKUP for that. So I'm inclined to
> > propose something more specific for this like WAL_CONTROL or
> > XLOG_OPERATOR, say.
>
> I'm a little nervous that we're going to end up with a whole bunch of
> things with names like X_control, Y_operator, and Z_admin, which I
> think is particularly bad if we end up with a mix of styles and also
> bad (though less so) if we end up just tacking the word "operator"
> onto the end of everything.

Yeah, that's certainly a good point.

> I'd suggest calling these capabilities, and allow:
>
> GRANT CAPABILITY whatever TO somebody;

So, we went back to just role attributes to avoid the keyword issue..
The above would require making 'CAPABILITY' a reserved word, and there
really isn't a 'good' already-reserved word we can use there that I
found.

Also, role attributes aren't inheirited nor is there an 'ADMIN' option
for them as there is for GRANT- both of which I feel are correct for
these capabilities. Or, to say it another way, I don't think these
should have an 'ADMIN' option and I don't think they need to be
inheirited through role membership the way granted privileges are.

We could still use 'GRANT <keyword> whatever TO somebody;' without the
admin opton and without inheiritance, but I think it'd just be
confusing for users who are familiar with how GRANT works already.

Thanks!

Stephen


From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2014-10-16 19:04:00
Message-ID: CA+TgmoZt1WDjY+kTcKVhTG4DFBzm_ZvrM5E7wtRxb0cdErDDhA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Thu, Oct 16, 2014 at 2:59 PM, Stephen Frost <sfrost(at)snowman(dot)net> wrote:
> * Robert Haas (robertmhaas(at)gmail(dot)com) wrote:
>> On Thu, Oct 16, 2014 at 11:24 AM, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com> wrote:
>> > To me, what this repeated discussion on this particular BACKUP point
>> > says, is that the ability to run pg_start/stop_backend and the xlog
>> > related functions should be a different privilege, i.e. something other
>> > than BACKUP; because later we will want the ability to grant someone the
>> > ability to run pg_dump on the whole database without being superuser,
>> > and we will want to use the name BACKUP for that. So I'm inclined to
>> > propose something more specific for this like WAL_CONTROL or
>> > XLOG_OPERATOR, say.
>>
>> I'm a little nervous that we're going to end up with a whole bunch of
>> things with names like X_control, Y_operator, and Z_admin, which I
>> think is particularly bad if we end up with a mix of styles and also
>> bad (though less so) if we end up just tacking the word "operator"
>> onto the end of everything.
>
> Yeah, that's certainly a good point.
>
>> I'd suggest calling these capabilities, and allow:
>>
>> GRANT CAPABILITY whatever TO somebody;
>
> So, we went back to just role attributes to avoid the keyword issue..
> The above would require making 'CAPABILITY' a reserved word, and there
> really isn't a 'good' already-reserved word we can use there that I
> found.

Ah, good point. Using ALTER ROLE is better. Maybe we should do ALTER
ROLE .. [ ADD | DROP ] CAPABILITY x. That would still require making
CAPABILITY a keyword, but it could be unreserved.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2014-10-16 19:09:46
Message-ID: 20141016190945.GI28859@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

* Robert Haas (robertmhaas(at)gmail(dot)com) wrote:
> Ah, good point. Using ALTER ROLE is better. Maybe we should do ALTER
> ROLE .. [ ADD | DROP ] CAPABILITY x. That would still require making
> CAPABILITY a keyword, but it could be unreserved.

That works for me- would we change the existing role attributes to be
configurable this way and change everything over to using an int64 in
the catalog? Unless I'm having trouble counting, I think that would
actually result in the pg_authid catalog not changing in size at all
while giving us the ability to add these capabilities and something like
50 others if we had cause to.

Thanks,

Stephen


From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2014-10-16 19:27:02
Message-ID: CA+TgmobkYXNOWKEKzX2qGPSr_nvacFGueV=orxND-xmZvOVYvg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Thu, Oct 16, 2014 at 3:09 PM, Stephen Frost <sfrost(at)snowman(dot)net> wrote:
> * Robert Haas (robertmhaas(at)gmail(dot)com) wrote:
>> Ah, good point. Using ALTER ROLE is better. Maybe we should do ALTER
>> ROLE .. [ ADD | DROP ] CAPABILITY x. That would still require making
>> CAPABILITY a keyword, but it could be unreserved.
>
> That works for me- would we change the existing role attributes to be
> configurable this way and change everything over to using an int64 in
> the catalog? Unless I'm having trouble counting, I think that would
> actually result in the pg_authid catalog not changing in size at all
> while giving us the ability to add these capabilities and something like
> 50 others if we had cause to.

I definitely think we should support the new syntax for the existing
attributes. I could go either way on whether to change the catalog
storage for the existing attributes. Some people might prefer to
avoid the backward compatibility break, and I can see that argument.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2014-10-16 19:34:54
Message-ID: 20141016193454.GJ28859@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

* Robert Haas (robertmhaas(at)gmail(dot)com) wrote:
> On Thu, Oct 16, 2014 at 3:09 PM, Stephen Frost <sfrost(at)snowman(dot)net> wrote:
> > * Robert Haas (robertmhaas(at)gmail(dot)com) wrote:
> >> Ah, good point. Using ALTER ROLE is better. Maybe we should do ALTER
> >> ROLE .. [ ADD | DROP ] CAPABILITY x. That would still require making
> >> CAPABILITY a keyword, but it could be unreserved.
> >
> > That works for me- would we change the existing role attributes to be
> > configurable this way and change everything over to using an int64 in
> > the catalog? Unless I'm having trouble counting, I think that would
> > actually result in the pg_authid catalog not changing in size at all
> > while giving us the ability to add these capabilities and something like
> > 50 others if we had cause to.
>
> I definitely think we should support the new syntax for the existing
> attributes.

Ok.

> I could go either way on whether to change the catalog
> storage for the existing attributes. Some people might prefer to
> avoid the backward compatibility break, and I can see that argument.

There's really two issues when it comes to backwards compatibility here-
the catalog representation and the syntax.

My feeling is basically this- either we make a clean break to the new
syntax and catalog representation, or we just use the same approach the
existing attriubtes use. Long term, I think your proposed syntax and an
int64 representation is better but it'll mean a lot of client code that
has to change. I don't really like the idea of changing the syntax but
not the representation, nor am I thrilled with the idea of supporting
both syntaxes, and changing the syntax without changing the
representation just doesn't make sense to me as I think we'd end up
wanting to change it later, making clients have to update their code
twice.

Thanks!

Stephen


From: Simon Riggs <simon(at)2ndQuadrant(dot)com>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Stephen Frost <sfrost(at)snowman(dot)net>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2014-10-16 19:35:07
Message-ID: CA+U5nMKoHB9cahd1sTiXOOcZNa_HwPajX-exMKQh2G6g1e-_9w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 16 October 2014 20:04, Robert Haas <robertmhaas(at)gmail(dot)com> wrote:

>>> I'd suggest calling these capabilities, and allow:
>>>
>>> GRANT CAPABILITY whatever TO somebody;
>>
>> So, we went back to just role attributes to avoid the keyword issue..
>> The above would require making 'CAPABILITY' a reserved word, and there
>> really isn't a 'good' already-reserved word we can use there that I
>> found.
>
> Ah, good point. Using ALTER ROLE is better. Maybe we should do ALTER
> ROLE .. [ ADD | DROP ] CAPABILITY x. That would still require making
> CAPABILITY a keyword, but it could be unreserved.

I thought you had it right first time. It is mighty annoying that some
privileges are GRANTed and others ALTER ROLEd.

And we did agree earlier to call these capabilities.

How about

GRANT EXECUTE [PRIVILEGES] ON CAPABILITY foo TO bar;

That is similar to granting execution privs on a function. And I think
gets round the keyword issue?

--
Simon Riggs http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Simon Riggs <simon(at)2ndQuadrant(dot)com>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2014-10-16 19:37:09
Message-ID: 20141016193709.GK28859@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

* Simon Riggs (simon(at)2ndQuadrant(dot)com) wrote:
> On 16 October 2014 20:04, Robert Haas <robertmhaas(at)gmail(dot)com> wrote:
> >>> GRANT CAPABILITY whatever TO somebody;
> >>
> >> So, we went back to just role attributes to avoid the keyword issue..
> >> The above would require making 'CAPABILITY' a reserved word, and there
> >> really isn't a 'good' already-reserved word we can use there that I
> >> found.
> >
> > Ah, good point. Using ALTER ROLE is better. Maybe we should do ALTER
> > ROLE .. [ ADD | DROP ] CAPABILITY x. That would still require making
> > CAPABILITY a keyword, but it could be unreserved.
>
> I thought you had it right first time. It is mighty annoying that some
> privileges are GRANTed and others ALTER ROLEd.

Yeah- but there's a material difference in the two, as I tried to
outline previously..

> How about
>
> GRANT EXECUTE [PRIVILEGES] ON CAPABILITY foo TO bar;
>
> That is similar to granting execution privs on a function. And I think
> gets round the keyword issue?

No, it doesn't.. EXECUTE isn't reserved at all.

Thanks,

Stephen


From: Jim Nasby <Jim(dot)Nasby(at)BlueTreble(dot)com>
To: Stephen Frost <sfrost(at)snowman(dot)net>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
Cc: Petr Jelinek <petr(at)2ndquadrant(dot)com>, <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2014-10-16 19:45:08
Message-ID: 54402044.5070806@BlueTreble.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 10/16/14, 10:47 AM, Stephen Frost wrote:
>>>> As others have commented, I too think this should support pg_dump.
>>> > >
>>> > >I'm uttly mystified as to what that*means*. Everyone asking for it is
>>> > >great but until someone can define what "support pg_dump" means, there's
>>> > >not much progress I can make towards it..
>> >
>> >To me, what this repeated discussion on this particular BACKUP point
>> >says, is that the ability to run pg_start/stop_backend and the xlog
>> >related functions should be a different privilege, i.e. something other
>> >than BACKUP; because later we will want the ability to grant someone the
>> >ability to run pg_dump on the whole database without being superuser,
>> >and we will want to use the name BACKUP for that. So I'm inclined to
>> >propose something more specific for this like WAL_CONTROL or
>> >XLOG_OPERATOR, say.
> Ok. Not sure that I see 'XLOG_OPERATOR' as making sense for
> 'pg_start_backup' though, and I see the need to support pg_dump'ing the
> whole database as a non-superuser being more like a 'READONLY' kind of
> role.
>
> We've actually already looked at the notion of a 'READONLY' or 'READALL'
> role attribute and, well, it's quite simple to implement.. We're
> talking about a few lines of code to implicitly allow 'USAGE' on all
> schemas, plus a minor change in ExecCheckRTEPerms to always (or perhaps
> *only*) include SELECT rights. As there's so much interest in that
> capability, perhaps we should add it..
>
> One of the big question is- do we take steps to try and prevent a role
> with this attribute from being able to modify the database in any way?
> Or would this role attribute only ever increase your rights?

Let me address the pg_dump case first, because it's simpler. I want a way to allow certain roles to successfully run pg_dump without being superuser and without having to manually try and maintain a magic read-all role. Note that pg_dump might (today or in the future) need more than just read-all so it's probably wise to treat the two features (pg_dump vs a plain read-all) as separate.

For PITR, I see 3 different needs:

1) The ability for someone to start a backup, and if needed cancel that backup
2) The ability to manage running backups/archiving
3) The ability to actually setup/modify PITR infrastructure

#2 is probably a weak case that may not be needed; I include it because someone mentioned stopping a backup that someone else started.

I think #3 should just require superuser.

#1 is what you'd want a more junior person to handle. "Bob needs a snapshot of cluster A". This role needs to be able to run everything you need to get that backup started, monitor it, and cancel if needed.
--
Jim Nasby, Data Architect, Blue Treble Consulting
Data in Trouble? Get it in Treble! http://BlueTreble.com


From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2014-10-16 20:41:43
Message-ID: CA+TgmoYDq_ci-6XA+_GYwWEy=RL2kGTas7ARKZ-FeOJ3VdDWNg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Thu, Oct 16, 2014 at 3:34 PM, Stephen Frost <sfrost(at)snowman(dot)net> wrote:
> * Robert Haas (robertmhaas(at)gmail(dot)com) wrote:
>> On Thu, Oct 16, 2014 at 3:09 PM, Stephen Frost <sfrost(at)snowman(dot)net> wrote:
>> > * Robert Haas (robertmhaas(at)gmail(dot)com) wrote:
>> >> Ah, good point. Using ALTER ROLE is better. Maybe we should do ALTER
>> >> ROLE .. [ ADD | DROP ] CAPABILITY x. That would still require making
>> >> CAPABILITY a keyword, but it could be unreserved.
>> >
>> > That works for me- would we change the existing role attributes to be
>> > configurable this way and change everything over to using an int64 in
>> > the catalog? Unless I'm having trouble counting, I think that would
>> > actually result in the pg_authid catalog not changing in size at all
>> > while giving us the ability to add these capabilities and something like
>> > 50 others if we had cause to.
>>
>> I definitely think we should support the new syntax for the existing
>> attributes.
>
> Ok.
>
>> I could go either way on whether to change the catalog
>> storage for the existing attributes. Some people might prefer to
>> avoid the backward compatibility break, and I can see that argument.
>
> There's really two issues when it comes to backwards compatibility here-
> the catalog representation and the syntax.
>
> My feeling is basically this- either we make a clean break to the new
> syntax and catalog representation, or we just use the same approach the
> existing attriubtes use. Long term, I think your proposed syntax and an
> int64 representation is better but it'll mean a lot of client code that
> has to change. I don't really like the idea of changing the syntax but
> not the representation, nor am I thrilled with the idea of supporting
> both syntaxes, and changing the syntax without changing the
> representation just doesn't make sense to me as I think we'd end up
> wanting to change it later, making clients have to update their code
> twice.

I don't see any reason why it has to be both or neither.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2014-10-16 20:54:19
Message-ID: 20141016205419.GL28859@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

* Robert Haas (robertmhaas(at)gmail(dot)com) wrote:
> On Thu, Oct 16, 2014 at 3:34 PM, Stephen Frost <sfrost(at)snowman(dot)net> wrote:
> > My feeling is basically this- either we make a clean break to the new
> > syntax and catalog representation, or we just use the same approach the
> > existing attriubtes use. Long term, I think your proposed syntax and an
> > int64 representation is better but it'll mean a lot of client code that
> > has to change. I don't really like the idea of changing the syntax but
> > not the representation, nor am I thrilled with the idea of supporting
> > both syntaxes, and changing the syntax without changing the
> > representation just doesn't make sense to me as I think we'd end up
> > wanting to change it later, making clients have to update their code
> > twice.
>
> I don't see any reason why it has to be both or neither.

My reasoning on that is that either breaks existing clients and so
they'll have to update and if we're going to force that then we might as
well go whole-hog and get it over with once.

If my assumption is incorrect and we don't think changes to the catalog
representation will break existing clients then I withdraw the argument
that they should be done together.

For the syntax piece of it, my feeling is that all these role attributes
should be handled the same way. There's three ways to address that-
support them using the existing syntax, change to a new syntax and only
support that, or have two different syntaxes. I don't like the idea
that these new attributes will be supported with one syntax but the old
attributes would be supported with a different syntax.

If we think it's too much to change in one release, I could see changing
the catalog representation and then providing the new syntax while
supporting the old syntax as deprecated, but we do have a pretty bad
history of such changes and any maintained client should be getting
updated for the new role attributes anyway..

Thanks!

Stephen


From: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Stephen Frost <sfrost(at)snowman(dot)net>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2014-10-16 20:56:38
Message-ID: 20141016205637.GA7246@eldon.alvh.no-ip.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Robert Haas wrote:
> On Thu, Oct 16, 2014 at 3:34 PM, Stephen Frost <sfrost(at)snowman(dot)net> wrote:

> > My feeling is basically this- either we make a clean break to the new
> > syntax and catalog representation, or we just use the same approach the
> > existing attriubtes use. Long term, I think your proposed syntax and an
> > int64 representation is better but it'll mean a lot of client code that
> > has to change. I don't really like the idea of changing the syntax but
> > not the representation, nor am I thrilled with the idea of supporting
> > both syntaxes, and changing the syntax without changing the
> > representation just doesn't make sense to me as I think we'd end up
> > wanting to change it later, making clients have to update their code
> > twice.
>
> I don't see any reason why it has to be both or neither.

I was thinking we would change the catalogs and implement the new syntax
for new and old settings, but also keep the old syntax working as a
backward compatibility measure. I don't see what's so terrible about
continuing to support the old syntax; we do that in COPY and EXPLAIN,
for example.

--
Álvaro Herrera http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services


From: Simon Riggs <simon(at)2ndQuadrant(dot)com>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2014-10-16 20:56:48
Message-ID: CA+U5nMKgv2hYos_P97C5rvNhcLMhVcuQdbzpO879NUvrYgej8Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 16 October 2014 20:37, Stephen Frost <sfrost(at)snowman(dot)net> wrote:

>> How about
>>
>> GRANT EXECUTE [PRIVILEGES] ON CAPABILITY foo TO bar;
>>
>> That is similar to granting execution privs on a function. And I think
>> gets round the keyword issue?
>
> No, it doesn't.. EXECUTE isn't reserved at all.

Yet GRANT EXECUTE is already valid syntax, so that should work.

--
Simon Riggs http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Simon Riggs <simon(at)2ndQuadrant(dot)com>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2014-10-16 21:02:30
Message-ID: 20141016210230.GM28859@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

* Simon Riggs (simon(at)2ndQuadrant(dot)com) wrote:
> On 16 October 2014 20:37, Stephen Frost <sfrost(at)snowman(dot)net> wrote:
>
> >> How about
> >>
> >> GRANT EXECUTE [PRIVILEGES] ON CAPABILITY foo TO bar;
> >>
> >> That is similar to granting execution privs on a function. And I think
> >> gets round the keyword issue?
> >
> > No, it doesn't.. EXECUTE isn't reserved at all.
>
> Yet GRANT EXECUTE is already valid syntax, so that should work.

Yeah, sorry, the issue with the above is that the "ON CAPABILITY" would
mean CAPABILITY needs to be reserved as otherwise we don't know if it's
a function or something else.

The keyword issue is with

GRANT <something> TO <role>;

As <something> could be a role.

Not sure offhand if

GRANT EXECUTE PRIVILEGES ON CAPABILITY foo TO bar;

would work.. In general, I'm not anxious to get involved in the
SQL-specified GRANT syntax though unless there's really good reason to.

Also, these aren't like normally granted privileges which can have an
ADMIN option and which are inheirited through role membership..

Thanks,

Stephen


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2014-10-16 21:05:30
Message-ID: 20141016210530.GN28859@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

* Alvaro Herrera (alvherre(at)2ndquadrant(dot)com) wrote:
> Robert Haas wrote:
> > On Thu, Oct 16, 2014 at 3:34 PM, Stephen Frost <sfrost(at)snowman(dot)net> wrote:
>
> > > My feeling is basically this- either we make a clean break to the new
> > > syntax and catalog representation, or we just use the same approach the
> > > existing attriubtes use. Long term, I think your proposed syntax and an
> > > int64 representation is better but it'll mean a lot of client code that
> > > has to change. I don't really like the idea of changing the syntax but
> > > not the representation, nor am I thrilled with the idea of supporting
> > > both syntaxes, and changing the syntax without changing the
> > > representation just doesn't make sense to me as I think we'd end up
> > > wanting to change it later, making clients have to update their code
> > > twice.
> >
> > I don't see any reason why it has to be both or neither.
>
> I was thinking we would change the catalogs and implement the new syntax
> for new and old settings, but also keep the old syntax working as a
> backward compatibility measure. I don't see what's so terrible about
> continuing to support the old syntax; we do that in COPY and EXPLAIN,
> for example.

It just complicates things and I'm not sure there's much benefit to it.
Clients are going to need to be updated to support the new attributes
anyway, and if the new attributes can only be used through the new
syntax, well, I don't know why they'd want to deal with the old syntax
too.

That said, I don't feel very strongly about that position, so if you and
Robert (and others on the thread) agree that's the right approach then
I'll see about getting it done.

Thanks!

Stephen


From: Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2014-11-03 16:44:10
Message-ID: CAKRt6CTbzLBC88kj_eHgcFCZh3DYOmcGLrJssjHDJ3vKg4b0iw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

All,

> That said, I don't feel very strongly about that position, so if you and
> Robert (and others on the thread) agree that's the right approach then
> I'll see about getting it done.

We haven't reached consensus on this one yet and I didn't want it to fall
too far off the radar.

Here is what I summarize as the current state of the discussion:

1. Syntax:

ALTER ROLE <role> { ADD | DROP } CAPABILITY <capability>

* I think this is the most straight forward approach as it still close to
the current syntax.
* Perhaps keeping the current syntax around as deprecated to be removed in
a scheduled future version. (provide a "deprecated" message to the user?)

or

GRANT EXECUTE PRIVILEGES ON <capability> TO <role>

* Though, this will be tricky since EXECUTE is not reserved and the
currently state of GRANT in the grammar would require either refactoring or
making it RESERVED... neither I think are acceptable at this point in time
for obvious reasons.

2. Catalog Representation:

Condense all attributes in pg_authid to single int64 column and create
bitmasks accordingly.

Obviously there is some concern for upgrading and whether to do both at
once or to do them incrementally. IMHO, I think if the changes are going
to be made, then we should go ahead and do them at the same time. Though,
would it be beneficial to separate in to two distinct patches?

-Adam

--
Adam Brightwell - adam(dot)brightwell(at)crunchydatasolutions(dot)com
Database Engineer - www.crunchydatasolutions.com


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>
Cc: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2014-11-03 17:08:05
Message-ID: 20141103170805.GX28859@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

* Adam Brightwell (adam(dot)brightwell(at)crunchydatasolutions(dot)com) wrote:
> > That said, I don't feel very strongly about that position, so if you and
> > Robert (and others on the thread) agree that's the right approach then
> > I'll see about getting it done.

Thanks for trying to make progress on this.

> We haven't reached consensus on this one yet and I didn't want it to fall
> too far off the radar.
>
> Here is what I summarize as the current state of the discussion:

For my 2c- I don't think we'd be able to drop the old syntax and
therefore I'm not sure that I really see the point in adding new syntax.
I don't hold that position strongly, but I don't like the idea that
we're just going to be sitting on our thumbs because we can't agree on
the color of the bike shed.

If there is agreement to move forward with using the syntax below,
great, that can be implemented in relatively short order. If there
isn't, then let's move forward with the existing syntax and change it
later, if there is agreement to do so at some point in the future.

I don't like the idea of tying it into GRANT. GRANT is SQL-spec
defined, quite overloaded already, and role attributes don't act like
GRANTs anyway (there's no ADMIN option and they aren't inheirited).

> 2. Catalog Representation:
>
> Condense all attributes in pg_authid to single int64 column and create
> bitmasks accordingly.

I'd suggest we do this regardless and the only question is if we feel
there is need to provide a view to split them back out again or not.
I'm inclined to say 'no' to another view and instead suggest we provide
SQL-level "has_whatever_privilege" for these which match the existing C
functions, update our clients to use those, and encourage others to do
the same. Probably also helpful would be a single function that returns
a simple list of the non-default role attributes which a user has and
we'd simplify psql's describeRoles by having it use that instead.

> Obviously there is some concern for upgrading and whether to do both at
> once or to do them incrementally. IMHO, I think if the changes are going
> to be made, then we should go ahead and do them at the same time. Though,
> would it be beneficial to separate in to two distinct patches?

I agree that doing these changes at the same time makes sense, if we can
get agreement on what exactly to do. I've shared my thoughts, but we
really need input from others, ideally of the form of "I prefer X over
Y" rather than "well, we could do X or Y".

Thanks!

Stephen


From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>
Cc: Stephen Frost <sfrost(at)snowman(dot)net>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2014-11-06 02:31:59
Message-ID: CA+TgmoYJ=J24z0FqjShd-5K1pPzzSJQRgHWmrYQ5NxO417vbrw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Mon, Nov 3, 2014 at 11:44 AM, Adam Brightwell
<adam(dot)brightwell(at)crunchydatasolutions(dot)com> wrote:
>> That said, I don't feel very strongly about that position, so if you and
>> Robert (and others on the thread) agree that's the right approach then
>> I'll see about getting it done.
>
> We haven't reached consensus on this one yet and I didn't want it to fall
> too far off the radar.
>
> Here is what I summarize as the current state of the discussion:
>
> 1. Syntax:
>
> ALTER ROLE <role> { ADD | DROP } CAPABILITY <capability>

Seems reasonable.

> * Perhaps keeping the current syntax around as deprecated to be removed in a
> scheduled future version. (provide a "deprecated" message to the user?)

Yeah, I don't think we should remove the existing syntax because a lot
of people are used to it. We still have some very old COPY syntax
around for backward-compatibility, and it's not hurting us, either.
At the same time, I think recasting the existing capability-like
things as capabilities per se is a good idea, because otherwise we've
got this old stuff that is randomly different for no especially good
reason.

> GRANT EXECUTE PRIVILEGES ON <capability> TO <role>

Yuck.

The only other approach I can think of is have some magic, hard-coded
roles that implicitly have each capability, and then those can be
granted. e.g. have a role pg_unrestricted_copy or whatever with a
given OID, and then test has_privs_of_role() with that OID.

> Condense all attributes in pg_authid to single int64 column and create
> bitmasks accordingly.
>
> Obviously there is some concern for upgrading and whether to do both at once
> or to do them incrementally. IMHO, I think if the changes are going to be
> made, then we should go ahead and do them at the same time. Though, would
> it be beneficial to separate in to two distinct patches?

If we're going to change the catalog representation for the existing
capabilities, I'd recommend that the first patch change the catalog
representation and add the new syntax without adding any more
capabilities; and then the second and subsequent patches can add
additional capabilities.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


From: Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2014-11-18 20:30:04
Message-ID: CAKRt6CTs-X-OKE5w2PWG5rmuZzz+f6AY-b0NHaQXgu9GchRc9Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

All,

> 2. Catalog Representation:
>
> Condense all attributes in pg_authid to single int64 column and create
> bitmasks accordingly.
>

I have been working on these changes and I was hoping for some
assistance/recommendations.

Currently, I am using int32 simply because int64 is causing some issues.
The issue is that genbki.pl is not able to associate it with the int8 type
as defined in pg_type.h. Therefore Schema_pg_authid in schemapg.h isn't
defined correctly. I've been digging and scratching my head on this one
but I have reached a point where I think it would be better just to ask.

Any thoughts or recommendations on how I should approach this?

-Adam

--
Adam Brightwell - adam(dot)brightwell(at)crunchydatasolutions(dot)com
Database Engineer - www.crunchydatasolutions.com


From: Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2014-11-18 21:58:46
Message-ID: CAKRt6CTgJdeGFqXevrp-DizaeHmg8gNVqu8n5T=ix3JAvpwwDQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

All,

> Currently, I am using int32 simply because int64 is causing some issues.
> The issue is that genbki.pl is not able to associate it with the int8
> type as defined in pg_type.h. Therefore Schema_pg_authid in schemapg.h
> isn't defined correctly. I've been digging and scratching my head on this
> one but I have reached a point where I think it would be better just to ask.
>

Attached is a quite trivial patch that addresses the int64 (C) to int8
(SQL) mapping issue.

Further digging revealed that Catalog.pm wasn't accounting for int64
(thanks Stephen). Would it be better to include this change as a separate
patch (as attached) or would it be preferable to include with a larger role
attribute bitmask patch?

Thanks,
Adam

--
Adam Brightwell - adam(dot)brightwell(at)crunchydatasolutions(dot)com
Database Engineer - www.crunchydatasolutions.com

Attachment Content-Type Size
int64_catalog_atttype.patch text/x-patch 465 bytes

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>
Cc: Stephen Frost <sfrost(at)snowman(dot)net>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2014-11-18 22:16:01
Message-ID: 23374.1416348961@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com> writes:
> Currently, I am using int32 simply because int64 is causing some issues.
> The issue is that genbki.pl is not able to associate it with the int8 type
> as defined in pg_type.h. Therefore Schema_pg_authid in schemapg.h isn't
> defined correctly. I've been digging and scratching my head on this one
> but I have reached a point where I think it would be better just to ask.

> Any thoughts or recommendations on how I should approach this?

Teach src/backend/catalog/Catalog.pm about it.

There once was a policy against using int64 in the system catalogs, which
is why it wasn't there already; but the reason for that policy is long
gone.

regards, tom lane


From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Stephen Frost <sfrost(at)snowman(dot)net>
Cc: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2014-11-18 22:26:02
Message-ID: 546BC77A.8030801@dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers


On 11/18/2014 04:58 PM, Adam Brightwell wrote:
> All,
>
> Currently, I am using int32 simply because int64 is causing some
> issues. The issue is that genbki.pl <http://genbki.pl> is not
> able to associate it with the int8 type as defined in pg_type.h.
> Therefore Schema_pg_authid in schemapg.h isn't defined correctly.
> I've been digging and scratching my head on this one but I have
> reached a point where I think it would be better just to ask.
>
>
> Attached is a quite trivial patch that addresses the int64 (C) to int8
> (SQL) mapping issue.
>
> Further digging revealed that Catalog.pm wasn't accounting for int64
> (thanks Stephen). Would it be better to include this change as a
> separate patch (as attached) or would it be preferable to include with
> a larger role attribute bitmask patch?
>
>

I think we should just apply this now. As Tom said the reason for not
doing it is long gone.

cheers

andrew


From: Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Stephen Frost <sfrost(at)snowman(dot)net>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2014-11-19 20:50:48
Message-ID: CAKRt6CRKVJLsRXsMNxJKRiADGCVv4SfAKantLiKou-2EqmxfJw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

All,

> If we're going to change the catalog representation for the existing
> capabilities, I'd recommend that the first patch change the catalog
> representation and add the new syntax without adding any more
> capabilities; and then the second and subsequent patches can add
> additional capabilities.

Attached is an initial patch for review and discussion that takes a swing
at changing the catalog representation.

This patch includes:

* int64 (C) to int8 (SQL) mapping for genbki.
* replace all role attributes columns in pg_authid with single int64 column
named rolattr.
* update CreateRole and AlterRole to use rolattr.
* update all has_*_privilege functions to check rolattr.
* builtin SQL function 'has_role_attribute' that takes a role oid and text
name of the attribute as input and returns a boolean.

Items not currently addressed:

* New syntax - more discussion needs to occur around these potential
changes. Specifically, how would CREATE USER/ROLE be affected? I suppose
it is OK to keep it as WITH <attribute_or_capability>, though if ALTER ROLE
is modified to have ADD | DROP CAPABILITY for consistency would WITH
CAPABILITY <value,...>, make more sense for CREATE? At any rate, I think
there is obviously much more discussion that needs to be had.
* Documentation - want to gain feedback on implementation prior to making
changes.
* Update regression tests, rules test for system_views - want to gain
feedback on approach to handling pg_roles, etc. before updating.

Also, what would be the community preference on tracking these
attached/proposed changes? Should I create a separate entry in the next CF
for this item (seems prudent) or would it be preferred to keep it attached
to the current 'new attributes' CF entry?

Thanks,
Adam

--
Adam Brightwell - adam(dot)brightwell(at)crunchydatasolutions(dot)com
Database Engineer - www.crunchydatasolutions.com

Attachment Content-Type Size
role-attribute-bitmask-v1.patch text/x-patch 37.5 KB

From: José Luis Tallón <jltallon(at)adv-solutions(dot)net>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Additional role attributes && superuser review
Date: 2014-11-21 20:38:55
Message-ID: 546FA2DF.4000007@adv-solutions.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 11/06/2014 03:31 AM, Robert Haas wrote:
> [snip]
>> We haven't reached consensus on this one yet and I didn't want it to fall
>> too far off the radar.
>>
>> Here is what I summarize as the current state of the discussion:
>>
>> 1. Syntax:
>>
>> ALTER ROLE <role> { ADD | DROP } CAPABILITY <capability>

Though a bit late to this thread, I would like to request comments on
potentially beneficial new roles ?? and/or capabilities which I have
recently found needing myself.
The suggested syntax looks intuitive and potentially very flexible.
I'll try to summarize up what I recall from the thread plus my own
itchs, to try and get others to comment and expand on the matter.

We currently have:
* SUPERUSER / CREATEUSER
* CREATEDB
* CREATEROLE
* LOGIN
* REPLICATION

(plus INHERITS and ADMIN options, of course)

It has also been suggested to include a
* BACKUP role (capability?) i.e. ability to take an snapshot and
read all relations, views, triggers and functions (even bypassing RLS)
and the catalog in order to produce a full, consistent dump of the whole
cluster.

and I seem to recall something along the lines of
* AUDIT, potentially limited to just engage

I am hereby suggesting the addition of a
* MAINTENANCE role, which would be able to perform VACUUM, ANALYZE,
REINDEX *CONCURRENTLY* and REFRESH MATERIALIZED VIEW *CONCURRENTLY* ...
and potentially even ALTER TABLE VALIDATE CONSTRAINT (if we are able to
produce a non-blocking/fully concurrent version)

... which might become very useful for DBAs wishing to use some
password-less roles for scheduled maintenance routines while at the same
time reducing the exposure.

While at it, the replication role might as well gain the ability to
promote/demote a cluster (standby<->active), or shall it be some kind of
FAILOVER role/capability ?

Thanks in advance.

/ J.L.


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Andrew Dunstan <andrew(at)dunslane(dot)net>
Cc: Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2014-11-25 17:14:11
Message-ID: 20141125171411.GM28859@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

* Andrew Dunstan (andrew(at)dunslane(dot)net) wrote:
> On 11/18/2014 04:58 PM, Adam Brightwell wrote:
> >Attached is a quite trivial patch that addresses the int64 (C) to
> >int8 (SQL) mapping issue.
>
> I think we should just apply this now. As Tom said the reason for
> not doing it is long gone.

Alright, done.

Thanks!

Stephen


From: Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: Andrew Dunstan <andrew(at)dunslane(dot)net>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2014-12-24 17:48:07
Message-ID: CAKRt6CSbXMddV9uvmsnz0vq=Q1xtMLwwFS-2SPz_rmAiSk79pg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

All,

I want to revive this thread and continue to move these new role attributes
forward.

In summary, the ultimate goal is to include new role attributes for common
operations which currently require superuser privileges.

Initially proposed were the following attributes:

* BACKUP - allows role to perform backup operations
* LOGROTATE - allows role to rotate log files
* MONITOR - allows role to view pg_stat_* details
* PROCSIGNAL - allows role to signal backend processes

It seems that PROCSIGNAL and MONITOR were generally well received and
probably don't warrant much more discussion at this point.

However, based on previous discussions, there seemed to be some uncertainty
on how to handle BACKUP and LOGROTATE.

Concerns:

* LOGROTATE - only associated with one function/operation.
* BACKUP - perceived to be too broad of a permission as it it would provide
the ability to run pg_start/stop_backend and the xlog related functions.
It is general sentiment is that these should be handled as separate
privileges.
* BACKUP - preferred usage is with pg_dump to giving a user the ability to
run pg_dump on the whole database without being superuser.

Previous Recommendations:

* LOGROTATE - Use OPERATOR - concern was expressed that this might be too
general of an attribute for this purpose. Also, concern for privilege
'upgrades' as it includes more capabilities in later releases.
* LOGROTATE - Use LOG_OPERATOR - generally accepted, but concern was raise
for using extraneous descriptors such as '_OPERATOR' and '_ADMIN', etc.
* BACKUP - Use WAL_CONTROL for pg_start/stop_backup - no major
disagreement, though same concern regarding extraneous descriptors.
* BACKUP - Use XLOG_OPERATOR for xlog operations - no major disagreement,
though same concern regarding extraneous descriptors.
* BACKUP - Use BACKUP for granting non-superuser ability to run pg_dump on
whole database.

Given the above and previous discussions:

I'd like to propose the following new role attributes:

BACKUP - allows role to perform pg_dump* backups of whole database.
WAL - allows role to execute pg_start_backup/pg_stop_backup functions.
XLOG - allows role to execute xlog operations.
LOG - allows role to rotate log files - remains broad enough to consider
future log related operations.
MONITOR - allows role to view pg_stat_* details.
PROCSIGNAL - allows role to signal backend processes.

If these seem reasonable, then I'll begin updating the initial/current
patch submitted. But in either case, feedback and suggestions are
certainly welcome and appreciated.

Thanks,
Adam

--
Adam Brightwell - adam(dot)brightwell(at)crunchydatasolutions(dot)com
Database Engineer - www.crunchydatasolutions.com


From: Magnus Hagander <magnus(at)hagander(dot)net>
To: Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>
Cc: Stephen Frost <sfrost(at)snowman(dot)net>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2014-12-26 11:21:48
Message-ID: CABUevEyjjZenOZuGOq84Yi_3NOevdSCuj1v_H6fW7Rn3aLBppQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Wed, Dec 24, 2014 at 6:48 PM, Adam Brightwell <
adam(dot)brightwell(at)crunchydatasolutions(dot)com> wrote:

> All,
>
> I want to revive this thread and continue to move these new role
> attributes forward.
>
> In summary, the ultimate goal is to include new role attributes for common
> operations which currently require superuser privileges.
>
> Initially proposed were the following attributes:
>
> * BACKUP - allows role to perform backup operations
> * LOGROTATE - allows role to rotate log files
> * MONITOR - allows role to view pg_stat_* details
> * PROCSIGNAL - allows role to signal backend processes
>
> It seems that PROCSIGNAL and MONITOR were generally well received and
> probably don't warrant much more discussion at this point.
>
> However, based on previous discussions, there seemed to be some
> uncertainty on how to handle BACKUP and LOGROTATE.
>
> Concerns:
>
> * LOGROTATE - only associated with one function/operation.
> * BACKUP - perceived to be too broad of a permission as it it would
> provide the ability to run pg_start/stop_backend and the xlog related
> functions. It is general sentiment is that these should be handled as
> separate privileges.
>
* BACKUP - preferred usage is with pg_dump to giving a user the ability to
> run pg_dump on the whole database without being superuser.
>
> Previous Recommendations:
>
> * LOGROTATE - Use OPERATOR - concern was expressed that this might be too
> general of an attribute for this purpose. Also, concern for privilege
> 'upgrades' as it includes more capabilities in later releases.
> * LOGROTATE - Use LOG_OPERATOR - generally accepted, but concern was raise
> for using extraneous descriptors such as '_OPERATOR' and '_ADMIN', etc.
> * BACKUP - Use WAL_CONTROL for pg_start/stop_backup - no major
> disagreement, though same concern regarding extraneous descriptors.
> * BACKUP - Use XLOG_OPERATOR for xlog operations - no major disagreement,
> though same concern regarding extraneous descriptors.
> * BACKUP - Use BACKUP for granting non-superuser ability to run pg_dump on
> whole database.
>
> Given the above and previous discussions:
>
> I'd like to propose the following new role attributes:
>
> BACKUP - allows role to perform pg_dump* backups of whole database.
>

I'd suggest it's called DUMP if that's what it allows, to keep it separate
from the backup parts.

> WAL - allows role to execute pg_start_backup/pg_stop_backup functions.
>
XLOG - allows role to execute xlog operations.

That seems really bad names, IMHO. Why? Because we use WAL and XLOG
throughout documentation and parameters and code to mean *the same thing*.
And here they'd suddenly mean different things. If we need them as separate
privileges, I think we need much better names. (And a better description -
what is "xlog operations" really?)

And the one under WAL would be very similar to what REPLICATION does today.
Or are you saying that it should specifically *not* allow base backups done
through the replication protocol, only the exclusive ones?

--
Magnus Hagander
Me: http://www.hagander.net/
Work: http://www.redpill-linpro.com/


From: Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>
To: Magnus Hagander <magnus(at)hagander(dot)net>
Cc: Stephen Frost <sfrost(at)snowman(dot)net>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2014-12-29 21:34:14
Message-ID: CAKRt6CRoMQNHMKJEisTAdpJtjhvuMAaNtk7A69oERO3ARMs0yw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Magnus,

Thanks for the feedback.

>> BACKUP - allows role to perform pg_dump* backups of whole database.
>>
>
> I'd suggest it's called DUMP if that's what it allows, to keep it separate
> from the backup parts.
>

Makes sense to me.

That seems really bad names, IMHO. Why? Because we use WAL and XLOG
> throughout documentation and parameters and code to mean *the same thing*.
> And here they'd suddenly mean different things. If we need them as separate
> privileges, I think we need much better names. (And a better description -
> what is "xlog operations" really?)
>

Fair enough, ultimately what I was trying to address is the following
concern raised by Alvaro:

"To me, what this repeated discussion on this particular BACKUP point
says, is that the ability to run pg_start/stop_backend and the xlog
related functions should be a different privilege, i.e. something other
than BACKUP; because later we will want the ability to grant someone the
ability to run pg_dump on the whole database without being superuser,
and we will want to use the name BACKUP for that. So I'm inclined to
propose something more specific for this like WAL_CONTROL or
XLOG_OPERATOR, say."

Upon re-reading it (and other discussions around it) I believe that I must
have misinterpreted. Initially, I read it to mean that we needed the
following separate permissions.

1) ability to pg_dump
2) ability to start/stop backups
3) ability to execute xlog related functions

When indeed, what it meant was to have the following separate (effectively
merging #2 and #3):

1) ability to pg_dump
2) ability to start/stop backups *and* ability to execute xlog related
functions.

My apologies on that confusion.

Given this clarification:

I think #1 could certainly be answered by using DUMP. I have no strong
opinion in either direction, though I do think that BACKUP does make the
most sense for #2. Previously, Stephen had mentioned a READONLY capability
that could effectively work for pg_dump, though, Jim's suggestion of
keeping 'read-all' separate from 'ability to pg_dump' seems logical. In
either case, I certainly wouldn't mind having a wider agreement/consensus
on this approach.

So, here is a revised list of proposed attributes:

* BACKUP - allows role to perform backup operations (as originally proposed)
* LOG - allows role to rotate log files - remains broad enough to consider
future log related operations
* DUMP - allows role to perform pg_dump* backups of whole database
* MONITOR - allows role to view pg_stat_* details (as originally proposed)
* PROCSIGNAL - allows role to signal backend processes (as originally
proposed)well

Thanks,
Adam

--
Adam Brightwell - adam(dot)brightwell(at)crunchydatasolutions(dot)com
Database Engineer - www.crunchydatasolutions.com


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>
Cc: Magnus Hagander <magnus(at)hagander(dot)net>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2014-12-29 22:01:25
Message-ID: 20141229220125.GF3062@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Adam,

* Adam Brightwell (adam(dot)brightwell(at)crunchydatasolutions(dot)com) wrote:
> > I'd suggest it's called DUMP if that's what it allows, to keep it separate
> > from the backup parts.
>
> Makes sense to me.

I'm fine calling it 'DUMP', but for different reasons.

We have no (verifiable) idea what client program is being used to
connect and therefore we shouldn't try to tie the name of the client
program to the permission.

That said, a 'DUMP' privilege which allows the user to dump the contents
of the entire database is entirely reasonable. We need to be clear in
the documentation though- such a 'DUMP' privilege is essentially
granting USAGE on all schemas and table-level SELECT on all tables and
sequences (anything else..?). To be clear, a user with this privilege
can utilize that access without using pg_dump.

One other point is that this shouldn't imply any other privileges, imv.
I'm specifically thinking of BYPASSRLS- that's independently grantable
and therefore should be explicitly set, if it's intended. Things
should work 'sanely' with any combination of the two options.
Similairly, DUMP shouldn't imply BACKUP or visa-versa. In particular,
I'd like to see roles which have only the BACKUP privilege be unable to
directly read any data (modulo things granted to PUBLIC). This would
allow an unprivileged user to manage backups, kick off ad-hoc ones, etc,
without being able to actually access any of the data (this would
require the actual backup system to have a similar control, but that's
entirely possible with more advanced SANs and enterprise backup
solutions).

> > That seems really bad names, IMHO. Why? Because we use WAL and XLOG
> > throughout documentation and parameters and code to mean *the same thing*.
> > And here they'd suddenly mean different things. If we need them as separate
> > privileges, I think we need much better names. (And a better description -
> > what is "xlog operations" really?)
> >
>
> Fair enough, ultimately what I was trying to address is the following
> concern raised by Alvaro:
>
> "To me, what this repeated discussion on this particular BACKUP point
> says, is that the ability to run pg_start/stop_backend and the xlog
> related functions should be a different privilege, i.e. something other
> than BACKUP; because later we will want the ability to grant someone the
> ability to run pg_dump on the whole database without being superuser,
> and we will want to use the name BACKUP for that. So I'm inclined to
> propose something more specific for this like WAL_CONTROL or
> XLOG_OPERATOR, say."

Note that the BACKUP role attribute was never intended to cover the
pg_dump use-case. Simply the name of it caused confusion though. I'm
not sure if adding a DUMP role attribute is sufficient enough to address
that confusion, but I haven't got a better idea either.

> When indeed, what it meant was to have the following separate (effectively
> merging #2 and #3):
>
> 1) ability to pg_dump
> 2) ability to start/stop backups *and* ability to execute xlog related
> functions.

That sounds reasonable to me (and is what was initially proposed, though
I've come around to the thinking that this BACKUP role attribute should
also allow pg_xlog_replay_pause/resume(), as those can be useful on
replicas).

> Given this clarification:
>
> I think #1 could certainly be answered by using DUMP. I have no strong
> opinion in either direction, though I do think that BACKUP does make the
> most sense for #2. Previously, Stephen had mentioned a READONLY capability
> that could effectively work for pg_dump, though, Jim's suggestion of
> keeping 'read-all' separate from 'ability to pg_dump' seems logical. In
> either case, I certainly wouldn't mind having a wider agreement/consensus
> on this approach.

The read-all vs. ability-to-pg_dump distinction doesn't really exist for
role attributes, as I see it (see my comments above). That said, having
DUMP or read-all is different from read-*only*, which would probably be
good to have independently. I can imagine a use-case for a read-only
account which only has read ability for those tables, schemas, etc,
explicitly granted to it.

There is one issue that occurs to me, however. We're talking about
pg_dump, but what about pg_dumpall? In particular, I don't think the
DUMP privilege should provide access to pg_authid, as that would allow
the user to bypass the privilege system in some environments by using
the hash to log in as a superuser. Now, I don't encourage using
password based authentication, especially for superuser accounts, but
lots of people do. The idea with these privileges is to allow certain
operations to be performed by a non-superuser while preventing trivial
access to superuser. Perhaps it's pie-in-the-sky, but my hope is to
achieve that.

> So, here is a revised list of proposed attributes:
>
> * BACKUP - allows role to perform backup operations (as originally proposed)
> * LOG - allows role to rotate log files - remains broad enough to consider
> future log related operations
> * DUMP - allows role to perform pg_dump* backups of whole database
> * MONITOR - allows role to view pg_stat_* details (as originally proposed)
> * PROCSIGNAL - allows role to signal backend processes (as originally
> proposed)well

Looks reasonable to me.

Thanks!

Stephen


From: Jim Nasby <Jim(dot)Nasby(at)BlueTreble(dot)com>
To: Stephen Frost <sfrost(at)snowman(dot)net>, Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>
Cc: Magnus Hagander <magnus(at)hagander(dot)net>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2014-12-30 00:46:44
Message-ID: 54A1F5F4.7010504@BlueTreble.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 12/29/14, 4:01 PM, Stephen Frost wrote:
> Adam,
>
> * Adam Brightwell (adam(dot)brightwell(at)crunchydatasolutions(dot)com) wrote:
>>> I'd suggest it's called DUMP if that's what it allows, to keep it separate
>>> from the backup parts.
>>
>> Makes sense to me.
>
> I'm fine calling it 'DUMP', but for different reasons.
>
> We have no (verifiable) idea what client program is being used to
> connect and therefore we shouldn't try to tie the name of the client
> program to the permission.
>
> That said, a 'DUMP' privilege which allows the user to dump the contents
> of the entire database is entirely reasonable. We need to be clear in
> the documentation though- such a 'DUMP' privilege is essentially
> granting USAGE on all schemas and table-level SELECT on all tables and
> sequences (anything else..?). To be clear, a user with this privilege
> can utilize that access without using pg_dump.

Yeah... it may be better to call this something other than DUMP (see below).

> One other point is that this shouldn't imply any other privileges, imv.
> I'm specifically thinking of BYPASSRLS- that's independently grantable
> and therefore should be explicitly set, if it's intended. Things
> should work 'sanely' with any combination of the two options.

That does violate POLA, but it's probably worth doing so...

> Similairly, DUMP shouldn't imply BACKUP or visa-versa. In particular,
> I'd like to see roles which have only the BACKUP privilege be unable to
> directly read any data (modulo things granted to PUBLIC). This would
> allow an unprivileged user to manage backups, kick off ad-hoc ones, etc,
> without being able to actually access any of the data (this would
> require the actual backup system to have a similar control, but that's
> entirely possible with more advanced SANs and enterprise backup
> solutions).

Yes, since a binary backup doesn't need to actually "read" data, it shouldn't implicitly allow a user granted that role to either.

>> Given this clarification:
>>
>> I think #1 could certainly be answered by using DUMP. I have no strong
>> opinion in either direction, though I do think that BACKUP does make the
>> most sense for #2. Previously, Stephen had mentioned a READONLY capability
>> that could effectively work for pg_dump, though, Jim's suggestion of
>> keeping 'read-all' separate from 'ability to pg_dump' seems logical. In
>> either case, I certainly wouldn't mind having a wider agreement/consensus
>> on this approach.
>
> The read-all vs. ability-to-pg_dump distinction doesn't really exist for
> role attributes, as I see it (see my comments above). That said, having
> DUMP or read-all is different from read-*only*, which would probably be
> good to have independently. I can imagine a use-case for a read-only
> account which only has read ability for those tables, schemas, etc,
> explicitly granted to it.

My specific concern about DUMP vs read all/only is IIRC dump needs to do more extensive locking than regular selects do, which can cause production problems.

> There is one issue that occurs to me, however. We're talking about
> pg_dump, but what about pg_dumpall? In particular, I don't think the
> DUMP privilege should provide access to pg_authid, as that would allow
> the user to bypass the privilege system in some environments by using
> the hash to log in as a superuser. Now, I don't encourage using
> password based authentication, especially for superuser accounts, but
> lots of people do. The idea with these privileges is to allow certain
> operations to be performed by a non-superuser while preventing trivial
> access to superuser. Perhaps it's pie-in-the-sky, but my hope is to
> achieve that.

Ugh, hadn't thought about that. :(

>> So, here is a revised list of proposed attributes:
>>
>> * BACKUP - allows role to perform backup operations (as originally proposed)
>> * LOG - allows role to rotate log files - remains broad enough to consider
>> future log related operations
>> * DUMP - allows role to perform pg_dump* backups of whole database
>> * MONITOR - allows role to view pg_stat_* details (as originally proposed)
>> * PROCSIGNAL - allows role to signal backend processes (as originally
>> proposed)well

Given the confusion that can exist with the data reading stuff, perhaps BINARY BACKUP or XLOG would be a better term, especially since this will probably have some overlap with streaming replication.

Likewise, if we segregate "DUMP" and BYPASSRLS then I think we need to call DUMP something else. Otherwise, it's a massive foot-gun; you get a "successful" backup only to find out it contains only a small part of the database.

My how this has become a can of worms...
--
Jim Nasby, Data Architect, Blue Treble Consulting
Data in Trouble? Get it in Treble! http://BlueTreble.com


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Jim Nasby <Jim(dot)Nasby(at)BlueTreble(dot)com>
Cc: Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Magnus Hagander <magnus(at)hagander(dot)net>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2014-12-30 01:22:59
Message-ID: 20141230012259.GH3062@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Jim,

* Jim Nasby (Jim(dot)Nasby(at)BlueTreble(dot)com) wrote:
> On 12/29/14, 4:01 PM, Stephen Frost wrote:
> >That said, a 'DUMP' privilege which allows the user to dump the contents
> >of the entire database is entirely reasonable. We need to be clear in
> >the documentation though- such a 'DUMP' privilege is essentially
> >granting USAGE on all schemas and table-level SELECT on all tables and
> >sequences (anything else..?). To be clear, a user with this privilege
> >can utilize that access without using pg_dump.
>
> Yeah... it may be better to call this something other than DUMP (see below).

Did you favor something else below..? I don't see it.

> >One other point is that this shouldn't imply any other privileges, imv.
> >I'm specifically thinking of BYPASSRLS- that's independently grantable
> >and therefore should be explicitly set, if it's intended. Things
> >should work 'sanely' with any combination of the two options.
>
> That does violate POLA, but it's probably worth doing so...

That really depends on your view of the privilege. I'm inclined to view
it from the more-tightly-constrained point of view which matches up with
what I anticipate it actually providing. That doesn't translate into a
short name very well though, unfortunately.

> >The read-all vs. ability-to-pg_dump distinction doesn't really exist for
> >role attributes, as I see it (see my comments above). That said, having
> >DUMP or read-all is different from read-*only*, which would probably be
> >good to have independently. I can imagine a use-case for a read-only
> >account which only has read ability for those tables, schemas, etc,
> >explicitly granted to it.
>
> My specific concern about DUMP vs read all/only is IIRC dump needs to do more extensive locking than regular selects do, which can cause production problems.

The locks aren't any more extensive than regular selects, it's just that
the entire pg_dump works inside of one large transaction which lasts a
good long time and simply that can cause issues with high-rate update
systems.

> >There is one issue that occurs to me, however. We're talking about
> >pg_dump, but what about pg_dumpall? In particular, I don't think the
> >DUMP privilege should provide access to pg_authid, as that would allow
> >the user to bypass the privilege system in some environments by using
> >the hash to log in as a superuser. Now, I don't encourage using
> >password based authentication, especially for superuser accounts, but
> >lots of people do. The idea with these privileges is to allow certain
> >operations to be performed by a non-superuser while preventing trivial
> >access to superuser. Perhaps it's pie-in-the-sky, but my hope is to
> >achieve that.
>
> Ugh, hadn't thought about that. :(

I don't think it kills the whole idea, but we do need to work out how to
address it.

> >>* BACKUP - allows role to perform backup operations (as originally proposed)
> >>* LOG - allows role to rotate log files - remains broad enough to consider
> >>future log related operations
> >>* DUMP - allows role to perform pg_dump* backups of whole database
> >>* MONITOR - allows role to view pg_stat_* details (as originally proposed)
> >>* PROCSIGNAL - allows role to signal backend processes (as originally
> >>proposed)well
>
> Given the confusion that can exist with the data reading stuff, perhaps BINARY BACKUP or XLOG would be a better term, especially since this will probably have some overlap with streaming replication.

I don't really like 'xlog' as a permission. BINARY BACKUP is
interesting but if we're going to go multi-word, I would think we would
do PITR BACKUP or something FILESYSTEM BACKUP or similar. I'm not
really a big fan of the two-word options though.

> Likewise, if we segregate "DUMP" and BYPASSRLS then I think we need to call DUMP something else. Otherwise, it's a massive foot-gun; you get a "successful" backup only to find out it contains only a small part of the database.

That's actually already dealt with. pg_dump defaults to setting the
row_security GUC to 'off', in which case you'll get an error if you hit
a table that has RLS enabled and you don't have BYPASSRLS. If you're
not checking for errors from pg_dump, well, there's a lot of ways you
could run into problems.

> My how this has become a can of worms...

I'm not sure it's as bad as all that, but it does require some
thinking..

Thanks,

Stephen


From: Jim Nasby <Jim(dot)Nasby(at)BlueTreble(dot)com>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Magnus Hagander <magnus(at)hagander(dot)net>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2014-12-30 02:07:27
Message-ID: 54A208DF.5030307@BlueTreble.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 12/29/14, 7:22 PM, Stephen Frost wrote:
>>> One other point is that this shouldn't imply any other privileges, imv.
>>> > >I'm specifically thinking of BYPASSRLS- that's independently grantable
>>> > >and therefore should be explicitly set, if it's intended. Things
>>> > >should work 'sanely' with any combination of the two options.
>> >
>> >That does violate POLA, but it's probably worth doing so...
> That really depends on your view of the privilege. I'm inclined to view
> it from the more-tightly-constrained point of view which matches up with
> what I anticipate it actually providing. That doesn't translate into a
> short name very well though, unfortunately.

READ MOST? ;)

>>> > >The read-all vs. ability-to-pg_dump distinction doesn't really exist for
>>> > >role attributes, as I see it (see my comments above). That said, having
>>> > >DUMP or read-all is different from read-*only*, which would probably be
>>> > >good to have independently. I can imagine a use-case for a read-only
>>> > >account which only has read ability for those tables, schemas, etc,
>>> > >explicitly granted to it.
>> >
>> >My specific concern about DUMP vs read all/only is IIRC dump needs to do more extensive locking than regular selects do, which can cause production problems.
> The locks aren't any more extensive than regular selects, it's just that
> the entire pg_dump works inside of one large transaction which lasts a
> good long time and simply that can cause issues with high-rate update
> systems.

Good, so really DUMP and READ ALL are the same.

>>> > >There is one issue that occurs to me, however. We're talking about
>>> > >pg_dump, but what about pg_dumpall? In particular, I don't think the
>>> > >DUMP privilege should provide access to pg_authid, as that would allow
>>> > >the user to bypass the privilege system in some environments by using
>>> > >the hash to log in as a superuser. Now, I don't encourage using
>>> > >password based authentication, especially for superuser accounts, but
>>> > >lots of people do. The idea with these privileges is to allow certain
>>> > >operations to be performed by a non-superuser while preventing trivial
>>> > >access to superuser. Perhaps it's pie-in-the-sky, but my hope is to
>>> > >achieve that.
>> >
>> >Ugh, hadn't thought about that.:(
> I don't think it kills the whole idea, but we do need to work out how to
> address it.

Yeah... it does indicate that we shouldn't call this thing DUMP, but perhaps as long as we put appropriate HINTS in the error paths that pg_dumpall would hit it's OK to call it DUMP. (My specific concern is it's natural to assume that DUMP would include pg_dumpall).

>> >Given the confusion that can exist with the data reading stuff, perhaps BINARY BACKUP or XLOG would be a better term, especially since this will probably have some overlap with streaming replication.
> I don't really like 'xlog' as a permission. BINARY BACKUP is
> interesting but if we're going to go multi-word, I would think we would
> do PITR BACKUP or something FILESYSTEM BACKUP or similar. I'm not
> really a big fan of the two-word options though.

BINARY? Though that's pretty generic. STREAM might be better, even though it's not exactly accurate for a simple backup.

Perhaps this is just a documentation issue, but there's enough caveats floating around here that I'm reluctant to rely on that.

>> >Likewise, if we segregate "DUMP" and BYPASSRLS then I think we need to call DUMP something else. Otherwise, it's a massive foot-gun; you get a "successful" backup only to find out it contains only a small part of the database.
> That's actually already dealt with. pg_dump defaults to setting the
> row_security GUC to 'off', in which case you'll get an error if you hit
> a table that has RLS enabled and you don't have BYPASSRLS. If you're
> not checking for errors from pg_dump, well, there's a lot of ways you
> could run into problems.

This also indicates DUMP is better than something like READ ALL, if we can handle the pg_dumpall case.

Based on all this, my inclination is DUMP with appropriate hints for pg_dumpall, and BINARY.
--
Jim Nasby, Data Architect, Blue Treble Consulting
Data in Trouble? Get it in Treble! http://BlueTreble.com


From: Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: Jim Nasby <Jim(dot)Nasby(at)bluetreble(dot)com>, Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Magnus Hagander <magnus(at)hagander(dot)net>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2014-12-30 07:02:41
Message-ID: CAA4eK1LhCXjjEe-XtsGRtbgWEuSuZU4qFYXRdbefqFAz1J=MNg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Tue, Dec 30, 2014 at 6:52 AM, Stephen Frost <sfrost(at)snowman(dot)net> wrote:
> > >There is one issue that occurs to me, however. We're talking about
> > >pg_dump, but what about pg_dumpall? In particular, I don't think the
> > >DUMP privilege should provide access to pg_authid, as that would allow
> > >the user to bypass the privilege system in some environments by using
> > >the hash to log in as a superuser. Now, I don't encourage using
> > >password based authentication, especially for superuser accounts, but
> > >lots of people do. The idea with these privileges is to allow certain
> > >operations to be performed by a non-superuser while preventing trivial
> > >access to superuser. Perhaps it's pie-in-the-sky, but my hope is to
> > >achieve that.
> >
> > Ugh, hadn't thought about that. :(
>
> I don't think it kills the whole idea, but we do need to work out how to
> address it.
>

One way to address this might be to allow this only for superusers,
another could be have a separate privilege (DBA) or a role which is
not a superuser, however can be used to perform such tasks.

> > >>* BACKUP - allows role to perform backup operations (as originally
proposed)
> > >>* LOG - allows role to rotate log files - remains broad enough to
consider
> > >>future log related operations
> > >>* DUMP - allows role to perform pg_dump* backups of whole database
> > >>* MONITOR - allows role to view pg_stat_* details (as originally
proposed)
> > >>* PROCSIGNAL - allows role to signal backend processes (as originally
> > >>proposed)well
> >
> > Given the confusion that can exist with the data reading stuff, perhaps
BINARY BACKUP or XLOG would be a better term, especially since this will
probably have some overlap with streaming replication.
>
> I don't really like 'xlog' as a permission. BINARY BACKUP is
> interesting but if we're going to go multi-word, I would think we would
> do PITR BACKUP or something FILESYSTEM BACKUP or similar. I'm not
> really a big fan of the two-word options though.
>

How about PHYSICAL BACKUP (for basebackup) and LOGICAL BACKUP
for pg_dump?

This is normally the terminology I have seen people using for these
backup's.

With Regards,
Amit Kapila.
EnterpriseDB: http://www.enterprisedb.com


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>
Cc: Jim Nasby <Jim(dot)Nasby(at)bluetreble(dot)com>, Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Magnus Hagander <magnus(at)hagander(dot)net>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2014-12-30 13:05:45
Message-ID: 20141230130545.GL3062@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

* Amit Kapila (amit(dot)kapila16(at)gmail(dot)com) wrote:
> On Tue, Dec 30, 2014 at 6:52 AM, Stephen Frost <sfrost(at)snowman(dot)net> wrote:
> > > >There is one issue that occurs to me, however. We're talking about
> > > >pg_dump, but what about pg_dumpall? In particular, I don't think the
> > > >DUMP privilege should provide access to pg_authid, as that would allow
> > > >the user to bypass the privilege system in some environments by using
> > > >the hash to log in as a superuser. Now, I don't encourage using
> > > >password based authentication, especially for superuser accounts, but
> > > >lots of people do. The idea with these privileges is to allow certain
> > > >operations to be performed by a non-superuser while preventing trivial
> > > >access to superuser. Perhaps it's pie-in-the-sky, but my hope is to
> > > >achieve that.
> > >
> > > Ugh, hadn't thought about that. :(
> >
> > I don't think it kills the whole idea, but we do need to work out how to
> > address it.
>
> One way to address this might be to allow this only for superusers,

Huh? The point here is to have a role account which isn't a superuser
who can perform these actions.

> another could be have a separate privilege (DBA) or a role which is
> not a superuser, however can be used to perform such tasks.

I'm pretty sure we've agreed that having a catch-all role attribute like
'DBA' is a bad idea because we'd likely be adding privileges to it later
which would expand the rights of users with that attribute, possibly
beyond what is intended.

> > I don't really like 'xlog' as a permission. BINARY BACKUP is
> > interesting but if we're going to go multi-word, I would think we would
> > do PITR BACKUP or something FILESYSTEM BACKUP or similar. I'm not
> > really a big fan of the two-word options though.
>
> How about PHYSICAL BACKUP (for basebackup) and LOGICAL BACKUP
> for pg_dump?

Again, this makes it look like the read-all right would be specific to
users executing pg_dump, which is incorrect and misleading. "PHYSICAL"
might also imply the ability to do pg_basebackup.

> This is normally the terminology I have seen people using for these
> backup's.

I do like the idea of trying to find a correlation in the documentation
for these rights, though I'm not sure we'll be able to.

Thanks,

Stephen


From: Magnus Hagander <magnus(at)hagander(dot)net>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2014-12-30 14:38:12
Message-ID: CABUevEz7BZ0r85VUt4RVXX0JkpiH8hP8ToqzGVpuFL0KvcvBNg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Mon, Dec 29, 2014 at 11:01 PM, Stephen Frost <sfrost(at)snowman(dot)net> wrote:

>
> * Adam Brightwell (adam(dot)brightwell(at)crunchydatasolutions(dot)com) wrote:
> > > I'd suggest it's called DUMP if that's what it allows, to keep it
> separate
> > > from the backup parts.
> >
> > Makes sense to me.
>
> I'm fine calling it 'DUMP', but for different reasons.
>
> We have no (verifiable) idea what client program is being used to
> connect and therefore we shouldn't try to tie the name of the client
> program to the permission.
>
> That said, a 'DUMP' privilege which allows the user to dump the contents
> of the entire database is entirely reasonable. We need to be clear in
> the documentation though- such a 'DUMP' privilege is essentially
> granting USAGE on all schemas and table-level SELECT on all tables and

sequences (anything else..?). To be clear, a user with this privilege
> can utilize that access without using pg_dump.
>

Well, it would not give you full USAGE - granted USAGE on a schema, you can
execute functions in there for example (provided permissions). This
privilege would not do that, it would only give you COPY access. (And also
COPY != SELECT in the way that the rule system applies, I think? And this
one could be for COPY only)

But other than that I agree - for *all* these privileges, it needs to be
clearly documented that they are not limited to a specific client side
application, even if their name happens to be similar to one.

One other point is that this shouldn't imply any other privileges, imv.
> I'm specifically thinking of BYPASSRLS- that's independently grantable
> and therefore should be explicitly set, if it's intended. Things
>

I think BYPASSRLS would have to be implicitly granted by the DUMP
privilege. Without that, the DUMP privilege is more or less meaningless
(for anybody who uses RLS - but if they don't use RLS, then having it
include BYPASSRLS makes no difference). Worse than that, you may end up
with a dump that you cannot restore.

Similar concerns would exist for the existing REPLICATION role for example
- that one clearly lets you bypass RLS as well, just not with a SQL
statement.

should work 'sanely' with any combination of the two options.
> Similairly, DUMP shouldn't imply BACKUP or visa-versa. In particular,
> I'd like to see roles which have only the BACKUP privilege be unable to
> directly read any data (modulo things granted to PUBLIC). This would
> allow an unprivileged user to manage backups, kick off ad-hoc ones, etc,
> without being able to actually access any of the data (this would
> require the actual backup system to have a similar control, but that's
> entirely possible with more advanced SANs and enterprise backup
> solutions).
>

So you're saying a privilege that would allow you to do
pg_start_backup()/pg_stop_backup() but *not* actually use pg_basebackup?
That would be "EXCLUSIVEBACKUP" or something like that, to be consistent
with existing terminology though.

> > That seems really bad names, IMHO. Why? Because we use WAL and XLOG
> > > throughout documentation and parameters and code to mean *the same
> thing*.
> > > And here they'd suddenly mean different things. If we need them as
> separate
> > > privileges, I think we need much better names. (And a better
> description -
> > > what is "xlog operations" really?)
> > >
> >
> > Fair enough, ultimately what I was trying to address is the following
> > concern raised by Alvaro:
> >
> > "To me, what this repeated discussion on this particular BACKUP point
> > says, is that the ability to run pg_start/stop_backend and the xlog
> > related functions should be a different privilege, i.e. something other
> > than BACKUP; because later we will want the ability to grant someone the
> > ability to run pg_dump on the whole database without being superuser,
> > and we will want to use the name BACKUP for that. So I'm inclined to
> > propose something more specific for this like WAL_CONTROL or
> > XLOG_OPERATOR, say."
>
> Note that the BACKUP role attribute was never intended to cover the
> pg_dump use-case. Simply the name of it caused confusion though. I'm
> not sure if adding a DUMP role attribute is sufficient enough to address
> that confusion, but I haven't got a better idea either.
>

We need to separate the logical backups (pg_dump) from the physical ones
(start/stop+filesystem and pg_basebackup). We might also need to separate
the two different ways of doing physical backups.

Personalyl I think using the DUMP name makes that a lot more clear. Maybe
we need to avoid using BACKUP alone as well, to make sure it doesn't go the
other way - using BASEBACKUP and EXCLUSIVEBACKUP for those two different
ones perhaps?

> When indeed, what it meant was to have the following separate (effectively
> > merging #2 and #3):
> >
> > 1) ability to pg_dump
> > 2) ability to start/stop backups *and* ability to execute xlog related
> > functions.
>

We probably also need to define what those "xlog related functions"
actually arse. pg_current_xlog_location() is definitely an xlog related
function, but does it need the privilege? pg_switch_xlog()?
pg_start_backup()? pg_xlog_replay_pause()?

I think just calling them "xlog related functions" is doing us a disservice
there. Definitely once we have an actual documentation to write for it, but
also in this discussion.

That sounds reasonable to me (and is what was initially proposed, though
> I've come around to the thinking that this BACKUP role attribute should
> also allow pg_xlog_replay_pause/resume(), as those can be useful on
> replicas).
>

If it's for replicas, then why are we not using the REPLICATION privilege
which is extremely similar to this?

> Given this clarification:
> >
> > I think #1 could certainly be answered by using DUMP. I have no strong
> > opinion in either direction, though I do think that BACKUP does make the
> > most sense for #2. Previously, Stephen had mentioned a READONLY
> capability
> > that could effectively work for pg_dump, though, Jim's suggestion of
> > keeping 'read-all' separate from 'ability to pg_dump' seems logical. In
> > either case, I certainly wouldn't mind having a wider agreement/consensus
> > on this approach.
>
> The read-all vs. ability-to-pg_dump distinction doesn't really exist for
> role attributes, as I see it (see my comments above). That said, having
> DUMP or read-all is different from read-*only*, which would probably be
> good to have independently. I can imagine a use-case for a read-only
> account which only has read ability for those tables, schemas, etc,
> explicitly granted to it.
>

You mean something that restricts the user to read even *if* write
permissions has been granted on an individual table? Yeah, that would
actually be quite useful, I think - sort of a "reverse privilege".

There is one issue that occurs to me, however. We're talking about
> pg_dump, but what about pg_dumpall? In particular, I don't think the
> DUMP privilege should provide access to pg_authid, as that would allow
> the user to bypass the privilege system in some environments by using
> the hash to log in as a superuser. Now, I don't encourage using
> password based authentication, especially for superuser accounts, but
> lots of people do. The idea with these privileges is to allow certain
> operations to be performed by a non-superuser while preventing trivial
> access to superuser. Perhaps it's pie-in-the-sky, but my hope is to
> achieve that.
>

Well, from an actual security perspective that would make it equivalent to
superuser in the case of anybody using password auth. I'm not sure we cant
to grant that out to DUMP by default - perhaps we need a separate one for
DUMPAUTH or DUMPPASSWORDS.

(We could dump all the users *without* passwords with just the DUMP
privilege)

--
Magnus Hagander
Me: http://www.hagander.net/
Work: http://www.redpill-linpro.com/


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Magnus Hagander <magnus(at)hagander(dot)net>
Cc: Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2014-12-30 15:16:30
Message-ID: 20141230151630.GP3062@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

* Magnus Hagander (magnus(at)hagander(dot)net) wrote:
> On Mon, Dec 29, 2014 at 11:01 PM, Stephen Frost <sfrost(at)snowman(dot)net> wrote:
> > That said, a 'DUMP' privilege which allows the user to dump the contents
> > of the entire database is entirely reasonable. We need to be clear in
> > the documentation though- such a 'DUMP' privilege is essentially
> > granting USAGE on all schemas and table-level SELECT on all tables and
>
> sequences (anything else..?). To be clear, a user with this privilege
> > can utilize that access without using pg_dump.
>
> Well, it would not give you full USAGE - granted USAGE on a schema, you can
> execute functions in there for example (provided permissions). This
> privilege would not do that,

The approach I was thinking was to document and implement this as
impliciting granting exactly USAGE and SELECT rights, no more (not
BYPASSRLS) and no less (yes, the role could execute functions). I agree
that doing so would be strictly more than what pg_dump actually requires
but it's also what we actually have support for in our privilege system.

> it would only give you COPY access. (And also
> COPY != SELECT in the way that the rule system applies, I think? And this
> one could be for COPY only)

COPY certainly does equal SELECT rights.. We haven't got an independent
COPY privilege and I don't think it makes sense to invent one. It
sounds like you're suggesting that we add a hack directly into COPY for
this privilege, but my thinking is that the right place to change for
this is in the privilege system and not hack it into individual
commands.. I'm also a bit nervous that we'll end up painting ourselves
into a corner if we hack this to mean exactly what pg_dump needs today.

Lastly, I've been considering other use-cases for this privilege beyond
the pg_dump one (thinking about auditing, for example).

> But other than that I agree - for *all* these privileges, it needs to be
> clearly documented that they are not limited to a specific client side
> application, even if their name happens to be similar to one.

Right.

> One other point is that this shouldn't imply any other privileges, imv.
> > I'm specifically thinking of BYPASSRLS- that's independently grantable
> > and therefore should be explicitly set, if it's intended. Things
>
> I think BYPASSRLS would have to be implicitly granted by the DUMP
> privilege. Without that, the DUMP privilege is more or less meaningless
> (for anybody who uses RLS - but if they don't use RLS, then having it
> include BYPASSRLS makes no difference). Worse than that, you may end up
> with a dump that you cannot restore.

The dump would fail, as I mentioned before. I don't see why BYPASSRLS
has to be implicitly granted by the DUMP privilege and can absolutely
see use-cases for it to *not* be. Those use-cases would require passing
pg_dump the --enable-row-security option, but that's why it's there.

Implementations which don't use RLS are not impacted either way, so we
don't need to consider them. Implementations which *do* use RLS, in my
experience, would certainly understand and expect BYPASSRLS to be
required if they want this role to be able to dump all data out
regardless of the RLS policies. What does implicitly including
BYPASSRLS in this privilege gain us? A slightly less irritated DBA who
forgot to include BYPASSRLS and ended up getting a pg_dump error because
of it. On the other hand, it walls off any possibility of using this
privilege for roles who shouldn't be allowed to bypass RLS or for
pg_dumps to be done across the entire system for specific RLS policies.

> Similar concerns would exist for the existing REPLICATION role for example
> - that one clearly lets you bypass RLS as well, just not with a SQL
> statement.

I'm not sure that I see the point you're making here. Yes, REPLICATION
allows you to do a filesystem copy of the entire database and that
clearly bypasses RLS and *all* of our privilege system. I'm suggesting
that this role attribute work as an implicit grant of privileges we
already have. That strikes me as easy to document and very clear for
users.

> should work 'sanely' with any combination of the two options.
> > Similairly, DUMP shouldn't imply BACKUP or visa-versa. In particular,
> > I'd like to see roles which have only the BACKUP privilege be unable to
> > directly read any data (modulo things granted to PUBLIC). This would
> > allow an unprivileged user to manage backups, kick off ad-hoc ones, etc,
> > without being able to actually access any of the data (this would
> > require the actual backup system to have a similar control, but that's
> > entirely possible with more advanced SANs and enterprise backup
> > solutions).
>
> So you're saying a privilege that would allow you to do
> pg_start_backup()/pg_stop_backup() but *not* actually use pg_basebackup?

Yes.

> That would be "EXCLUSIVEBACKUP" or something like that, to be consistent
> with existing terminology though.

Ok. I agree that working out the specific naming is difficult and would
like to focus on that, but we probably need to agree on the specific
capabilities first. :)

> > > Fair enough, ultimately what I was trying to address is the following
> > > concern raised by Alvaro:
> > >
> > > "To me, what this repeated discussion on this particular BACKUP point
> > > says, is that the ability to run pg_start/stop_backend and the xlog
> > > related functions should be a different privilege, i.e. something other
> > > than BACKUP; because later we will want the ability to grant someone the
> > > ability to run pg_dump on the whole database without being superuser,
> > > and we will want to use the name BACKUP for that. So I'm inclined to
> > > propose something more specific for this like WAL_CONTROL or
> > > XLOG_OPERATOR, say."
> >
> > Note that the BACKUP role attribute was never intended to cover the
> > pg_dump use-case. Simply the name of it caused confusion though. I'm
> > not sure if adding a DUMP role attribute is sufficient enough to address
> > that confusion, but I haven't got a better idea either.
>
> We need to separate the logical backups (pg_dump) from the physical ones
> (start/stop+filesystem and pg_basebackup). We might also need to separate
> the two different ways of doing physical backups.

Right, I view those as three distinct types of privileges (see below).

> Personalyl I think using the DUMP name makes that a lot more clear. Maybe
> we need to avoid using BACKUP alone as well, to make sure it doesn't go the
> other way - using BASEBACKUP and EXCLUSIVEBACKUP for those two different
> ones perhaps?

DUMP - implicitly grants existing rights, to facilitate pg_dump and
perhaps some other use-cases
BASEBACKUP - allows pg_basebackup, which means bypassing all in-DB
privilege systems
EXCLUSIVEBACKUP - just allows pg_start/stop_backup and friends

I'm still not entirely happy with the naming, but I feel like we're
getting there. One thought I had was using ARCHIVE somewhere, but I
kind of like BASEBACKUP meaning what's needed to run pg_basebackup, and,
well, we say 'backup' in the pg_start/stop_backup function names, so
it's kind of hard to avoid that. EXCLUSIVEBACKUP seems really long tho.

> > When indeed, what it meant was to have the following separate (effectively
> > > merging #2 and #3):
> > >
> > > 1) ability to pg_dump
> > > 2) ability to start/stop backups *and* ability to execute xlog related
> > > functions.
> >
>
> We probably also need to define what those "xlog related functions"
> actually arse. pg_current_xlog_location() is definitely an xlog related
> function, but does it need the privilege? pg_switch_xlog()?
> pg_start_backup()? pg_xlog_replay_pause()?

I had defined them when I started the thread:

pg_start_backup
pg_stop_backup
pg_switch_xlog
pg_create_restore_point

Later I added:

pg_xlog_replay_pause
pg_xlog_replay_resume

Though I'd be find if the xlog_replay ones were their own privilege (eg:
REPLAY or something).

> I think just calling them "xlog related functions" is doing us a disservice
> there. Definitely once we have an actual documentation to write for it, but
> also in this discussion.

It wasn't my intent to be ambiguous about it, I just wasn't repeating
the list with each post. The discussion starts here:

20141015052259(dot)GG28859(at)tamriel(dot)snowman(dot)net

> That sounds reasonable to me (and is what was initially proposed, though
> > I've come around to the thinking that this BACKUP role attribute should
> > also allow pg_xlog_replay_pause/resume(), as those can be useful on
> > replicas).
> >
>
> If it's for replicas, then why are we not using the REPLICATION privilege
> which is extremely similar to this?

I don't actually see REPLICATION as being the same.

The point is to have a role which can log into the replica, pause
the stream to be able to run whatever queries they're permitted to
(which might not include all of the data) and then resume it when done.
Perhaps that needs to be independent of the EXCLUSIVEBACKUP role, but
it's definitely different from the REPLICATION privilege.

> > The read-all vs. ability-to-pg_dump distinction doesn't really exist for
> > role attributes, as I see it (see my comments above). That said, having
> > DUMP or read-all is different from read-*only*, which would probably be
> > good to have independently. I can imagine a use-case for a read-only
> > account which only has read ability for those tables, schemas, etc,
> > explicitly granted to it.
>
> You mean something that restricts the user to read even *if* write
> permissions has been granted on an individual table? Yeah, that would
> actually be quite useful, I think - sort of a "reverse privilege".

Yes. My thinking on how to approach this was to forcibly set all of
their transactions to read-only.

> There is one issue that occurs to me, however. We're talking about
> > pg_dump, but what about pg_dumpall? In particular, I don't think the
> > DUMP privilege should provide access to pg_authid, as that would allow
> > the user to bypass the privilege system in some environments by using
> > the hash to log in as a superuser. Now, I don't encourage using
> > password based authentication, especially for superuser accounts, but
> > lots of people do. The idea with these privileges is to allow certain
> > operations to be performed by a non-superuser while preventing trivial
> > access to superuser. Perhaps it's pie-in-the-sky, but my hope is to
> > achieve that.
>
> Well, from an actual security perspective that would make it equivalent to
> superuser in the case of anybody using password auth. I'm not sure we cant
> to grant that out to DUMP by default - perhaps we need a separate one for
> DUMPAUTH or DUMPPASSWORDS.

That makes sense to me- DUMPAUTH or maybe just DUMPALL (to go with
pg_dumpall).

> (We could dump all the users *without* passwords with just the DUMP
> privilege)

Agreed. That's actually something that I think would be *really* nice-
an option to dump the necessary globals for whatever database you're
running pg_dump against. We have existing problems in this area
(database-level GUCs aren't considered database-specific and therefore
aren't picked up by pg_dump, for example..), but being able to also dump
the roles which are used in a given database with pg_dump would be
*really* nice..

Thanks,

Stephen


From: Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: Jim Nasby <Jim(dot)Nasby(at)bluetreble(dot)com>, Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Magnus Hagander <magnus(at)hagander(dot)net>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2014-12-31 04:38:49
Message-ID: CAA4eK1+tUC_BvxnrwXQy8_oWfZ5Mg4gNtXJz3irnUMOvSoFHHw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Tue, Dec 30, 2014 at 6:35 PM, Stephen Frost <sfrost(at)snowman(dot)net> wrote:
> * Amit Kapila (amit(dot)kapila16(at)gmail(dot)com) wrote:
> > On Tue, Dec 30, 2014 at 6:52 AM, Stephen Frost <sfrost(at)snowman(dot)net>
wrote:
>
> > another could be have a separate privilege (DBA) or a role which is
> > not a superuser, however can be used to perform such tasks.
>
> I'm pretty sure we've agreed that having a catch-all role attribute like
> 'DBA' is a bad idea because we'd likely be adding privileges to it later
> which would expand the rights of users with that attribute, possibly
> beyond what is intended.
>

Yes, that could happen but do you want to say that is the only reason
to consider server level roles (such as DBA) a bad idea. Can't we make
users aware of such things via documentation and then there will be
some onus on user's to give such a privilege with care.

On looking around, it seems many of the databases provides such
roles
https://dbbulletin.wordpress.com/2013/05/29/backup-privileges-needed-to-backup-databases/

In the link, though they are talking about physical (file level) backup,
there is mention about such roles in other databases.

The other way as discussed on this thread is to use something like
DUMPALL (or DUMPFULL) privilege which also sounds to be a good
way, apart from the fact that the same privilege can be used for
non-dump purposes to extract the information from database/cluster.

> > > I don't really like 'xlog' as a permission. BINARY BACKUP is
> > > interesting but if we're going to go multi-word, I would think we
would
> > > do PITR BACKUP or something FILESYSTEM BACKUP or similar. I'm not
> > > really a big fan of the two-word options though.
> >
> > How about PHYSICAL BACKUP (for basebackup) and LOGICAL BACKUP
> > for pg_dump?
>
> Again, this makes it look like the read-all right would be specific to
> users executing pg_dump, which is incorrect and misleading. "PHYSICAL"
> might also imply the ability to do pg_basebackup.
>

That's right, however having unrelated privileges for doing physical
backup via pg_basebackup and pg_start*/pg_stop* method also
doesn't sound to be the best way (can be slightly difficult for
users to correlate after reading docs). Don't you think in this case
we should have some form of hierarchy for privileges (like user
having privilege to do pg_basebackup can also perform the
backup via pg_start*/pg_stop* method or some other way to relate
both forms of physical backup)?

With Regards,
Amit Kapila.
EnterpriseDB: http://www.enterprisedb.com


From: José Luis Tallón <jltallon(at)adv-solutions(dot)net>
To: Stephen Frost <sfrost(at)snowman(dot)net>, Magnus Hagander <magnus(at)hagander(dot)net>
Cc: Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2014-12-31 13:00:01
Message-ID: 54A3F351.7060200@adv-solutions.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 12/30/2014 04:16 PM, Stephen Frost wrote:
> [snip]
> The approach I was thinking was to document and implement this as
> impliciting granting exactly USAGE and SELECT rights, no more (not
> BYPASSRLS) and no less (yes, the role could execute functions). I agree
> that doing so would be strictly more than what pg_dump actually requires
> but it's also what we actually have support for in our privilege system.

Hmmm.... coupled with your comments below, I'd say some tweaking of the
existing privileges is actually needed if we want to add these new
"capabilities".

BTW, and since this is getting a bit bigger than originally considered:
would it be interesting to support some extension-defined capabilities, too?
(for things can't be easily controlled by the existing USAGE /
SELECT / ... rights, I mean)

>> it would only give you COPY access. (And also
>> COPY != SELECT in the way that the rule system applies, I think? And this
>> one could be for COPY only)
> COPY certainly does equal SELECT rights.. We haven't got an independent
> COPY privilege and I don't think it makes sense to invent one.

FWIW, a COPY(DUMP?) privilege different from SELECT would make sense.
Considering your below comments it would be better that it not imply
BYPASSRLS, though.

> It
> sounds like you're suggesting that we add a hack directly into COPY for
> this privilege, but my thinking is that the right place to change for
> this is in the privilege system and not hack it into individual
> commands.. I'm also a bit nervous that we'll end up painting ourselves
> into a corner if we hack this to mean exactly what pg_dump needs today.
Agreed.

> Lastly, I've been considering other use-cases for this privilege beyond
> the pg_dump one (thinking about auditing, for example).

ISTR there was something upthread on an AUDIT role, right?
This might be the moment to add it....

> [snip]
>> Similar concerns would exist for the existing REPLICATION role for example
>> - that one clearly lets you bypass RLS as well, just not with a SQL
>> statement.
> I'm not sure that I see the point you're making here. Yes, REPLICATION
> allows you to do a filesystem copy of the entire database and that
> clearly bypasses RLS and *all* of our privilege system. I'm suggesting
> that this role attribute work as an implicit grant of privileges we
> already have. That strikes me as easy to document and very clear for
> users.

+1
> [snip]
> So you're saying a privilege that would allow you to do
> pg_start_backup()/pg_stop_backup() but *not* actually use pg_basebackup?
> Yes.
>
>> That would be "EXCLUSIVEBACKUP" or something like that, to be consistent
>> with existing terminology though.
> Ok. I agree that working out the specific naming is difficult and would
> like to focus on that, but we probably need to agree on the specific
> capabilities first. :)

Yes :)
For the record, LOGBACKUP vs PHYSBACKUP was suggested a couple days ago.
I'd favor DUMP(logical) and BACKUP(physical) --- for lack of a better name.
The above reasoning would have pg_basebackup requiring REPLICATION,
which is a logical consequence of the implementation but strikes me as a
bit surprising in the light of these other privileges.

>
> [snip]
>> Personalyl I think using the DUMP name makes that a lot more clear. Maybe
>> we need to avoid using BACKUP alone as well, to make sure it doesn't go the
>> other way - using BASEBACKUP and EXCLUSIVEBACKUP for those two different
>> ones perhaps?
> DUMP - implicitly grants existing rights, to facilitate pg_dump and
> perhaps some other use-cases
> BASEBACKUP - allows pg_basebackup, which means bypassing all in-DB
> privilege systems
> EXCLUSIVEBACKUP - just allows pg_start/stop_backup and friends
>
> I'm still not entirely happy with the naming, but I feel like we're
> getting there. One thought I had was using ARCHIVE somewhere, but I
> kind of like BASEBACKUP meaning what's needed to run pg_basebackup, and,
> well, we say 'backup' in the pg_start/stop_backup function names, so
> it's kind of hard to avoid that. EXCLUSIVEBACKUP seems really long tho.

ARCHIVE, though completely appropriate for the "exclusivebackup" case
above (so this would become DUMP/BASEBACKUP/ARCHIVE +REPLICATION) might
end up causing quite some confusion ... ("what? WAL archiving is NOT
granted by the "archive" privilege, but requires a superuser to turn it
on(via ALTER SYSTEM)?

POLA again....
> I had defined them when I started the thread:
>
> pg_start_backup
> pg_stop_backup
> pg_switch_xlog
> pg_create_restore_point

... for "BACKUP" / EXCLUSIVEBACKUP (or, actually, FSBACKUP/PHYSBACKUP ...)
> Later I added:
>
> pg_xlog_replay_pause
> pg_xlog_replay_resume
>
> Though I'd be find if the xlog_replay ones were their own privilege (eg:
> REPLAY or something).
+1
>> I think just calling them "xlog related functions" is doing us a disservice
>> there. Definitely once we have an actual documentation to write for it, but
>> also in this discussion.
> [snip]
>> If it's for replicas, then why are we not using the REPLICATION privilege
>> which is extremely similar to this?
> I don't actually see REPLICATION as being the same.

REPLICATION (ability to replicate) vs REPLICAOPERATOR (ability to
control *the replica* or the R/O behaviour of the server, for that
matter...)

> The point is to have a role which can log into the replica, pause
> the stream to be able to run whatever queries they're permitted to
> (which might not include all of the data) and then resume it when done.
> Perhaps that needs to be independent of the EXCLUSIVEBACKUP role, but
> it's definitely different from the REPLICATION privilege.

Looks like it is.
>>> The read-all vs. ability-to-pg_dump distinction doesn't really exist for
>>> role attributes, as I see it (see my comments above). That said, having
>>> DUMP or read-all is different from read-*only*, which would probably be
>>> good to have independently. I can imagine a use-case for a read-only
>>> account which only has read ability for those tables, schemas, etc,
>>> explicitly granted to it.
>> You mean something that restricts the user to read even *if* write
>> permissions has been granted on an individual table? Yeah, that would
>> actually be quite useful, I think - sort of a "reverse privilege".
> Yes. My thinking on how to approach this was to forcibly set all of
> their transactions to read-only.

So "READONLY" ?

>> There is one issue that occurs to me, however. We're talking about
>>> pg_dump, but what about pg_dumpall? In particular, I don't think the
>>> DUMP privilege should provide access to pg_authid, as that would allow
>>> the user to bypass the privilege system in some environments by using
>>> the hash to log in as a superuser. Now, I don't encourage using
>>> password based authentication, especially for superuser accounts, but
>>> lots of people do. The idea with these privileges is to allow certain
>>> operations to be performed by a non-superuser while preventing trivial
>>> access to superuser. Perhaps it's pie-in-the-sky, but my hope is to
>>> achieve that.
>> Well, from an actual security perspective that would make it equivalent to
>> superuser in the case of anybody using password auth. I'm not sure we cant
>> to grant that out to DUMP by default - perhaps we need a separate one for
>> DUMPAUTH or DUMPPASSWORDS.
> That makes sense to me- DUMPAUTH or maybe just DUMPALL (to go with
> pg_dumpall).

+1
>> (We could dump all the users *without* passwords with just the DUMP
>> privilege)
> Agreed. That's actually something that I think would be *really* nice-
> an option to dump the necessary globals for whatever database you're
> running pg_dump against. We have existing problems in this area
> (database-level GUCs aren't considered database-specific and therefore
> aren't picked up by pg_dump, for example..), but being able to also dump
> the roles which are used in a given database with pg_dump would be
> *really* nice..

Ok, so this would imply modifying pg_dump to include database-level
configs. I would heartily welcome this.

So, it seems to me that we are actually evolving towards a set of
"low-level" "capabilities" and some "high-level" (use case-focused)
"privileges".
I am hereby volunteering to compile this thread into some wiki page. I'm
thinking "Privileges" as the title for starters. Suggestions?

Thanks,

/ J.L.


From: Magnus Hagander <magnus(at)hagander(dot)net>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2014-12-31 13:27:46
Message-ID: CABUevEzSR=w4v1ereJM2qaZ+zvfzAe_v9POdYxxnP=r6V1U1YQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Tue, Dec 30, 2014 at 4:16 PM, Stephen Frost <sfrost(at)snowman(dot)net> wrote:

> * Magnus Hagander (magnus(at)hagander(dot)net) wrote:
> > On Mon, Dec 29, 2014 at 11:01 PM, Stephen Frost <sfrost(at)snowman(dot)net>
> wrote:
> > > That said, a 'DUMP' privilege which allows the user to dump the
> contents
> > > of the entire database is entirely reasonable. We need to be clear in
> > > the documentation though- such a 'DUMP' privilege is essentially
> > > granting USAGE on all schemas and table-level SELECT on all tables and
> >
> > sequences (anything else..?). To be clear, a user with this privilege
> > > can utilize that access without using pg_dump.
> >
> > Well, it would not give you full USAGE - granted USAGE on a schema, you
> can
> > execute functions in there for example (provided permissions). This
> > privilege would not do that,
>
> The approach I was thinking was to document and implement this as
> impliciting granting exactly USAGE and SELECT rights, no more (not
> BYPASSRLS) and no less (yes, the role could execute functions). I agree
>

If the role could execute functions, it's *not* "exactly USAGE and SELECT
rights", it's now "USAGE and SELECT and EXECUTE" rights... Just to be
nitpicking, but see below.

> that doing so would be strictly more than what pg_dump actually requires
> but it's also what we actually have support for in our privilege system.
>

Yeah, but would it also be what people would actually *want*?

I think having it do exactly what pg_dump needs, and not things like
execute functions etc, would be the thing people want for a 'DUMP'
privilege.

We might *also* want a USAGEANDSELECTANDEXECUTEANDWHATNOTBUTNOBYPASSURL
(crap, it has to fit within NAMEDATALEN?) privilege, but I think that's a
different thing.

> it would only give you COPY access. (And also
> > COPY != SELECT in the way that the rule system applies, I think? And this
> > one could be for COPY only)
>
> COPY certainly does equal SELECT rights.. We haven't got an independent
> COPY privilege and I don't think it makes sense to invent one. It
>

We don't, but I'm saying it might make sense to implement this. Not as a
regular privilige, but as a role attribute. I'm not sure it's the right
thing, but it might actually be interesting to entertain.

> sounds like you're suggesting that we add a hack directly into COPY for
> this privilege, but my thinking is that the right place to change for
> this is in the privilege system and not hack it into individual
> commands.. I'm also a bit nervous that we'll end up painting ourselves
> into a corner if we hack this to mean exactly what pg_dump needs today.
>

One point would be that if we define it as "exactly what pg_dump needs",
that definition can change in a future major version.

> One other point is that this shouldn't imply any other privileges, imv.
> > > I'm specifically thinking of BYPASSRLS- that's independently grantable
> > > and therefore should be explicitly set, if it's intended. Things
> >
> > I think BYPASSRLS would have to be implicitly granted by the DUMP
> > privilege. Without that, the DUMP privilege is more or less meaningless
> > (for anybody who uses RLS - but if they don't use RLS, then having it
> > include BYPASSRLS makes no difference). Worse than that, you may end up
> > with a dump that you cannot restore.
>
> The dump would fail, as I mentioned before. I don't see why BYPASSRLS
> has to be implicitly granted by the DUMP privilege and can absolutely
> see use-cases for it to *not* be. Those use-cases would require passing
> pg_dump the --enable-row-security option, but that's why it's there.
>

So you're basically saying that if RLS is in use anywhere, this priviliege
alone would be useless, correct? And you would get a hard failure at *dump
time*, not at reload time? That would at least make it acceptable, as you
would know it's wrong. and we could make the error messages shown
specifically hint that you need to grant both privileges to make it useful.

We could/should also throw a WARNING if DUMP Is granted to a role without
BYPASSRLS in case row level security is enabled in the system, I think. But
that's more of an implementation detail.

Implementations which don't use RLS are not impacted either way, so we
> don't need to consider them. Implementations which *do* use RLS, in my
> experience, would certainly understand and expect BYPASSRLS to be
> required if they want this role to be able to dump all data out
> regardless of the RLS policies. What does implicitly including
> BYPASSRLS in this privilege gain us? A slightly less irritated DBA who
> forgot to include BYPASSRLS and ended up getting a pg_dump error because
> of it. On the other hand, it walls off any possibility of using this
> privilege for roles who shouldn't be allowed to bypass RLS or for
> pg_dumps to be done across the entire system for specific RLS policies.
>

Yeah, I think that's acceptable as long as we get the error at dump, and
not at reload (when it's too late to fix it).

> Similar concerns would exist for the existing REPLICATION role for example
> > - that one clearly lets you bypass RLS as well, just not with a SQL
> > statement.
>
> I'm not sure that I see the point you're making here. Yes, REPLICATION
> allows you to do a filesystem copy of the entire database and that
> clearly bypasses RLS and *all* of our privilege system. I'm suggesting
> that this role attribute work as an implicit grant of privileges we
> already have. That strikes me as easy to document and very clear for
> users.
>

It does - though documenting that it implicitly gives you a different
privilege as well is also easy :)

But it does potentially limit us to what we can actually do with the
priviliges. One reason to use them is exactly because we *cannot* express
this with our regular permissions (such as BYPASSRLS or REPLICATION).

For regular permissions, we could just pre-populate the system with
predefined roles and use regular GRANTs to those roles, instead of relying
on role attributes, which might in that case make it even more clear?

> should work 'sanely' with any combination of the two options.
> > > Similairly, DUMP shouldn't imply BACKUP or visa-versa. In particular,
> > > I'd like to see roles which have only the BACKUP privilege be unable to
> > > directly read any data (modulo things granted to PUBLIC). This would
> > > allow an unprivileged user to manage backups, kick off ad-hoc ones,
> etc,
> > > without being able to actually access any of the data (this would
> > > require the actual backup system to have a similar control, but that's
> > > entirely possible with more advanced SANs and enterprise backup
> > > solutions).
> >
> > So you're saying a privilege that would allow you to do
> > pg_start_backup()/pg_stop_backup() but *not* actually use pg_basebackup?
>
> Yes.
>

What's really the usecase for that? I'd say that pg_start/stop backup is a
superset and a higher privilige than using pg_basebackup, since you can for
example destroy other peoples backups using it (by running pg_stop_backup
while they are running).

> That would be "EXCLUSIVEBACKUP" or something like that, to be consistent
> > with existing terminology though.
>
> Ok. I agree that working out the specific naming is difficult and would
> like to focus on that, but we probably need to agree on the specific
> capabilities first. :)
>

:)

> > > Fair enough, ultimately what I was trying to address is the following
> > > > concern raised by Alvaro:
> > > >
> > > > "To me, what this repeated discussion on this particular BACKUP point
> > > > says, is that the ability to run pg_start/stop_backend and the xlog
> > > > related functions should be a different privilege, i.e. something
> other
> > > > than BACKUP; because later we will want the ability to grant someone
> the
> > > > ability to run pg_dump on the whole database without being superuser,
> > > > and we will want to use the name BACKUP for that. So I'm inclined to
> > > > propose something more specific for this like WAL_CONTROL or
> > > > XLOG_OPERATOR, say."
> > >
> > > Note that the BACKUP role attribute was never intended to cover the
> > > pg_dump use-case. Simply the name of it caused confusion though. I'm
> > > not sure if adding a DUMP role attribute is sufficient enough to
> address
> > > that confusion, but I haven't got a better idea either.
> >
> > We need to separate the logical backups (pg_dump) from the physical ones
> > (start/stop+filesystem and pg_basebackup). We might also need to separate
> > the two different ways of doing physical backups.
>
> Right, I view those as three distinct types of privileges (see below).

> Personalyl I think using the DUMP name makes that a lot more clear. Maybe
> > we need to avoid using BACKUP alone as well, to make sure it doesn't go
> the
> > other way - using BASEBACKUP and EXCLUSIVEBACKUP for those two different
> > ones perhaps?
>
> DUMP - implicitly grants existing rights, to facilitate pg_dump and
> perhaps some other use-cases
> BASEBACKUP - allows pg_basebackup, which means bypassing all in-DB
> privilege systems
>

That's equivalent of REPLICATION, yes?

> EXCLUSIVEBACKUP - just allows pg_start/stop_backup and friends
>

I'd say there is no "just" there really - that's a higher level privilege,
but I see your point :)

I'm still not entirely happy with the naming, but I feel like we're
> getting there. One thought I had was using ARCHIVE somewhere, but I
> kind of like BASEBACKUP meaning what's needed to run pg_basebackup, and,
> well, we say 'backup' in the pg_start/stop_backup function names, so
> it's kind of hard to avoid that. EXCLUSIVEBACKUP seems really long tho.
>

I don't like ARCHIVE in that it sounds like something to do with log
archiving. If anything, that would affect pg_receivexlog, but that's
definitely REPLICATION. I'd rather keep that one for a future time where we
might let users actually do something about log archiving directly, which
would then use the name.

The reason I like EXCLUSIVEBACKUP is that it's a term we already use. It's
only 4 chars longer than REPLICATION for example - does that really matter?
As long as we don't store the name, it should have no effect at all, and
even if we do, I'm not sure it matters. If you want it shorter, we can have
EXCLBACKUP :)

> > When indeed, what it meant was to have the following separate
> (effectively
> > > > merging #2 and #3):
> > > >
> > > > 1) ability to pg_dump
> > > > 2) ability to start/stop backups *and* ability to execute xlog
> related
> > > > functions.
> > >
> >
> > We probably also need to define what those "xlog related functions"
> > actually arse. pg_current_xlog_location() is definitely an xlog related
> > function, but does it need the privilege? pg_switch_xlog()?
> > pg_start_backup()? pg_xlog_replay_pause()?
>
> I had defined them when I started the thread:
>

Apologies - I had missed that part.

pg_start_backup
> pg_stop_backup
> pg_switch_xlog
> pg_create_restore_point
>

Ok. That makes sense.

Later I added:
>
> pg_xlog_replay_pause
> pg_xlog_replay_resume
>
> Though I'd be find if the xlog_replay ones were their own privilege (eg:
> REPLAY or something).
>

I think it makes more sense to have those replay functions to be a separate
privilege, yes. They have nothing to actually do with taking the backups -
they are for restoring them. And to restore the backups, you clearly
already have superuser level privileges on the system outside the db (at
least as long as we only allow full cluster restores).

> That sounds reasonable to me (and is what was initially proposed, though
> > > I've come around to the thinking that this BACKUP role attribute should
> > > also allow pg_xlog_replay_pause/resume(), as those can be useful on
> > > replicas).
> > >
> >
> > If it's for replicas, then why are we not using the REPLICATION privilege
> > which is extremely similar to this?
>
> I don't actually see REPLICATION as being the same.
>
> The point is to have a role which can log into the replica, pause
> the stream to be able to run whatever queries they're permitted to
> (which might not include all of the data) and then resume it when done.
> Perhaps that needs to be independent of the EXCLUSIVEBACKUP role, but
> it's definitely different from the REPLICATION privilege.
>

Agreed per above, now that I realize what we mean. I do think it needs to
be at least as independent from EXCLUSIVEBACKUP as it does froM REPLICATION
though.

> > The read-all vs. ability-to-pg_dump distinction doesn't really exist for
> > > role attributes, as I see it (see my comments above). That said,
> having
> > > DUMP or read-all is different from read-*only*, which would probably be
> > > good to have independently. I can imagine a use-case for a read-only
> > > account which only has read ability for those tables, schemas, etc,
> > > explicitly granted to it.
> >
> > You mean something that restricts the user to read even *if* write
> > permissions has been granted on an individual table? Yeah, that would
> > actually be quite useful, I think - sort of a "reverse privilege".
>
> Yes. My thinking on how to approach this was to forcibly set all of
> their transactions to read-only.
>

Agreed that this would be very useful.

> There is one issue that occurs to me, however. We're talking about
> > > pg_dump, but what about pg_dumpall? In particular, I don't think the
> > > DUMP privilege should provide access to pg_authid, as that would allow
> > > the user to bypass the privilege system in some environments by using
> > > the hash to log in as a superuser. Now, I don't encourage using
> > > password based authentication, especially for superuser accounts, but
> > > lots of people do. The idea with these privileges is to allow certain
> > > operations to be performed by a non-superuser while preventing trivial
> > > access to superuser. Perhaps it's pie-in-the-sky, but my hope is to
> > > achieve that.
> >
> > Well, from an actual security perspective that would make it equivalent
> to
> > superuser in the case of anybody using password auth. I'm not sure we
> cant
> > to grant that out to DUMP by default - perhaps we need a separate one for
> > DUMPAUTH or DUMPPASSWORDS.
>
> That makes sense to me- DUMPAUTH or maybe just DUMPALL (to go with
> pg_dumpall).
>

I'd prefer DUMPAUTH specifically because it makes it glaringly obvious that
you're going to be dumping authentication data.

> (We could dump all the users *without* passwords with just the DUMP
> > privilege)
>
> Agreed. That's actually something that I think would be *really* nice-
> an option to dump the necessary globals for whatever database you're
> running pg_dump against. We have existing problems in this area
> (database-level GUCs aren't considered database-specific and therefore
> aren't picked up by pg_dump, for example..), but being able to also dump
> the roles which are used in a given database with pg_dump would be
> *really* nice..
>

Yes. Shouldn't be *that* hard, completely independent of this privilege
work. Famous last words, I'm sure...

--
Magnus Hagander
Me: http://www.hagander.net/
Work: http://www.redpill-linpro.com/


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Magnus Hagander <magnus(at)hagander(dot)net>
Cc: Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2014-12-31 14:08:42
Message-ID: 20141231140841.GQ3062@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

* Magnus Hagander (magnus(at)hagander(dot)net) wrote:
> On Tue, Dec 30, 2014 at 4:16 PM, Stephen Frost <sfrost(at)snowman(dot)net> wrote:
> > The approach I was thinking was to document and implement this as
> > impliciting granting exactly USAGE and SELECT rights, no more (not
> > BYPASSRLS) and no less (yes, the role could execute functions). I agree
>
> If the role could execute functions, it's *not* "exactly USAGE and SELECT
> rights", it's now "USAGE and SELECT and EXECUTE" rights... Just to be
> nitpicking, but see below.

We seem to be coming at it from two different directions, so I'll try to
clarify. What I'm suggesting is that this role attribute be strictly
*additive*. Any other privileges granted to the role with this role
attribute would still be applicable, including grants made to PUBLIC.

This role attribute would *not* include EXECUTE rights, by that logic.
However, if PUBLIC was granted EXECUTE rights for the function, then
this role could execute that function.

What it sounds like is you're imagining this role attribute to mean the
role has *only* USAGE and SELECT (or COPY or whatever) rights across the
board and that any grants done explicitly to this role or to public
wouldn't be respected. In my view, that moves this away from a role
*attribute* to being a pre-defined *role*, as such a role would not be
usable for anything else.

> > that doing so would be strictly more than what pg_dump actually requires
> > but it's also what we actually have support for in our privilege system.
>
> Yeah, but would it also be what people would actually *want*?

I can certainly see reasons why you'd want such a role to be able to
execute functions- in particular, consider xlog_pause anx xlog_resume.
If this role can't execute those functions then they probably can't
successfully run pg_dump against a replica.

> I think having it do exactly what pg_dump needs, and not things like
> execute functions etc, would be the thing people want for a 'DUMP'
> privilege.

What if we want pg_dump in 9.6 to have an option to execute xlog_pause
and xlog_resume for you? You wouldn't be able to run that against a 9.5
database (or at least, that option wouldn't work).

> We might *also* want a USAGEANDSELECTANDEXECUTEANDWHATNOTBUTNOBYPASSURL
> (crap, it has to fit within NAMEDATALEN?) privilege, but I think that's a
> different thing.

Our privilege system doesn't currently allow for negative grants (deny
user X the ability to run functions, even if EXECUTE is granted to
PUBLIC). I'm not against that idea, but I don't see it as the same as
this.

> > it would only give you COPY access. (And also
> > > COPY != SELECT in the way that the rule system applies, I think? And this
> > > one could be for COPY only)
> >
> > COPY certainly does equal SELECT rights.. We haven't got an independent
> > COPY privilege and I don't think it makes sense to invent one. It
>
> We don't, but I'm saying it might make sense to implement this. Not as a
> regular privilige, but as a role attribute. I'm not sure it's the right
> thing, but it might actually be interesting to entertain.

We've discussed having a role attribute for COPY-from-filesystem, but
pg_dump doesn't use that ever, it only uses COPY TO STDOUT. I'm not
a fan of making a COPY_TO_STDOUT-vs-SELECT distinction just for this..

> > sounds like you're suggesting that we add a hack directly into COPY for
> > this privilege, but my thinking is that the right place to change for
> > this is in the privilege system and not hack it into individual
> > commands.. I'm also a bit nervous that we'll end up painting ourselves
> > into a corner if we hack this to mean exactly what pg_dump needs today.
>
> One point would be that if we define it as "exactly what pg_dump needs",
> that definition can change in a future major version.

Sure, but that then gets a bit ugly because we encourage running the
latest version of pg_dump against the prior-major-version.

> > > I think BYPASSRLS would have to be implicitly granted by the DUMP
> > > privilege. Without that, the DUMP privilege is more or less meaningless
> > > (for anybody who uses RLS - but if they don't use RLS, then having it
> > > include BYPASSRLS makes no difference). Worse than that, you may end up
> > > with a dump that you cannot restore.
> >
> > The dump would fail, as I mentioned before. I don't see why BYPASSRLS
> > has to be implicitly granted by the DUMP privilege and can absolutely
> > see use-cases for it to *not* be. Those use-cases would require passing
> > pg_dump the --enable-row-security option, but that's why it's there.
>
> So you're basically saying that if RLS is in use anywhere, this priviliege
> alone would be useless, correct?

No, it would still be *extremely* useful. We have an option to pg_dump
to say "please dump with RLS enabled". What that means is that you'd be
able to dump the entire database for all data you're allowed to see
through RLS policies. How is that useless? I certainly think it'd be
very handy and a good way to get *segregated* dumps according to policy.

> And you would get a hard failure at *dump
> time*, not at reload time?

If you attempt to pg_dump a relation which has RLS enabled, and you
don't enable RLS with pg_dump, then you'll get a failure at dump time,
yes. That's far better than a reload-time failure.

> That would at least make it acceptable, as you
> would know it's wrong. and we could make the error messages shown
> specifically hint that you need to grant both privileges to make it useful.

Agreed, having such a hint makes sense.

> We could/should also throw a WARNING if DUMP Is granted to a role without
> BYPASSRLS in case row level security is enabled in the system, I think. But
> that's more of an implementation detail.

That's a bit ugly and RLS could be added to a relation after the DUMP
privilege is granted.

What I think this part of the discussion is getting at is that there's a
lot of people who view pg_dump as explicitly for "dump the ENTIRE
database". While that's one use-case it is certainly not the only one.
I find "pg_dump schema X" to be very common and often find that pg_dump
against an entire database isn't practical because of the size of the
database.

> Implementations which don't use RLS are not impacted either way, so we
> > don't need to consider them. Implementations which *do* use RLS, in my
> > experience, would certainly understand and expect BYPASSRLS to be
> > required if they want this role to be able to dump all data out
> > regardless of the RLS policies. What does implicitly including
> > BYPASSRLS in this privilege gain us? A slightly less irritated DBA who
> > forgot to include BYPASSRLS and ended up getting a pg_dump error because
> > of it. On the other hand, it walls off any possibility of using this
> > privilege for roles who shouldn't be allowed to bypass RLS or for
> > pg_dumps to be done across the entire system for specific RLS policies.
> >
>
> Yeah, I think that's acceptable as long as we get the error at dump, and
> not at reload (when it's too late to fix it).

Right, that's the same decision we came to in the general RLS
discussion.

> > Similar concerns would exist for the existing REPLICATION role for example
> > > - that one clearly lets you bypass RLS as well, just not with a SQL
> > > statement.
> >
> > I'm not sure that I see the point you're making here. Yes, REPLICATION
> > allows you to do a filesystem copy of the entire database and that
> > clearly bypasses RLS and *all* of our privilege system. I'm suggesting
> > that this role attribute work as an implicit grant of privileges we
> > already have. That strikes me as easy to document and very clear for
> > users.
>
> It does - though documenting that it implicitly gives you a different
> privilege as well is also easy :)
>
> But it does potentially limit us to what we can actually do with the
> priviliges. One reason to use them is exactly because we *cannot* express
> this with our regular permissions (such as BYPASSRLS or REPLICATION).

Ok, I see the point you're making that we could make this into a
capability which isn't something which can be expressed through our
existing GRANT system. That strikes me as a solution trying to find a
problem though. There's no need to invent such an oddity for this
particular use-case, I don't think.

> For regular permissions, we could just pre-populate the system with
> predefined roles and use regular GRANTs to those roles, instead of relying
> on role attributes, which might in that case make it even more clear?

The reason for this approach is to address exactly the nightmare that is
trying to maintain those regular permissions across all the objects in
the system. Today, people simply give the role trying to do the pg_dump
superuser, which is the best option we have. Saying 'grant SELECT on
all the tables and USAGE on all the schemas' isn't suggested because
it's a huge pain. This role attribute provides a middle ground where
the pg_dump'ing role isn't a superuser, but you don't have to ensure
usage and select are granted to it for every relation.

> > should work 'sanely' with any combination of the two options.
> > > > Similairly, DUMP shouldn't imply BACKUP or visa-versa. In particular,
> > > > I'd like to see roles which have only the BACKUP privilege be unable to
> > > > directly read any data (modulo things granted to PUBLIC). This would
> > > > allow an unprivileged user to manage backups, kick off ad-hoc ones,
> > etc,
> > > > without being able to actually access any of the data (this would
> > > > require the actual backup system to have a similar control, but that's
> > > > entirely possible with more advanced SANs and enterprise backup
> > > > solutions).
> > >
> > > So you're saying a privilege that would allow you to do
> > > pg_start_backup()/pg_stop_backup() but *not* actually use pg_basebackup?
> >
> > Yes.
>
> What's really the usecase for that? I'd say that pg_start/stop backup is a
> superset and a higher privilige than using pg_basebackup, since you can for
> example destroy other peoples backups using it (by running pg_stop_backup
> while they are running).

One use-case is to allow unprivileged users to run adhoc backups.
Another is simply that you don't want the cronjob that runs the backup
to be able to read any of the data directly (why would you?). I agree
that the individuals who have this capability would still need to
coordinate or at lesat not step on each other or they could end up with
bad backups.

Another way to address that would be to require that the role calling
stop_backup be a member of the role which called start_backup (that also
address the superuser case, as superusers are considered members of all
roles). That seems like a pretty reasonable sanity check requirement.

> > Personalyl I think using the DUMP name makes that a lot more clear. Maybe
> > > we need to avoid using BACKUP alone as well, to make sure it doesn't go
> > the
> > > other way - using BASEBACKUP and EXCLUSIVEBACKUP for those two different
> > > ones perhaps?
> >
> > DUMP - implicitly grants existing rights, to facilitate pg_dump and
> > perhaps some other use-cases
> > BASEBACKUP - allows pg_basebackup, which means bypassing all in-DB
> > privilege systems
>
> That's equivalent of REPLICATION, yes?

Ah, yeah, seems like it would be. Got ahead of myself. :)

> > EXCLUSIVEBACKUP - just allows pg_start/stop_backup and friends
>
> I'd say there is no "just" there really - that's a higher level privilege,
> but I see your point :)

Well, see above, but ok.

> I'm still not entirely happy with the naming, but I feel like we're
> > getting there. One thought I had was using ARCHIVE somewhere, but I
> > kind of like BASEBACKUP meaning what's needed to run pg_basebackup, and,
> > well, we say 'backup' in the pg_start/stop_backup function names, so
> > it's kind of hard to avoid that. EXCLUSIVEBACKUP seems really long tho.
> >
>
> I don't like ARCHIVE in that it sounds like something to do with log
> archiving. If anything, that would affect pg_receivexlog, but that's
> definitely REPLICATION. I'd rather keep that one for a future time where we
> might let users actually do something about log archiving directly, which
> would then use the name.

Ok.

> The reason I like EXCLUSIVEBACKUP is that it's a term we already use. It's
> only 4 chars longer than REPLICATION for example - does that really matter?

Eh, I guess not. :)

> As long as we don't store the name, it should have no effect at all, and
> even if we do, I'm not sure it matters. If you want it shorter, we can have
> EXCLBACKUP :)

Eh.

> > I had defined them when I started the thread:
>
> Apologies - I had missed that part.

No prob.

> pg_start_backup
> > pg_stop_backup
> > pg_switch_xlog
> > pg_create_restore_point
> >
>
> Ok. That makes sense.
>
>
> Later I added:
> >
> > pg_xlog_replay_pause
> > pg_xlog_replay_resume
> >
> > Though I'd be find if the xlog_replay ones were their own privilege (eg:
> > REPLAY or something).
> >
>
> I think it makes more sense to have those replay functions to be a separate
> privilege, yes. They have nothing to actually do with taking the backups -
> they are for restoring them. And to restore the backups, you clearly
> already have superuser level privileges on the system outside the db (at
> least as long as we only allow full cluster restores).

Not quite- remember that reply_pause/resume can be done on a replica, so
they are useful to be able to grant independent from superuser. Perhaps
we call such a role attribute XLOGREPLAY ?

> > I don't actually see REPLICATION as being the same.
> >
> > The point is to have a role which can log into the replica, pause
> > the stream to be able to run whatever queries they're permitted to
> > (which might not include all of the data) and then resume it when done.
> > Perhaps that needs to be independent of the EXCLUSIVEBACKUP role, but
> > it's definitely different from the REPLICATION privilege.
> >
>
> Agreed per above, now that I realize what we mean. I do think it needs to
> be at least as independent from EXCLUSIVEBACKUP as it does froM REPLICATION
> though.

Ok.

> > > You mean something that restricts the user to read even *if* write
> > > permissions has been granted on an individual table? Yeah, that would
> > > actually be quite useful, I think - sort of a "reverse privilege".
> >
> > Yes. My thinking on how to approach this was to forcibly set all of
> > their transactions to read-only.
>
> Agreed that this would be very useful.

Glad we agree.. Any thoughts on implementation? :)

> > > Well, from an actual security perspective that would make it equivalent
> > to
> > > superuser in the case of anybody using password auth. I'm not sure we
> > cant
> > > to grant that out to DUMP by default - perhaps we need a separate one for
> > > DUMPAUTH or DUMPPASSWORDS.
> >
> > That makes sense to me- DUMPAUTH or maybe just DUMPALL (to go with
> > pg_dumpall).
> >
>
> I'd prefer DUMPAUTH specifically because it makes it glaringly obvious that
> you're going to be dumping authentication data.

Ok.

> > (We could dump all the users *without* passwords with just the DUMP
> > > privilege)
> >
> > Agreed. That's actually something that I think would be *really* nice-
> > an option to dump the necessary globals for whatever database you're
> > running pg_dump against. We have existing problems in this area
> > (database-level GUCs aren't considered database-specific and therefore
> > aren't picked up by pg_dump, for example..), but being able to also dump
> > the roles which are used in a given database with pg_dump would be
> > *really* nice..
> >
>
> Yes. Shouldn't be *that* hard, completely independent of this privilege
> work. Famous last words, I'm sure...

Indeed.

Thanks!

Stephen


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>
Cc: Jim Nasby <Jim(dot)Nasby(at)bluetreble(dot)com>, Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Magnus Hagander <magnus(at)hagander(dot)net>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2014-12-31 14:35:05
Message-ID: 20141231143505.GR3062@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Amit,

* Amit Kapila (amit(dot)kapila16(at)gmail(dot)com) wrote:
> On Tue, Dec 30, 2014 at 6:35 PM, Stephen Frost <sfrost(at)snowman(dot)net> wrote:
> > I'm pretty sure we've agreed that having a catch-all role attribute like
> > 'DBA' is a bad idea because we'd likely be adding privileges to it later
> > which would expand the rights of users with that attribute, possibly
> > beyond what is intended.
>
> Yes, that could happen but do you want to say that is the only reason
> to consider server level roles (such as DBA) a bad idea.

No, the other reason is that having more granular permissions is better
than catch-all's. 'superuser' is that catch-all today.

> Can't we make
> users aware of such things via documentation and then there will be
> some onus on user's to give such a privilege with care.

Perhaps, but if we're going to go in that direction, I'd rather have a
hierarchy which is built upon more granular options rather than assuming
we know exactly what the 'DBA' role should have for every environment.

> On looking around, it seems many of the databases provides such
> roles
> https://dbbulletin.wordpress.com/2013/05/29/backup-privileges-needed-to-backup-databases/
>
> In the link, though they are talking about physical (file level) backup,
> there is mention about such roles in other databases.

Most of this discussion is about non-physical-level-backups. We have
the REPLICATION role attribute for physical-level-backups and I don't
think anyone wants to get rid of that in favor of pulling it into some
'DBA' role attribute.

> The other way as discussed on this thread is to use something like
> DUMPALL (or DUMPFULL) privilege which also sounds to be a good
> way, apart from the fact that the same privilege can be used for
> non-dump purposes to extract the information from database/cluster.

I think we're probably going to go with DUMPAUTH as the specific role
attribute privilege, to make it clear that it includes authentication
information. That's really the only distinction between DUMP (or
whatever) and a privilege to support pg_dumpall.

This does make me think that we need to consider if this role attribute
implicitly grants CONNECT to all databases also.

> > > How about PHYSICAL BACKUP (for basebackup) and LOGICAL BACKUP
> > > for pg_dump?
> >
> > Again, this makes it look like the read-all right would be specific to
> > users executing pg_dump, which is incorrect and misleading. "PHYSICAL"
> > might also imply the ability to do pg_basebackup.
>
> That's right, however having unrelated privileges for doing physical
> backup via pg_basebackup and pg_start*/pg_stop* method also
> doesn't sound to be the best way (can be slightly difficult for
> users to correlate after reading docs).

We should definitely segregate the privilege to run start/stop backup
and run pg_basebackup. One allows you to read the database files off
the filesystem more-or-less directly and the other doesn't. That's a
big difference.

> Don't you think in this case
> we should have some form of hierarchy for privileges (like user
> having privilege to do pg_basebackup can also perform the
> backup via pg_start*/pg_stop* method or some other way to relate
> both forms of physical backup)?

If we had a specific privilege for pg_basebackup then I would agree that
it would allow call pg_start/stop_backup. The same is not true in
reverse though.

Thanks,

Stephen


From: Magnus Hagander <magnus(at)hagander(dot)net>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2014-12-31 14:38:59
Message-ID: CABUevEw8qeWZMbEPcKPjWG6ocE9ba69k7pSVJU1+RQJZ7cZXWA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Wed, Dec 31, 2014 at 3:08 PM, Stephen Frost <sfrost(at)snowman(dot)net> wrote:

> * Magnus Hagander (magnus(at)hagander(dot)net) wrote:
> > On Tue, Dec 30, 2014 at 4:16 PM, Stephen Frost <sfrost(at)snowman(dot)net>
> wrote:
> > > The approach I was thinking was to document and implement this as
> > > impliciting granting exactly USAGE and SELECT rights, no more (not
> > > BYPASSRLS) and no less (yes, the role could execute functions). I
> agree
> >
> > If the role could execute functions, it's *not* "exactly USAGE and SELECT
> > rights", it's now "USAGE and SELECT and EXECUTE" rights... Just to be
> > nitpicking, but see below.
>
> We seem to be coming at it from two different directions, so I'll try to
> clarify. What I'm suggesting is that this role attribute be strictly
> *additive*. Any other privileges granted to the role with this role
> attribute would still be applicable, including grants made to PUBLIC.
>
> This role attribute would *not* include EXECUTE rights, by that logic.
> However, if PUBLIC was granted EXECUTE rights for the function, then
> this role could execute that function.
>

Ah, ok, mistunderstood that part.

What it sounds like is you're imagining this role attribute to mean the
> role has *only* USAGE and SELECT (or COPY or whatever) rights across the
> board and that any grants done explicitly to this role or to public
> wouldn't be respected. In my view, that moves this away from a role
> *attribute* to being a pre-defined *role*, as such a role would not be
> usable for anything else.
>

No, i meant additive as well. I misread you.

> > that doing so would be strictly more than what pg_dump actually requires
> > > but it's also what we actually have support for in our privilege
> system.
> >
> > Yeah, but would it also be what people would actually *want*?
>
> I can certainly see reasons why you'd want such a role to be able to
> execute functions- in particular, consider xlog_pause anx xlog_resume.

If this role can't execute those functions then they probably can't
> successfully run pg_dump against a replica.
>

uh, pg_dump doesn't run those commands :P I don't see why that's a
requirement at all. And you can still always grant those things on top of
whatever the privilege gives you.

> I think having it do exactly what pg_dump needs, and not things like
> > execute functions etc, would be the thing people want for a 'DUMP'
> > privilege.
>
> What if we want pg_dump in 9.6 to have an option to execute xlog_pause
> and xlog_resume for you? You wouldn't be able to run that against a 9.5
> database (or at least, that option wouldn't work).
>

It would if you added an explicit grant for it, which would have to be
documented.

I don't see how that's different if the definition is "allows select on all
tables". That wouldn't automatically give it the ability to do xlog_pause
in an old version either.

> We might *also* want a USAGEANDSELECTANDEXECUTEANDWHATNOTBUTNOBYPASSURL
> > (crap, it has to fit within NAMEDATALEN?) privilege, but I think that's a
> > different thing.
>
> Our privilege system doesn't currently allow for negative grants (deny
> user X the ability to run functions, even if EXECUTE is granted to
> PUBLIC). I'm not against that idea, but I don't see it as the same as
> this.
>

Agreed. That's what I said - different thing :)

> > it would only give you COPY access. (And also
> > > > COPY != SELECT in the way that the rule system applies, I think? And
> this
> > > > one could be for COPY only)
> > >
> > > COPY certainly does equal SELECT rights.. We haven't got an
> independent
> > > COPY privilege and I don't think it makes sense to invent one. It
> >
> > We don't, but I'm saying it might make sense to implement this. Not as a
> > regular privilige, but as a role attribute. I'm not sure it's the right
> > thing, but it might actually be interesting to entertain.
>
> We've discussed having a role attribute for COPY-from-filesystem, but
> pg_dump doesn't use that ever, it only uses COPY TO STDOUT. I'm not
> a fan of making a COPY_TO_STDOUT-vs-SELECT distinction just for this..
>

Yeah, it's probably going overboard with it, since AFAICT the only thing
that would actually be affected is RULEs on SELECT, which I bet most people
don't use on their tables.

> > sounds like you're suggesting that we add a hack directly into COPY for
> > > this privilege, but my thinking is that the right place to change for
> > > this is in the privilege system and not hack it into individual
> > > commands.. I'm also a bit nervous that we'll end up painting ourselves
> > > into a corner if we hack this to mean exactly what pg_dump needs today.
> >
> > One point would be that if we define it as "exactly what pg_dump needs",
> > that definition can change in a future major version.
>
> Sure, but that then gets a bit ugly because we encourage running the
> latest version of pg_dump against the prior-major-version.
>

But the latest version of pg_dump *knows* how the prior major version
behaved with these things, and can either adapt, or give the user a message
about what they need to do to adapt.

> > > I think BYPASSRLS would have to be implicitly granted by the DUMP
> > > > privilege. Without that, the DUMP privilege is more or less
> meaningless
> > > > (for anybody who uses RLS - but if they don't use RLS, then having it
> > > > include BYPASSRLS makes no difference). Worse than that, you may end
> up
> > > > with a dump that you cannot restore.
> > >
> > > The dump would fail, as I mentioned before. I don't see why BYPASSRLS
> > > has to be implicitly granted by the DUMP privilege and can absolutely
> > > see use-cases for it to *not* be. Those use-cases would require
> passing
> > > pg_dump the --enable-row-security option, but that's why it's there.
> >
> > So you're basically saying that if RLS is in use anywhere, this
> priviliege
> > alone would be useless, correct?
>
> No, it would still be *extremely* useful. We have an option to pg_dump
> to say "please dump with RLS enabled". What that means is that you'd be
> able to dump the entire database for all data you're allowed to see
> through RLS policies. How is that useless? I certainly think it'd be
> very handy and a good way to get *segregated* dumps according to policy.
>

Hmm. Yeah, I guess - my mindset was int he "database backup" mode, where a
"silently partial" backup is a really scary thing rather than a feature :)
I guess as long as you still dump all the parts, RLS itself ensures that
foreign keys etc will actually be valid upon a reaload?

> And you would get a hard failure at *dump
> > time*, not at reload time?
>
> If you attempt to pg_dump a relation which has RLS enabled, and you
> don't enable RLS with pg_dump, then you'll get a failure at dump time,
> yes. That's far better than a reload-time failure.
>

Good.

> That would at least make it acceptable, as you
> > would know it's wrong. and we could make the error messages shown
> > specifically hint that you need to grant both privileges to make it
> useful.
>
> Agreed, having such a hint makes sense.
>
> > We could/should also throw a WARNING if DUMP Is granted to a role without
> > BYPASSRLS in case row level security is enabled in the system, I think.
> But
> > that's more of an implementation detail.
>
> That's a bit ugly and RLS could be added to a relation after the DUMP
> privilege is granted.
>

Yes, it's not going to be all-covering, but it can still be a useful
hint/warning in the cases where it *does* that. We obviously still need
pg_dump to give the error in both scenarios.

What I think this part of the discussion is getting at is that there's a
> lot of people who view pg_dump as explicitly for "dump the ENTIRE
> database". While that's one use-case it is certainly not the only one.
> I find "pg_dump schema X" to be very common and often find that pg_dump
> against an entire database isn't practical because of the size of the
> database.
>

Agreed. I was in that mindset since we were talking about other backups.
And FWIW, one reason I like to call it "DUMP" and not anything to do with
BACKUP is exactly that. pg_dump is often not very useful for backups
anymore, due to the size of databases, but it's very useful for other
things.

> > Similar concerns would exist for the existing REPLICATION role for
> example
> > > > - that one clearly lets you bypass RLS as well, just not with a SQL
> > > > statement.
> > >
> > > I'm not sure that I see the point you're making here. Yes, REPLICATION
> > > allows you to do a filesystem copy of the entire database and that
> > > clearly bypasses RLS and *all* of our privilege system. I'm suggesting
> > > that this role attribute work as an implicit grant of privileges we
> > > already have. That strikes me as easy to document and very clear for
> > > users.
> >
> > It does - though documenting that it implicitly gives you a different
> > privilege as well is also easy :)
> >
> > But it does potentially limit us to what we can actually do with the
> > priviliges. One reason to use them is exactly because we *cannot* express
> > this with our regular permissions (such as BYPASSRLS or REPLICATION).
>
> Ok, I see the point you're making that we could make this into a
> capability which isn't something which can be expressed through our
> existing GRANT system. That strikes me as a solution trying to find a
> problem though. There's no need to invent such an oddity for this
> particular use-case, I don't think.
>

Maybe not, but we should make sure we don't paint ourselves into a corner
where we cannot do it in the future either.

> For regular permissions, we could just pre-populate the system with
> > predefined roles and use regular GRANTs to those roles, instead of
> relying
> > on role attributes, which might in that case make it even more clear?
>
> The reason for this approach is to address exactly the nightmare that is
> trying to maintain those regular permissions across all the objects in
> the system. Today, people simply give the role trying to do the pg_dump
> superuser, which is the best option we have. Saying 'grant SELECT on
> all the tables and USAGE on all the schemas' isn't suggested because
> it's a huge pain. This role attribute provides a middle ground where
> the pg_dump'ing role isn't a superuser, but you don't have to ensure
> usage and select are granted to it for every relation.
>

No, what I'm saying is we could have *predefined role* that allows "select
on all the tables and usage on all the schemas". And you are unable to
actually remove that. It's not stored on the object, so you cannot REVOKE
the permission on the *object*. Since it's not store on the object it will
also automatically apply to all new objects, regardless of what you've done
with DEFAULT PRIVILEGES etc.

But you can grant users and other roles access to this role, and it's dealt
with like other roles from the "who has it" perspective, instead of being
special-cased.

Instead of "ALTER USER foo WITH DUMP" (or whatever), you'd just do a "GRANT
pgdump TO foo" (which would then also work through things like group
membership as well)

> > should work 'sanely' with any combination of the two options.
> > > > > Similairly, DUMP shouldn't imply BACKUP or visa-versa. In
> particular,
> > > > > I'd like to see roles which have only the BACKUP privilege be
> unable to
> > > > > directly read any data (modulo things granted to PUBLIC). This
> would
> > > > > allow an unprivileged user to manage backups, kick off ad-hoc ones,
> > > etc,
> > > > > without being able to actually access any of the data (this would
> > > > > require the actual backup system to have a similar control, but
> that's
> > > > > entirely possible with more advanced SANs and enterprise backup
> > > > > solutions).
> > > >
> > > > So you're saying a privilege that would allow you to do
> > > > pg_start_backup()/pg_stop_backup() but *not* actually use
> pg_basebackup?
> > >
> > > Yes.
> >
> > What's really the usecase for that? I'd say that pg_start/stop backup is
> a
> > superset and a higher privilige than using pg_basebackup, since you can
> for
> > example destroy other peoples backups using it (by running pg_stop_backup
> > while they are running).
>
> One use-case is to allow unprivileged users to run adhoc backups.

Another is simply that you don't want the cronjob that runs the backup
> to be able to read any of the data directly (why would you?). I agree
> that the individuals who have this capability would still need to
> coordinate or at lesat not step on each other or they could end up with
> bad backups.
>
> Another way to address that would be to require that the role calling
> stop_backup be a member of the role which called start_backup (that also
> address the superuser case, as superusers are considered members of all
> roles). That seems like a pretty reasonable sanity check requirement.
>

This diverges a bit from the actual role attribute discussion here, but I
think a better solution to this is to actually have a separate interface
rather than pg_start/pg_stop backup. One of the main problems with
pg_start/pg_stop vs pg_basebackup is that you can easily leave the system
in a broken state (for example by forgetting to pg_stop_backup, or by
accidentally pg_stop_backup:ing in the middle of someone elses backup).
pg_basebackup gets around this by automatically executing do_pg_stop_backup
if the client disconnects. This also lets us allow parallel base backups.
We could have an equivalent functionality exposed through a SQL function,
or argument to pg_start_backup - it would require the backup software to
keep the connection running as it works and then disconnect when it's done,
but for anything beyond the most trivial shellscript that's not exactly
hard, and it would make the backups safer.

If we did that, perhaps we don't even need a separate privilege for
pg_start_backup() as it is today, btu can leave that as superuser?

> > Personalyl I think using the DUMP name makes that a lot more clear.
> Maybe
> > > > we need to avoid using BACKUP alone as well, to make sure it doesn't
> go
> > > the
> > > > other way - using BASEBACKUP and EXCLUSIVEBACKUP for those two
> different
> > > > ones perhaps?
> > >
> > > DUMP - implicitly grants existing rights, to facilitate pg_dump and
> > > perhaps some other use-cases
> > > BASEBACKUP - allows pg_basebackup, which means bypassing all in-DB
> > > privilege systems
> >
> > That's equivalent of REPLICATION, yes?
>
> Ah, yeah, seems like it would be. Got ahead of myself. :)
>
> > > EXCLUSIVEBACKUP - just allows pg_start/stop_backup and friends
> >
> > I'd say there is no "just" there really - that's a higher level
> privilege,
> > but I see your point :)
>
> Well, see above, but ok.
>
> > Later I added:
> > >
> > > pg_xlog_replay_pause
> > > pg_xlog_replay_resume
> > >
> > > Though I'd be find if the xlog_replay ones were their own privilege
> (eg:
> > > REPLAY or something).
> > >
> >
> > I think it makes more sense to have those replay functions to be a
> separate
> > privilege, yes. They have nothing to actually do with taking the backups
> -
> > they are for restoring them. And to restore the backups, you clearly
> > already have superuser level privileges on the system outside the db (at
> > least as long as we only allow full cluster restores).
>
> Not quite- remember that reply_pause/resume can be done on a replica, so
> they are useful to be able to grant independent from superuser. Perhaps
> we call such a role attribute XLOGREPLAY ?
>

Yes, that's what I meant - they are useful, but they're not interesting for
the bacukp itself. So yes, something like XLOGREPLAY makes sense.

> > > You mean something that restricts the user to read even *if* write
> > > > permissions has been granted on an individual table? Yeah, that would
> > > > actually be quite useful, I think - sort of a "reverse privilege".
> > >
> > > Yes. My thinking on how to approach this was to forcibly set all of
> > > their transactions to read-only.
> >
> > Agreed that this would be very useful.
>
> Glad we agree.. Any thoughts on implementation? :)
>

Where's your patch? :)

In theory we'd just have to trap any attempt to set the value for
transaction_read_only, no? Same as hot_standby does?

--
Magnus Hagander
Me: http://www.hagander.net/
Work: http://www.redpill-linpro.com/


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: José Luis Tallón <jltallon(at)adv-solutions(dot)net>
Cc: Magnus Hagander <magnus(at)hagander(dot)net>, Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2014-12-31 14:46:10
Message-ID: 20141231144610.GS3062@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

José,

* José Luis Tallón (jltallon(at)adv-solutions(dot)net) wrote:
> On 12/30/2014 04:16 PM, Stephen Frost wrote:
> >The approach I was thinking was to document and implement this as
> >impliciting granting exactly USAGE and SELECT rights, no more (not
> >BYPASSRLS) and no less (yes, the role could execute functions). I agree
> >that doing so would be strictly more than what pg_dump actually requires
> >but it's also what we actually have support for in our privilege system.
>
> Hmmm.... coupled with your comments below, I'd say some tweaking of
> the existing privileges is actually needed if we want to add these
> new "capabilities".

Not sure I see how..? Can you clarify what you think needs to be
changed in the existing privilege system?

> BTW, and since this is getting a bit bigger than originally
> considered: would it be interesting to support some
> extension-defined capabilities, too?
> (for things can't be easily controlled by the existing USAGE /
> SELECT / ... rights, I mean)

Not entirely following what you mean here either, but to the extent that
it's independent from the current discussion, perhaps it deserves to be
on its own thread?

> >>it would only give you COPY access. (And also
> >>COPY != SELECT in the way that the rule system applies, I think? And this
> >>one could be for COPY only)
> >COPY certainly does equal SELECT rights.. We haven't got an independent
> >COPY privilege and I don't think it makes sense to invent one.
>
> FWIW, a COPY(DUMP?) privilege different from SELECT would make sense.
> Considering your below comments it would be better that it not imply
> BYPASSRLS, though.

How would a COPY-to-STDOUT privilege be different from SELECT?

> >Lastly, I've been considering other use-cases for this privilege beyond
> >the pg_dump one (thinking about auditing, for example).
>
> ISTR there was something upthread on an AUDIT role, right?
> This might be the moment to add it....

One of the challenges to adding such a role is defining what it means.
What privileges do you think such a role would have? I can see that
perhaps it would include read-only access to everything, but I'd want it
to also have read access to the logs..

> >>That would be "EXCLUSIVEBACKUP" or something like that, to be consistent
> >>with existing terminology though.
> >Ok. I agree that working out the specific naming is difficult and would
> >like to focus on that, but we probably need to agree on the specific
> >capabilities first. :)
>
> Yes :)
> For the record, LOGBACKUP vs PHYSBACKUP was suggested a couple days
> ago. I'd favor DUMP(logical) and BACKUP(physical) --- for lack of a
> better name.

I think I'm coming around to the EXCLUSIVEBACKUP option, per the
discussion with Magnus. I don't particularly like LOGBACKUP and don't
think it really makes sense, while PHYSBACKUP seems like it'd cover what
REPLICATION already does.

> The above reasoning would have pg_basebackup requiring REPLICATION,
> which is a logical consequence of the implementation but strikes me
> as a bit surprising in the light of these other privileges.

I see what you mean that it's a bit strange for pg_basebackup to require
the REPLICATION role attribute, but, well, that's already the case, no?
Don't think we're going to change that..

> ARCHIVE, though completely appropriate for the "exclusivebackup"
> case above (so this would become DUMP/BASEBACKUP/ARCHIVE
> +REPLICATION) might end up causing quite some confusion ... ("what?
> WAL archiving is NOT granted by the "archive" privilege, but
> requires a superuser to turn it on(via ALTER SYSTEM)?

Yeah, Magnus didn't like ARCHIVE either and I understand his reasoning.

> >pg_xlog_replay_pause
> >pg_xlog_replay_resume
> >
> >Though I'd be find if the xlog_replay ones were their own privilege (eg:
> >REPLAY or something).
> +1

Yeah, Magnus was also agreeing that they should be independent.

> >>I think just calling them "xlog related functions" is doing us a disservice
> >>there. Definitely once we have an actual documentation to write for it, but
> >>also in this discussion.
> >[snip]
> >>If it's for replicas, then why are we not using the REPLICATION privilege
> >>which is extremely similar to this?
> >I don't actually see REPLICATION as being the same.
>
> REPLICATION (ability to replicate) vs REPLICAOPERATOR (ability to
> control *the replica* or the R/O behaviour of the server, for that
> matter...)

Right, think Magnus and I clarified what was meant there.

> >Yes. My thinking on how to approach this was to forcibly set all of
> >their transactions to read-only.
>
> So "READONLY" ?

Right.

> >Agreed. That's actually something that I think would be *really* nice-
> >an option to dump the necessary globals for whatever database you're
> >running pg_dump against. We have existing problems in this area
> >(database-level GUCs aren't considered database-specific and therefore
> >aren't picked up by pg_dump, for example..), but being able to also dump
> >the roles which are used in a given database with pg_dump would be
> >*really* nice..
>
> Ok, so this would imply modifying pg_dump to include database-level
> configs. I would heartily welcome this.

I think a lot of people would like to see that, though I do think it's
at least somewhat independent from this particular proposal.

> So, it seems to me that we are actually evolving towards a set of
> "low-level" "capabilities" and some "high-level" (use case-focused)
> "privileges".

Well, I would argue that we're making a good set of 'low-level'
capabilities which users are then able to pull together as they see fit
into specific 'roles' for their environment. One environment might see
a DBA role as having X, Y, Z, while another only wants X and Y.

> I am hereby volunteering to compile this thread into some wiki page.
> I'm thinking "Privileges" as the title for starters. Suggestions?

A wiki page would certainly be useful, especially if it's done in such a
way that we can take and make it into the documentation to go along with
these role attributes easily.

Thanks!

Stephen


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Magnus Hagander <magnus(at)hagander(dot)net>
Cc: Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2014-12-31 15:23:25
Message-ID: 20141231152324.GT3062@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

* Magnus Hagander (magnus(at)hagander(dot)net) wrote:
> On Wed, Dec 31, 2014 at 3:08 PM, Stephen Frost <sfrost(at)snowman(dot)net> wrote:
> > * Magnus Hagander (magnus(at)hagander(dot)net) wrote:
> > > that doing so would be strictly more than what pg_dump actually requires
> > > > but it's also what we actually have support for in our privilege
> > system.
> > >
> > > Yeah, but would it also be what people would actually *want*?
> >
> > I can certainly see reasons why you'd want such a role to be able to
> > execute functions- in particular, consider xlog_pause anx xlog_resume.
>
> If this role can't execute those functions then they probably can't
> > successfully run pg_dump against a replica.
>
> uh, pg_dump doesn't run those commands :P I don't see why that's a
> requirement at all. And you can still always grant those things on top of
> whatever the privilege gives you.

Ok, so, first off, this is all about the discussion around "is this
additive or not".. Since we just agreed that it's additive, I'm not
sure I see the need to discuss the EXECUTE privileges..

Having said that though..

If you can't pause/resume then you can end up with your pg_dump
transaction getting killed. I'm aware of folks who already do this
today, by hand with shell scripts.. I agree that pg_dump doesn't do it,
but I do think it'd be nice to have and I can certainly see the use-case
for them..

> > I think having it do exactly what pg_dump needs, and not things like
> > > execute functions etc, would be the thing people want for a 'DUMP'
> > > privilege.
> >
> > What if we want pg_dump in 9.6 to have an option to execute xlog_pause
> > and xlog_resume for you? You wouldn't be able to run that against a 9.5
> > database (or at least, that option wouldn't work).
>
> It would if you added an explicit grant for it, which would have to be
> documented.

Huh? An explicit grant for xlog_pause/xlog_resume won't work as we
check role attributes rights inside the function..

> I don't see how that's different if the definition is "allows select on all
> tables". That wouldn't automatically give it the ability to do xlog_pause
> in an old version either.

Ok, that I agree with- you don't automatically get xlog_pause rights if
you have the 'select on all tables' right.

> > We've discussed having a role attribute for COPY-from-filesystem, but
> > pg_dump doesn't use that ever, it only uses COPY TO STDOUT. I'm not
> > a fan of making a COPY_TO_STDOUT-vs-SELECT distinction just for this..
>
> Yeah, it's probably going overboard with it, since AFAICT the only thing
> that would actually be affected is RULEs on SELECT, which I bet most people
> don't use on their tables.

Well, we could make SELECT not work, but if you've got COPY then you can
still get all the data, so, yeah, not much different. I seriously doubt
many people are using rules..

> > > One point would be that if we define it as "exactly what pg_dump needs",
> > > that definition can change in a future major version.
> >
> > Sure, but that then gets a bit ugly because we encourage running the
> > latest version of pg_dump against the prior-major-version.
>
> But the latest version of pg_dump *knows* how the prior major version
> behaved with these things, and can either adapt, or give the user a message
> about what they need to do to adapt.

Yes, that's true.

> > No, it would still be *extremely* useful. We have an option to pg_dump
> > to say "please dump with RLS enabled". What that means is that you'd be
> > able to dump the entire database for all data you're allowed to see
> > through RLS policies. How is that useless? I certainly think it'd be
> > very handy and a good way to get *segregated* dumps according to policy.
>
> Hmm. Yeah, I guess - my mindset was int he "database backup" mode, where a
> "silently partial" backup is a really scary thing rather than a feature :)

Agreed, we don't ever want that.

> I guess as long as you still dump all the parts, RLS itself ensures that
> foreign keys etc will actually be valid upon a reaload?

If you set up your policies correctly, yes. RLS is flexible enough that
you could create policies which fail, but you have the same problem
today to some extent (consider tables you don't have SELECT rights on).

> > > We could/should also throw a WARNING if DUMP Is granted to a role without
> > > BYPASSRLS in case row level security is enabled in the system, I think.
> > But
> > > that's more of an implementation detail.
> >
> > That's a bit ugly and RLS could be added to a relation after the DUMP
> > privilege is granted.
>
> Yes, it's not going to be all-covering, but it can still be a useful
> hint/warning in the cases where it *does* that. We obviously still need
> pg_dump to give the error in both scenarios.

I'm not against doing it, personally, but I suspect others won't like it
(or at least, that's been the case in the past with other things..).

> What I think this part of the discussion is getting at is that there's a
> > lot of people who view pg_dump as explicitly for "dump the ENTIRE
> > database". While that's one use-case it is certainly not the only one.
> > I find "pg_dump schema X" to be very common and often find that pg_dump
> > against an entire database isn't practical because of the size of the
> > database.
>
> Agreed. I was in that mindset since we were talking about other backups.
> And FWIW, one reason I like to call it "DUMP" and not anything to do with
> BACKUP is exactly that. pg_dump is often not very useful for backups
> anymore, due to the size of databases, but it's very useful for other
> things.

Ok.

> > Ok, I see the point you're making that we could make this into a
> > capability which isn't something which can be expressed through our
> > existing GRANT system. That strikes me as a solution trying to find a
> > problem though. There's no need to invent such an oddity for this
> > particular use-case, I don't think.
>
> Maybe not, but we should make sure we don't paint ourselves into a corner
> where we cannot do it in the future either.

Agreed. Do you see a risk here of that?

> > For regular permissions, we could just pre-populate the system with
> > > predefined roles and use regular GRANTs to those roles, instead of
> > relying
> > > on role attributes, which might in that case make it even more clear?
> >
> > The reason for this approach is to address exactly the nightmare that is
> > trying to maintain those regular permissions across all the objects in
> > the system. Today, people simply give the role trying to do the pg_dump
> > superuser, which is the best option we have. Saying 'grant SELECT on
> > all the tables and USAGE on all the schemas' isn't suggested because
> > it's a huge pain. This role attribute provides a middle ground where
> > the pg_dump'ing role isn't a superuser, but you don't have to ensure
> > usage and select are granted to it for every relation.
>
> No, what I'm saying is we could have *predefined role* that allows "select
> on all the tables and usage on all the schemas". And you are unable to
> actually remove that. It's not stored on the object, so you cannot REVOKE
> the permission on the *object*. Since it's not store on the object it will
> also automatically apply to all new objects, regardless of what you've done
> with DEFAULT PRIVILEGES etc.
>
> But you can grant users and other roles access to this role, and it's dealt
> with like other roles from the "who has it" perspective, instead of being
> special-cased.
>
> Instead of "ALTER USER foo WITH DUMP" (or whatever), you'd just do a "GRANT
> pgdump TO foo" (which would then also work through things like group
> membership as well)

There's a definite backwards-compatibility concern with this, of course,
but I see where you're coming from. This only really applies with this
particular pg_dump-related role-attribute discussion though, right?

This role wouldn't be able to be logged in with, I presume? Would it
show up when you run \du? What about in pg_authid? I feel like it
would have to and I worry that users might not care for it- and what
happens if they want to remove it?

The question about role-attribute vs. inheirited-right is one that I've
been wondering about also though.

> Another is simply that you don't want the cronjob that runs the backup
> > to be able to read any of the data directly (why would you?). I agree
> > that the individuals who have this capability would still need to
> > coordinate or at lesat not step on each other or they could end up with
> > bad backups.
> >
> > Another way to address that would be to require that the role calling
> > stop_backup be a member of the role which called start_backup (that also
> > address the superuser case, as superusers are considered members of all
> > roles). That seems like a pretty reasonable sanity check requirement.
>
> This diverges a bit from the actual role attribute discussion here, but I
> think a better solution to this is to actually have a separate interface
> rather than pg_start/pg_stop backup. One of the main problems with
> pg_start/pg_stop vs pg_basebackup is that you can easily leave the system
> in a broken state (for example by forgetting to pg_stop_backup, or by
> accidentally pg_stop_backup:ing in the middle of someone elses backup).

I agree. I've had this happen to me a number of times and it really
stinks to have your *next* backup fail because the last one failed
half-way and didn't run pg_stop_backup.

> pg_basebackup gets around this by automatically executing do_pg_stop_backup
> if the client disconnects. This also lets us allow parallel base backups.
> We could have an equivalent functionality exposed through a SQL function,
> or argument to pg_start_backup - it would require the backup software to
> keep the connection running as it works and then disconnect when it's done,
> but for anything beyond the most trivial shellscript that's not exactly
> hard, and it would make the backups safer.

Agreed, I do like that idea.

> If we did that, perhaps we don't even need a separate privilege for
> pg_start_backup() as it is today, btu can leave that as superuser?

I don't see how this follows though.. We are not talking about only
pg_basebackup or only about where the user running pg_start/stop
has filesystem-level access to the database.

> > Not quite- remember that reply_pause/resume can be done on a replica, so
> > they are useful to be able to grant independent from superuser. Perhaps
> > we call such a role attribute XLOGREPLAY ?
>
> Yes, that's what I meant - they are useful, but they're not interesting for
> the bacukp itself. So yes, something like XLOGREPLAY makes sense.

Ok, that works for me.

> > > > You mean something that restricts the user to read even *if* write
> > > > > permissions has been granted on an individual table? Yeah, that would
> > > > > actually be quite useful, I think - sort of a "reverse privilege".
> > > >
> > > > Yes. My thinking on how to approach this was to forcibly set all of
> > > > their transactions to read-only.
> > >
> > > Agreed that this would be very useful.
> >
> > Glad we agree.. Any thoughts on implementation? :)
>
> Where's your patch? :)

Haha. :P

> In theory we'd just have to trap any attempt to set the value for
> transaction_read_only, no? Same as hot_standby does?

I like the idea.. Will have to give it a shot and see what happens. :)

Thanks!

Stephen


From: Magnus Hagander <magnus(at)hagander(dot)net>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2015-01-01 21:27:28
Message-ID: CABUevEw1ojemZDBFLB4eAhhzwZuTADmdw5h8RAgjftfr2BXyrw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Wed, Dec 31, 2014 at 4:23 PM, Stephen Frost <sfrost(at)snowman(dot)net> wrote:

> * Magnus Hagander (magnus(at)hagander(dot)net) wrote:
> > On Wed, Dec 31, 2014 at 3:08 PM, Stephen Frost <sfrost(at)snowman(dot)net>
> wrote:
> > > * Magnus Hagander (magnus(at)hagander(dot)net) wrote:
> > > I think having it do exactly what pg_dump needs, and not things like
> > > > execute functions etc, would be the thing people want for a 'DUMP'
> > > > privilege.
> > >
> > > What if we want pg_dump in 9.6 to have an option to execute xlog_pause
> > > and xlog_resume for you? You wouldn't be able to run that against a
> 9.5
> > > database (or at least, that option wouldn't work).
> >
> > It would if you added an explicit grant for it, which would have to be
> > documented.
>
> Huh? An explicit grant for xlog_pause/xlog_resume won't work as we
> check role attributes rights inside the function..
>

Correct, of course. I was confusing myself.

> > We've discussed having a role attribute for COPY-from-filesystem, but
> > > pg_dump doesn't use that ever, it only uses COPY TO STDOUT. I'm not
> > > a fan of making a COPY_TO_STDOUT-vs-SELECT distinction just for this..
> >
> > Yeah, it's probably going overboard with it, since AFAICT the only thing
> > that would actually be affected is RULEs on SELECT, which I bet most
> people
> > don't use on their tables.
>
> Well, we could make SELECT not work, but if you've got COPY then you can
> still get all the data, so, yeah, not much different. I seriously doubt
> many people are using rules..
>

Yeah.

> > > We could/should also throw a WARNING if DUMP Is granted to a role
> without
> > > > BYPASSRLS in case row level security is enabled in the system, I
> think.
> > > But
> > > > that's more of an implementation detail.
> > >
> > > That's a bit ugly and RLS could be added to a relation after the DUMP
> > > privilege is granted.
> >
> > Yes, it's not going to be all-covering, but it can still be a useful
> > hint/warning in the cases where it *does* that. We obviously still need
> > pg_dump to give the error in both scenarios.
>
> I'm not against doing it, personally, but I suspect others won't like it
> (or at least, that's been the case in the past with other things..).
>

Heh, let's defer to a third party then :)

> > Ok, I see the point you're making that we could make this into a
> > > capability which isn't something which can be expressed through our
> > > existing GRANT system. That strikes me as a solution trying to find a
> > > problem though. There's no need to invent such an oddity for this
> > > particular use-case, I don't think.
> >
> > Maybe not, but we should make sure we don't paint ourselves into a corner
> > where we cannot do it in the future either.
>
> Agreed. Do you see a risk here of that?
>

Not really, anymore, i think :)

> > For regular permissions, we could just pre-populate the system with
> > > > predefined roles and use regular GRANTs to those roles, instead of
> > > relying
> > > > on role attributes, which might in that case make it even more clear?
> > >
> > > The reason for this approach is to address exactly the nightmare that
> is
> > > trying to maintain those regular permissions across all the objects in
> > > the system. Today, people simply give the role trying to do the
> pg_dump
> > > superuser, which is the best option we have. Saying 'grant SELECT on
> > > all the tables and USAGE on all the schemas' isn't suggested because
> > > it's a huge pain. This role attribute provides a middle ground where
> > > the pg_dump'ing role isn't a superuser, but you don't have to ensure
> > > usage and select are granted to it for every relation.
> >
> > No, what I'm saying is we could have *predefined role* that allows
> "select
> > on all the tables and usage on all the schemas". And you are unable to
> > actually remove that. It's not stored on the object, so you cannot REVOKE
> > the permission on the *object*. Since it's not store on the object it
> will
> > also automatically apply to all new objects, regardless of what you've
> done
> > with DEFAULT PRIVILEGES etc.
> >
> > But you can grant users and other roles access to this role, and it's
> dealt
> > with like other roles from the "who has it" perspective, instead of being
> > special-cased.
> >
> > Instead of "ALTER USER foo WITH DUMP" (or whatever), you'd just do a
> "GRANT
> > pgdump TO foo" (which would then also work through things like group
> > membership as well)
>
> There's a definite backwards-compatibility concern with this, of course,
> but I see where you're coming from. This only really applies with this
> particular pg_dump-related role-attribute discussion though, right?
>

Yes, I believe so. Because it's so similar to the regular permissions,
where as something like "being able to take a base backup" is more of a
boolean - it doesn't apply to actual objects in the database cluster, it's
more global.

This role wouldn't be able to be logged in with, I presume?

Definitely not.

> Would it
> show up when you run \du? What about in pg_authid? I feel like it
> would have to and I worry that users might not care for it- and what
> happens if they want to remove it?
>

Well, going by experience from other systems that have such a role, I'd say
yes it should show up, and it should throw an error when you try to remove
it.

The question about role-attribute vs. inheirited-right is one that I've
> been wondering about also though.
>
> > This diverges a bit from the actual role attribute discussion here, but I
> > think a better solution to this is to actually have a separate interface
> > rather than pg_start/pg_stop backup. One of the main problems with
> > pg_start/pg_stop vs pg_basebackup is that you can easily leave the system
> > in a broken state (for example by forgetting to pg_stop_backup, or by
> > accidentally pg_stop_backup:ing in the middle of someone elses backup).
>
> I agree. I've had this happen to me a number of times and it really
> stinks to have your *next* backup fail because the last one failed
> half-way and didn't run pg_stop_backup.
>

I've seen things so much worse than just that :)

> pg_basebackup gets around this by automatically executing
> do_pg_stop_backup
> > if the client disconnects. This also lets us allow parallel base backups.
> > We could have an equivalent functionality exposed through a SQL function,
> > or argument to pg_start_backup - it would require the backup software to
> > keep the connection running as it works and then disconnect when it's
> done,
> > but for anything beyond the most trivial shellscript that's not exactly
> > hard, and it would make the backups safer.
>
> Agreed, I do like that idea.
>
> > If we did that, perhaps we don't even need a separate privilege for
> > pg_start_backup() as it is today, btu can leave that as superuser?
>
> I don't see how this follows though.. We are not talking about only
> pg_basebackup or only about where the user running pg_start/stop
> has filesystem-level access to the database.
>

Hmm, yeah, i guess you're right. While from a security perspective they can
already read all the data, they can't read it safely without that. And the
fact that you *also* need a local account with file system access is a
second layer of security or something like that.

--
Magnus Hagander
Me: http://www.hagander.net/
Work: http://www.redpill-linpro.com/


From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>
Cc: Stephen Frost <sfrost(at)snowman(dot)net>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2015-01-05 16:49:59
Message-ID: CA+TgmoY8q6-mohzcq58eQUiQs4nQHpxuq8AQUSZO_x4oWv3f7Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Wed, Dec 24, 2014 at 12:48 PM, Adam Brightwell
<adam(dot)brightwell(at)crunchydatasolutions(dot)com> wrote:
> * BACKUP - allows role to perform backup operations
> * LOGROTATE - allows role to rotate log files
> * MONITOR - allows role to view pg_stat_* details
> * PROCSIGNAL - allows role to signal backend processes

How about just "SIGNAL" instead of "PROCSIGNAL"?

Generally, I think we'll be happier if these capabilities have names
that are actual words - or combinations of words - rather than partial
words, so I'd suggest avoiding things like PROC for PROCESS and AUTH
for AUTHORIZATION.

In this particular case, it seems like the name of the capability is
based off the name of an internal system data structure. That's the
sort of thing that we do not want to expose to users. As far as we
can, we should try to describe what the capability allows, not the
details of how that is (currently) implemented.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


From: Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Stephen Frost <sfrost(at)snowman(dot)net>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2015-01-05 17:35:46
Message-ID: CAKRt6CQJY-jhkyggB5nCTC8wf3Md_kH_VmLdQbK0pWL5zX=2pw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Mon, Jan 5, 2015 at 11:49 AM, Robert Haas <robertmhaas(at)gmail(dot)com> wrote:

> On Wed, Dec 24, 2014 at 12:48 PM, Adam Brightwell
> <adam(dot)brightwell(at)crunchydatasolutions(dot)com> wrote:
> > * BACKUP - allows role to perform backup operations
> > * LOGROTATE - allows role to rotate log files
> > * MONITOR - allows role to view pg_stat_* details
> > * PROCSIGNAL - allows role to signal backend processes
>
> How about just "SIGNAL" instead of "PROCSIGNAL"?
>

Sure.

> Generally, I think we'll be happier if these capabilities have names
> that are actual words - or combinations of words - rather than partial
> words, so I'd suggest avoiding things like PROC for PROCESS and AUTH
> for AUTHORIZATION.
>

Agreed.

> In this particular case, it seems like the name of the capability is
> based off the name of an internal system data structure. That's the
> sort of thing that we do not want to expose to users. As far as we
> can, we should try to describe what the capability allows, not the
> details of how that is (currently) implemented.

Agreed.

If others are also in agreement on this point then I'll update the patch
accordingly.

Thanks,
Adam

--
Adam Brightwell - adam(dot)brightwell(at)crunchydatasolutions(dot)com
Database Engineer - www.crunchydatasolutions.com


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2015-01-05 18:37:27
Message-ID: 20150105183727.GR3062@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Adam, all,

* Adam Brightwell (adam(dot)brightwell(at)crunchydatasolutions(dot)com) wrote:
> If others are also in agreement on this point then I'll update the patch
> accordingly.

Works for me.

Thanks!

Stephen


From: Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2015-01-15 23:03:24
Message-ID: CAKRt6CSx=HOB0XovCfR4VBeh=hoa_AabAfMYNGAYrzUy1ghujg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

All,

Attached is a patch that proposes the following additional role attributes
for review:

* ONLINE_BACKUP - allows role to perform backup operations
- originally proposed as BACKUP - due to concern for the use of that term
in relation to other potential backup related permissions this form is in
line with the documentation as it describes the affected backup operations
as being 'online backups'.
- applies only to the originally proposed backup functions.
* XLOG_REPLAY - allows role to perform pause and resume on xlog_replay
operations ('pg_xlog_replay_pause' and 'pg_xlog_replay_resume')
- following the recommendation from Stephen and Magnus.
* LOG - allows role to rotate log files - remains broad enough to consider
future log related operations
* MONITOR - allows role to view pg_stat_* details (as originally proposed)
* SIGNAL - allows role to signal backend processes (as originally proposed)

The documentation still needs to be updated. If this these attributes and
the capabilities they provide are acceptable, then I'll begin moving
forward on making those updates as well.

Regarding the discussion on a DUMP/READONLY permission. I believe that
topic needs much further discussion and decided it is probably best to keep
it as a separate patch/effort. I'd certainly be willing to continue that
discussion and assist in moving any related effort forward, therefore,
please let me know if there is anything I can do to help.

Thanks,
Adam

--
Adam Brightwell - adam(dot)brightwell(at)crunchydatasolutions(dot)com
Database Engineer - www.crunchydatasolutions.com

Attachment Content-Type Size
role-attributes-v2.patch text/x-patch 41.0 KB

From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>
Cc: Stephen Frost <sfrost(at)snowman(dot)net>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2015-01-19 13:33:27
Message-ID: CA+TgmoZo6HW4xukJ8KHVrebo8J69Fh-NG60rXFOk6LiyaKsOZQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Thu, Jan 15, 2015 at 6:03 PM, Adam Brightwell
<adam(dot)brightwell(at)crunchydatasolutions(dot)com> wrote:
> * ONLINE_BACKUP - allows role to perform backup operations
> - originally proposed as BACKUP - due to concern for the use of that term
> in relation to other potential backup related permissions this form is in
> line with the documentation as it describes the affected backup operations
> as being 'online backups'.
> - applies only to the originally proposed backup functions.

I'm slightly mystified as to how including the word "online" helps
here. It's unlikely that there will be an offline_backup permission,
because if the system is off-line, SQL-level permissions are
irrelevant.

> * LOG - allows role to rotate log files - remains broad enough to consider
> future log related operations

Maybe LOGFILE? Only because some confusion with the LOG message level
seems possible; or confusion about whether this is a permission that
lets you log things.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


From: Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Stephen Frost <sfrost(at)snowman(dot)net>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2015-01-19 14:00:56
Message-ID: CAKRt6CS5XFDoacWLvqMsvsgED+83XRcxASi5KQyku2ksxoVU=A@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Robert,

Thanks for the feedback.

I'm slightly mystified as to how including the word "online" helps
> here. It's unlikely that there will be an offline_backup permission,
> because if the system is off-line, SQL-level permissions are
> irrelevant.

I'm certainly open to recommendations on this one. Initially, BACKUP was
proposed, but based on the discussion, it is unacceptable. As mentioned,
the documentation for the affected functions refer to starting/stopping an
'on-line backup', hence the current proposal. I feel like it is obviously
more in line with the documentation and removes the ambiguity in what
'type' of backup it allows, as that seemed to be one of the major concerns
of just using BACKUP. However, I could certainly understand if there was a
confusion on the terminology of 'online' vs 'offline' if those are not
regularly used terms or concepts. At any rate, I'll certainly continue to
give this one thought, but I wouldn't mind any recommendations/suggestions
anyone was willing to throw my way.

> * LOG - allows role to rotate log files - remains broad enough to consider
> > future log related operations
>
> Maybe LOGFILE? Only because some confusion with the LOG message level
> seems possible; or confusion about whether this is a permission that
> lets you log things.

That's a good point. I'll change this one up.

Thanks,
Adam

--
Adam Brightwell - adam(dot)brightwell(at)crunchydatasolutions(dot)com
Database Engineer - www.crunchydatasolutions.com


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2015-01-19 14:03:55
Message-ID: 20150119140354.GG3062@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

* Robert Haas (robertmhaas(at)gmail(dot)com) wrote:
> On Thu, Jan 15, 2015 at 6:03 PM, Adam Brightwell
> <adam(dot)brightwell(at)crunchydatasolutions(dot)com> wrote:
> > * ONLINE_BACKUP - allows role to perform backup operations
> > - originally proposed as BACKUP - due to concern for the use of that term
> > in relation to other potential backup related permissions this form is in
> > line with the documentation as it describes the affected backup operations
> > as being 'online backups'.
> > - applies only to the originally proposed backup functions.
>
> I'm slightly mystified as to how including the word "online" helps
> here. It's unlikely that there will be an offline_backup permission,
> because if the system is off-line, SQL-level permissions are
> irrelevant.

ONLINE does match up with what we call the pg_start/stop_backup based
backups in the documentation, at least. Also, it's intended to contrast
against pg_dump-based backups, not offline backups (which we don't
discuss at all in the docs that I can see).

Looking over the docs again a bit though, what about BACKUP_CONTROL,
following the title of 9.26.3?

Suggestions certainly welcome.

> > * LOG - allows role to rotate log files - remains broad enough to consider
> > future log related operations
>
> Maybe LOGFILE? Only because some confusion with the LOG message level
> seems possible; or confusion about whether this is a permission that
> lets you log things.

LOGFILE works for me.

Thanks!

Stephen


From: Simon Riggs <simon(at)2ndQuadrant(dot)com>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2015-01-19 14:59:14
Message-ID: CA+U5nMLdQRRHOdotxcg-nN_yLqs6QsxzEt1+YUC8jxeHc+jvGw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 3 November 2014 at 17:08, Stephen Frost <sfrost(at)snowman(dot)net> wrote:

> role attributes don't act like
> GRANTs anyway (there's no ADMIN option and they aren't inheirited).

I'm happy with us *not* doing this using GRANTs, as long as we spend
some love on the docs to show there is a very clear distinction
between the two.

Users get confused between privs, role attributes and SETs that apply to roles.

Introducing the new word "capability" needs to also have some clarity.
Is that the same thing as "role attribute", or is that a 4th kind of
thang?

Make things make sense and they're easy to agree.

--
Simon Riggs http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, RemoteDBA, Training & Services


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Simon Riggs <simon(at)2ndQuadrant(dot)com>
Cc: Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2015-01-19 15:26:52
Message-ID: 20150119152652.GH3062@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

* Simon Riggs (simon(at)2ndQuadrant(dot)com) wrote:
> On 3 November 2014 at 17:08, Stephen Frost <sfrost(at)snowman(dot)net> wrote:
> > role attributes don't act like
> > GRANTs anyway (there's no ADMIN option and they aren't inheirited).
>
> I'm happy with us *not* doing this using GRANTs, as long as we spend
> some love on the docs to show there is a very clear distinction
> between the two.

The distinction already exists. I agree that the documentation should
be improved to clarify how GRANT'd privileges are different from role
attributes (which is what our existing superuser, createrole, etc
options are).

> Users get confused between privs, role attributes and SETs that apply to roles.

Agreed.

> Introducing the new word "capability" needs to also have some clarity.
> Is that the same thing as "role attribute", or is that a 4th kind of
> thang?

At present, it's exactly the same as 'role attribute' and, for my part
at least, I was thinking it would remain the same. I believe the idea
was to migrate the terminology from 'role attribute' to 'capability' as
the latter better represents both the existing options and the new ones.

Thanks!

Stephen


From: Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Stephen Frost <sfrost(at)snowman(dot)net>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2015-01-21 16:27:31
Message-ID: CAKRt6CSk1O6sHukQA7CmMXc==8X9JpDpnCyds4hrSinqjm1L+w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

All,

>
> I'm slightly mystified as to how including the word "online" helps
> here. It's unlikely that there will be an offline_backup permission,
> because if the system is off-line, SQL-level permissions are
> irrelevant.

After re-reading through this thread is seems like EXCLUSIVEBACKUP
(proposed by Magnus) seemed to be a potentially acceptable alternative.

----
Relevant post:
http://www.postgresql.org/message-id/CABUevEz7BZ0r85VUt4RVXX0JkpiH8hP8ToqzGVpuFL0KvcvBNg@mail.gmail.com
----
We need to separate the logical backups (pg_dump) from the physical ones
(start/stop+filesystem and pg_basebackup). We might also need to separate
the two different ways of doing physical backups.

Personalyl I think using the DUMP name makes that a lot more clear. Maybe
we need to avoid using BACKUP alone as well, to make sure it doesn't go the
other way - using BASEBACKUP and EXCLUSIVEBACKUP for those two different
ones perhaps?
----

----
Relevant post:
http://www.postgresql.org/message-id/20141231144610.GS3062@tamriel.snowman.net
----
I think I'm coming around to the EXCLUSIVEBACKUP option, per the
discussion with Magnus. I don't particularly like LOGBACKUP and don't
think it really makes sense, while PHYSBACKUP seems like it'd cover what
REPLICATION already does.
----

Thoughts?

-Adam

--
Adam Brightwell - adam(dot)brightwell(at)crunchydatasolutions(dot)com
Database Engineer - www.crunchydatasolutions.com


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2015-01-22 17:08:03
Message-ID: 20150122170803.GF3854@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Adam, all,

* Adam Brightwell (adam(dot)brightwell(at)crunchydatasolutions(dot)com) wrote:
> After re-reading through this thread is seems like EXCLUSIVEBACKUP
> (proposed by Magnus) seemed to be a potentially acceptable alternative.

I just chatted a bit on IRC w/ Magnus about this and I'm on-board with
his proposal to use EXCLUSIVEBACKUP, but there's a couple additional
things which need doing as part of that:

We need to actually define what an 'exclusive backup' is in the
documentation- it's not there today.

pg_start_backup/pg_stop_backup docs should be updated to refer to those
operations as relating to "on-line exclusive backup," same as
pg_is_in_backup() and pg_backup_start_time() do.

The docs for the EXCLUSIVEBACKUP attribute should, of course, refer to
where EXCLUSIVE BACKUP is defined.

Hopefully that wraps up the last of the debate around the naming of
these options and we can move forward, once the patch is updated to
reflect this and docs are written. Would be great to hear from anyone
who feels otherwise.

Regarding the pg_dump/read-only/etc discussion- that wasn't intended to
be part of this and I continue to feel it'd be best addressed on a new
thread specifically for that. Once we have this initial round of role
attribute additions settled, I'd be more than happy to support that
discussion and see what we can do to provide such a role.

Thanks!

Stephen


From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>
Cc: Stephen Frost <sfrost(at)snowman(dot)net>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2015-01-26 18:31:07
Message-ID: CA+TgmoZ4P6Hf7GO8w0=_ZB7f2UmTYYNBGQ28QhYNdOCSBZBQpA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Wed, Jan 21, 2015 at 11:27 AM, Adam Brightwell
<adam(dot)brightwell(at)crunchydatasolutions(dot)com> wrote:
> After re-reading through this thread is seems like EXCLUSIVEBACKUP (proposed
> by Magnus) seemed to be a potentially acceptable alternative.

So this would let you do pg_start_backup() and pg_stop_backup(), but
it wouldn't let you run pg_basebackup against the server?

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2015-01-26 18:47:02
Message-ID: 20150126184702.GV3854@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

* Robert Haas (robertmhaas(at)gmail(dot)com) wrote:
> On Wed, Jan 21, 2015 at 11:27 AM, Adam Brightwell
> <adam(dot)brightwell(at)crunchydatasolutions(dot)com> wrote:
> > After re-reading through this thread is seems like EXCLUSIVEBACKUP (proposed
> > by Magnus) seemed to be a potentially acceptable alternative.
>
> So this would let you do pg_start_backup() and pg_stop_backup(), but
> it wouldn't let you run pg_basebackup against the server?

Right. We already have a role attribute which allows pg_basebackup
(replication). Also, with pg_basebackup / rolreplication, your role
is able to read the entire data directory from the server, that's not
the case with only rights to run pg_start/stop_backup.

In conjunction with enterprise backup solutions and SANs, which offer
similar controls where a generally unprivileged user can have a snapshot
of the system taken through the SAN interface, you can give users the
ability to run ad-hoc backups of the cluster without giving them
superuser-level access or replication-level access.

Even with simpler solutions, it means that the backup user doesn't
have to be able to run some superuser-level script against the database
to run the backup.

As for pg_basebackup itself, I agree that it's not exactly intuitive
that 'replication' is what grants you the right to run pg_basebackup..
Perhaps we could rename it or make an alias for it, or something along
those lines? I wasn't looking to do anything with it at this time, but
it would probably be good to improve it somehow, if you (or anyone) have
suggestions on how best to do so.

Thanks!

Stephen


From: Andres Freund <andres(at)2ndquadrant(dot)com>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2015-01-26 18:59:01
Message-ID: 20150126185901.GB5568@awork2.anarazel.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 2015-01-26 13:47:02 -0500, Stephen Frost wrote:
> * Robert Haas (robertmhaas(at)gmail(dot)com) wrote:
> > On Wed, Jan 21, 2015 at 11:27 AM, Adam Brightwell
> > <adam(dot)brightwell(at)crunchydatasolutions(dot)com> wrote:
> > > After re-reading through this thread is seems like EXCLUSIVEBACKUP (proposed
> > > by Magnus) seemed to be a potentially acceptable alternative.
> >
> > So this would let you do pg_start_backup() and pg_stop_backup(), but
> > it wouldn't let you run pg_basebackup against the server?
>
> Right. We already have a role attribute which allows pg_basebackup
> (replication). Also, with pg_basebackup / rolreplication, your role
> is able to read the entire data directory from the server, that's not
> the case with only rights to run pg_start/stop_backup.
>
> In conjunction with enterprise backup solutions and SANs, which offer
> similar controls where a generally unprivileged user can have a snapshot
> of the system taken through the SAN interface, you can give users the
> ability to run ad-hoc backups of the cluster without giving them
> superuser-level access or replication-level access.

I'm sorry if this has already been discussed, but the thread is awfully
long already. But what's actually the point of having a separate
EXCLUSIVEBACKUP permission? Using it still requires full file system
access to the data directory, so the additional permissions granted by
replication aren't really relevant.

I don't think the comparison with the SAN snapshot functionality is apt:
The SAN solution itself will still run with full data access. Just
pressing the button for the snapshot requires less. You're comparing
that button to pg_start/stop_backup() - but that doesn't make sense,
because it's only useful if somebody actually takes the backup during
that time.

Greetings,

Andres Freund

--
Andres Freund http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services


From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Andres Freund <andres(at)2ndquadrant(dot)com>
Cc: Stephen Frost <sfrost(at)snowman(dot)net>, Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2015-01-26 19:03:20
Message-ID: CA+TgmoZnbcPRLWPsrx=UiBnMcTq2iKhJw8h4EmC1Fre87pQLZA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Mon, Jan 26, 2015 at 1:59 PM, Andres Freund <andres(at)2ndquadrant(dot)com> wrote:
> On 2015-01-26 13:47:02 -0500, Stephen Frost wrote:
>> * Robert Haas (robertmhaas(at)gmail(dot)com) wrote:
>> > On Wed, Jan 21, 2015 at 11:27 AM, Adam Brightwell
>> > <adam(dot)brightwell(at)crunchydatasolutions(dot)com> wrote:
>> > > After re-reading through this thread is seems like EXCLUSIVEBACKUP (proposed
>> > > by Magnus) seemed to be a potentially acceptable alternative.
>> >
>> > So this would let you do pg_start_backup() and pg_stop_backup(), but
>> > it wouldn't let you run pg_basebackup against the server?
>>
>> Right. We already have a role attribute which allows pg_basebackup
>> (replication). Also, with pg_basebackup / rolreplication, your role
>> is able to read the entire data directory from the server, that's not
>> the case with only rights to run pg_start/stop_backup.
>>
>> In conjunction with enterprise backup solutions and SANs, which offer
>> similar controls where a generally unprivileged user can have a snapshot
>> of the system taken through the SAN interface, you can give users the
>> ability to run ad-hoc backups of the cluster without giving them
>> superuser-level access or replication-level access.
>
> I'm sorry if this has already been discussed, but the thread is awfully
> long already. But what's actually the point of having a separate
> EXCLUSIVEBACKUP permission? Using it still requires full file system
> access to the data directory, so the additional permissions granted by
> replication aren't really relevant.

That's not necessarily true. You could be able to run a command like
"san_snapshot $PGDATA" without necessarily having the permissions to
inspect the contents of the resulting snapshot. Of course somebody
should be doing that, but in accord with the principle of least
privilege, there's no reason that the account running the unattended
backup needs to have those rights.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Andres Freund <andres(at)2ndquadrant(dot)com>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2015-01-26 19:05:03
Message-ID: 20150126190503.GW3854@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

* Andres Freund (andres(at)2ndquadrant(dot)com) wrote:
> On 2015-01-26 13:47:02 -0500, Stephen Frost wrote:
> > Right. We already have a role attribute which allows pg_basebackup
> > (replication). Also, with pg_basebackup / rolreplication, your role
> > is able to read the entire data directory from the server, that's not
> > the case with only rights to run pg_start/stop_backup.
> >
> > In conjunction with enterprise backup solutions and SANs, which offer
> > similar controls where a generally unprivileged user can have a snapshot
> > of the system taken through the SAN interface, you can give users the
> > ability to run ad-hoc backups of the cluster without giving them
> > superuser-level access or replication-level access.
>
> I'm sorry if this has already been discussed, but the thread is awfully
> long already. But what's actually the point of having a separate
> EXCLUSIVEBACKUP permission? Using it still requires full file system
> access to the data directory, so the additional permissions granted by
> replication aren't really relevant.

I agree that it's a pretty long thread for what amount to a few
relatively straight-forward role attributes (at least, in my view).

> I don't think the comparison with the SAN snapshot functionality is apt:
> The SAN solution itself will still run with full data access. Just
> pressing the button for the snapshot requires less. You're comparing
> that button to pg_start/stop_backup() - but that doesn't make sense,
> because it's only useful if somebody actually takes the backup during
> that time.

I'm not following your logic here.. You're right- just pressing the
button to take a snapshot can be granted out to a lower-level user using
the SAN solution. That snapshot's useless unless the user can first run
pg_start_backup though (and subsequently run pg_stop_backup afterwards).
Clearly, XLOG archiving has to be set up already, but that would be set
up when the system is initially brought online.

This capability would be used in conjunction with the SAN snapshot
capability, it's not intended to be a comparison to what SANs offer.

Thanks!

Stephen


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Andres Freund <andres(at)2ndquadrant(dot)com>, Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2015-01-26 19:06:05
Message-ID: 20150126190605.GX3854@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

* Robert Haas (robertmhaas(at)gmail(dot)com) wrote:
> On Mon, Jan 26, 2015 at 1:59 PM, Andres Freund <andres(at)2ndquadrant(dot)com> wrote:
> > On 2015-01-26 13:47:02 -0500, Stephen Frost wrote:
> >> Right. We already have a role attribute which allows pg_basebackup
> >> (replication). Also, with pg_basebackup / rolreplication, your role
> >> is able to read the entire data directory from the server, that's not
> >> the case with only rights to run pg_start/stop_backup.
> >>
> >> In conjunction with enterprise backup solutions and SANs, which offer
> >> similar controls where a generally unprivileged user can have a snapshot
> >> of the system taken through the SAN interface, you can give users the
> >> ability to run ad-hoc backups of the cluster without giving them
> >> superuser-level access or replication-level access.
> >
> > I'm sorry if this has already been discussed, but the thread is awfully
> > long already. But what's actually the point of having a separate
> > EXCLUSIVEBACKUP permission? Using it still requires full file system
> > access to the data directory, so the additional permissions granted by
> > replication aren't really relevant.
>
> That's not necessarily true. You could be able to run a command like
> "san_snapshot $PGDATA" without necessarily having the permissions to
> inspect the contents of the resulting snapshot. Of course somebody
> should be doing that, but in accord with the principle of least
> privilege, there's no reason that the account running the unattended
> backup needs to have those rights.

Right! You explained it more clearly than I did.

Thanks!

Stephen


From: Andres Freund <andres(at)2ndquadrant(dot)com>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2015-01-26 19:11:54
Message-ID: 20150126191154.GC5568@awork2.anarazel.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 2015-01-26 14:05:03 -0500, Stephen Frost wrote:
> This capability would be used in conjunction with the SAN snapshot
> capability, it's not intended to be a comparison to what SANs offer.

Oh, on a reread that's now clear. Many of those actually allow hooks to
be run when taking a snapshot, that'd probably be a better approach. But
I can now see the point.

Thanks,

Andres Freund

--
Andres Freund http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services


From: Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2015-01-28 01:14:30
Message-ID: CAKRt6CTg60vQ0cc_rh-fb7zRphQYgwrTFvHFSEacjUAh2hL7DQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

All,

I have attached and updated patch for review.

Thanks,
Adam

--
Adam Brightwell - adam(dot)brightwell(at)crunchydatasolutions(dot)com
Database Engineer - www.crunchydatasolutions.com

Attachment Content-Type Size
role-attributes-v3.patch text/x-patch 48.4 KB

From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2015-03-01 03:10:41
Message-ID: 20150301031041.GT29780@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Adam,

* Adam Brightwell (adam(dot)brightwell(at)crunchydatasolutions(dot)com) wrote:
> I have attached and updated patch for review.

Thanks! I've gone over this and made quite a few documentation and
comment updates, but not too much else, so I'm pretty happy with how
this is coming along. As mentioned elsewhere, this conflicts with the
GetUserId() to has_privs_of_role() cleanup, but as I anticipate handling
both this patch and that one, I'll find some way to manage. :)

Updated patch attached. Barring objections, I'll be moving forward with
this soonish. Would certainly appreciate any additional testing or
review that you (or anyone!) has time to provide.

Thanks again!

Stephen

Attachment Content-Type Size
role-attributes-v4.patch text/x-diff 46.6 KB

From: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2015-03-01 14:36:59
Message-ID: 20150301143659.GO2384@alvh.no-ip.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Stephen Frost wrote:

> Thanks! I've gone over this and made quite a few documentation and
> comment updates, but not too much else, so I'm pretty happy with how
> this is coming along. As mentioned elsewhere, this conflicts with the
> GetUserId() to has_privs_of_role() cleanup, but as I anticipate handling
> both this patch and that one, I'll find some way to manage. :)
>
> Updated patch attached. Barring objections, I'll be moving forward with
> this soonish. Would certainly appreciate any additional testing or
> review that you (or anyone!) has time to provide.

I thought I saw a comment about using underscore to separate words in
privilege names, such as EXCLUSIVE_BACKUP rather than running it all
together. Was that idea discarded?

--
Álvaro Herrera http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
Cc: Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2015-03-01 15:14:38
Message-ID: 20150301151438.GV29780@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

* Alvaro Herrera (alvherre(at)2ndquadrant(dot)com) wrote:
> Stephen Frost wrote:
>
> > Thanks! I've gone over this and made quite a few documentation and
> > comment updates, but not too much else, so I'm pretty happy with how
> > this is coming along. As mentioned elsewhere, this conflicts with the
> > GetUserId() to has_privs_of_role() cleanup, but as I anticipate handling
> > both this patch and that one, I'll find some way to manage. :)
> >
> > Updated patch attached. Barring objections, I'll be moving forward with
> > this soonish. Would certainly appreciate any additional testing or
> > review that you (or anyone!) has time to provide.
>
> I thought I saw a comment about using underscore to separate words in
> privilege names, such as EXCLUSIVE_BACKUP rather than running it all
> together. Was that idea discarded?

Hrm, I'm not finding that on a quick look through the archives. Looking
at the other role options, we don't have any with underscores but we do
have a couple of cases where we uses spaces, eg:

CONNECTION LIMIT
VALID UNTIL

So, using EXCLUSIVE BACKUP would be similar to those, but we'd then need
to have the 'NO' version as 'NO EXCLUSIVE BACKUP', I'd think, and I'm
not sure we really want to go there.

On the other hand, we do run together the 'CREATE' options (CREATEDB,
CREATEROLE), and I've not heard anyone suggesting to change those.

I guess for my part, at least, having it run together as
'EXCLUSIVEBACKUP' seems fine, but this does make me realize that I need
to go add tab-completion for these new options. :)

Thanks!

Stephen


From: Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>
To: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
Cc: Stephen Frost <sfrost(at)snowman(dot)net>, Robert Haas <robertmhaas(at)gmail(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2015-03-02 15:25:03
Message-ID: CAKRt6CTU-NjVHPoT4YoPp1+GLM7JYCZn+X9EgKk5giL+MRR8SA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Alvaro,

I thought I saw a comment about using underscore to separate words in
> privilege names, such as EXCLUSIVE_BACKUP rather than running it all
> together. Was that idea discarded?
>

I'm not sure there was an actual discussion on the topic. Though, at one
point I had proposed it as one of the forms of this attribute. Personally,
I think it is easier to read with the underscore. But, ultimately, I
defaulted to no underscore to remain consistent with the other attributes,
such as CREATEDB and CREATEROLE.

Thanks,
Adam

--
Adam Brightwell - adam(dot)brightwell(at)crunchydatasolutions(dot)com
Database Engineer - www.crunchydatasolutions.com


From: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
To: Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>
Cc: Stephen Frost <sfrost(at)snowman(dot)net>, Robert Haas <robertmhaas(at)gmail(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2015-03-02 15:59:07
Message-ID: 20150302155907.GA3291@alvh.no-ip.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Adam Brightwell wrote:
> Alvaro,
>
> > I thought I saw a comment about using underscore to separate words
> > in privilege names, such as EXCLUSIVE_BACKUP rather than running it
> > all together. Was that idea discarded?
>
> I'm not sure there was an actual discussion on the topic. Though, at one
> point I had proposed it as one of the forms of this attribute. Personally,
> I think it is easier to read with the underscore. But, ultimately, I
> defaulted to no underscore to remain consistent with the other attributes,
> such as CREATEDB and CREATEROLE.

If we were choosing those names nowadays, would we choose CREATEDB at
all in the first place? I think we'd go for something more verbose,
probably CREATE_DATABASE. (CREATEROLE is not as old as CREATEDB, but my
bet is that it was modelled after CREATEUSER without considering the
whole readability topic too much.)

Anyway it doesn't seem to me that consistency with lack of separators in
those very old names should be our guiding principle here.

--
Álvaro Herrera http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
Cc: Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2015-03-02 16:34:06
Message-ID: 20150302163406.GN29780@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

* Alvaro Herrera (alvherre(at)2ndquadrant(dot)com) wrote:
> Adam Brightwell wrote:
> > I'm not sure there was an actual discussion on the topic. Though, at one
> > point I had proposed it as one of the forms of this attribute. Personally,
> > I think it is easier to read with the underscore. But, ultimately, I
> > defaulted to no underscore to remain consistent with the other attributes,
> > such as CREATEDB and CREATEROLE.
>
> If we were choosing those names nowadays, would we choose CREATEDB at
> all in the first place? I think we'd go for something more verbose,
> probably CREATE_DATABASE. (CREATEROLE is not as old as CREATEDB, but my
> bet is that it was modelled after CREATEUSER without considering the
> whole readability topic too much.)
>
> Anyway it doesn't seem to me that consistency with lack of separators in
> those very old names should be our guiding principle here.

So you'd advocate EXCLUSIVE_BACKUP and NOEXCLUSIVE_BACKUP? Or
NO_EXCLUSIVE_BACKUP? Or..? If this was a green field, I think we might
actually use spaces instead, but I'm really not sure we want to go
through and redo everything that way at this point.. We'd end up
breaking a lot of scripts that currently work today and I'm really not
convinced it's better enough to justify that.

Thanks!

Stephen


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2015-03-02 17:39:52
Message-ID: 6097.1425317992@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Stephen Frost <sfrost(at)snowman(dot)net> writes:
> * Alvaro Herrera (alvherre(at)2ndquadrant(dot)com) wrote:
>> If we were choosing those names nowadays, would we choose CREATEDB at
>> all in the first place? I think we'd go for something more verbose,
>> probably CREATE_DATABASE. (CREATEROLE is not as old as CREATEDB, but my
>> bet is that it was modelled after CREATEUSER without considering the
>> whole readability topic too much.)
>>
>> Anyway it doesn't seem to me that consistency with lack of separators in
>> those very old names should be our guiding principle here.

> So you'd advocate EXCLUSIVE_BACKUP and NOEXCLUSIVE_BACKUP? Or
> NO_EXCLUSIVE_BACKUP? Or..? If this was a green field, I think we might
> actually use spaces instead, but I'm really not sure we want to go
> through and redo everything that way at this point.. We'd end up
> breaking a lot of scripts that currently work today and I'm really not
> convinced it's better enough to justify that.

FWIW, I agree with Alvaro, and I'd go with e.g. NO_EXCLUSIVE_BACKUP.

I concur that multiple separate words would be a syntax mess, but I
see no reason not to use underscores instead.

regards, tom lane


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2015-03-02 17:41:22
Message-ID: 20150302174122.GP29780@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

* Tom Lane (tgl(at)sss(dot)pgh(dot)pa(dot)us) wrote:
> Stephen Frost <sfrost(at)snowman(dot)net> writes:
> > * Alvaro Herrera (alvherre(at)2ndquadrant(dot)com) wrote:
> >> If we were choosing those names nowadays, would we choose CREATEDB at
> >> all in the first place? I think we'd go for something more verbose,
> >> probably CREATE_DATABASE. (CREATEROLE is not as old as CREATEDB, but my
> >> bet is that it was modelled after CREATEUSER without considering the
> >> whole readability topic too much.)
> >>
> >> Anyway it doesn't seem to me that consistency with lack of separators in
> >> those very old names should be our guiding principle here.
>
> > So you'd advocate EXCLUSIVE_BACKUP and NOEXCLUSIVE_BACKUP? Or
> > NO_EXCLUSIVE_BACKUP? Or..? If this was a green field, I think we might
> > actually use spaces instead, but I'm really not sure we want to go
> > through and redo everything that way at this point.. We'd end up
> > breaking a lot of scripts that currently work today and I'm really not
> > convinced it's better enough to justify that.
>
> FWIW, I agree with Alvaro, and I'd go with e.g. NO_EXCLUSIVE_BACKUP.

Ok, works for me. Will update (including tab completion) and send out
for review.

Thanks!

Stephen


From: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2015-03-02 17:51:46
Message-ID: 20150302175146.GB3291@alvh.no-ip.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Stephen Frost wrote:

> So you'd advocate EXCLUSIVE_BACKUP and NOEXCLUSIVE_BACKUP? Or
> NO_EXCLUSIVE_BACKUP? Or..? If this was a green field, I think we might
> actually use spaces instead, but I'm really not sure we want to go
> through and redo everything that way at this point.. We'd end up
> breaking a lot of scripts that currently work today and I'm really not
> convinced it's better enough to justify that.

Well, all things considered, we actually are in a green field here,
aren't we. We don't have to break old scripts, but no existing script
is using
ALTER USER foo NOEXCLUSIVEBACKUP
because that option doesn't currently exist.

That being so, I would consider the idea that the NO bit is a separate
word rather than run together with the actual privilege name. And given
that CREATE has all the options default to "NO", there is no need to
have these options at all in CREATE, is there?

So we would have only the "positive" actions in create:

CREATE USER foo REPLICATION EXCLUSIVE_BACKUP
(if you want no EXCLUSIVE_BACKUP privilege, just leave it out. It isn't
any more complicated than saying NOEXCLUSIVEBACKUP)

You could turn these off in ALTER:

ALTER USER foo NO EXCLUSIVE_BACKUP;
or perhaps
ALTER USER foo DROP EXCLUSIVE_BACKUP;
or some such.

(REVOKE would be nicer, I guess, but IIRC that conflicts with other
stuff. I guess another option, in line with the current optional WITH,
would be to have WITHOUT:
ALTER USER foo WITHOUT EXCLUSIVE_BACKUP;
But that looks a bit silly to me.)

Then things such as
ALTER USER foo NOREPLICATION
become synonyms for
ALTER USER foo NO REPLICATION (or whatever)

Something like that would be my choice for UI, anyway. The existing
stuff seems to clutter it overly, and while it works sorta OK for half a
dozen privs, it becomes clunkier as you have more of them. From the
perspective of docs, I think this whole thing becomes simpler if you
split out the NO from each privilege name; currently we have

alvherre=# \h alter user
Command: ALTER USER
Description: change a database role
Syntax:
ALTER USER name [ [ WITH ] option [ ... ] ]

where option can be:

SUPERUSER | NOSUPERUSER
| CREATEDB | NOCREATEDB
| CREATEROLE | NOCREATEROLE
| CREATEUSER | NOCREATEUSER
| INHERIT | NOINHERIT
| LOGIN | NOLOGIN
| REPLICATION | NOREPLICATION
| CONNECTION LIMIT connlimit
| [ ENCRYPTED | UNENCRYPTED ] PASSWORD 'password'
| VALID UNTIL 'timestamp'

And it would become something like

ALTER USER name [ WITH ] { [ NO ] privilege | option } [ ... ]

where privilege can be:
SUPERUSER | CREATEDB | CREATEROLE
| CREATEUSER | INHERIT | LOGIN
| REPLICATION | EXCLUSIVE_BACKUP | ...
and option can be:
CONNECTION LIMIT connlimit
| [ ENCRYPTED | UNENCRYPTED ] PASSWORD 'password'
| VALID UNTIL 'timestamp'

(the NOSUPERUSER etc forms of the old options would continue to work for
the sake of backwards compatibility, but we wouldn't provide NO-
prefixed forms of the new privileges.)

I'm not wedded to any of this, but I think it ought to be at least given
some consideration.

--
Álvaro Herrera http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
Cc: Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2015-03-02 18:02:26
Message-ID: 20150302180226.GQ29780@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Alvaro,

* Alvaro Herrera (alvherre(at)2ndquadrant(dot)com) wrote:
> Stephen Frost wrote:
> > So you'd advocate EXCLUSIVE_BACKUP and NOEXCLUSIVE_BACKUP? Or
> > NO_EXCLUSIVE_BACKUP? Or..? If this was a green field, I think we might
> > actually use spaces instead, but I'm really not sure we want to go
> > through and redo everything that way at this point.. We'd end up
> > breaking a lot of scripts that currently work today and I'm really not
> > convinced it's better enough to justify that.
>
> Well, all things considered, we actually are in a green field here,
> aren't we. We don't have to break old scripts, but no existing script
> is using
> ALTER USER foo NOEXCLUSIVEBACKUP
> because that option doesn't currently exist.

Sorry for not being clear, I was talking about how we'd deal with the
existing ones (to try and have a consistent approach across all of the
options).

> That being so, I would consider the idea that the NO bit is a separate
> word rather than run together with the actual privilege name. And given
> that CREATE has all the options default to "NO", there is no need to
> have these options at all in CREATE, is there?

That's a good point, except that INHERIT is actually on by default, and
LOGIN defaults to 'on' if you use CREATE USER, and 'off' if you use
CREATE ROLE. If they were actually all 'no' by default then this
simplication would work but it's not and therefore I don't think we want
to have some which are allowed at CREATE time with 'on' and some with
'off' depending on whatever the default is. Today, you can write a
script to easily duplicate an existing role by just looking at what is
on and off and using X and NOX. This approach would require that script
to know what's valid at CREATE time and what isn't.

> Then things such as
> ALTER USER foo NOREPLICATION
> become synonyms for
> ALTER USER foo NO REPLICATION (or whatever)

I'm not against supporting this and if it's a synonym then it won't
break existing scripts. I can look into this, but it ends up being an
independent discussion from actually adding these new options.

> Something like that would be my choice for UI, anyway. The existing
> stuff seems to clutter it overly, and while it works sorta OK for half a
> dozen privs, it becomes clunkier as you have more of them. From the
> perspective of docs, I think this whole thing becomes simpler if you
> split out the NO from each privilege name; currently we have

I agree that it does get clunkier and this is certainly an interesting
discussion as we might be able to do something better, which would
certainly be great.

> alvherre=# \h alter user
> Command: ALTER USER
> Description: change a database role
> Syntax:
> ALTER USER name [ [ WITH ] option [ ... ] ]
>
> where option can be:
>
> SUPERUSER | NOSUPERUSER
> | CREATEDB | NOCREATEDB
> | CREATEROLE | NOCREATEROLE
> | CREATEUSER | NOCREATEUSER
> | INHERIT | NOINHERIT
> | LOGIN | NOLOGIN
> | REPLICATION | NOREPLICATION
> | CONNECTION LIMIT connlimit
> | [ ENCRYPTED | UNENCRYPTED ] PASSWORD 'password'
> | VALID UNTIL 'timestamp'
>
> And it would become something like
>
> ALTER USER name [ WITH ] { [ NO ] privilege | option } [ ... ]
>
> where privilege can be:
> SUPERUSER | CREATEDB | CREATEROLE
> | CREATEUSER | INHERIT | LOGIN
> | REPLICATION | EXCLUSIVE_BACKUP | ...
> and option can be:
> CONNECTION LIMIT connlimit
> | [ ENCRYPTED | UNENCRYPTED ] PASSWORD 'password'
> | VALID UNTIL 'timestamp'

With the 'NO' distinct, as discussed above, it seems like we should be
able to support this.. I certainly like it more too.

> (the NOSUPERUSER etc forms of the old options would continue to work for
> the sake of backwards compatibility, but we wouldn't provide NO-
> prefixed forms of the new privileges.)

I'm not sure that I like that.. My initial reaction is that it'd
complicate the code and confuse people coming to this later- and to what
purpose..? To force everyone to use 'NO<space>' instead? Maybe in some
far off future we could say that the old 'NOX' format was deprecated and
remove it, but I have a hard time seeing the need to.

> I'm not wedded to any of this, but I think it ought to be at least given
> some consideration.

Certainly, and I like where you're going with this, just seems like
there's a couple wrinkles to deal with.

Thanks!

Stephen


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
Cc: Stephen Frost <sfrost(at)snowman(dot)net>, Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2015-03-02 18:04:03
Message-ID: 6722.1425319443@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Alvaro Herrera <alvherre(at)2ndquadrant(dot)com> writes:
> That being so, I would consider the idea that the NO bit is a separate
> word rather than run together with the actual privilege name. And given
> that CREATE has all the options default to "NO", there is no need to
> have these options at all in CREATE, is there?

FWIW, I disagree with that, mainly because I don't think we should cast in
stone the assumption that NO will always be the default for everything we
might invent in the future. Also, the precedent of the existing options
will lead people to expect that they can explicitly say NO-whatever.

regards, tom lane


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2015-03-02 18:09:05
Message-ID: 20150302180905.GR29780@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

* Tom Lane (tgl(at)sss(dot)pgh(dot)pa(dot)us) wrote:
> Alvaro Herrera <alvherre(at)2ndquadrant(dot)com> writes:
> > That being so, I would consider the idea that the NO bit is a separate
> > word rather than run together with the actual privilege name. And given
> > that CREATE has all the options default to "NO", there is no need to
> > have these options at all in CREATE, is there?
>
> FWIW, I disagree with that, mainly because I don't think we should cast in
> stone the assumption that NO will always be the default for everything we
> might invent in the future. Also, the precedent of the existing options
> will lead people to expect that they can explicitly say NO-whatever.

Right, and, in fact, not everything is 'NO' by default today anyway.

Further, people might try to say 'NO CONNECTION LIMIT', and while we
might want to try and support that, there might be options where 'NO'
doesn't actually make sense ('NO VALID UNTIL'?).

Thanks!

Stephen


From: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2015-03-02 19:21:32
Message-ID: 20150302192132.GD3291@alvh.no-ip.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Stephen Frost wrote:
> Alvaro,
>
> * Alvaro Herrera (alvherre(at)2ndquadrant(dot)com) wrote:

> > That being so, I would consider the idea that the NO bit is a separate
> > word rather than run together with the actual privilege name. And given
> > that CREATE has all the options default to "NO", there is no need to
> > have these options at all in CREATE, is there?
>
> That's a good point, except that INHERIT is actually on by default, and
> LOGIN defaults to 'on' if you use CREATE USER, and 'off' if you use
> CREATE ROLE. If they were actually all 'no' by default then this
> simplication would work but it's not and therefore I don't think we want
> to have some which are allowed at CREATE time with 'on' and some with
> 'off' depending on whatever the default is. Today, you can write a
> script to easily duplicate an existing role by just looking at what is
> on and off and using X and NOX. This approach would require that script
> to know what's valid at CREATE time and what isn't.

All true.

> > where privilege can be:
> > SUPERUSER | CREATEDB | CREATEROLE
> > | CREATEUSER | INHERIT | LOGIN
> > | REPLICATION | EXCLUSIVE_BACKUP | ...
> > and option can be:
> > CONNECTION LIMIT connlimit
> > | [ ENCRYPTED | UNENCRYPTED ] PASSWORD 'password'
> > | VALID UNTIL 'timestamp'
>
> With the 'NO' distinct, as discussed above, it seems like we should be
> able to support this.. I certainly like it more too.

Great.

> Certainly, and I like where you're going with this, just seems like
> there's a couple wrinkles to deal with.

Yeah.

Let's go with the "NO_" prefix then ... that seems better to me than no
separator.

--
Álvaro Herrera http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
Cc: Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2015-03-02 19:41:30
Message-ID: 20150302194130.GV29780@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Alvaro,

* Alvaro Herrera (alvherre(at)2ndquadrant(dot)com) wrote:
> Let's go with the "NO_" prefix then ... that seems better to me than no
> separator.

Works for me.

Thanks!

Stephen


From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: Stephen Frost <sfrost(at)snowman(dot)net>, Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2015-03-05 02:34:26
Message-ID: 54F7C0B2.3020308@gmx.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 2/28/15 10:10 PM, Stephen Frost wrote:
> Adam,
>
> * Adam Brightwell (adam(dot)brightwell(at)crunchydatasolutions(dot)com) wrote:
>> I have attached and updated patch for review.
>
> Thanks! I've gone over this and made quite a few documentation and
> comment updates, but not too much else, so I'm pretty happy with how
> this is coming along. As mentioned elsewhere, this conflicts with the
> GetUserId() to has_privs_of_role() cleanup, but as I anticipate handling
> both this patch and that one, I'll find some way to manage. :)
>
> Updated patch attached. Barring objections, I'll be moving forward with
> this soonish. Would certainly appreciate any additional testing or
> review that you (or anyone!) has time to provide.

Let's move this discussion to the right thread.

Why are we not using roles and function execute privileges for this?


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Peter Eisentraut <peter_e(at)gmx(dot)net>
Cc: Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2015-03-05 16:42:57
Message-ID: 20150305164257.GA29780@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

* Peter Eisentraut (peter_e(at)gmx(dot)net) wrote:
> On 2/28/15 10:10 PM, Stephen Frost wrote:
> > * Adam Brightwell (adam(dot)brightwell(at)crunchydatasolutions(dot)com) wrote:
> >> I have attached and updated patch for review.
> >
> > Thanks! I've gone over this and made quite a few documentation and
> > comment updates, but not too much else, so I'm pretty happy with how
> > this is coming along. As mentioned elsewhere, this conflicts with the
> > GetUserId() to has_privs_of_role() cleanup, but as I anticipate handling
> > both this patch and that one, I'll find some way to manage. :)
> >
> > Updated patch attached. Barring objections, I'll be moving forward with
> > this soonish. Would certainly appreciate any additional testing or
> > review that you (or anyone!) has time to provide.
>
> Let's move this discussion to the right thread.

Agreed.

> Why are we not using roles and function execute privileges for this?

There isn't a particular reason not to, except that the existing checks
are in C code and those would need to be removed and the permission
changes done at initdb time to revoke EXECUTE from PUBLIC for these
functions. Further, as you pointed out, we'd need to dump out the
permissions for the catalog tables and functions with this approach. I
don't expect that to be too difficult to do though.

Thanks!

Stephen


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Peter Eisentraut <peter_e(at)gmx(dot)net>
Cc: Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2015-03-07 21:39:35
Message-ID: 20150307213935.GO29780@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Peter, all,

* Peter Eisentraut (peter_e(at)gmx(dot)net) wrote:
> Why are we not using roles and function execute privileges for this?

Alright, I've got an initial patch to do this for pg_start/stop_backup,
pg_switch_xlog, and pg_create_restore_point. The actual backend changes
are quite small, as expected. I'll add in the changes for the other
functions being discussed and adapt the documentation changes from
the earlier patch to make sense, but what I'd really appreciate are any
comments or thoughts regarding the changes to pg_dump (which are generic
to all of the function changes, of course).

I've added a notion of "the catalog schema" to pg_dump's internal
_namespaceinfo representation and then marked pg_catalog as being that
schema, as well as being a "dumpable" schema. Throughout the
selectDumpable functions, I've made changes to only mark the objects in
the catalog as dumpable if they are functions. I'm planning to look
into the extension and binary upgrade paths since I'm a bit worried
those may not work with this approach, but I wanted to get this out
there for at least an initial review as, if people feel this makes
things too ugly on the pg_dump side of things then we may want to
reconsider using the role attributes instead.

Thanks!

Stephen

Attachment Content-Type Size
catalog_function_acls.patch text/x-diff 11.3 KB

From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Peter Eisentraut <peter_e(at)gmx(dot)net>
Cc: Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2015-03-16 20:22:55
Message-ID: 20150316202255.GW29780@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

All,

* Stephen Frost (sfrost(at)snowman(dot)net) wrote:
> Alright, I've got an initial patch to do this for pg_start/stop_backup,
> pg_switch_xlog, and pg_create_restore_point. The actual backend changes
> are quite small, as expected. I'll add in the changes for the other
> functions being discussed and adapt the documentation changes from
> the earlier patch to make sense, but what I'd really appreciate are any
> comments or thoughts regarding the changes to pg_dump (which are generic
> to all of the function changes, of course).

So, I've tested this approach with extensions and binary upgrade and
things appear to all be working correctly, but there's a few issues
remaining to discuss:

The functions pg_start_backup and pg_stop_backup can currently be run by
replication roles but those roles won't have any permissions on those
functions with the new approach unless we GRANT those rights during
pg_dump and/or pg_upgrade. Note that this isn't an issue for tools
which use the replication protocol (eg: pg_basebackup) since the
replication protocol calls do_pg_start_bacup() directly. As such, my
first question is- do we want to worry about this? We should certainly
mention it in the release notes but I'm not sure if we really want to do
anything else.

The second question is in regards to pg_stat_activity. My first
suggestion for how to address that would be to have the function return
everything and then have the view perform the filtering to return only
what's shown today for users. Admins could then grant access to the
function for whichever users they want to have access to everything.
That strikes me as the best way to avoid changing common usage while
still providing the flexibility. Another option would be to still
invent the MONITOR role attribute and keep the rest the same. Again,
we'd want to mention something in the release notes regarding this
change.

Lastly, there is the question of pg_cancel_backend and
pg_terminate_backend. My thinking on this is to create a new
'pg_signal_backend' which admins could grant access to and leave the
existing functions alone (modulo the change for has_privs_of_role as
discussed previously). We'd rename the current 'pg_signal_backend' to
something else (maybe '_helper'); it's not exposed anywhere and
therefore renaming it shouldn't cause any heartache.

For pg_create_restore_point, pg_switch_xlog, pg_xlog_replay_pause,
pg_xlog_replay_resume, pg_rotate_logfile, we can just remove the
if(!superuser()) ereport() checks and REVOKE rights on them during the
initdb process, since there isn't anything complicated happening for
those today.

One other question which I've been thinking about is if we want to try
and preserve permission changes associated with other catalog objects
(besides functions), or if we even want to change how functions are
handled regarding permission changes. We don't currently preserve any
such changes across dump/restore or even binary upgrades and this would
be changing that. I don't recall any complaints about not preserving
permission changes to objects in pg_catalog, but one could argue that
our lack of doing so today is a bug.

Thoughts?

Thanks!

Stephen


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: Peter Eisentraut <peter_e(at)gmx(dot)net>, Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2015-03-16 20:43:32
Message-ID: 8154.1426538612@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Stephen Frost <sfrost(at)snowman(dot)net> writes:
> ... Lastly, there is the question of pg_cancel_backend and
> pg_terminate_backend. My thinking on this is to create a new
> 'pg_signal_backend' which admins could grant access to and leave the
> existing functions alone (modulo the change for has_privs_of_role as
> discussed previously). We'd rename the current 'pg_signal_backend' to
> something else (maybe '_helper'); it's not exposed anywhere and
> therefore renaming it shouldn't cause any heartache.

That seems fairly ugly. Why would we need a new, duplicative function
here? (Apologies if the reasoning was spelled out upthread, I've not
been paying much attention.)

regards, tom lane


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Peter Eisentraut <peter_e(at)gmx(dot)net>, Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2015-03-16 20:49:06
Message-ID: 20150316204906.GZ29780@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

* Tom Lane (tgl(at)sss(dot)pgh(dot)pa(dot)us) wrote:
> Stephen Frost <sfrost(at)snowman(dot)net> writes:
> > ... Lastly, there is the question of pg_cancel_backend and
> > pg_terminate_backend. My thinking on this is to create a new
> > 'pg_signal_backend' which admins could grant access to and leave the
> > existing functions alone (modulo the change for has_privs_of_role as
> > discussed previously). We'd rename the current 'pg_signal_backend' to
> > something else (maybe '_helper'); it's not exposed anywhere and
> > therefore renaming it shouldn't cause any heartache.
>
> That seems fairly ugly. Why would we need a new, duplicative function
> here? (Apologies if the reasoning was spelled out upthread, I've not
> been paying much attention.)

Currently, those functions allow users to signal backends which are
owned by them, which means they can be used by anyone. Simply
REVOKE'ing access to them would remove that capability and an admin who
then GRANT's access to the function would need to understand that
they're allowing that user the ability to cancel/terminate any backends
(except those initiated by superusers, at least if we keep that check as
discussed upthread).

If those functions just had simply superuser() checks that prevented
anyone else from using them then this wouldn't be an issue.

REVOKE'ing access *without* removing the permissions checks would defeat
the intent of these changes, which is to allow an administrator to grant
the ability for a certain set of users to cancel and/or terminate
backends started by other users, without also granting those users
superuser rights.

Thanks!

Stephen


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: Peter Eisentraut <peter_e(at)gmx(dot)net>, Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2015-03-16 21:01:43
Message-ID: 8730.1426539703@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Stephen Frost <sfrost(at)snowman(dot)net> writes:
> * Tom Lane (tgl(at)sss(dot)pgh(dot)pa(dot)us) wrote:
>> That seems fairly ugly. Why would we need a new, duplicative function
>> here? (Apologies if the reasoning was spelled out upthread, I've not
>> been paying much attention.)

> Currently, those functions allow users to signal backends which are
> owned by them, which means they can be used by anyone. Simply
> REVOKE'ing access to them would remove that capability and an admin who
> then GRANT's access to the function would need to understand that
> they're allowing that user the ability to cancel/terminate any backends
> (except those initiated by superusers, at least if we keep that check as
> discussed upthread).

> If those functions just had simply superuser() checks that prevented
> anyone else from using them then this wouldn't be an issue.

> REVOKE'ing access *without* removing the permissions checks would defeat
> the intent of these changes, which is to allow an administrator to grant
> the ability for a certain set of users to cancel and/or terminate
> backends started by other users, without also granting those users
> superuser rights.

I see: we have two different use-cases and no way for GRANT/REVOKE
to manage both cases using permissions on a single object. Carry
on then.

regards, tom lane


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Peter Eisentraut <peter_e(at)gmx(dot)net>, Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2015-04-02 04:53:11
Message-ID: 20150402045311.GW3663@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

* Tom Lane (tgl(at)sss(dot)pgh(dot)pa(dot)us) wrote:
> Stephen Frost <sfrost(at)snowman(dot)net> writes:
> > REVOKE'ing access *without* removing the permissions checks would defeat
> > the intent of these changes, which is to allow an administrator to grant
> > the ability for a certain set of users to cancel and/or terminate
> > backends started by other users, without also granting those users
> > superuser rights.
>
> I see: we have two different use-cases and no way for GRANT/REVOKE
> to manage both cases using permissions on a single object. Carry
> on then.

Alright, after going about this three or four different ways, I've
settled on the approach proposed in the attached patch. Most of it is
pretty straight-forward: drop the hard-coded check in the function
itself and REVOKE EXECUTE on the function from PUBLIC. The interesting
bits are those pieces which are more complex than the "all-or-nothing"
cases.

This adds a few new SQL-level functions which return unfiltered results,
if you're allowed to call them based on the GRANT system (and EXECUTE
privileges for them are REVOKE'd from PUBLIC, of course). These are:
pg_stat_get_activity_all, pg_stat_get_wal_senders_all, and
pg_signal_backend (which is similar but not the same- that allows you to
send signals to other backends as a regular user, if you are allowed to
call that function and the other backend wasn't started by a superuser).

There are two new views added, which simply sit on top of the new
functions: pg_stat_activity_all and pg_stat_replication_all.

Minimizing the amount of code duplication wasn't too hard with the
pg_stat_get_wal_senders case; as it was already returning a tuplestore
and so I simply moved most of the logic into a "helper" function which
handled populating the tuplestore and then each call path was relatively
small and mostly boilerplate. pg_stat_get_activity required a bit more
in the way of changes, but they were essentially to modify it to return
a tuplestore like pg_stat_get_wal_senders, and then add in the extra
function and boilerplate for the non-filtered path.

I had considered (and spent a good bit of time implementing...) a number
of alternatives, mostly around trying to do more at the SQL level when
it came to filtering, but that got very ugly very quickly. There's no
simple way to find out "what was the effective role of the caller of
this function" from inside of a security definer function (which would
be required for the filtering, as it would need to be able to call the
function underneath). This is necessary, of course, because functions
in views run as the caller of the view, not as the view owner (that's
useful in some cases, less useful in others). I looked at exposing the
information about the effective role which was calling a function, but
that got pretty ugly too. The GUC system has a stack, but we don't
actually update the 'role' GUC when we are in security definer
functions. There's the notion of an "outer" role ID, but that doesn't
account for intermediate security definer functions and so, while it's
fine for what it does, it wasn't really helpful in this case.

I do still think it'd be nice to provide that information and perhaps we
can do so with fmgr_security_definer(), but it's beyond what's really
needed here and I don't think it'd end up being particularly cleaner to
do it all in SQL now that I've refactored pg_stat_get_activity.

I'd further like to see the ability to declare on either a function call
by function call basis (inside a view defintion), of even at the view
level (as that would allow me to build up multiple views with different
parameters) "who to run this function as", where the options would be
"view owner" or "view querier", very similar to our SECURITY DEFINER vs.
SECURITY INVOKER options for functions today. This is interesting
because, more and more, we're building functions which are actually
returning data sets, not individual values, and we want to filter those
sets sometimes and not other times. In any case, those are really
thoughts for the future and get away from what this is all about, which
is reducing the need for monitoring and/or "regular" admins to have the
"superuser" bit when they don't really need it.

Clearly, further testing and documentation is required and I'll be
getting to that over the next couple of days, but it's pretty darn late
and I'm currently getting libpq undefined reference errors, probably
because I need to set LD_LIBRARY_PATH, but I'm just too tired to now. :)

Thoughts?

Thanks!

Stephen

Attachment Content-Type Size
catalog_function_acls_v2.patch text/x-diff 50.8 KB

From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>, Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2015-04-02 13:07:00
Message-ID: CA+TgmobkSvg1gqeWBshVkAErDmPnb8fLiwyVSLPoKaebEtyoxQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Thu, Apr 2, 2015 at 12:53 AM, Stephen Frost <sfrost(at)snowman(dot)net> wrote:
> * Tom Lane (tgl(at)sss(dot)pgh(dot)pa(dot)us) wrote:
>> Stephen Frost <sfrost(at)snowman(dot)net> writes:
>> > REVOKE'ing access *without* removing the permissions checks would defeat
>> > the intent of these changes, which is to allow an administrator to grant
>> > the ability for a certain set of users to cancel and/or terminate
>> > backends started by other users, without also granting those users
>> > superuser rights.
>>
>> I see: we have two different use-cases and no way for GRANT/REVOKE
>> to manage both cases using permissions on a single object. Carry
>> on then.
>
> Alright, after going about this three or four different ways, I've
> settled on the approach proposed in the attached patch. Most of it is
> pretty straight-forward: drop the hard-coded check in the function
> itself and REVOKE EXECUTE on the function from PUBLIC. The interesting
> bits are those pieces which are more complex than the "all-or-nothing"
> cases.
>
> This adds a few new SQL-level functions which return unfiltered results,
> if you're allowed to call them based on the GRANT system (and EXECUTE
> privileges for them are REVOKE'd from PUBLIC, of course). These are:
> pg_stat_get_activity_all, pg_stat_get_wal_senders_all, and
> pg_signal_backend (which is similar but not the same- that allows you to
> send signals to other backends as a regular user, if you are allowed to
> call that function and the other backend wasn't started by a superuser).
>
> There are two new views added, which simply sit on top of the new
> functions: pg_stat_activity_all and pg_stat_replication_all.
>
> Minimizing the amount of code duplication wasn't too hard with the
> pg_stat_get_wal_senders case; as it was already returning a tuplestore
> and so I simply moved most of the logic into a "helper" function which
> handled populating the tuplestore and then each call path was relatively
> small and mostly boilerplate. pg_stat_get_activity required a bit more
> in the way of changes, but they were essentially to modify it to return
> a tuplestore like pg_stat_get_wal_senders, and then add in the extra
> function and boilerplate for the non-filtered path.
>
> I had considered (and spent a good bit of time implementing...) a number
> of alternatives, mostly around trying to do more at the SQL level when
> it came to filtering, but that got very ugly very quickly. There's no
> simple way to find out "what was the effective role of the caller of
> this function" from inside of a security definer function (which would
> be required for the filtering, as it would need to be able to call the
> function underneath). This is necessary, of course, because functions
> in views run as the caller of the view, not as the view owner (that's
> useful in some cases, less useful in others). I looked at exposing the
> information about the effective role which was calling a function, but
> that got pretty ugly too. The GUC system has a stack, but we don't
> actually update the 'role' GUC when we are in security definer
> functions. There's the notion of an "outer" role ID, but that doesn't
> account for intermediate security definer functions and so, while it's
> fine for what it does, it wasn't really helpful in this case.
>
> I do still think it'd be nice to provide that information and perhaps we
> can do so with fmgr_security_definer(), but it's beyond what's really
> needed here and I don't think it'd end up being particularly cleaner to
> do it all in SQL now that I've refactored pg_stat_get_activity.
>
> I'd further like to see the ability to declare on either a function call
> by function call basis (inside a view defintion), of even at the view
> level (as that would allow me to build up multiple views with different
> parameters) "who to run this function as", where the options would be
> "view owner" or "view querier", very similar to our SECURITY DEFINER vs.
> SECURITY INVOKER options for functions today. This is interesting
> because, more and more, we're building functions which are actually
> returning data sets, not individual values, and we want to filter those
> sets sometimes and not other times. In any case, those are really
> thoughts for the future and get away from what this is all about, which
> is reducing the need for monitoring and/or "regular" admins to have the
> "superuser" bit when they don't really need it.
>
> Clearly, further testing and documentation is required and I'll be
> getting to that over the next couple of days, but it's pretty darn late
> and I'm currently getting libpq undefined reference errors, probably
> because I need to set LD_LIBRARY_PATH, but I'm just too tired to now. :)
>
> Thoughts?

The tricky part of this seems to me to be the pg_dump changes. The
new catalog flag seems a little sketchy to me; wouldn't it be better
to make the dump flag into an enum, DUMP_EVERYTHING, DUMP_ACL,
DUMP_NONE?

Is this creating a user-visible API break, where pg_stat_activity and
pg_stat_replication now always show only the publicly-visible
information, and privileged users must explicitly decide to query the
_all versions? If so, -1 from me on that part of this.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>, Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2015-04-02 17:27:36
Message-ID: 20150402172736.GX3663@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Robert,

* Robert Haas (robertmhaas(at)gmail(dot)com) wrote:
> On Thu, Apr 2, 2015 at 12:53 AM, Stephen Frost <sfrost(at)snowman(dot)net> wrote:
> > Clearly, further testing and documentation is required and I'll be
> > getting to that over the next couple of days, but it's pretty darn late
> > and I'm currently getting libpq undefined reference errors, probably
> > because I need to set LD_LIBRARY_PATH, but I'm just too tired to now. :)
> >
> > Thoughts?
>
> The tricky part of this seems to me to be the pg_dump changes. The
> new catalog flag seems a little sketchy to me; wouldn't it be better
> to make the dump flag into an enum, DUMP_EVERYTHING, DUMP_ACL,
> DUMP_NONE?

I agree that the pg_dump changes are a very big part of this change.
I'll look at using an enum and see if that would work.

> Is this creating a user-visible API break, where pg_stat_activity and
> pg_stat_replication now always show only the publicly-visible
> information, and privileged users must explicitly decide to query the
> _all versions? If so, -1 from me on that part of this.

Thanks for bringing it up. No, the existing API is exactly the same for
the existing views- the only difference is that now there are _all
versions which provide unfiltered data (but you have to have permission
to call the _all() functions underneath, or you get a permission denied
error).

Where this does have an API change is with the simpler functions that
used to do "if (superuser() || replication_role())" and now depend on
the GRANT system instead. We can't (today, at least) say:

GRANT EXECUTE ON function_whatever() TO replication_roles;

And have that be kept current as that role attribute is modified. I've
not done it yet, but we could certainly have pg_dump dump out GRANTs for
the *current* users which have that role attribute and give those users
access to the functions via the normal permissions system. I'm not
really sure that's a good idea though- it might be better to have a
clean break here (and one which is clearly in the "more secure/explicit"
direction) and tell admins in the release notes to GRANT EXECUTE on the
functions for the roles they want to give permission to. We could also
duplicate the functions and have the existing ones remain as-is and have
the new ones just depend on the GRANT system, but I don't particularly
like that since I'm afraid we'd end up in the same boat we're in now
with pg_user and friends.

Thanks!

Stephen


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>, Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2015-04-14 04:24:17
Message-ID: 20150414042417.GX3663@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Robert,

* Stephen Frost (sfrost(at)snowman(dot)net) wrote:
> * Robert Haas (robertmhaas(at)gmail(dot)com) wrote:
> > On Thu, Apr 2, 2015 at 12:53 AM, Stephen Frost <sfrost(at)snowman(dot)net> wrote:
> > > Clearly, further testing and documentation is required and I'll be
> > > getting to that over the next couple of days, but it's pretty darn late
> > > and I'm currently getting libpq undefined reference errors, probably
> > > because I need to set LD_LIBRARY_PATH, but I'm just too tired to now. :)
> > >
> > > Thoughts?
> >
> > The tricky part of this seems to me to be the pg_dump changes. The
> > new catalog flag seems a little sketchy to me; wouldn't it be better
> > to make the dump flag into an enum, DUMP_EVERYTHING, DUMP_ACL,
> > DUMP_NONE?
>
> I agree that the pg_dump changes are a very big part of this change.
> I'll look at using an enum and see if that would work.

I've implemented this approach and there are things which I like about
it and things which I don't. I'd love to hear your thoughts. As
mentioned previously, this patch does not break the pg_stat_activity or
pg_stat_replication view APIs. Similairly, the functions which directly
feed those views return the same results they did previously, there are
just additional functions now which provide everything, and view on top
of those, for users who are GRANT'd access to them.

This does change the API of a few functions which previously allowed
roles with the "replication" attribute to call them. We could provide
additional functions to provide both paths but I don't believe it's
really necessary. Indeed, I feel it's better for administrators to
explicit grant access to those functions instead.

Note that this doesn't use an enum but a bit field for which components
of a given object should be dumped out. While I like that in general,
it meant a lot of changes and I'll be the first to admit that I've not
tested every possible pg_dump option permutation to make sure that the
correct results are returned. I plan to do that in the coming weeks and
will address any issues found.

Is this, more-or-less, what you were thinking of? I looked at removing
the relatively grotty options (dataOnly, aclsSkip, etc) and it didn't
appear trivial to use the bitmask instead. I can look into that further
though, as I do feel that it'd be good if we could reduce our dependence
on those options in favor of the bitmask approach.

Thoughts?

Thanks!

Stephen

Attachment Content-Type Size
catalog_function_acls_v3.patch text/x-diff 109.8 KB

From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>, Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2015-04-29 14:47:22
Message-ID: 20150429144722.GY30322@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Robert, all,

* Stephen Frost (sfrost(at)snowman(dot)net) wrote:
> * Stephen Frost (sfrost(at)snowman(dot)net) wrote:
> > * Robert Haas (robertmhaas(at)gmail(dot)com) wrote:
> > > The tricky part of this seems to me to be the pg_dump changes. The
> > > new catalog flag seems a little sketchy to me; wouldn't it be better
> > > to make the dump flag into an enum, DUMP_EVERYTHING, DUMP_ACL,
> > > DUMP_NONE?
> >
> > I agree that the pg_dump changes are a very big part of this change.
> > I'll look at using an enum and see if that would work.
>
> I've implemented this approach and there are things which I like about
> it and things which I don't. I'd love to hear your thoughts. As
> mentioned previously, this patch does not break the pg_stat_activity or
> pg_stat_replication view APIs. Similairly, the functions which directly
> feed those views return the same results they did previously, there are
> just additional functions now which provide everything, and view on top
> of those, for users who are GRANT'd access to them.

Here is the latest revision of this patch.

The big change here is the addition of default roles. This approach has
been brought up a few times and Magnus recently mentioned it to me
again. Having the default roles greatly reduced the impact of this
change on the test_deparse regression test, which was quite nice.

Updates are included for pg_upgrade and pg_dumpall to handle roles which
start with "pg_" specially as we are now claiming those as "System
defined" roles (similar to how we claim schemas starting with pg_ are
system defined, etc). These new default roles are in line with the
previously discussed role attributes, but have the advantage that they
act just like normal roles and work inside of the normal permissions
system. They are:

pg_backup - Start and stop backups, switch xlogs, create restore points.
pg_monitor - View privileged system info (user activity, replica lag)
pg_replay - Control XLOG replay on replica (pause, resume)
pg_replication - Create, destroy, work with replication slots

pg_admin - All of the above, plus rotate logfiles and signal backends

Feedback on all of this would be great. One interesting idea is that,
with these defined default roles, we could rip out the majority of the
changes to pg_dump and declare that users have to use only the roles we
provide to manage access to those functions (or risk any changes they
make to the ACLs of system objects disappearing across upgrades or
pg_dump/restore's, which is what happens today anyway). I'm a bit on
the fence about it myself; it'd certainly reduce the risk of this change
but it would also limit users to only being able to operate at the
pre-defined levels we've set, but then again, the same was going to be
true with the role attributes-based approach and I don't recall any
complaints during that discussion.

Thoughts? Feedback on this would be most welcome; it's been a long time
incubating and I'd really like to get this capability in and close it
out of the current commitfest. I'm certainly of the opinion that it
will be a welcome step forward for quite a few of our users as the
discussion about how to create non-superuser roles for certain
operations (a monitor role, in particular, but also backup and replay)
has come up quite a bit, both on the lists and directly from clients.

Thanks!

Stephen

Attachment Content-Type Size
catalog_function_acls_v4.patch text/x-diff 119.5 KB

From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>, Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2015-04-29 21:12:43
Message-ID: CA+TgmobH4tdccajn7VmPT-1RqBdzLYcAz5jUz4bJ=rkqs_gADA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Wed, Apr 29, 2015 at 10:47 AM, Stephen Frost <sfrost(at)snowman(dot)net> wrote:
> Here is the latest revision of this patch.

I think this patch is too big and does too many things. It should be
broken up into small patches which can be discussed and validated
independently. The fact that your commit message is incredibly long
is a sign that there's too much going on here, and that message
doesn't even cover all of it.

It seems to me that the core change here is really to pg_dump. You're
adding the ability for pg_dump to dump and restore privileges on
objects in pg_dump. That capability is a complete - and useful -
feature in its own right, with no other changes.

Then the next thing you've got here is a series of patches that change
the rights to execute various utility functions. Some of those, like
the changes to pg_stop_backup(), are pretty much a slam-dunk, because
they don't really change user-visible behavior; they just give the DBA
more options. Others, like the changes to replication permissions,
are likely to be more controversial. You should split the stuff
that's a slam-dunk apart from the stuff that makes policy decisions,
and plan to commit the former changes first, and the latter changes
only if and when there is very clear agreement on the specific
policies to be changed.

Finally, you've got the idea of making pg_ a reserved prefix for
roles, adding some predefined roles, and giving them some predefined
privileges. That should be yet another patch.

I think that if you commit this the way you have it today, everybody
will go, oh, look, Stephen committed something, but it looks
complicated, I won't pay attention. And then, six months from now
when we're in beta, or maybe after final, people will start looking at
this and realizing that there are parts of it they hate, but it will
be hard to fix at that point. Breaking it out will hopefully allow
more discussion on the individual features of in here, of which there
are probably at least four. It will also make it easier to revert
part of it rather than all of it if that turns out to be needed.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


From: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Stephen Frost <sfrost(at)snowman(dot)net>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>, Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2015-04-30 00:20:04
Message-ID: 20150430002004.GL4369@alvh.no-ip.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Robert Haas wrote:

> I think that if you commit this the way you have it today, everybody
> will go, oh, look, Stephen committed something, but it looks
> complicated, I won't pay attention.

Yeah, that sucks.

> Finally, you've got the idea of making pg_ a reserved prefix for
> roles, adding some predefined roles, and giving them some predefined
> privileges. That should be yet another patch.

On this part I have a bit of a problem -- the prefix is not really
reserved, is it. I mean, evidently it's still possible to create roles
with the pg_ prefix ... otherwise, how come the new lines to
system_views.sql that create the "predefined" roles work in the first
place? I think if we're going to reserve role names, we should reserve
them for real: CREATE ROLE should flat out reject creation of such
roles, and the default ones should be created during bootstrap.

IMO anyway.

--
Álvaro Herrera http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services


From: Gavin Flower <GavinFlower(at)archidevsys(dot)co(dot)nz>
To: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Stephen Frost <sfrost(at)snowman(dot)net>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>, Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2015-04-30 00:33:57
Message-ID: 55417875.6040103@archidevsys.co.nz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 30/04/15 12:20, Alvaro Herrera wrote:
> Robert Haas wrote:
>
>> I think that if you commit this the way you have it today, everybody
>> will go, oh, look, Stephen committed something, but it looks
>> complicated, I won't pay attention.
> Yeah, that sucks.
>
>> Finally, you've got the idea of making pg_ a reserved prefix for
>> roles, adding some predefined roles, and giving them some predefined
>> privileges. That should be yet another patch.
> On this part I have a bit of a problem -- the prefix is not really
> reserved, is it. I mean, evidently it's still possible to create roles
> with the pg_ prefix ... otherwise, how come the new lines to
> system_views.sql that create the "predefined" roles work in the first
> place? I think if we're going to reserve role names, we should reserve
> them for real: CREATE ROLE should flat out reject creation of such
> roles, and the default ones should be created during bootstrap.
>
> IMO anyway.
>
What if I had a company with several subsidiaries using the same
database, and want to prefix roles and other things with the
subsidiary's initials? (I am not saying this would be a good
architecture!!!)

For example if one subsidiary was called 'Perfect Gentleman', so I would
want roles prefixed by 'pg_' and would be annoyed if I couldn't!

Cheers,
Gavin


From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
Cc: Stephen Frost <sfrost(at)snowman(dot)net>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>, Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2015-04-30 00:48:33
Message-ID: CA+TgmoaSqq2tuCuVcfiQ_6nAroMC2NepXN=xP=86A_kSBvUVPQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Wed, Apr 29, 2015 at 8:20 PM, Alvaro Herrera
<alvherre(at)2ndquadrant(dot)com> wrote:
>> Finally, you've got the idea of making pg_ a reserved prefix for
>> roles, adding some predefined roles, and giving them some predefined
>> privileges. That should be yet another patch.
>
> On this part I have a bit of a problem -- the prefix is not really
> reserved, is it. I mean, evidently it's still possible to create roles
> with the pg_ prefix ... otherwise, how come the new lines to
> system_views.sql that create the "predefined" roles work in the first
> place? I think if we're going to reserve role names, we should reserve
> them for real: CREATE ROLE should flat out reject creation of such
> roles, and the default ones should be created during bootstrap.
>
> IMO anyway.

This is exactly what I mean about needing separate discussion for
separate parts of the patch. There's so much different stuff in there
right now that objections like this won't necessarily come out until
it's far too late to change things around.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Gavin Flower <GavinFlower(at)archidevsys(dot)co(dot)nz>
Cc: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>, Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2015-05-08 04:35:50
Message-ID: 20150508043550.GQ30322@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Gavin,

* Gavin Flower (GavinFlower(at)archidevsys(dot)co(dot)nz) wrote:
> What if I had a company with several subsidiaries using the same
> database, and want to prefix roles and other things with the
> subsidiary's initials? (I am not saying this would be a good
> architecture!!!)

If you admit that it's not a good solution then I'm not quite sure how
much we really want to worry about it. :)

> For example if one subsidiary was called 'Perfect Gentleman', so I
> would want roles prefixed by 'pg_' and would be annoyed if I
> couldn't!

You might try creating a schema for that user.. You'll hopefully find
it difficult to do. :)

In consideration of the fact that you can't create schemas which start
with "pg_" and therefore the default search_path wouldn't work for that
user, and that we also reserve "pg_" for tablespaces, I'm not inclined
to worry too much about this case. Further, if we accept this argument,
then we simply can't ever provide additional default or system roles,
ever. That'd be a pretty narrow corner to have painted ourselves into.

Thanks!

Stephen


From: Heikki Linnakangas <hlinnaka(at)iki(dot)fi>
To: Stephen Frost <sfrost(at)snowman(dot)net>, Gavin Flower <GavinFlower(at)archidevsys(dot)co(dot)nz>
Cc: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>, Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2015-07-10 21:06:01
Message-ID: 55A033B9.2030606@iki.fi
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 05/08/2015 07:35 AM, Stephen Frost wrote:
> Gavin,
>
> * Gavin Flower (GavinFlower(at)archidevsys(dot)co(dot)nz) wrote:
>> What if I had a company with several subsidiaries using the same
>> database, and want to prefix roles and other things with the
>> subsidiary's initials? (I am not saying this would be a good
>> architecture!!!)
>
> If you admit that it's not a good solution then I'm not quite sure how
> much we really want to worry about it. :)
>
>> For example if one subsidiary was called 'Perfect Gentleman', so I
>> would want roles prefixed by 'pg_' and would be annoyed if I
>> couldn't!
>
> You might try creating a schema for that user.. You'll hopefully find
> it difficult to do. :)
>
> In consideration of the fact that you can't create schemas which start
> with "pg_" and therefore the default search_path wouldn't work for that
> user, and that we also reserve "pg_" for tablespaces, I'm not inclined
> to worry too much about this case. Further, if we accept this argument,
> then we simply can't ever provide additional default or system roles,
> ever. That'd be a pretty narrow corner to have painted ourselves into.

Well, you could still provide them through some other mechanism, like
require typing "SYSTEM ROLE pg_backup" any time you mean that magic
role. But I agree, reserving pg_* is much better. I wish we had done it
when we invented roles (6.5?), so there would be no risk that you would
upgrade from a system that already has a "pg_foo" role. But I think it'd
still be OK.

I agree with Robert's earlier point that this needs to be split into
multiple patches, which can then be reviewed and discussed separately.
Pending that, I'm going to mark this as "Waiting on author" in the
commitfest.

- Heikki


From: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
To: Heikki Linnakangas <hlinnaka(at)iki(dot)fi>
Cc: Stephen Frost <sfrost(at)snowman(dot)net>, Gavin Flower <GavinFlower(at)archidevsys(dot)co(dot)nz>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>, Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2015-08-25 13:08:38
Message-ID: CAB7nPqTg7BAe2YAyfAPqNSFr7fXkvu-ovQ7g-aKEHxntuEVuZA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Sat, Jul 11, 2015 at 6:06 AM, Heikki Linnakangas wrote:
> On 05/08/2015 07:35 AM, Stephen Frost wrote:
>> In consideration of the fact that you can't create schemas which start
>> with "pg_" and therefore the default search_path wouldn't work for that
>> user, and that we also reserve "pg_" for tablespaces, I'm not inclined
>> to worry too much about this case. Further, if we accept this argument,
>> then we simply can't ever provide additional default or system roles,
>> ever. That'd be a pretty narrow corner to have painted ourselves into.
>
>
> Well, you could still provide them through some other mechanism, like
> require typing "SYSTEM ROLE pg_backup" any time you mean that magic role.
> But I agree, reserving pg_* is much better. I wish we had done it when we
> invented roles (6.5?), so there would be no risk that you would upgrade from
> a system that already has a "pg_foo" role. But I think it'd still be OK.
>
> I agree with Robert's earlier point that this needs to be split into
> multiple patches, which can then be reviewed and discussed separately.
> Pending that, I'm going to mark this as "Waiting on author" in the
> commitfest.

... And now marked as returned with feedback.
--
Michael


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Heikki Linnakangas <hlinnaka(at)iki(dot)fi>
Cc: Gavin Flower <GavinFlower(at)archidevsys(dot)co(dot)nz>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>, Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2015-09-30 11:11:20
Message-ID: 20150930111120.GM3685@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

* Heikki Linnakangas (hlinnaka(at)iki(dot)fi) wrote:
> I agree with Robert's earlier point that this needs to be split into
> multiple patches, which can then be reviewed and discussed
> separately. Pending that, I'm going to mark this as "Waiting on
> author" in the commitfest.

Attached is an initial split which divides up reserving the role names
from actually adding the initial set of default roles.

Thanks!

Stephen

Attachment Content-Type Size
default_roles_v6.patch text/x-diff 33.4 KB

From: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, Gavin Flower <GavinFlower(at)archidevsys(dot)co(dot)nz>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>, Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2015-11-18 13:06:38
Message-ID: CAB7nPqSRJKN_CXK+YYyy=CZG3bpXNetHtNQR_wMzpHj9aTYYeA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Wed, Sep 30, 2015 at 8:11 PM, Stephen Frost <sfrost(at)snowman(dot)net> wrote:
> * Heikki Linnakangas (hlinnaka(at)iki(dot)fi) wrote:
>> I agree with Robert's earlier point that this needs to be split into
>> multiple patches, which can then be reviewed and discussed
>> separately. Pending that, I'm going to mark this as "Waiting on
>> author" in the commitfest.
>
> Attached is an initial split which divides up reserving the role names
> from actually adding the initial set of default roles.

I have begun looking at this patch, and here are some comments after
screening it.

Patch needs a rebase, some catalog OIDs and there was a conflict in misc.c
(see attached for the rebase. none of the comments mentioning issues are
fixed by it).

=# grant pg_replay to pg_backup ;
GRANT ROLE
=# \du pg_backup
List of roles
Role name | Attributes | Member of
-----------+--------------+-------------
pg_backup | Cannot login | {pg_replay}
Perhaps we should restrict granting a default role to another default role?

+ <para>
+ Also note that changing the permissions on objects in the system
+ catalogs, while possible, is unlikely to have the desired effect as
+ the internal lookup functions use a cache and do not check the
+ permissions nor policies of tables in the system catalog. Further,
+ permission changes to objects in the system catalogs are not
+ preserved by pg_dump or across upgrades.
+ </para>
This bit could be perhaps applied as a separate patch.

+ <row>
+ <entry>pg_backup</entry>
+ <entry>Start and stop backups, switch xlogs, and create restore
points.</entry>
+ </row>
s/switch xlogs/switch to a new transaction log file/
It seems weird to not have a dedicated role for pg_switch_xlog.

In func.sgml, the descriptions of pg_switch_xlog, pg_xlog_replay_pause and
pg_xlog_replay_resume still mention that those functions are restricted
only to superusers. The documentation needs an update. It would be good to
double-check if there are similar mistakes for the other functions.

+ <entry>pg_montior</entry>
Typo, pg_monitor.

+ <entry>Pause and resume xlog replay on replicas.</entry>
Those descriptions should be complete sentences or not? Both styles are
mixed in user-manag.sgml.

+ <row>
+ <entry>pg_replication</entry>
+ <entry>Create, destroy, and work with replication slots.</entry>
+ </row>
pg_replication_slots would be more adapted?

+ <row>
+ <entry>pg_file_settings</entry>
+ <entry>Allowed to view config settings from all config files</entry>
+ </row>
I would say "configuration files" instead. An abbreviation is not adapted.

+ <entry>pg_admin</entry>
+ <entry>
+ Granted pg_backup, pg_monitor, pg_reply, pg_replication,
+ pg_rotate_logfile, pg_signal_backend and pg_file_settings roles.
+ </entry>
Typo, s/pg_reply/pg_replay and I think that there should be <literal>
markups around those role names. I am actually not convinced that we
actually need it.

+ if (IsReservedName(stmt->role))
+ ereport(ERROR,
+ (errcode(ERRCODE_RESERVED_NAME),
+ errmsg("role name \"%s\" is reserved",
+ stmt->role),
+ errdetail("Role names starting with
\"pg_\" are reserved.")));
Perhaps this could be a separate change? It seems that restricting roles
with pg_ on the cluster is not a bad restriction in any case. You may want
to add regression tests to trigger those errors as well.

Shouldn't pg_current_xlog_location, pg_current_xlog_insert_location,
pg_last_xlog_receive_location and pg_last_xlog_replay_location fall under a
restriction category like pg_monitor? I recall of course that we discussed
that some months ago and that a lot of people were reluctant to harden this
area to not break any existing monitoring tool, still this patch may be the
occasion to restrict a bit those functions, particularly on servers where
wal_compression is enabled.

It would be nice to have regression tests as well to check that role
restrictions are applied where they should.
Regards,
--
Michael

Attachment Content-Type Size
20151118_default_roles.patch text/x-diff 31.7 KB

From: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, Gavin Flower <GavinFlower(at)archidevsys(dot)co(dot)nz>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>, Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2015-11-18 13:09:49
Message-ID: CAB7nPqQfHiqrMXcKxmhAcPeW3eXqVWp9jBVXw3_J7QsZks-irg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Wed, Nov 18, 2015 at 10:06 PM, Michael Paquier <michael(dot)paquier(at)gmail(dot)com
> wrote:

>
>
> On Wed, Sep 30, 2015 at 8:11 PM, Stephen Frost <sfrost(at)snowman(dot)net> wrote:
> > * Heikki Linnakangas (hlinnaka(at)iki(dot)fi) wrote:
> >> I agree with Robert's earlier point that this needs to be split into
> >> multiple patches, which can then be reviewed and discussed
> >> separately. Pending that, I'm going to mark this as "Waiting on
> >> author" in the commitfest.
> >
> > Attached is an initial split which divides up reserving the role names
> > from actually adding the initial set of default roles.
>
> I have begun looking at this patch, and here are some comments after
> screening it.
>
> Patch needs a rebase, some catalog OIDs and there was a conflict in misc.c
> (see attached for the rebase. none of the comments mentioning issues are
> fixed by it).
>
> =# grant pg_replay to pg_backup ;
> GRANT ROLE
> =# \du pg_backup
> List of roles
> Role name | Attributes | Member of
> -----------+--------------+-------------
> pg_backup | Cannot login | {pg_replay}
> Perhaps we should restrict granting a default role to another default role?
>
> + <para>
> + Also note that changing the permissions on objects in the system
> + catalogs, while possible, is unlikely to have the desired effect as
> + the internal lookup functions use a cache and do not check the
> + permissions nor policies of tables in the system catalog. Further,
> + permission changes to objects in the system catalogs are not
> + preserved by pg_dump or across upgrades.
> + </para>
> This bit could be perhaps applied as a separate patch.
>
> + <row>
> + <entry>pg_backup</entry>
> + <entry>Start and stop backups, switch xlogs, and create restore
> points.</entry>
> + </row>
> s/switch xlogs/switch to a new transaction log file/
> It seems weird to not have a dedicated role for pg_switch_xlog.
>
> In func.sgml, the descriptions of pg_switch_xlog, pg_xlog_replay_pause and
> pg_xlog_replay_resume still mention that those functions are restricted
> only to superusers. The documentation needs an update. It would be good to
> double-check if there are similar mistakes for the other functions.
>
> + <entry>pg_montior</entry>
> Typo, pg_monitor.
>
> + <entry>Pause and resume xlog replay on replicas.</entry>
> Those descriptions should be complete sentences or not? Both styles are
> mixed in user-manag.sgml.
>
> + <row>
> + <entry>pg_replication</entry>
> + <entry>Create, destroy, and work with replication slots.</entry>
> + </row>
> pg_replication_slots would be more adapted?
>
> + <row>
> + <entry>pg_file_settings</entry>
> + <entry>Allowed to view config settings from all config
> files</entry>
> + </row>
> I would say "configuration files" instead. An abbreviation is not adapted.
>
> + <entry>pg_admin</entry>
> + <entry>
> + Granted pg_backup, pg_monitor, pg_reply, pg_replication,
> + pg_rotate_logfile, pg_signal_backend and pg_file_settings roles.
> + </entry>
> Typo, s/pg_reply/pg_replay and I think that there should be <literal>
> markups around those role names. I am actually not convinced that we
> actually need it.
>
> + if (IsReservedName(stmt->role))
> + ereport(ERROR,
> + (errcode(ERRCODE_RESERVED_NAME),
> + errmsg("role name \"%s\" is reserved",
> + stmt->role),
> + errdetail("Role names starting with
> \"pg_\" are reserved.")));
> Perhaps this could be a separate change? It seems that restricting roles
> with pg_ on the cluster is not a bad restriction in any case. You may want
> to add regression tests to trigger those errors as well.
>
> Shouldn't pg_current_xlog_location, pg_current_xlog_insert_location,
> pg_last_xlog_receive_location and pg_last_xlog_replay_location fall under a
> restriction category like pg_monitor? I recall of course that we discussed
> that some months ago and that a lot of people were reluctant to harden this
> area to not break any existing monitoring tool, still this patch may be the
> occasion to restrict a bit those functions, particularly on servers where
> wal_compression is enabled.
>
> It would be nice to have regression tests as well to check that role
> restrictions are applied where they should.
>

Bonus:
-static void
-check_permissions(void)
-{
- if (!superuser() && !has_rolreplication(GetUserId()))
- ereport(ERROR,
- (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
- (errmsg("must be superuser or replication
role to use replication slots"))));
-}
I would have let check_permissions and directly done the checks on
has_rolreplication and has_privs_of_role in it, the same code being
duplicated three times.
--
Michael


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
Cc: Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, Gavin Flower <GavinFlower(at)archidevsys(dot)co(dot)nz>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>, Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2015-11-18 22:10:30
Message-ID: 20151118221030.GC3685@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Michael,

Thanks for the review!

* Michael Paquier (michael(dot)paquier(at)gmail(dot)com) wrote:
> Patch needs a rebase, some catalog OIDs and there was a conflict in misc.c
> (see attached for the rebase. none of the comments mentioning issues are
> fixed by it).

Done (did it a bit differently from what you had, to hopefully avoid
future OID conflicts and also to allow us a bit of room to add
additional default roles later, if we choose, in nearby OID space).

> =# grant pg_replay to pg_backup ;
> GRANT ROLE
> =# \du pg_backup
> List of roles
> Role name | Attributes | Member of
> -----------+--------------+-------------
> pg_backup | Cannot login | {pg_replay}
> Perhaps we should restrict granting a default role to another default role?

Done (in the second patch in the series, the one reserving 'pg_').

> + <para>
> + Also note that changing the permissions on objects in the system
> + catalogs, while possible, is unlikely to have the desired effect as
> + the internal lookup functions use a cache and do not check the
> + permissions nor policies of tables in the system catalog. Further,
> + permission changes to objects in the system catalogs are not
> + preserved by pg_dump or across upgrades.
> + </para>
> This bit could be perhaps applied as a separate patch.

Done as a separate patch (first one in the series).

> + <row>
> + <entry>pg_backup</entry>
> + <entry>Start and stop backups, switch xlogs, and create restore
> points.</entry>
> + </row>
> s/switch xlogs/switch to a new transaction log file/

Fixed.

> It seems weird to not have a dedicated role for pg_switch_xlog.

I didn't add a pg_switch_xlog default role in this patch series, but
would be happy to do so if that's the consensus. It's quite easy to do.

> In func.sgml, the descriptions of pg_switch_xlog, pg_xlog_replay_pause and
> pg_xlog_replay_resume still mention that those functions are restricted
> only to superusers. The documentation needs an update. It would be good to
> double-check if there are similar mistakes for the other functions.

Fixed. Also did a review and found a number of other places which
required updating, so those have also been fixed.

> + <entry>pg_montior</entry>
> Typo, pg_monitor.

Fixed.

> + <entry>Pause and resume xlog replay on replicas.</entry>
> Those descriptions should be complete sentences or not? Both styles are
> mixed in user-manag.sgml.

I didn't take any action on this.

> + <row>
> + <entry>pg_replication</entry>
> + <entry>Create, destroy, and work with replication slots.</entry>
> + </row>
> pg_replication_slots would be more adapted?

Perhaps... I didn't make this change, but if others agree that adding
"_slots" would help, I'd be happy to do so. Personally, I'd like to
keep these names shorter, if possible, but I don't want it to be
confusing either.

> + <row>
> + <entry>pg_file_settings</entry>
> + <entry>Allowed to view config settings from all config files</entry>
> + </row>
> I would say "configuration files" instead. An abbreviation is not adapted.

Done.

> + <entry>pg_admin</entry>
> + <entry>
> + Granted pg_backup, pg_monitor, pg_reply, pg_replication,
> + pg_rotate_logfile, pg_signal_backend and pg_file_settings roles.
> + </entry>
> Typo, s/pg_reply/pg_replay and I think that there should be <literal>
> markups around those role names. I am actually not convinced that we
> actually need it.

I added <literal> markups around the role names, where used.

I'm guessing you were referring to pg_admin with your comment that you
were "not convinced that we actually need it." After thinking about
it for a bit, I tend to agree. A user could certainly create their own
role which combines these all together if they wanted to (or do any
other combinations, based on their particular needs). I've gone ahead
and removed pg_admin from the set of default roles.

> + if (IsReservedName(stmt->role))
> + ereport(ERROR,
> + (errcode(ERRCODE_RESERVED_NAME),
> + errmsg("role name \"%s\" is reserved",
> + stmt->role),
> + errdetail("Role names starting with
> \"pg_\" are reserved.")));
> Perhaps this could be a separate change? It seems that restricting roles
> with pg_ on the cluster is not a bad restriction in any case. You may want
> to add regression tests to trigger those errors as well.

I'm a bit confused- this is a separate change. Note that the previous
patch was actually a git patchset which had two patches- one to do the
reservation and a second to add the default roles. The attached
patchset is actually three patches:

1- Update to catalog documentation regarding permissions
2- Reserve 'pg_' role namespace
3- Add default roles

> Shouldn't pg_current_xlog_location, pg_current_xlog_insert_location,
> pg_last_xlog_receive_location and pg_last_xlog_replay_location fall under a
> restriction category like pg_monitor? I recall of course that we discussed
> that some months ago and that a lot of people were reluctant to harden this
> area to not break any existing monitoring tool, still this patch may be the
> occasion to restrict a bit those functions, particularly on servers where
> wal_compression is enabled.

For my 2c, I believe they should. I've not modified them in that way in
this patchset, but I can certainly do so if others agree.

> It would be nice to have regression tests as well to check that role
> restrictions are applied where they should.

I've added regression tests for the default roles where it was
relatively straight-forward to do so. I don't see a trivial way to test
that the pg_signal_backend role works though, as an example.

> Bonus:
> -static void
> -check_permissions(void)
> -{
> - if (!superuser() && !has_rolreplication(GetUserId()))
> - ereport(ERROR,
> - (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
> - (errmsg("must be superuser or replication
> role to use replication slots"))));
> -}
> I would have let check_permissions and directly done the checks on
> has_rolreplication and has_privs_of_role in it, the same code being
> duplicated three times.

For my 2c, I dislike the notion of "check_permissions()" functions being
added throughout the codebase as I'm afraid it'd get confusing, which is
why I got rid of it. I'm much happier seeing the actual permissions
check as it should be happening early on in the primary function which
is being called into. If there is really a push to go back to having a
'check_permissions()' like function, I'd argue that we should make the
function name more descriptive of what's actually being done and have
them be distinct from each other. As I recall, I discussed this change
with Andres and he didn't feel particularly strongly about this one way
or the other, therefore, I've not made this change for this patchset.

Thanks!

Stephen

Attachment Content-Type Size
default_roles_v7.patch text/x-diff 52.4 KB

From: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, Gavin Flower <GavinFlower(at)archidevsys(dot)co(dot)nz>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>, Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2015-11-19 07:13:24
Message-ID: CAB7nPqQ9ardcbwGezkVsoxsj3XC4mGX_7VPQPjQMA+rURXBsEw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Thu, Nov 19, 2015 at 7:10 AM, Stephen Frost wrote:
> * Michael Paquier (michael(dot)paquier(at)gmail(dot)com) wrote:
>> It seems weird to not have a dedicated role for pg_switch_xlog.
>
> I didn't add a pg_switch_xlog default role in this patch series, but
> would be happy to do so if that's the consensus. It's quite easy to do.

Agreed. I am not actually getting why that's part of the backup
actually. That would be more related to archiving, both being
unrelated concepts. But at this point I guess that's mainly a
philosophical split.

> I'm guessing you were referring to pg_admin with your comment that you
> were "not convinced that we actually need it." After thinking about
> it for a bit, I tend to agree. A user could certainly create their own
> role which combines these all together if they wanted to (or do any
> other combinations, based on their particular needs). I've gone ahead
> and removed pg_admin from the set of default roles.

Yeah that 's what I meant. Thanks, I should have been more precise
with my words.

>> + if (IsReservedName(stmt->role))
>> + ereport(ERROR,
>> + (errcode(ERRCODE_RESERVED_NAME),
>> + errmsg("role name \"%s\" is reserved",
>> + stmt->role),
>> + errdetail("Role names starting with
>> \"pg_\" are reserved.")));
>> Perhaps this could be a separate change? It seems that restricting roles
>> with pg_ on the cluster is not a bad restriction in any case. You may want
>> to add regression tests to trigger those errors as well.
>
> I'm a bit confused- this is a separate change. Note that the previous
> patch was actually a git patchset which had two patches- one to do the
> reservation and a second to add the default roles. The attached
> patchset is actually three patches:
> 1- Update to catalog documentation regarding permissions
> 2- Reserve 'pg_' role namespace
> 3- Add default roles

I see, that's why I got confused. I just downloaded your file and
applied it blindly with git apply or patch (don't recall which). Other
folks tend to publish that as a separate set of files generated by
git-format-patch.

>> Shouldn't pg_current_xlog_location, pg_current_xlog_insert_location,
>> pg_last_xlog_receive_location and pg_last_xlog_replay_location fall under a
>> restriction category like pg_monitor? I recall of course that we discussed
>> that some months ago and that a lot of people were reluctant to harden this
>> area to not break any existing monitoring tool, still this patch may be the
>> occasion to restrict a bit those functions, particularly on servers where
>> wal_compression is enabled.
>
> For my 2c, I believe they should. I've not modified them in that way in
> this patchset, but I can certainly do so if others agree.

My vote goes into hardening them a bit this way.

> I've added regression tests for the default roles where it was
> relatively straight-forward to do so. I don't see a trivial way to test
> that the pg_signal_backend role works though, as an example.

It is at least possible to check that the error code paths are
working. For the code paths where a backend would be actually running,
you could use the following:
SET client_min_messages TO 'error';
-- This should return "1" and not an ERROR nor a WARNING if PID does not exist.
select count(pg_terminate_backend(0));
But that's ugly depending on your taste.

>> Bonus:
>> -static void
>> -check_permissions(void)
>> -{
>> - if (!superuser() && !has_rolreplication(GetUserId()))
>> - ereport(ERROR,
>> - (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
>> - (errmsg("must be superuser or replication
>> role to use replication slots"))));
>> -}
>> I would have let check_permissions and directly done the checks on
>> has_rolreplication and has_privs_of_role in it, the same code being
>> duplicated three times.
>
> For my 2c, I dislike the notion of "check_permissions()" functions being
> added throughout the codebase as I'm afraid it'd get confusing, which is
> why I got rid of it. I'm much happier seeing the actual permissions
> check as it should be happening early on in the primary function which
> is being called into. If there is really a push to go back to having a
> 'check_permissions()' like function, I'd argue that we should make the
> function name more descriptive of what's actually being done and have
> them be distinct from each other. As I recall, I discussed this change
> with Andres and he didn't feel particularly strongly about this one way
> or the other, therefore, I've not made this change for this patchset.

Fine for me. Usually people point out such code duplications are bad
things, and here we just have a static routine being used for a set of
functions interacting with the same kind of object, here a replication
slot. But I'm fine either way.

Do you think that it makes sense to add tests as well in the second
patch to check that restrictions pg_* are in place? Except that I
don't have much more to say about patches 1 and 2 which are rather
straight-forward.

Regarding patch 3, the documentation of psql should mention the new
subommands \dgS and \dgS+. That's a one-liner.

+GRANT pg_backup TO regressuser1;
+SET SESSION AUTHORIZATION regressuser1;
+SELECT pg_start_backup('abc'); -- fail
+ERROR: WAL level not sufficient for making an online backup
+HINT: wal_level must be set to "archive", "hot_standby", or
"logical" at server start.
make install would wal on a server with something else than wal_level
= minimal. Just checking that errors kick correctly looks fine to me
here.

+GRANT pg_backup TO pg_monitor; -- error
+ERROR: role "pg_monitor" is reserved
+DETAIL: Roles starting with "pg_" are reserved.
+GRANT testrol0 TO pg_backup; -- error
+ERROR: role "pg_backup" is reserved
We would gain with verbose error messages here, like, "cannot GRANT
somerole to a system role", and "cannot GRANT system role to
somerole".
--
Michael


From: David Steele <david(at)pgmasters(dot)net>
To: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, Stephen Frost <sfrost(at)snowman(dot)net>
Cc: Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, Gavin Flower <GavinFlower(at)archidevsys(dot)co(dot)nz>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>, Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2015-11-19 13:23:17
Message-ID: 564DCD45.1010401@pgmasters.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 11/19/15 2:13 AM, Michael Paquier wrote:
> On Thu, Nov 19, 2015 at 7:10 AM, Stephen Frost wrote:
>> * Michael Paquier (michael(dot)paquier(at)gmail(dot)com) wrote:
>>> It seems weird to not have a dedicated role for pg_switch_xlog.
>>
>> I didn't add a pg_switch_xlog default role in this patch series, but
>> would be happy to do so if that's the consensus. It's quite easy to do.
>
> Agreed. I am not actually getting why that's part of the backup
> actually. That would be more related to archiving, both being
> unrelated concepts. But at this point I guess that's mainly a
> philosophical split.

I wouldn't say that backup and archiving are unrelated since backups
aren't valid without the proper set of WAL segments.

When configuring archiving/backup I use pg_switch_xlog() to verify that
WAL segments are getting to the archive.

I also use pg_switch_xlog() after pg_create_restore_point() to force the
WAL segment containing the restore point record to the archive.
Otherwise it might not be possible (or at least not easy) to recover to
the restore point in case of a problem. The required WAL segment is
likely to get pushed to the archive before it is needed but I would
rather not bet on that.

--
-David
david(at)pgmasters(dot)net


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, David Steele <david(at)pgmasters(dot)net>
Cc: Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, Gavin Flower <GavinFlower(at)archidevsys(dot)co(dot)nz>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>, Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2015-11-20 17:29:54
Message-ID: 20151120172954.GD3685@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

* Michael Paquier (michael(dot)paquier(at)gmail(dot)com) wrote:
> On Thu, Nov 19, 2015 at 7:10 AM, Stephen Frost wrote:
> > * Michael Paquier (michael(dot)paquier(at)gmail(dot)com) wrote:
> >> It seems weird to not have a dedicated role for pg_switch_xlog.
> >
> > I didn't add a pg_switch_xlog default role in this patch series, but
> > would be happy to do so if that's the consensus. It's quite easy to do.
>
> Agreed. I am not actually getting why that's part of the backup
> actually. That would be more related to archiving, both being
> unrelated concepts. But at this point I guess that's mainly a
> philosophical split.

As David notes, they're actually quite related. Note that in our
documentation pg_switch_xlog() is listed in the "Backup Control
Functions" table.

I can think of a use-case for a user who can call pg_switch_xlog, but
not pg_start_backup()/pg_stop_backup(), but I have to admit that it
seems rather limited and I'm on the fence about it being a worthwhile
distinction.

Even so, in the interest of having more fine-grained permission
controls, I've gone ahead and added a pg_switch_xlog default role.
Note that this means that pg_switch_xlog() can be called by both
pg_switch_xlog roles and pg_backup roles. I'd be very much against
removing the ability to call pg_switch_xlog from the pg_backup role as
that really is a capability which is needed by users running backups and
it'd just add unnecessary complexity to require users setting up backup
tools to grant two different roles to get the backup to work.

> > I'm a bit confused- this is a separate change. Note that the previous
> > patch was actually a git patchset which had two patches- one to do the
> > reservation and a second to add the default roles. The attached
> > patchset is actually three patches:
> > 1- Update to catalog documentation regarding permissions
> > 2- Reserve 'pg_' role namespace
> > 3- Add default roles
>
> I see, that's why I got confused. I just downloaded your file and
> applied it blindly with git apply or patch (don't recall which). Other
> folks tend to publish that as a separate set of files generated by
> git-format-patch.

The file was generated using 'git format-patch', but sent to one file
instead of multiple. 'git am' understands that format and will add the
independent commits to the current branch. Note that the git
documentation (see 'man git-format-patch' and 'man git-apply', at least
on Debian-based systems) specifically recommends using 'git am' to
create commits from patches generated by 'git format-patch'.

The workflow you're describing would require saving off each patch,
doing a 'patch' or 'git apply' run for each, then committing the changes
with your own commit message and only then would you have the entire
series. That doesn't seem like a better approach.

> >> Shouldn't pg_current_xlog_location, pg_current_xlog_insert_location,
> >> pg_last_xlog_receive_location and pg_last_xlog_replay_location fall under a
> >> restriction category like pg_monitor? I recall of course that we discussed
> >> that some months ago and that a lot of people were reluctant to harden this
> >> area to not break any existing monitoring tool, still this patch may be the
> >> occasion to restrict a bit those functions, particularly on servers where
> >> wal_compression is enabled.
> >
> > For my 2c, I believe they should. I've not modified them in that way in
> > this patchset, but I can certainly do so if others agree.
>
> My vote goes into hardening them a bit this way.

I've made those changes in this patch set. Note that these functions
can now only be called by roles which are members of pg_monitor,
pg_backup, or pg_switch_xlog (or superuser, of course).

> > I've added regression tests for the default roles where it was
> > relatively straight-forward to do so. I don't see a trivial way to test
> > that the pg_signal_backend role works though, as an example.
>
> It is at least possible to check that the error code paths are
> working.

Perhaps, but...

> For the code paths where a backend would be actually running,
> you could use the following:
> SET client_min_messages TO 'error';
> -- This should return "1" and not an ERROR nor a WARNING if PID does not exist.
> select count(pg_terminate_backend(0));
> But that's ugly depending on your taste.

I really dislike that.

> Do you think that it makes sense to add tests as well in the second
> patch to check that restrictions pg_* are in place? Except that I
> don't have much more to say about patches 1 and 2 which are rather
> straight-forward.

Ah, yes. I've now moved those hunks to the second patch where they
really should have been.

> Regarding patch 3, the documentation of psql should mention the new
> subommands \dgS and \dgS+. That's a one-liner.

Ah, right. I've updated the psql SGML documentation for \duS and \dgS.
The '\h' output had already been updated. Was there something else
which you meant above that I've missed? Note that these fixes went into
the second patch.

> +GRANT pg_backup TO regressuser1;
> +SET SESSION AUTHORIZATION regressuser1;
> +SELECT pg_start_backup('abc'); -- fail
> +ERROR: WAL level not sufficient for making an online backup
> +HINT: wal_level must be set to "archive", "hot_standby", or
> "logical" at server start.
> make install would wal on a server with something else than wal_level
> = minimal. Just checking that errors kick correctly looks fine to me
> here.

I've removed those checks as they could get annoying on the buildfarm or
for people doing make installcheck, as you say, but I'm not really
thrilled that we're only testing the failure paths.

> +GRANT pg_backup TO pg_monitor; -- error
> +ERROR: role "pg_monitor" is reserved
> +DETAIL: Roles starting with "pg_" are reserved.
> +GRANT testrol0 TO pg_backup; -- error
> +ERROR: role "pg_backup" is reserved
> We would gain with verbose error messages here, like, "cannot GRANT
> somerole to a system role", and "cannot GRANT system role to
> somerole".

Alright, I've changed these to have better detail messages.

Updated patchset attached.

Thanks!

Stephen

Attachment Content-Type Size
default_roles_v8.patch text/x-diff 59.8 KB

From: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: David Steele <david(at)pgmasters(dot)net>, Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, Gavin Flower <GavinFlower(at)archidevsys(dot)co(dot)nz>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>, Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2015-11-21 14:44:39
Message-ID: CAB7nPqQtPb+qq8rNJ3BRuUh+dziOqm29RUc8dr1z0cy1tR9q2g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Sat, Nov 21, 2015 at 2:29 AM, Stephen Frost <sfrost(at)snowman(dot)net> wrote:
> * Michael Paquier (michael(dot)paquier(at)gmail(dot)com) wrote:
> Even so, in the interest of having more fine-grained permission
> controls, I've gone ahead and added a pg_switch_xlog default role.
> Note that this means that pg_switch_xlog() can be called by both
> pg_switch_xlog roles and pg_backup roles. I'd be very much against
> removing the ability to call pg_switch_xlog from the pg_backup role as
> that really is a capability which is needed by users running backups and
> it'd just add unnecessary complexity to require users setting up backup
> tools to grant two different roles to get the backup to work.

There is going to be many opinions regarding the granularity of this
control, each one of us having a different opinion at the end. I don't
think this should be a stopper for this patch, hence I am fine with the
judgement you think is good. We could still more finely tune those default
roles later in the dev cycle of 9.6 (10.0?).

>> For the code paths where a backend would be actually running,
>> you could use the following:
>> SET client_min_messages TO 'error';
>> -- This should return "1" and not an ERROR nor a WARNING if PID does not
exist.
>> select count(pg_terminate_backend(0));
>> But that's ugly depending on your taste.
>
> I really dislike that.
>
>> Do you think that it makes sense to add tests as well in the second
>> patch to check that restrictions pg_* are in place? Except that I
>> don't have much more to say about patches 1 and 2 which are rather
>> straight-forward.
>
> Ah, yes. I've now moved those hunks to the second patch where they
> really should have been.
>
>> Regarding patch 3, the documentation of psql should mention the new
>> subommands \dgS and \dgS+. That's a one-liner.
>
> Ah, right. I've updated the psql SGML documentation for \duS and \dgS.
> The '\h' output had already been updated. Was there something else
> which you meant above that I've missed? Note that these fixes went into
> the second patch.

Thanks, this looks good to me.

>> +GRANT pg_backup TO regressuser1;
>> +SET SESSION AUTHORIZATION regressuser1;
>> +SELECT pg_start_backup('abc'); -- fail
>> +ERROR: WAL level not sufficient for making an online backup
>> +HINT: wal_level must be set to "archive", "hot_standby", or
>> "logical" at server start.
>> make install would wal on a server with something else than wal_level
>> = minimal. Just checking that errors kick correctly looks fine to me
>> here.
>
> I've removed those checks as they could get annoying on the buildfarm or
> for people doing make installcheck, as you say, but I'm not really
> thrilled that we're only testing the failure paths.

I guess that's better than nothing.

>> +GRANT pg_backup TO pg_monitor; -- error
>> +ERROR: role "pg_monitor" is reserved
>> +DETAIL: Roles starting with "pg_" are reserved.
>> +GRANT testrol0 TO pg_backup; -- error
>> +ERROR: role "pg_backup" is reserved
>> We would gain with verbose error messages here, like, "cannot GRANT
>> somerole to a system role", and "cannot GRANT system role to
>> somerole".
>
> Alright, I've changed these to have better detail messages.

@@ -183,6 +190,13 @@ pg_current_xlog_location(PG_FUNCTION_ARGS)
{
XLogRecPtr current_recptr;

+ if (!has_privs_of_role(GetUserId(), DEFAULT_ROLE_BACKUPID) &&
+ !has_privs_of_role(GetUserId(), DEFAULT_ROLE_MONITORID) &&
+ !has_privs_of_role(GetUserId(), DEFAULT_ROLE_SWITCH_XLOGID))
+ ereport(ERROR,
+ (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
+ errmsg("must be superuser or member of
pg_monitor, pg_backup, or pg_switch_xlog to switch transaction log
files")));

I don't think you mean to refer to the switch of segments files here. Same
comment for pg_current_xlog_insert_location, pg_last_xlog_receive_location
and pg_last_xlog_replay_location.

+ ereport(ERROR,
+ (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
+ errmsg("must be superuser or member of
pg_file_settings to see all config file settings")));
Should avoid abbreviations => "all configuration file settings".

<varlistentry>
- <term><literal>\dg[+] [ <link
linkend="APP-PSQL-patterns"><replaceable
class="parameter">pattern</replaceable></link> ]</literal></term>
+ <term><literal>\dgS[+] [ <link
linkend="APP-PSQL-patterns"><replaceable
class="parameter">pattern</replaceable></link> ]</literal></term>
<listitem>
I'm picky here, but that should be "\dg[S+]". Same for \du[S+].

The rest looks fine.
Regards,
--
Michael


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
Cc: David Steele <david(at)pgmasters(dot)net>, Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, Gavin Flower <GavinFlower(at)archidevsys(dot)co(dot)nz>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>, Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2015-11-24 20:26:34
Message-ID: 20151124202634.GT3685@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Michael,

* Michael Paquier (michael(dot)paquier(at)gmail(dot)com) wrote:
> On Sat, Nov 21, 2015 at 2:29 AM, Stephen Frost <sfrost(at)snowman(dot)net> wrote:
> > * Michael Paquier (michael(dot)paquier(at)gmail(dot)com) wrote:
> > Even so, in the interest of having more fine-grained permission
> > controls, I've gone ahead and added a pg_switch_xlog default role.
> > Note that this means that pg_switch_xlog() can be called by both
> > pg_switch_xlog roles and pg_backup roles. I'd be very much against
> > removing the ability to call pg_switch_xlog from the pg_backup role as
> > that really is a capability which is needed by users running backups and
> > it'd just add unnecessary complexity to require users setting up backup
> > tools to grant two different roles to get the backup to work.
>
> There is going to be many opinions regarding the granularity of this
> control, each one of us having a different opinion at the end. I don't
> think this should be a stopper for this patch, hence I am fine with the
> judgement you think is good. We could still more finely tune those default
> roles later in the dev cycle of 9.6 (10.0?).

Agreed.

> Thanks, this looks good to me.

Great.

> I guess that's better than nothing.

Agreed.

> I don't think you mean to refer to the switch of segments files here. Same
> comment for pg_current_xlog_insert_location, pg_last_xlog_receive_location
> and pg_last_xlog_replay_location.

Urgh. Got a bit ahead of myself there, apologies. I've updated all of
these and a number of other minor typos and incorrect comments along the
way.

> + ereport(ERROR,
> + (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
> + errmsg("must be superuser or member of
> pg_file_settings to see all config file settings")));
> Should avoid abbreviations => "all configuration file settings".

Fixed.

> <varlistentry>
> - <term><literal>\dg[+] [ <link
> linkend="APP-PSQL-patterns"><replaceable
> class="parameter">pattern</replaceable></link> ]</literal></term>
> + <term><literal>\dgS[+] [ <link
> linkend="APP-PSQL-patterns"><replaceable
> class="parameter">pattern</replaceable></link> ]</literal></term>
> <listitem>
> I'm picky here, but that should be "\dg[S+]". Same for \du[S+].

Fixed

Updated patch attached.

Thanks!

Stephen

Attachment Content-Type Size
default_roles_v9.patch text/x-diff 60.1 KB

From: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, David Steele <david(at)pgmasters(dot)net>, Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, Gavin Flower <GavinFlower(at)archidevsys(dot)co(dot)nz>, Robert Haas <robertmhaas(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>, Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2015-11-24 20:53:19
Message-ID: 20151124205319.GH4073@alvherre.pgsql
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Stephen Frost wrote:

> Even so, in the interest of having more fine-grained permission
> controls, I've gone ahead and added a pg_switch_xlog default role.
> Note that this means that pg_switch_xlog() can be called by both
> pg_switch_xlog roles and pg_backup roles. I'd be very much against
> removing the ability to call pg_switch_xlog from the pg_backup role as
> that really is a capability which is needed by users running backups and
> it'd just add unnecessary complexity to require users setting up backup
> tools to grant two different roles to get the backup to work.

Isn't it simpler to grant pg_switch_xlog to pg_backup in the default
config?

--
Álvaro Herrera http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
Cc: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, David Steele <david(at)pgmasters(dot)net>, Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, Gavin Flower <GavinFlower(at)archidevsys(dot)co(dot)nz>, Robert Haas <robertmhaas(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>, Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2015-11-24 20:56:55
Message-ID: CAOuzzgqjw186Nj2DFKeOj1HABaXwtsWXOpe-GB1s5fexVCoo3Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Tuesday, November 24, 2015, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
wrote:

> Stephen Frost wrote:
>
> > Even so, in the interest of having more fine-grained permission
> > controls, I've gone ahead and added a pg_switch_xlog default role.
> > Note that this means that pg_switch_xlog() can be called by both
> > pg_switch_xlog roles and pg_backup roles. I'd be very much against
> > removing the ability to call pg_switch_xlog from the pg_backup role as
> > that really is a capability which is needed by users running backups and
> > it'd just add unnecessary complexity to require users setting up backup
> > tools to grant two different roles to get the backup to work.
>
> Isn't it simpler to grant pg_switch_xlog to pg_backup in the default
> config?
>

I'm not against it, but it would imply a set of data lines for
pg_auth_members, which we don't have today. We can't easily directly GRANT
the role due to the restrictions put in place to prevent regular users from
changing the system roles. On the other hand, we could change the check to
only apply when we aren't in bootstrap mode.

Thanks!

Stephen


From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, David Steele <david(at)pgmasters(dot)net>, Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, Gavin Flower <GavinFlower(at)archidevsys(dot)co(dot)nz>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>, Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2015-11-30 17:52:58
Message-ID: CA+TgmoZ8zqF0Dmp8O5sywt3DWORCZn6DZiykpu5wTLOxZuuKQg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Fri, Nov 20, 2015 at 12:29 PM, Stephen Frost <sfrost(at)snowman(dot)net> wrote:
> * Michael Paquier (michael(dot)paquier(at)gmail(dot)com) wrote:
>> On Thu, Nov 19, 2015 at 7:10 AM, Stephen Frost wrote:
>> > * Michael Paquier (michael(dot)paquier(at)gmail(dot)com) wrote:
>> >> It seems weird to not have a dedicated role for pg_switch_xlog.
>> >
>> > I didn't add a pg_switch_xlog default role in this patch series, but
>> > would be happy to do so if that's the consensus. It's quite easy to do.
>>
>> Agreed. I am not actually getting why that's part of the backup
>> actually. That would be more related to archiving, both being
>> unrelated concepts. But at this point I guess that's mainly a
>> philosophical split.
>
> As David notes, they're actually quite related. Note that in our
> documentation pg_switch_xlog() is listed in the "Backup Control
> Functions" table.
>
> I can think of a use-case for a user who can call pg_switch_xlog, but
> not pg_start_backup()/pg_stop_backup(), but I have to admit that it
> seems rather limited and I'm on the fence about it being a worthwhile
> distinction.

Sounds too narrow to me. Are we going to have a separate predefined
role for every security-restricted function to which someone might
want to grant access? That seems over the top to me.

I don't think we should make it our goal to completely eliminate the
use of SECURITY DEFINER functions for privilege delegation. Of
course, being able to grant privileges directly is nicer, because then
the client code doesn't have to know about it. But I think it's OK,
even good, if the predefined roles cater to the common cases, and the
less common cases aren't handled quite as elegantly.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, David Steele <david(at)pgmasters(dot)net>, Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, Gavin Flower <GavinFlower(at)archidevsys(dot)co(dot)nz>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>, Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2015-11-30 18:32:52
Message-ID: 20151130183252.GH3685@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

* Robert Haas (robertmhaas(at)gmail(dot)com) wrote:
> On Fri, Nov 20, 2015 at 12:29 PM, Stephen Frost <sfrost(at)snowman(dot)net> wrote:
> > * Michael Paquier (michael(dot)paquier(at)gmail(dot)com) wrote:
> >> On Thu, Nov 19, 2015 at 7:10 AM, Stephen Frost wrote:
> >> > * Michael Paquier (michael(dot)paquier(at)gmail(dot)com) wrote:
> >> >> It seems weird to not have a dedicated role for pg_switch_xlog.
> >> >
> >> > I didn't add a pg_switch_xlog default role in this patch series, but
> >> > would be happy to do so if that's the consensus. It's quite easy to do.
> >>
> >> Agreed. I am not actually getting why that's part of the backup
> >> actually. That would be more related to archiving, both being
> >> unrelated concepts. But at this point I guess that's mainly a
> >> philosophical split.
> >
> > As David notes, they're actually quite related. Note that in our
> > documentation pg_switch_xlog() is listed in the "Backup Control
> > Functions" table.
> >
> > I can think of a use-case for a user who can call pg_switch_xlog, but
> > not pg_start_backup()/pg_stop_backup(), but I have to admit that it
> > seems rather limited and I'm on the fence about it being a worthwhile
> > distinction.
>
> Sounds too narrow to me. Are we going to have a separate predefined
> role for every security-restricted function to which someone might
> want to grant access? That seems over the top to me.

I certainly don't want to go down to that level and was, as seen above,
unsure about having pg_switch_xlog() as a differentiated privilege.
Michael, do you still see that as a useful independent capability?

> I don't think we should make it our goal to completely eliminate the
> use of SECURITY DEFINER functions for privilege delegation. Of
> course, being able to grant privileges directly is nicer, because then
> the client code doesn't have to know about it. But I think it's OK,
> even good, if the predefined roles cater to the common cases, and the
> less common cases aren't handled quite as elegantly.

Agreed.

Thanks!

Stephen


From: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, David Steele <david(at)pgmasters(dot)net>, Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, Gavin Flower <GavinFlower(at)archidevsys(dot)co(dot)nz>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>, Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2015-11-30 19:44:30
Message-ID: 20151130194430.GB2763@alvherre.pgsql
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Stephen Frost wrote:
> * Robert Haas (robertmhaas(at)gmail(dot)com) wrote:

> > > I can think of a use-case for a user who can call pg_switch_xlog, but
> > > not pg_start_backup()/pg_stop_backup(), but I have to admit that it
> > > seems rather limited and I'm on the fence about it being a worthwhile
> > > distinction.
> >
> > Sounds too narrow to me. Are we going to have a separate predefined
> > role for every security-restricted function to which someone might
> > want to grant access? That seems over the top to me.
>
> I certainly don't want to go down to that level and was, as seen above,
> unsure about having pg_switch_xlog() as a differentiated privilege.
> Michael, do you still see that as a useful independent capability?

Hmm, Robert's argument seems reasonable -- we can continue to offer
access to individual elements by granting execute on a security-definer
function owned by predefined user pg_backup.

--
Álvaro Herrera http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services


From: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, David Steele <david(at)pgmasters(dot)net>, Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, Gavin Flower <GavinFlower(at)archidevsys(dot)co(dot)nz>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>, Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2015-12-01 00:18:52
Message-ID: CAB7nPqTFG8dLhg0ciAOUO0+vQ+uRTWvxJQAKeLSMAS46vDMS1g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Tue, Dec 1, 2015 at 3:32 AM, Stephen Frost <sfrost(at)snowman(dot)net> wrote:
> * Robert Haas (robertmhaas(at)gmail(dot)com) wrote:
>> On Fri, Nov 20, 2015 at 12:29 PM, Stephen Frost <sfrost(at)snowman(dot)net> wrote:
>> > * Michael Paquier (michael(dot)paquier(at)gmail(dot)com) wrote:
>> >> On Thu, Nov 19, 2015 at 7:10 AM, Stephen Frost wrote:
>> >> > * Michael Paquier (michael(dot)paquier(at)gmail(dot)com) wrote:
>> >> >> It seems weird to not have a dedicated role for pg_switch_xlog.
>> >> >
>> >> > I didn't add a pg_switch_xlog default role in this patch series, but
>> >> > would be happy to do so if that's the consensus. It's quite easy to do.
>> >>
>> >> Agreed. I am not actually getting why that's part of the backup
>> >> actually. That would be more related to archiving, both being
>> >> unrelated concepts. But at this point I guess that's mainly a
>> >> philosophical split.
>> >
>> > As David notes, they're actually quite related. Note that in our
>> > documentation pg_switch_xlog() is listed in the "Backup Control
>> > Functions" table.
>> >
>> > I can think of a use-case for a user who can call pg_switch_xlog, but
>> > not pg_start_backup()/pg_stop_backup(), but I have to admit that it
>> > seems rather limited and I'm on the fence about it being a worthwhile
>> > distinction.
>>
>> Sounds too narrow to me. Are we going to have a separate predefined
>> role for every security-restricted function to which someone might
>> want to grant access? That seems over the top to me.
>
> I certainly don't want to go down to that level and was, as seen above,
> unsure about having pg_switch_xlog() as a differentiated privilege.
> Michael, do you still see that as a useful independent capability?

OK, let's do so then by having this one fall under pg_backup. Let's
not be my grunting concerns be an obstacle for this patch, and we
could still change it afterwards in this release beta cycle anyway
based on user feedback.
--
Michael


From: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, David Steele <david(at)pgmasters(dot)net>, Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, Gavin Flower <GavinFlower(at)archidevsys(dot)co(dot)nz>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>, Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2015-12-20 13:17:16
Message-ID: CAB7nPqR6fy=0DTdSgWYec7++auYW4VWJrxHA-PBi_s6NpyHQJg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Tue, Dec 1, 2015 at 9:18 AM, Michael Paquier
<michael(dot)paquier(at)gmail(dot)com> wrote:
> On Tue, Dec 1, 2015 at 3:32 AM, Stephen Frost <sfrost(at)snowman(dot)net> wrote:
>> * Robert Haas (robertmhaas(at)gmail(dot)com) wrote:
>>> On Fri, Nov 20, 2015 at 12:29 PM, Stephen Frost <sfrost(at)snowman(dot)net> wrote:
>>> > * Michael Paquier (michael(dot)paquier(at)gmail(dot)com) wrote:
>>> >> On Thu, Nov 19, 2015 at 7:10 AM, Stephen Frost wrote:
>>> >> > * Michael Paquier (michael(dot)paquier(at)gmail(dot)com) wrote:
>>> >> >> It seems weird to not have a dedicated role for pg_switch_xlog.
>>> >> >
>>> >> > I didn't add a pg_switch_xlog default role in this patch series, but
>>> >> > would be happy to do so if that's the consensus. It's quite easy to do.
>>> >>
>>> >> Agreed. I am not actually getting why that's part of the backup
>>> >> actually. That would be more related to archiving, both being
>>> >> unrelated concepts. But at this point I guess that's mainly a
>>> >> philosophical split.
>>> >
>>> > As David notes, they're actually quite related. Note that in our
>>> > documentation pg_switch_xlog() is listed in the "Backup Control
>>> > Functions" table.
>>> >
>>> > I can think of a use-case for a user who can call pg_switch_xlog, but
>>> > not pg_start_backup()/pg_stop_backup(), but I have to admit that it
>>> > seems rather limited and I'm on the fence about it being a worthwhile
>>> > distinction.
>>>
>>> Sounds too narrow to me. Are we going to have a separate predefined
>>> role for every security-restricted function to which someone might
>>> want to grant access? That seems over the top to me.
>>
>> I certainly don't want to go down to that level and was, as seen above,
>> unsure about having pg_switch_xlog() as a differentiated privilege.
>> Michael, do you still see that as a useful independent capability?
>
> OK, let's do so then by having this one fall under pg_backup. Let's
> not be my grunting concerns be an obstacle for this patch, and we
> could still change it afterwards in this release beta cycle anyway
> based on user feedback.

Three weeks later...
This thread has not moved a iota. Stephen, are you planning to work
more on this patch? It seems that we found a consensus. If nothing
happens, I am afraid that the destiny of this patch will be to be
returned with feedback, it is the 5th CF where this entry is
registered.
--
Michael


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, David Steele <david(at)pgmasters(dot)net>, Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, Gavin Flower <GavinFlower(at)archidevsys(dot)co(dot)nz>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>, Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2015-12-20 13:24:32
Message-ID: 20151220132432.GO3685@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Michael,

* Michael Paquier (michael(dot)paquier(at)gmail(dot)com) wrote:
> On Tue, Dec 1, 2015 at 9:18 AM, Michael Paquier
> <michael(dot)paquier(at)gmail(dot)com> wrote:
> > OK, let's do so then by having this one fall under pg_backup. Let's
> > not be my grunting concerns be an obstacle for this patch, and we
> > could still change it afterwards in this release beta cycle anyway
> > based on user feedback.
>
> Three weeks later...
> This thread has not moved a iota. Stephen, are you planning to work
> more on this patch? It seems that we found a consensus. If nothing
> happens, I am afraid that the destiny of this patch will be to be
> returned with feedback, it is the 5th CF where this entry is
> registered.

Ok, seems you're right that we've got consensus on it. I'll post an
updated patch later today which I'll plan to commit.

Thanks!

Stephen


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, David Steele <david(at)pgmasters(dot)net>, Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, Gavin Flower <GavinFlower(at)archidevsys(dot)co(dot)nz>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>, Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2015-12-21 16:41:43
Message-ID: 20151221164143.GV3685@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Michael, all,

* Michael Paquier (michael(dot)paquier(at)gmail(dot)com) wrote:
> OK, let's do so then by having this one fall under pg_backup. Let's
> not be my grunting concerns be an obstacle for this patch, and we
> could still change it afterwards in this release beta cycle anyway
> based on user feedback.

Updated and rebased patch attached which takes the 'pg_switch_xlog'
default role back out, leaving us with:

pg_monitor - View privileged info
pg_backup - start/stop backups, switch xlog, create restore points
pg_replay - Pause/resume xlog replay on replicas
pg_replication - Create/destroy/etc replication slots
pg_rotate_logfile - Request logfile rotation
pg_signal_backend - Signal other backends (cancel query/terminate)
pg_file_settings - View configuration settings in all config files

Michael, another review would be great, if you don't mind. I'm going to
be going through it also more closely since it sounds like we've got
consensus on at least this initial set of default roles and rights. If
all looks good then I'll commit it.

Thanks!

Stephen

Attachment Content-Type Size
default_roles_v10.patch text/x-diff 57.3 KB

From: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, David Steele <david(at)pgmasters(dot)net>, Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, Gavin Flower <GavinFlower(at)archidevsys(dot)co(dot)nz>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>, Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2015-12-22 05:05:57
Message-ID: CAB7nPqTeYLt5hXKYx+u3f84-xh+M0k0FOMpvM_CgbHgaap6m4w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Tue, Dec 22, 2015 at 1:41 AM, Stephen Frost <sfrost(at)snowman(dot)net> wrote:
> Updated and rebased patch attached which takes the 'pg_switch_xlog'
> default role back out, leaving us with:
>
> pg_monitor - View privileged info
> pg_backup - start/stop backups, switch xlog, create restore points
> pg_replay - Pause/resume xlog replay on replicas
> pg_replication - Create/destroy/etc replication slots
> pg_rotate_logfile - Request logfile rotation
> pg_signal_backend - Signal other backends (cancel query/terminate)
> pg_file_settings - View configuration settings in all config files
>
> Michael, another review would be great, if you don't mind. I'm going to
> be going through it also more closely since it sounds like we've got
> consensus on at least this initial set of default roles and rights. If
> all looks good then I'll commit it.

Thanks. This looks fine to me. I just have one single comment:

+ <entry>Request logfile rotation.</entry>
s/logfile/transaction log file/
--
Michael


From: Amit Langote <Langote_Amit_f8(at)lab(dot)ntt(dot)co(dot)jp>
To: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, Stephen Frost <sfrost(at)snowman(dot)net>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, David Steele <david(at)pgmasters(dot)net>, Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, Gavin Flower <GavinFlower(at)archidevsys(dot)co(dot)nz>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>, Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2015-12-22 05:54:15
Message-ID: 5678E587.3010508@lab.ntt.co.jp
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 2015/12/22 14:05, Michael Paquier wrote:
> On Tue, Dec 22, 2015 at 1:41 AM, Stephen Frost <sfrost(at)snowman(dot)net> wrote:
>> Updated and rebased patch attached which takes the 'pg_switch_xlog'
>> default role back out, leaving us with:
>>
>> pg_monitor - View privileged info
>> pg_backup - start/stop backups, switch xlog, create restore points
>> pg_replay - Pause/resume xlog replay on replicas
>> pg_replication - Create/destroy/etc replication slots
>> pg_rotate_logfile - Request logfile rotation
>> pg_signal_backend - Signal other backends (cancel query/terminate)
>> pg_file_settings - View configuration settings in all config files
>
> Thanks. This looks fine to me. I just have one single comment:
>
> + <entry>Request logfile rotation.</entry>
> s/logfile/transaction log file/

Looks correct as is. Or maybe "server's log file" as in:

9.26.2. Server Signaling Functions

pg_rotate_logfile(): Rotate server's log file

Thanks,
Amit


From: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
To: Amit Langote <Langote_Amit_f8(at)lab(dot)ntt(dot)co(dot)jp>
Cc: Stephen Frost <sfrost(at)snowman(dot)net>, Robert Haas <robertmhaas(at)gmail(dot)com>, David Steele <david(at)pgmasters(dot)net>, Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, Gavin Flower <GavinFlower(at)archidevsys(dot)co(dot)nz>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>, Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2015-12-22 06:00:24
Message-ID: CAB7nPqRG5OPxyct4DSVqXnyQKNc5ngd968M39vUWa-ZcS_R9xg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Tue, Dec 22, 2015 at 2:54 PM, Amit Langote
<Langote_Amit_f8(at)lab(dot)ntt(dot)co(dot)jp> wrote:
> On 2015/12/22 14:05, Michael Paquier wrote:
>> On Tue, Dec 22, 2015 at 1:41 AM, Stephen Frost <sfrost(at)snowman(dot)net> wrote:
>>> Updated and rebased patch attached which takes the 'pg_switch_xlog'
>>> default role back out, leaving us with:
>>>
>>> pg_monitor - View privileged info
>>> pg_backup - start/stop backups, switch xlog, create restore points
>>> pg_replay - Pause/resume xlog replay on replicas
>>> pg_replication - Create/destroy/etc replication slots
>>> pg_rotate_logfile - Request logfile rotation
>>> pg_signal_backend - Signal other backends (cancel query/terminate)
>>> pg_file_settings - View configuration settings in all config files
>>
>> Thanks. This looks fine to me. I just have one single comment:
>>
>> + <entry>Request logfile rotation.</entry>
>> s/logfile/transaction log file/
>
> Looks correct as is. Or maybe "server's log file" as in:
>
> 9.26.2. Server Signaling Functions
>
> pg_rotate_logfile(): Rotate server's log file

You're right, this is not a WAL segment, just a normal log file. Your
phrasing is better.
--
Michael


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
Cc: Amit Langote <Langote_Amit_f8(at)lab(dot)ntt(dot)co(dot)jp>, Robert Haas <robertmhaas(at)gmail(dot)com>, David Steele <david(at)pgmasters(dot)net>, Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, Gavin Flower <GavinFlower(at)archidevsys(dot)co(dot)nz>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>, Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2015-12-22 22:23:47
Message-ID: 20151222222347.GJ3685@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

* Michael Paquier (michael(dot)paquier(at)gmail(dot)com) wrote:
> On Tue, Dec 22, 2015 at 2:54 PM, Amit Langote
> <Langote_Amit_f8(at)lab(dot)ntt(dot)co(dot)jp> wrote:
> > On 2015/12/22 14:05, Michael Paquier wrote:
> >> On Tue, Dec 22, 2015 at 1:41 AM, Stephen Frost <sfrost(at)snowman(dot)net> wrote:
> >>> Updated and rebased patch attached which takes the 'pg_switch_xlog'
> >>> default role back out, leaving us with:
> >>>
> >>> pg_monitor - View privileged info
> >>> pg_backup - start/stop backups, switch xlog, create restore points
> >>> pg_replay - Pause/resume xlog replay on replicas
> >>> pg_replication - Create/destroy/etc replication slots
> >>> pg_rotate_logfile - Request logfile rotation
> >>> pg_signal_backend - Signal other backends (cancel query/terminate)
> >>> pg_file_settings - View configuration settings in all config files
> >>
> >> Thanks. This looks fine to me. I just have one single comment:
> >>
> >> + <entry>Request logfile rotation.</entry>
> >> s/logfile/transaction log file/
> >
> > Looks correct as is. Or maybe "server's log file" as in:
> >
> > 9.26.2. Server Signaling Functions
> >
> > pg_rotate_logfile(): Rotate server's log file
>
> You're right, this is not a WAL segment, just a normal log file. Your
> phrasing is better.

Works for me.

Updated patch attached. I'll give it another good look and then commit
it, barring objections.

Thanks!

Stephen

Attachment Content-Type Size
default_roles_v11.patch text/x-diff 57.3 KB

From: Noah Misch <noah(at)leadboat(dot)com>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, Amit Langote <Langote_Amit_f8(at)lab(dot)ntt(dot)co(dot)jp>, Robert Haas <robertmhaas(at)gmail(dot)com>, David Steele <david(at)pgmasters(dot)net>, Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, Gavin Flower <GavinFlower(at)archidevsys(dot)co(dot)nz>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>, Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2015-12-24 04:05:34
Message-ID: 20151224040534.GA2608543@tornado.leadboat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Tue, Dec 22, 2015 at 05:23:47PM -0500, Stephen Frost wrote:
> > >> On Tue, Dec 22, 2015 at 1:41 AM, Stephen Frost <sfrost(at)snowman(dot)net> wrote:
> > >>> Updated and rebased patch attached which takes the 'pg_switch_xlog'
> > >>> default role back out, leaving us with:
> > >>>
> > >>> pg_monitor - View privileged info
> > >>> pg_backup - start/stop backups, switch xlog, create restore points
> > >>> pg_replay - Pause/resume xlog replay on replicas
> > >>> pg_replication - Create/destroy/etc replication slots
> > >>> pg_rotate_logfile - Request logfile rotation
> > >>> pg_signal_backend - Signal other backends (cancel query/terminate)
> > >>> pg_file_settings - View configuration settings in all config files

> Updated patch attached. I'll give it another good look and then commit
> it, barring objections.

This thread and its satellite[1] have worked their way through a few designs.
At first, it was adding role attributes, alongside existing attributes like
REPLICATION and BYPASSRLS. It switched[2] to making pg_dump preserve ACLs on
system objects. Built-in roles joined[3] the pg_dump work to offer predefined
collections of ACL grants. Finally, it dropped[4] the pg_dump side and
hard-coded the roles into the features they govern.

I find pg_dump support for system object ACLs to be the best of the goals
pursued here. [5] proposed a good division of pg_dump+roles into multiple
patches, and the pg_dump support for system object ACLs belongs as the first
of the series. There's nothing to like about today's behavior of allowing the
GRANT but omitting it from dumps, and attacking the problem at that layer will
provide considerable admin freedom. Starting there is important, because it
will change the roles design. I doubt we would add role pg_rotate_logfile if
"GRANT EXECUTE ON FUNCTION pg_rotate_logfile() TO mydba" were fully usable;
likewise for other roles that would carry a single ACL. Contrary to comments
upthread, we won't be particularly free to redefine the scope of built-in
roles later. Removing privileges from a role will be an ordinary
compatibility break, and adding privileges will be quite sensitive.

Your first patch, to catalogs.sgml, stands alone. May as well get that out of
the way. To answer one question you asked a few times, reserving the pg_ role
prefix is fine. (Whether any particular pg_foo role proposal sinks or floats
is a separate question.)

To summarize, I think the right next step is to resume designing pg_dump
support for system object ACLs. I looked over your other two patches and will
unshelve those reviews when their time comes.

Thanks,
nm

[1] http://www.postgresql.org/message-id/flat/20150508042928(dot)GP30322(at)tamriel(dot)snowman(dot)net
[2] http://www.postgresql.org/message-id/20150402045311.GW3663@tamriel.snowman.net
[3] http://www.postgresql.org/message-id/20150429144722.GY30322@tamriel.snowman.net
[4] http://www.postgresql.org/message-id/20150508042928.GP30322@tamriel.snowman.net
[5] http://www.postgresql.org/message-id/CA+TgmobH4tdccajn7VmPT-1RqBdzLYcAz5jUz4bJ=rkqs_gADA@mail.gmail.com


From: Amit Langote <Langote_Amit_f8(at)lab(dot)ntt(dot)co(dot)jp>
To: Stephen Frost <sfrost(at)snowman(dot)net>, Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, David Steele <david(at)pgmasters(dot)net>, Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, Gavin Flower <GavinFlower(at)archidevsys(dot)co(dot)nz>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>, Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2015-12-24 06:59:21
Message-ID: 567B97C9.1070003@lab.ntt.co.jp
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers


Hi,

On 2015/12/23 7:23, Stephen Frost wrote:
> Updated patch attached. I'll give it another good look and then commit
> it, barring objections.

Just a minor nitpick about a code comment -

/*
+ * Check that the user is not trying to create a role in the reserved
+ * "pg_" namespace.
+ */
+ if (IsReservedName(stmt->role))

The wording may be slightly confusing, especially saying "... in ...
namespace". ISTM, "namespace" is fairly extensively used around the code
to mean something like "a schema's namespace".

Could perhaps be reworded as:

/*
+ * Check that the user is not trying to create a role with reserved
+ * name, ie, one starting with "pg_".

If OK, there seems to be one more place further down in the patch with
similar wording.

Thanks,
Amit


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Noah Misch <noah(at)leadboat(dot)com>
Cc: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, Amit Langote <Langote_Amit_f8(at)lab(dot)ntt(dot)co(dot)jp>, Robert Haas <robertmhaas(at)gmail(dot)com>, David Steele <david(at)pgmasters(dot)net>, Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, Gavin Flower <GavinFlower(at)archidevsys(dot)co(dot)nz>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>, Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2015-12-29 13:35:50
Message-ID: 20151229133549.GP3685@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Noah,

* Noah Misch (noah(at)leadboat(dot)com) wrote:
> > Updated patch attached. I'll give it another good look and then commit
> > it, barring objections.
>
> This thread and its satellite[1] have worked their way through a few designs.
> At first, it was adding role attributes, alongside existing attributes like
> REPLICATION and BYPASSRLS. It switched[2] to making pg_dump preserve ACLs on
> system objects. Built-in roles joined[3] the pg_dump work to offer predefined
> collections of ACL grants. Finally, it dropped[4] the pg_dump side and
> hard-coded the roles into the features they govern.

Correct, after quite a bit of discussion and the conclusion that, while
pg_dump support for dumping ACLs might be interesting, it was quite a
bit more complex an approach than this use-case justified. Further,
adding support to pg_dump for dumping ACLs could be done independently
of default roles.

The one argument which you've put forth for adding the complexity of
dumping catalog ACLs is that we might reduce the number of default
roles provided to the user. I disagree that we would. Having a single
set of default roles which provide a sensible breakdown of permissions
is a better approach than asking every administrator and application
developer who is building tools on top of PG to try and work through
what makes sense themselves, even if that means we have a default role
with a small, or even only an individual, capability.

I also disagree that we won't be able to adjust the privileges granted
to a role in the future. We have certainly made adjustments to what a
'replication' role is able to do, which has largely been in the 'more
capabilities' direction that you opine concern over.

> To summarize, I think the right next step is to resume designing pg_dump
> support for system object ACLs. I looked over your other two patches and will
> unshelve those reviews when their time comes.

To be clear, I don't believe the two patches are particularly involved
with each other and don't feel that one needs to wait for the other.

Further, I'm not convinced that adding support for dumping ACLs or, in
general, encouraging users to define their own ACLs on catalog objects
is a good idea. We certainly have no mechanism in place today for those
ACLs to be respected by SysCache and encouraging their use when we won't
actually respect them is likely to be confusing. I had thought
differently at one point but my position changed during the discussion
when I realized the complexity and potential confusion it could cause
and considered that against the simplicity and relatively low cost of
having default roles.

Thanks!

Stephen


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Amit Langote <Langote_Amit_f8(at)lab(dot)ntt(dot)co(dot)jp>
Cc: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, David Steele <david(at)pgmasters(dot)net>, Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, Gavin Flower <GavinFlower(at)archidevsys(dot)co(dot)nz>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>, Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2015-12-29 14:55:41
Message-ID: 20151229145541.GR3685@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Amit,

* Amit Langote (Langote_Amit_f8(at)lab(dot)ntt(dot)co(dot)jp) wrote:
> On 2015/12/23 7:23, Stephen Frost wrote:
> > Updated patch attached. I'll give it another good look and then commit
> > it, barring objections.
>
> Just a minor nitpick about a code comment -
>
> /*
> + * Check that the user is not trying to create a role in the reserved
> + * "pg_" namespace.
> + */
> + if (IsReservedName(stmt->role))
>
> The wording may be slightly confusing, especially saying "... in ...
> namespace". ISTM, "namespace" is fairly extensively used around the code
> to mean something like "a schema's namespace".
>
> Could perhaps be reworded as:
>
> /*
> + * Check that the user is not trying to create a role with reserved
> + * name, ie, one starting with "pg_".
>
> If OK, there seems to be one more place further down in the patch with
> similar wording.

I could go either way on that, really. I don't find namespace to be
confusing when used in that way, but I'll change it since others do.

Thanks!

Stephen


From: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: Amit Langote <Langote_Amit_f8(at)lab(dot)ntt(dot)co(dot)jp>, Robert Haas <robertmhaas(at)gmail(dot)com>, David Steele <david(at)pgmasters(dot)net>, Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, Gavin Flower <GavinFlower(at)archidevsys(dot)co(dot)nz>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>, Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2015-12-30 02:14:36
Message-ID: CAB7nPqSEPKbSWy67eQuFCK76uqD9Wzh6ps-B9KVBpT3SMCkBzw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Tue, Dec 29, 2015 at 11:55 PM, Stephen Frost <sfrost(at)snowman(dot)net> wrote:
> I could go either way on that, really. I don't find namespace to be
> confusing when used in that way, but I'll change it since others do.

It seems to me that the way patch does it is fine..
--
Michael


From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: Noah Misch <noah(at)leadboat(dot)com>, Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, Amit Langote <Langote_Amit_f8(at)lab(dot)ntt(dot)co(dot)jp>, David Steele <david(at)pgmasters(dot)net>, Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, Gavin Flower <GavinFlower(at)archidevsys(dot)co(dot)nz>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>, Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2015-12-30 16:50:27
Message-ID: CA+Tgmob=rwu+FL=o=BhHVAgx7w4ZLXECP+CxBP--92SLEZYUnw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Tue, Dec 29, 2015 at 5:35 AM, Stephen Frost <sfrost(at)snowman(dot)net> wrote:
> * Noah Misch (noah(at)leadboat(dot)com) wrote:
>> > Updated patch attached. I'll give it another good look and then commit
>> > it, barring objections.
>>
>> This thread and its satellite[1] have worked their way through a few designs.
>> At first, it was adding role attributes, alongside existing attributes like
>> REPLICATION and BYPASSRLS. It switched[2] to making pg_dump preserve ACLs on
>> system objects. Built-in roles joined[3] the pg_dump work to offer predefined
>> collections of ACL grants. Finally, it dropped[4] the pg_dump side and
>> hard-coded the roles into the features they govern.
>
> Correct, after quite a bit of discussion and the conclusion that, while
> pg_dump support for dumping ACLs might be interesting, it was quite a
> bit more complex an approach than this use-case justified.

Hmm. I don't think I agree with that conclusion. Who were the
participants in that discussion, and how many people spoke in favor
from moving on from that proposal - which I rather liked - to what
you've got now? Do you have links to the relevant portion of the
relevant thread?

I think it's not a very good thing if we add roles that allow, say,
execution of exactly one SQL function. The
dump-grants-on-system-objects proposal would accomplish the same thing
in a much more flexible way, and with less catalog clutter. More
broadly, I'm not very convinced that even the roles which allow for
rights on multiple objects are going to meet with general approval.
There has been enough discussion of which roles should be created and
which things should be included in each one, and the overall tenor of
that discussion seems to be that different people have different
ideas. Under those circumstances, it seems very dubious to proceed
with this. Michael seems to think that we can go ahead and start
changing things and sort out whatever is broken later, but that
doesn't sound like a very good plan to me. We can change the
internals of a bad implementation later and replace it with a good
implementation, but changing user-visible behavior once people have
started relying on it is a lot harder.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


From: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Stephen Frost <sfrost(at)snowman(dot)net>, Noah Misch <noah(at)leadboat(dot)com>, Amit Langote <Langote_Amit_f8(at)lab(dot)ntt(dot)co(dot)jp>, David Steele <david(at)pgmasters(dot)net>, Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, Gavin Flower <GavinFlower(at)archidevsys(dot)co(dot)nz>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>, Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2015-12-31 00:12:13
Message-ID: CAB7nPqSuDAPziy7eA68fdkBtoz19g8yQGmCPzbq0ttcG4zDABw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Thu, Dec 31, 2015 at 1:50 AM, Robert Haas <robertmhaas(at)gmail(dot)com> wrote:
> Under those circumstances, it seems very dubious to proceed
> with this. Michael seems to think that we can go ahead and start
> changing things and sort out whatever is broken later, but that
> doesn't sound like a very good plan to me.

I meant [snip]tuning those roles during this development cycle.[/snip]
But I'll just withdraw as there are enough concerns, from two
committers on top of it. My point was just to move on with this patch
in the direction where the overall consensus seemed to be at the point
I begun participating in this thread.
--
Michael


From: Noah Misch <noah(at)leadboat(dot)com>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, Amit Langote <Langote_Amit_f8(at)lab(dot)ntt(dot)co(dot)jp>, Robert Haas <robertmhaas(at)gmail(dot)com>, David Steele <david(at)pgmasters(dot)net>, Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, Gavin Flower <GavinFlower(at)archidevsys(dot)co(dot)nz>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>, Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2015-12-31 07:26:15
Message-ID: 20151231072615.GA2865494@tornado.leadboat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Tue, Dec 29, 2015 at 08:35:50AM -0500, Stephen Frost wrote:
> * Noah Misch (noah(at)leadboat(dot)com) wrote:

> The one argument which you've put forth for adding the complexity of
> dumping catalog ACLs is that we might reduce the number of default
> roles provided to the user.

Right. If "GRANT EXECUTE ON FUNCTION pg_rotate_logfile() TO mydba" worked as
well as it works on user-defined functions, the community would not choose to
add a pg_rotate_logfile role holding just that one permission.

> I disagree that we would. Having a single
> set of default roles which provide a sensible breakdown of permissions
> is a better approach than asking every administrator and application
> developer who is building tools on top of PG to try and work through
> what makes sense themselves, even if that means we have a default role
> with a small, or even only an individual, capability.

The proposed pg_replication role introduces abstraction that could, as you
hope, spare a DBA from studying sets of functions to grant together. The
pg_rotate_logfile role, however, does not shield the DBA from complexity.
Being narrowly tied to a specific function, it's just a suboptimal spelling of
GRANT. The gap in GRANT has distorted the design for these predefined roles.
I do not anticipate a sound design discussion about specific predefined roles
so long as the state of GRANT clouds the matter.

> > To summarize, I think the right next step is to resume designing pg_dump
> > support for system object ACLs. I looked over your other two patches and will
> > unshelve those reviews when their time comes.
>
> To be clear, I don't believe the two patches are particularly involved
> with each other and don't feel that one needs to wait for the other.

Patch 2/3 could stand without patch 3/3, but not vice-versa. It's patch 2/3
that makes pg_dumpall skip ^pg_ roles, and that must be in place no later than
the first patch that adds a predefined ^pg_ role.

> Further, I'm not convinced that adding support for dumping ACLs or, in
> general, encouraging users to define their own ACLs on catalog objects
> is a good idea. We certainly have no mechanism in place today for those
> ACLs to be respected by SysCache and encouraging their use when we won't
> actually respect them is likely to be confusing.

What's this problem with syscache? It sounds important.

nm


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
Cc: Amit Langote <Langote_Amit_f8(at)lab(dot)ntt(dot)co(dot)jp>, Robert Haas <robertmhaas(at)gmail(dot)com>, David Steele <david(at)pgmasters(dot)net>, Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, Gavin Flower <GavinFlower(at)archidevsys(dot)co(dot)nz>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>, Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2016-01-04 04:25:11
Message-ID: 20160104042511.GU3685@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

* Michael Paquier (michael(dot)paquier(at)gmail(dot)com) wrote:
> On Tue, Dec 29, 2015 at 11:55 PM, Stephen Frost <sfrost(at)snowman(dot)net> wrote:
> > I could go either way on that, really. I don't find namespace to be
> > confusing when used in that way, but I'll change it since others do.
>
> It seems to me that the way patch does it is fine..

Alright, fair enough.

Thanks!

Stephen


From: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
To: Noah Misch <noah(at)leadboat(dot)com>
Cc: Stephen Frost <sfrost(at)snowman(dot)net>, Amit Langote <Langote_Amit_f8(at)lab(dot)ntt(dot)co(dot)jp>, Robert Haas <robertmhaas(at)gmail(dot)com>, David Steele <david(at)pgmasters(dot)net>, Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, Gavin Flower <GavinFlower(at)archidevsys(dot)co(dot)nz>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>, Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2016-01-04 04:37:33
Message-ID: CAB7nPqSRbHL5Lj0WWqrh+9SMY6qxpEQchkBqAiFgYcqm=Vtxjg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Thu, Dec 31, 2015 at 4:26 PM, Noah Misch <noah(at)leadboat(dot)com> wrote:
> On Tue, Dec 29, 2015 at 08:35:50AM -0500, Stephen Frost wrote:
>> * Noah Misch (noah(at)leadboat(dot)com) wrote:
>> I disagree that we would. Having a single
>> set of default roles which provide a sensible breakdown of permissions
>> is a better approach than asking every administrator and application
>> developer who is building tools on top of PG to try and work through
>> what makes sense themselves, even if that means we have a default role
>> with a small, or even only an individual, capability.
>
> The proposed pg_replication role introduces abstraction that could, as you
> hope, spare a DBA from studying sets of functions to grant together. The
> pg_rotate_logfile role, however, does not shield the DBA from complexity.
> Being narrowly tied to a specific function, it's just a suboptimal spelling of
> GRANT. The gap in GRANT has distorted the design for these predefined roles.
> I do not anticipate a sound design discussion about specific predefined roles
> so long as the state of GRANT clouds the matter.

As the patch stands, the system roles that are just close to synonyms
of GRANT/REVOKE are the following:
- pg_file_settings, which works just on the system view
pg_file_settings and the function pg_show_all_file_settings().
- pg_rotate_logfile as mentioned already.
- pg_signal_backend, which is just checked once in pg_signal_backend
Based on those concerns, it looks clear that they should be shaved off
from the patch.

>> > To summarize, I think the right next step is to resume designing pg_dump
>> > support for system object ACLs. I looked over your other two patches and will
>> > unshelve those reviews when their time comes.
>>
>> To be clear, I don't believe the two patches are particularly involved
>> with each other and don't feel that one needs to wait for the other.
>
> Patch 2/3 could stand without patch 3/3, but not vice-versa. It's patch 2/3
> that makes pg_dumpall skip ^pg_ roles, and that must be in place no later than
> the first patch that adds a predefined ^pg_ role.

I am a bit confused by this statement, and I disagree with Stephen's
point as well. It seems to me that 2/3 exists *because* 3/3 is here.
Why would we want to restrict the role names that can be used if we
are not going to introduce some system roles that are created at
bootstrap?
--
Michael


From: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
To: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
Cc: Noah Misch <noah(at)leadboat(dot)com>, Stephen Frost <sfrost(at)snowman(dot)net>, Amit Langote <Langote_Amit_f8(at)lab(dot)ntt(dot)co(dot)jp>, Robert Haas <robertmhaas(at)gmail(dot)com>, David Steele <david(at)pgmasters(dot)net>, Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, Gavin Flower <GavinFlower(at)archidevsys(dot)co(dot)nz>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>, Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2016-01-04 15:46:14
Message-ID: 20160104154614.GA157332@alvherre.pgsql
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Based on the feedback here, I have returned this patch to Needs Review
status. (Waiting on Author would be fairer actually, since we are
waiting for an updated version.)

As far as I can make it from Noah and Robert's comments, what we would
like to see here is a way for pg_dump to output nondefault grants to
system objects; that would solve part of the need here where this patch
proposes default roles for one or two system objects. Another part of
this patch, which could presumably be committed independently, is the
addition of default roles that are related to larger sets of system
objects.

--
Álvaro Herrera http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Noah Misch <noah(at)leadboat(dot)com>
Cc: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, Amit Langote <Langote_Amit_f8(at)lab(dot)ntt(dot)co(dot)jp>, Robert Haas <robertmhaas(at)gmail(dot)com>, David Steele <david(at)pgmasters(dot)net>, Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, Gavin Flower <GavinFlower(at)archidevsys(dot)co(dot)nz>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>, Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2016-01-04 17:55:16
Message-ID: 20160104175516.GC3685@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Noah,

* Noah Misch (noah(at)leadboat(dot)com) wrote:
> On Tue, Dec 29, 2015 at 08:35:50AM -0500, Stephen Frost wrote:
> > * Noah Misch (noah(at)leadboat(dot)com) wrote:
>
> > The one argument which you've put forth for adding the complexity of
> > dumping catalog ACLs is that we might reduce the number of default
> > roles provided to the user.
>
> Right. If "GRANT EXECUTE ON FUNCTION pg_rotate_logfile() TO mydba" worked as
> well as it works on user-defined functions, the community would not choose to
> add a pg_rotate_logfile role holding just that one permission.

I understand that's your position, but I disagree with your conclusion.

If we're going to provide default roles, which I continue to feel is a
good approach, then I would suggest we use them as an abstraction for
the permissions which we view as senible sets of grantable rights. I
dislike the idea of having default roles and then making an exception
for single-permission cases.

I'm approaching this largely from a 3rd-party application perspective.
There are two examples off-hand which I'm considering:

check_postgres
pgbackrest

I'd like to be able to include, in both of those, a simple set of
instructions for granting the necessary rights to the user who is
running those processes. A set of rights which an administrator can go
look up and easily read and understand the result of those grants. For
example:

check_postgres:

Most check_postgres sub-commands can be run without superuser
privileges by granting the pg_monitor role to the monitoring user:

GRANT pg_monitor TO monitor;

For information regarding the pg_monitor role, see:
http://www.postgresql.org/docs/current/static/roles/database-roles.html

pgbackrest:

To run pgbackrest as a non-superuser and not the 'postgres' system
user, grant the pg_backup role to the backrest user and ensure the
backrest system user has read access to the database files (eg: by
having the system user be a member of the 'postgres' group):

GRANT pg_backup to backrest;

For information regarding the pg_backup role, see:
http://www.postgresql.org/docs/current/static/roles/database-roles.html

I can see similar bits of documentation being included in pgAdmin or
other tools. For the pg_rotate_logfile permission, specifically, we
were asked by a client about that permission with the use case being a
logrotate-type of tool, which only has access to the log files but needs
to be able to perform a rotation. This particular client is pretty tech
savvy and I don't think they'd have a problem using GRANT EXECUTE if
that was the only option, but I can see a similar use-case with
logrotate or pgAdmin or even for regular non-superuser admins using psql
and, to reiterate what I said above, I'd rather have one abstraction for
these kinds of permissions instead of a mish-mash of instructions. The
difference I can imagine being between:

For backups and monitoring, you can use default roles:

GRANT pg_backup,pg_monitor to new_admin;

but for other regular privileges such as rotating logfiles, or sending
signals to other processes, you have to explicitly GRANT permissions:

GRANT EXECUTE ON FUNCTION pg_rotate_logfile() TO new_admin;
GRANT EXECUTE ON FUNCTION pg_signal_backend() TO new_admin;

> > I disagree that we would. Having a single
> > set of default roles which provide a sensible breakdown of permissions
> > is a better approach than asking every administrator and application
> > developer who is building tools on top of PG to try and work through
> > what makes sense themselves, even if that means we have a default role
> > with a small, or even only an individual, capability.
>
> The proposed pg_replication role introduces abstraction that could, as you
> hope, spare a DBA from studying sets of functions to grant together. The
> pg_rotate_logfile role, however, does not shield the DBA from complexity.

I disagree with the above statement. Having to understand only one
level of abstraction (the default roles) does reduce the complexity and
means that the DBA does not have to work out if the specifc GRANT
requested by the end user would result in some other access or if there
are any unexpected issues to encounter with issuing GRANTs directly on
catalog objects- something we don't currently support, so such concern
is certainly reasonable.

> Being narrowly tied to a specific function, it's just a suboptimal spelling of
> GRANT. The gap in GRANT has distorted the design for these predefined roles.
> I do not anticipate a sound design discussion about specific predefined roles
> so long as the state of GRANT clouds the matter.

I'm loathe to encourage any direct modification of catalog objects,
even if it's just ACLs. I've seen too many cases, as I imagine others
have, of users destroying their databases or running into unexpected
results when modifying the catalog. The catalog modifications supported
should be explicitly provided through other means rather than direct
commands against the catalog objects. I see the default roles approach
as being similar to having:

ALTER DATABASE db WITH CONNECTION LIMIT 5;

instead of suggesting users issue:

UPDATE DATABASE SET datconnlimit = 5 WHERE datname = 'db';

There is little difference between the two, technically, but I'm a whole
lot more comfortable with the ALTER DATABASE than with the user issuing
an UPDATE against a catalog table. With 9.5, we are adding
ALLOW_CONNECTIONS and IS_TEMPLATE also and I don't recall any particular
concern that those are overly redundant with the equivilant UPDATE
statement.

> > > To summarize, I think the right next step is to resume designing pg_dump
> > > support for system object ACLs. I looked over your other two patches and will
> > > unshelve those reviews when their time comes.
> >
> > To be clear, I don't believe the two patches are particularly involved
> > with each other and don't feel that one needs to wait for the other.
>
> Patch 2/3 could stand without patch 3/3, but not vice-versa. It's patch 2/3
> that makes pg_dumpall skip ^pg_ roles, and that must be in place no later than
> the first patch that adds a predefined ^pg_ role.

Apologies for not being clear on this- I was referring to pg_dump
support for GRANT on catalog objects vs. the default roles patch in my
statement by way of summary.

> > Further, I'm not convinced that adding support for dumping ACLs or, in
> > general, encouraging users to define their own ACLs on catalog objects
> > is a good idea. We certainly have no mechanism in place today for those
> > ACLs to be respected by SysCache and encouraging their use when we won't
> > actually respect them is likely to be confusing.
>
> What's this problem with syscache? It sounds important.

CREATE TABLE and DROP TABLE aren't going to care one bit if you have
access to pg_class or not. The same goes for basically everything else.

If we really want to support ACLs on the catalog, we'd have to either
caveat that none of the internal lookups will respect them or revamp
SysCache and any other direct catalog access to do permission checks
first, which I don't think we really want to do.

This entire discussion of privileges-on-catalog-objects should really
also consider the ongoing discussion about providing policies for the
catalog via RLS. If we start pg_dump'ing the ACLs of catalog objects
then we'd, presumably, also want to pg_dump out any policies defined
against catalog objects. I wonder if we may end up causing ourselves
trouble going with that approach though if we start providing a set of
default policies which SysCache knows how to work with but which users
can change.

Thanks!

Stephen


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Noah Misch <noah(at)leadboat(dot)com>, Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, Amit Langote <Langote_Amit_f8(at)lab(dot)ntt(dot)co(dot)jp>, David Steele <david(at)pgmasters(dot)net>, Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, Gavin Flower <GavinFlower(at)archidevsys(dot)co(dot)nz>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>, Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2016-01-04 20:07:41
Message-ID: 20160104200741.GF3685@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

* Robert Haas (robertmhaas(at)gmail(dot)com) wrote:
> On Tue, Dec 29, 2015 at 5:35 AM, Stephen Frost <sfrost(at)snowman(dot)net> wrote:
> > * Noah Misch (noah(at)leadboat(dot)com) wrote:
> >> > Updated patch attached. I'll give it another good look and then commit
> >> > it, barring objections.
> >>
> >> This thread and its satellite[1] have worked their way through a few designs.
> >> At first, it was adding role attributes, alongside existing attributes like
> >> REPLICATION and BYPASSRLS. It switched[2] to making pg_dump preserve ACLs on
> >> system objects. Built-in roles joined[3] the pg_dump work to offer predefined
> >> collections of ACL grants. Finally, it dropped[4] the pg_dump side and
> >> hard-coded the roles into the features they govern.
> >
> > Correct, after quite a bit of discussion and the conclusion that, while
> > pg_dump support for dumping ACLs might be interesting, it was quite a
> > bit more complex an approach than this use-case justified.
>
> Hmm. I don't think I agree with that conclusion. Who were the
> participants in that discussion, and how many people spoke in favor
> from moving on from that proposal - which I rather liked - to what
> you've got now? Do you have links to the relevant portion of the
> relevant thread?

I'm not sure it's entirely relevant now- I've outlined the reasoning in
my email to Noah as a, hopefully, pretty comprehensive summary. If that
doesn't sway your minds then it seems unlikely that a reference to a
thread from 6 months or a year ago would. Further, as happens, other
discussions were in person where I discussed the ideas with other
hackers at conferences. I got generally positive responses to the idea
of default roles with specific sets of rights, which is the path that
I've been on since. As with most decisions, there was not a formal vote
over the proposals for me to reference. I do specifically recall the
opinion that sets of privileges probably make more sense than granting
out individual ones, from Tom, if I'm remembering correctly.

In any case, I can work on the pg_dump support for catalog ACLs if there
is agreement now on that being the direction to go in. If there's
agreement that we are happy with the idea of default roles also then I
can strip out those few which are only one-permission and which
therefore wouldn't be necessary, if we had ACL support on catalog
objects, quite easily.

> I think it's not a very good thing if we add roles that allow, say,
> execution of exactly one SQL function. The
> dump-grants-on-system-objects proposal would accomplish the same thing
> in a much more flexible way, and with less catalog clutter.

For my 2c, I don't see a default role or two as creating terribly much
clutter. Changing all of our code that currently has internal checks to
rely on the external checks and adjusting the permissions on the
individual functions will be a fair bit of churn though.

> More
> broadly, I'm not very convinced that even the roles which allow for
> rights on multiple objects are going to meet with general approval.

There's been rather little oposition to the idea and support when I've
discussed it. Of course, that was before it got to the point where I
was planning to commit it. Perhaps there will be once it's actually in,
or maybe not until it's in the wild. In any case, I continue to feel,
as others have, that we can make adjustments moving forward.

> There has been enough discussion of which roles should be created and
> which things should be included in each one, and the overall tenor of
> that discussion seems to be that different people have different
> ideas.

Michael had a question about pg_switch_xlog, but he appeared to
reconsider that position after the subsequent discussion, which put us
back to essentially the same proposal that I started with, I believe. I
don't recall terribly much other discussion or concern about what roles
should be created or what should be included in each one, though I'd be
happy to hear your thoughts on what you'd like to see.

I certainly don't like the idea of punting on all of this to the user to
figure out, even if it does meet the specific requirements our clients
have asked for, it strikes me that we can do better.

Thanks!

Stephen


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
Cc: Noah Misch <noah(at)leadboat(dot)com>, Amit Langote <Langote_Amit_f8(at)lab(dot)ntt(dot)co(dot)jp>, Robert Haas <robertmhaas(at)gmail(dot)com>, David Steele <david(at)pgmasters(dot)net>, Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, Gavin Flower <GavinFlower(at)archidevsys(dot)co(dot)nz>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>, Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2016-01-04 20:20:01
Message-ID: 20160104202001.GG3685@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

* Michael Paquier (michael(dot)paquier(at)gmail(dot)com) wrote:
> On Thu, Dec 31, 2015 at 4:26 PM, Noah Misch <noah(at)leadboat(dot)com> wrote:
> > The proposed pg_replication role introduces abstraction that could, as you
> > hope, spare a DBA from studying sets of functions to grant together. The
> > pg_rotate_logfile role, however, does not shield the DBA from complexity.
> > Being narrowly tied to a specific function, it's just a suboptimal spelling of
> > GRANT. The gap in GRANT has distorted the design for these predefined roles.
> > I do not anticipate a sound design discussion about specific predefined roles
> > so long as the state of GRANT clouds the matter.
>
> As the patch stands, the system roles that are just close to synonyms
> of GRANT/REVOKE are the following:
> - pg_file_settings, which works just on the system view
> pg_file_settings and the function pg_show_all_file_settings().
> - pg_rotate_logfile as mentioned already.

The above are fine, I believe.

> - pg_signal_backend, which is just checked once in pg_signal_backend

This is a bit more complicated. pg_signal_backend() isn't directly
exposed, pg_cancel_backend() and pg_termiante_backend() are. I'm not
saying that doesn't mean we should, necessairly, keep the
pg_signal_backend role, just that it's more than just a single function.

Further, pg_terminate_backend and pg_cancel_backend are callable by
anyone today. We'd have to invent new functions or change user-visible
behavior in an unfortunate way- we don't want *anyone* to be able to
call those functions on *anyone* unless they've been specifically
granted that access. Today, you can cancel and/or terminate your own
backends and superusers can cancel and/or termiante anyone's. The point
of pg_signal_backend was to allow non-superusers to cancel and/or
terminate any non-superuser-started backends. With the default role
approach, we can provide exactly the intended semantics and not break
backwards compatibility for those functions.

> Based on those concerns, it looks clear that they should be shaved off
> from the patch.

I'd like to hear back regarding the summary email that I sent to Noah
and the follow-up I sent to Robert, as they have time to reply, of
course. It's certainly easy enough to remove those default roles if
that's the consensus though.

> >> > To summarize, I think the right next step is to resume designing pg_dump
> >> > support for system object ACLs. I looked over your other two patches and will
> >> > unshelve those reviews when their time comes.
> >>
> >> To be clear, I don't believe the two patches are particularly involved
> >> with each other and don't feel that one needs to wait for the other.
> >
> > Patch 2/3 could stand without patch 3/3, but not vice-versa. It's patch 2/3
> > that makes pg_dumpall skip ^pg_ roles, and that must be in place no later than
> > the first patch that adds a predefined ^pg_ role.
>
> I am a bit confused by this statement, and I disagree with Stephen's
> point as well. It seems to me that 2/3 exists *because* 3/3 is here.
> Why would we want to restrict the role names that can be used if we
> are not going to introduce some system roles that are created at
> bootstrap?

My comment was, evidently, not anywhere near clear enough. The two
patches I was referring to were the pg_dump-support-for-catalog-ACLs and
the default-roles patches. Apologies for the confusion there.

Thanks!

Stephen


From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: Noah Misch <noah(at)leadboat(dot)com>, Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, Amit Langote <Langote_Amit_f8(at)lab(dot)ntt(dot)co(dot)jp>, David Steele <david(at)pgmasters(dot)net>, Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, Gavin Flower <GavinFlower(at)archidevsys(dot)co(dot)nz>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>, Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2016-01-04 21:02:31
Message-ID: CA+TgmoanYNweQHOX_Ooh=zHKNFERu6c+w=6_Xrn63Z-ccfEr2Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Mon, Jan 4, 2016 at 12:55 PM, Stephen Frost <sfrost(at)snowman(dot)net> wrote:
> I'd like to be able to include, in both of those, a simple set of
> instructions for granting the necessary rights to the user who is
> running those processes. A set of rights which an administrator can go
> look up and easily read and understand the result of those grants. For
> example:
>
> check_postgres:
>
> Most check_postgres sub-commands can be run without superuser
> privileges by granting the pg_monitor role to the monitoring user:
>
> GRANT pg_monitor TO monitor;
>
> For information regarding the pg_monitor role, see:
> http://www.postgresql.org/docs/current/static/roles/database-roles.html
>
> pgbackrest:
>
> To run pgbackrest as a non-superuser and not the 'postgres' system
> user, grant the pg_backup role to the backrest user and ensure the
> backrest system user has read access to the database files (eg: by
> having the system user be a member of the 'postgres' group):
>
> GRANT pg_backup to backrest;
>
> For information regarding the pg_backup role, see:
> http://www.postgresql.org/docs/current/static/roles/database-roles.html

So I have two comments on this.

First, it's not really going to matter to users very much whether the
command to enable one of these features is a single GRANT command or a
short sequence of GRANT commands executed one after another. So even
if we don't have roles that bundle together multiple permissions, you
will still be able to do this; you just might need more than one
command. Probably, I'm guessing, not very many commands, but more
than one.

Second, I think it's really unlikely that you're going to maintain
perfect alignment between your predefined roles and the permissions
that third-party tools need over the course of multiple releases. I
think the chances of that working out are just about zero. Sure, you
can make the initial set of permissions granted to pg_backup match
exactly what pgbackrest needs, but it's a good bet that one of the six
or eight widely-used backup tools uses something that's not included
in that set. And even if not, it doesn't require very much
imagination to suppose that some tool, maybe pgbackrest or maybe
something else, that comes along over the next few releases will
require some extra permission. When that happens, will we include add
that permission to the pg_backup role, or not? If we do, then we'll
be giving excess permissions to all the other backup tools that don't
need that new right, and maybe surprising users who upgrade without
realizing that some of their roles now have new rights. If we don't,
then that tool won't be able to work without some additional
twiddling. I just find it incredibly unlikely that every monitoring
tool, or every backup tool, or every admin tool will require exactly
the same set of permissions.

> I can see similar bits of documentation being included in pgAdmin or
> other tools.

...and pgAdmin is a particularly good example. The permissions that
pgAdmin requires depend on what you want to do with it, and it does a
lot of things, and it might do more or fewer things in the future.
You can't even fairly assume that everyone wants to give the same
permissions to pgAdmin, let alone that some competing tool will
require the same set.

>> Being narrowly tied to a specific function, it's just a suboptimal spelling of
>> GRANT. The gap in GRANT has distorted the design for these predefined roles.
>> I do not anticipate a sound design discussion about specific predefined roles
>> so long as the state of GRANT clouds the matter.
>
> I'm loathe to encourage any direct modification of catalog objects,
> even if it's just ACLs. I've seen too many cases, as I imagine others
> have, of users destroying their databases or running into unexpected
> results when modifying the catalog. The catalog modifications supported
> should be explicitly provided through other means rather than direct
> commands against the catalog objects. I see the default roles approach
> as being similar to having:
>
> ALTER DATABASE db WITH CONNECTION LIMIT 5;
>
> instead of suggesting users issue:
>
> UPDATE DATABASE SET datconnlimit = 5 WHERE datname = 'db';

This doesn't make any sense to me. Nobody was proposing issuing an
UPDATE against pg_database directly (and it would have to be
pg_database, not just database as you wrote here). We're talking
about whether the user is going to GRANT pg_rotate_logfile TO ... or
GRANT EXECUTE ON FUNCTION pg_rotate_logfile() TO ... which is not the
same sort of thing at all.

>> What's this problem with syscache? It sounds important.
>
> CREATE TABLE and DROP TABLE aren't going to care one bit if you have
> access to pg_class or not. The same goes for basically everything else.
>
> If we really want to support ACLs on the catalog, we'd have to either
> caveat that none of the internal lookups will respect them or revamp
> SysCache and any other direct catalog access to do permission checks
> first, which I don't think we really want to do.

This doesn't make any sense to me, either. Calling a function from
the SQL checks the permissions on that function. This works just fine
today:

rhaas=# revoke execute on function pg_rotate_logfile() from public;
REVOKE
rhaas=# set role bob;
SET
rhaas=> select pg_rotate_logfile();
ERROR: permission denied for function pg_rotate_logfile

We can do that by default and it will Just Work. All we need to have
a complete solution here is (1) remove the superuser check from the C
code and (2) make pg_dump dump and restore the ACL properly.

Syscaches really have nothing to do with this.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: Noah Misch <noah(at)leadboat(dot)com>, Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, Amit Langote <Langote_Amit_f8(at)lab(dot)ntt(dot)co(dot)jp>, David Steele <david(at)pgmasters(dot)net>, Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, Gavin Flower <GavinFlower(at)archidevsys(dot)co(dot)nz>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>, Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2016-01-04 21:33:24
Message-ID: CA+Tgmobdk7n3oxT26REEU5aB=um+E8LrP1B2D05kA+KzuXkd=Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Mon, Jan 4, 2016 at 3:07 PM, Stephen Frost <sfrost(at)snowman(dot)net> wrote:
> I'm not sure it's entirely relevant now- I've outlined the reasoning in
> my email to Noah as a, hopefully, pretty comprehensive summary. If that
> doesn't sway your minds then it seems unlikely that a reference to a
> thread from 6 months or a year ago would. Further, as happens, other
> discussions were in person where I discussed the ideas with other
> hackers at conferences. I got generally positive responses to the idea
> of default roles with specific sets of rights, which is the path that
> I've been on since. As with most decisions, there was not a formal vote
> over the proposals for me to reference. I do specifically recall the
> opinion that sets of privileges probably make more sense than granting
> out individual ones, from Tom, if I'm remembering correctly.

To be honest, that's not really my point. You have cited off-list
discussions you've had over and over as a reason why you proceeded
down some particular path. That is fine up to a point - I discuss
lots of things with people off-list, too - but a consensus that a
particular design is acceptable for commit has to mean the consensus
on this mailing list, and nothing else. In seven years of reading
this mailing list, I can't remember a single other person on this
mailing list saying "I'm going to commit this because I talked to a
bunch of unspecified people at conferences I attended and they liked
it", but you've used essentially that rationale a couple of times now.

> For my 2c, I don't see a default role or two as creating terribly much
> clutter.

I don't believe any version of this proposal has involved only one or
two such roles. They've all had at least four or five AFAICS. Now
maybe that's still OK, but 4 or 5 > 1 or 2, and the number is only
likely to go up in the future.

> Changing all of our code that currently has internal checks to
> rely on the external checks and adjusting the permissions on the
> individual functions will be a fair bit of churn though.

I'm not sure it'll really be that bad, but if you have some evidence
that I'm wrong I'd like to hear it.

>> More
>> broadly, I'm not very convinced that even the roles which allow for
>> rights on multiple objects are going to meet with general approval.
>
> There's been rather little oposition to the idea and support when I've
> discussed it. Of course, that was before it got to the point where I
> was planning to commit it. Perhaps there will be once it's actually in,
> or maybe not until it's in the wild. In any case, I continue to feel,
> as others have, that we can make adjustments moving forward.

So, is this another case where the support is all in off-list fora and
thus invisible, or can you point to specific on-list discussions where
it was supported, and to the opinions offered in support? I don't
really remember many opinions that were any more positive than "I
wouldn't be strongly opposed to this" or "If we're going to do this
then we ought to do it in X way". I'm happy to be corrected if I'm
misrepresenting the record, but I'd characterize the overall reaction
to this proposal as tepid: nobody hated it, but nobody really loved it
either, and a bunch of mild concerns were offered.

>> There has been enough discussion of which roles should be created and
>> which things should be included in each one, and the overall tenor of
>> that discussion seems to be that different people have different
>> ideas.
>
> Michael had a question about pg_switch_xlog, but he appeared to
> reconsider that position after the subsequent discussion, which put us
> back to essentially the same proposal that I started with, I believe. I
> don't recall terribly much other discussion or concern about what roles
> should be created or what should be included in each one, though I'd be
> happy to hear your thoughts on what you'd like to see.

Honestly, my vote is for creating only those predefined roles that are
clearly endorsed by three people with different employers, which I
currently believe to be true of none of the proposed roles. It's not
even that I suspect you or anyone of ballot-stuffing; it's just that
people who work at different companies are likely to work with
different tools and those tools may have different requirements. I
mean, people at 2ndQuadrant probably mostly use repmgr; people at
Crunchy probably like pgbackrest; people at OmniTI probably use
PITRtools; and EnterpriseDB employees are more likely than average to
be familiar with BART. If several of those people come together and
say they all agree that predefined role X is perfect for the needs of
all of their respective tools, I'd consider that a really good sign
that we've hit on something that is of general utility. Otherwise,
I'd just the authors of each tool specify the GRANT EXECUTE ON
FUNCTION lines necessary for their own tool and call it good. I think
that's almost as convenient and a lot more flexible.

What really bothers me about this thread is that these predefined
roles are intended to be useful for third-party tools, but the people
who maintain those third-party tools have said basically nothing. I
don't recall, for example, Dave Page weighing in on what pgAdmin
needs, or anybody commenting on to what degree any of these proposals
would meet the needs of Slony or pgBouncer or pgPool or any backup
tool (other than perhaps pgbackrest, which I assume your proposals
cater to) or any monitoring tool. Like, we've heard zip. Either
those people don't know this thread exists, or they can't understand
it, or they think it's so boring that they can't be bothered to write
in and say whether this is useful or not. I'd have a lot more
confidence that we are making a good decision if some of those people
would show up and say "I have reviewed this proposal and it looks {
great | terrible | mediocre } for $TOOL because $REASON".

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Noah Misch <noah(at)leadboat(dot)com>, Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, Amit Langote <Langote_Amit_f8(at)lab(dot)ntt(dot)co(dot)jp>, David Steele <david(at)pgmasters(dot)net>, Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, Gavin Flower <GavinFlower(at)archidevsys(dot)co(dot)nz>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>, Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2016-01-04 21:56:34
Message-ID: 20160104215634.GK3685@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

* Robert Haas (robertmhaas(at)gmail(dot)com) wrote:
> On Mon, Jan 4, 2016 at 12:55 PM, Stephen Frost <sfrost(at)snowman(dot)net> wrote:
> > I'd like to be able to include, in both of those, a simple set of
> > instructions for granting the necessary rights to the user who is
> > running those processes. A set of rights which an administrator can go
> > look up and easily read and understand the result of those grants. For
> > example:
> >
> > check_postgres:
> >
> > Most check_postgres sub-commands can be run without superuser
> > privileges by granting the pg_monitor role to the monitoring user:
> >
> > GRANT pg_monitor TO monitor;
> >
> > For information regarding the pg_monitor role, see:
> > http://www.postgresql.org/docs/current/static/roles/database-roles.html
> >
> > pgbackrest:
> >
> > To run pgbackrest as a non-superuser and not the 'postgres' system
> > user, grant the pg_backup role to the backrest user and ensure the
> > backrest system user has read access to the database files (eg: by
> > having the system user be a member of the 'postgres' group):
> >
> > GRANT pg_backup to backrest;
> >
> > For information regarding the pg_backup role, see:
> > http://www.postgresql.org/docs/current/static/roles/database-roles.html
>
> So I have two comments on this.
>
> First, it's not really going to matter to users very much whether the
> command to enable one of these features is a single GRANT command or a
> short sequence of GRANT commands executed one after another. So even
> if we don't have roles that bundle together multiple permissions, you
> will still be able to do this; you just might need more than one
> command. Probably, I'm guessing, not very many commands, but more
> than one.

I disagree. I find that it does make a difference to users to be using
a well documented and clear approach over one which involves fiddling
with the individual pieces to get everything to work, and if a new
function comes along that is useful for backup users, that would have to
also be granted, even if it would clearly be useful to a backup role.

> Second, I think it's really unlikely that you're going to maintain
> perfect alignment between your predefined roles and the permissions
> that third-party tools need over the course of multiple releases. I
> think the chances of that working out are just about zero. Sure, you
> can make the initial set of permissions granted to pg_backup match
> exactly what pgbackrest needs, but it's a good bet that one of the six
> or eight widely-used backup tools uses something that's not included
> in that set.

There may be something I've missed with the proposed pg_backup role, but
I don't believe you're correct that there isn't a set of privileges
which all of those backup tools need and which could be provided through
the pg_backup role.

> And even if not, it doesn't require very much
> imagination to suppose that some tool, maybe pgbackrest or maybe
> something else, that comes along over the next few releases will
> require some extra permission. When that happens, will we include add
> that permission to the pg_backup role, or not? If we do, then we'll
> be giving excess permissions to all the other backup tools that don't
> need that new right, and maybe surprising users who upgrade without
> realizing that some of their roles now have new rights. If we don't,
> then that tool won't be able to work without some additional
> twiddling. I just find it incredibly unlikely that every monitoring
> tool, or every backup tool, or every admin tool will require exactly
> the same set of permissions.

As I pointed out previously, we've already been doing this with the
replication role attribute and I don't recall any complaining about it.

This discussion started out with the idea of adding more role
attributes to address this need to break out superuser rights, as we
have done in the past, and then moved to discussing default roles
instead because it's a better solution for abstracting permissions as
roles are more easily grantable, delegation of role granting can be
done, and role membership works with inheritance.

The arguments you raise here would apply nearly the same to the
replication role attribute, but in practice, we don't seem to have any
question regarding how that's handled, nor have we gotten complaints
about it. I expect the same would be true with default roles and don't
see any particular reason to fear otherwise.

> > I can see similar bits of documentation being included in pgAdmin or
> > other tools.
>
> ...and pgAdmin is a particularly good example. The permissions that
> pgAdmin requires depend on what you want to do with it, and it does a
> lot of things, and it might do more or fewer things in the future.
> You can't even fairly assume that everyone wants to give the same
> permissions to pgAdmin, let alone that some competing tool will
> require the same set.

I wasn't suggesting that we give everyone the same privileges to some
default 'pgAdmin' role but rather that providing an abstraction of the
set of privileges possible against the catalog objects, into sets that
make sense together, is a useful simplification for users and that it'd
be a better approach than asking users to figure out what sets make
sense on their own.

> >> Being narrowly tied to a specific function, it's just a suboptimal spelling of
> >> GRANT. The gap in GRANT has distorted the design for these predefined roles.
> >> I do not anticipate a sound design discussion about specific predefined roles
> >> so long as the state of GRANT clouds the matter.
> >
> > I'm loathe to encourage any direct modification of catalog objects,
> > even if it's just ACLs. I've seen too many cases, as I imagine others
> > have, of users destroying their databases or running into unexpected
> > results when modifying the catalog. The catalog modifications supported
> > should be explicitly provided through other means rather than direct
> > commands against the catalog objects. I see the default roles approach
> > as being similar to having:
> >
> > ALTER DATABASE db WITH CONNECTION LIMIT 5;
> >
> > instead of suggesting users issue:
> >
> > UPDATE DATABASE SET datconnlimit = 5 WHERE datname = 'db';
>
> This doesn't make any sense to me. Nobody was proposing issuing an
> UPDATE against pg_database directly (and it would have to be
> pg_database, not just database as you wrote here). We're talking
> about whether the user is going to GRANT pg_rotate_logfile TO ... or
> GRANT EXECUTE ON FUNCTION pg_rotate_logfile() TO ... which is not the
> same sort of thing at all.

I was showing them broadly under "making changes to catalog objects."
Granting a default role isn't making a modification to a catalog object
at all and would be explicitly supported. GRANT'ing EXECUTE on a
catalog function works today, but isn't really supported. The pg_dump
change would be explicitly changing that to be a supported operation.

> >> What's this problem with syscache? It sounds important.
> >
> > CREATE TABLE and DROP TABLE aren't going to care one bit if you have
> > access to pg_class or not. The same goes for basically everything else.
> >
> > If we really want to support ACLs on the catalog, we'd have to either
> > caveat that none of the internal lookups will respect them or revamp
> > SysCache and any other direct catalog access to do permission checks
> > first, which I don't think we really want to do.
>
> This doesn't make any sense to me, either. Calling a function from
> the SQL checks the permissions on that function. This works just fine
> today:

Yes, it does, I didn't mean to imply otherwise. The above discussion
was in regards to SysCache, as used internally by various commands.

> We can do that by default and it will Just Work. All we need to have
> a complete solution here is (1) remove the superuser check from the C
> code and (2) make pg_dump dump and restore the ACL properly.
>
> Syscaches really have nothing to do with this.

Adding pg_dump dump and restore support for catalog ACLs implies that
we're supporting ACLs on all catalog objects- including tables.
Otherwise, we're going to have to figure out exactly what objects we
allow setting ACLs on and which ones we don't.

REVOKE'ing SELECT access to pg_class isn't going to make DROP TABLE
stop working, even though it clearly is going to be accessing pg_class.
That's the point which I was attempting to make with regard to SysCache.

Another consideration is that the catalog changes pretty regularly and
we'd have to make sure that we are dumping out the correct set of
privileges and applying them correctly to the new catalog- and that's
only going to work reliably if the user is using the newer version of
pg_dump; we'll have no hope if they're using an old version. While
that's what we've always recommended, restoring an old dump into a newer
version, by-and-large, does work today and is certainly commonly done.

I'm not excited about the complaints we'd get if we implemented a change
which reliably broke that and I'm afraid this might and we wouldn't
realize it until we're on our second major release with that capability
and have already signed off on supporting catalog ACLs.

These complications and considerations are exactly the kind of
additional complexity that adding pg_dump dump/restore support for
catalog ACLs implies and that's why, while it sounds pretty interesting,
I don't believe it's necessairly a good idea. The default roles
approach is quite simple and similar to, while being better than, the
existing role attributes approach, in my view.

Thanks!

Stephen


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Noah Misch <noah(at)leadboat(dot)com>, Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, Amit Langote <Langote_Amit_f8(at)lab(dot)ntt(dot)co(dot)jp>, David Steele <david(at)pgmasters(dot)net>, Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, Gavin Flower <GavinFlower(at)archidevsys(dot)co(dot)nz>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>, Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2016-01-04 22:22:42
Message-ID: 20160104222241.GL3685@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

* Robert Haas (robertmhaas(at)gmail(dot)com) wrote:
> On Mon, Jan 4, 2016 at 3:07 PM, Stephen Frost <sfrost(at)snowman(dot)net> wrote:
> > I'm not sure it's entirely relevant now- I've outlined the reasoning in
> > my email to Noah as a, hopefully, pretty comprehensive summary. If that
> > doesn't sway your minds then it seems unlikely that a reference to a
> > thread from 6 months or a year ago would. Further, as happens, other
> > discussions were in person where I discussed the ideas with other
> > hackers at conferences. I got generally positive responses to the idea
> > of default roles with specific sets of rights, which is the path that
> > I've been on since. As with most decisions, there was not a formal vote
> > over the proposals for me to reference. I do specifically recall the
> > opinion that sets of privileges probably make more sense than granting
> > out individual ones, from Tom, if I'm remembering correctly.
>
> To be honest, that's not really my point. You have cited off-list
> discussions you've had over and over as a reason why you proceeded
> down some particular path. That is fine up to a point - I discuss
> lots of things with people off-list, too - but a consensus that a
> particular design is acceptable for commit has to mean the consensus
> on this mailing list, and nothing else. In seven years of reading
> this mailing list, I can't remember a single other person on this
> mailing list saying "I'm going to commit this because I talked to a
> bunch of unspecified people at conferences I attended and they liked
> it", but you've used essentially that rationale a couple of times now.

I've found consensus among folks on the lists for far more of my commits
than I've cited off-list discussions for. Further, consensus on these
lists is largely in the quiet, which is why I go out of my way to
attempt to engage parties who may be interested when there *isn't* much
discussion on the lists. I'm trying to do better than simply assuming
consensus based on no feedback to the contrary. Had I assumed minimal
response meant consensus for this patch, as is typically the norm, this
patch would have been committed six months ago. Instead, I tried to
engage people at conferences to ensure that there really was consensus
on the approach.

> > For my 2c, I don't see a default role or two as creating terribly much
> > clutter.
>
> I don't believe any version of this proposal has involved only one or
> two such roles. They've all had at least four or five AFAICS. Now
> maybe that's still OK, but 4 or 5 > 1 or 2, and the number is only
> likely to go up in the future.

The 'role or two' was under the expectation that we'd still have default
roles for the more complicated cases (pg_backup, et al) and that we
would only be removing the default role of pg_switch_xlog and
pg_file_settings (the only two which an individual GRANT could replace).

> > Changing all of our code that currently has internal checks to
> > rely on the external checks and adjusting the permissions on the
> > individual functions will be a fair bit of churn though.
>
> I'm not sure it'll really be that bad, but if you have some evidence
> that I'm wrong I'd like to hear it.

I implemented the discussed pg_dump support for ACLs and looked at the
changes required. I may not be remembering it entirely, but it's not
that I've not looked at it.

> >> More
> >> broadly, I'm not very convinced that even the roles which allow for
> >> rights on multiple objects are going to meet with general approval.
> >
> > There's been rather little oposition to the idea and support when I've
> > discussed it. Of course, that was before it got to the point where I
> > was planning to commit it. Perhaps there will be once it's actually in,
> > or maybe not until it's in the wild. In any case, I continue to feel,
> > as others have, that we can make adjustments moving forward.
>
> So, is this another case where the support is all in off-list fora and
> thus invisible, or can you point to specific on-list discussions where
> it was supported, and to the opinions offered in support? I don't
> really remember many opinions that were any more positive than "I
> wouldn't be strongly opposed to this" or "If we're going to do this
> then we ought to do it in X way". I'm happy to be corrected if I'm
> misrepresenting the record, but I'd characterize the overall reaction
> to this proposal as tepid: nobody hated it, but nobody really loved it
> either, and a bunch of mild concerns were offered.

I agree that this has largely been the on-list reaction. To be fair,
it's been largely the off-list reaction also, which I've expressly
tried to seek out, as mentioned above. I'm not asking anyone to love
it, I'm not entirely convinced it's lovable myself, but I do feel it's
useful and worth making an effort for.

> >> There has been enough discussion of which roles should be created and
> >> which things should be included in each one, and the overall tenor of
> >> that discussion seems to be that different people have different
> >> ideas.
> >
> > Michael had a question about pg_switch_xlog, but he appeared to
> > reconsider that position after the subsequent discussion, which put us
> > back to essentially the same proposal that I started with, I believe. I
> > don't recall terribly much other discussion or concern about what roles
> > should be created or what should be included in each one, though I'd be
> > happy to hear your thoughts on what you'd like to see.
>
> Honestly, my vote is for creating only those predefined roles that are
> clearly endorsed by three people with different employers, which I
> currently believe to be true of none of the proposed roles. It's not
> even that I suspect you or anyone of ballot-stuffing; it's just that
> people who work at different companies are likely to work with
> different tools and those tools may have different requirements.

I'd love to have folks from other companies involved in these
discussions. I'll even reach out explicitly to seek their comment, as
I've done with other hackers at conferences, and try to get them to
voice their opinions here.

> I
> mean, people at 2ndQuadrant probably mostly use repmgr; people at
> Crunchy probably like pgbackrest; people at OmniTI probably use
> PITRtools; and EnterpriseDB employees are more likely than average to
> be familiar with BART. If several of those people come together and
> say they all agree that predefined role X is perfect for the needs of
> all of their respective tools, I'd consider that a really good sign
> that we've hit on something that is of general utility. Otherwise,
> I'd just the authors of each tool specify the GRANT EXECUTE ON
> FUNCTION lines necessary for their own tool and call it good. I think
> that's almost as convenient and a lot more flexible.

If it didn't come with the other baggage that I've tried to explain, I'd
agree that having pg_dump support ACLs on catalog objects to be a
sensible and good thing, even if I might still argue that default roles
are better.

> What really bothers me about this thread is that these predefined
> roles are intended to be useful for third-party tools, but the people
> who maintain those third-party tools have said basically nothing.

For my 2c, I believe that to be, by-and-large, because they don't want
to get their hopes up until they see something actually get committed.
Following long and deep threads such as these are quite a committment.

> I
> don't recall, for example, Dave Page weighing in on what pgAdmin
> needs, or anybody commenting on to what degree any of these proposals
> would meet the needs of Slony or pgBouncer or pgPool or any backup
> tool (other than perhaps pgbackrest, which I assume your proposals
> cater to) or any monitoring tool. Like, we've heard zip. Either
> those people don't know this thread exists, or they can't understand
> it, or they think it's so boring that they can't be bothered to write
> in and say whether this is useful or not. I'd have a lot more
> confidence that we are making a good decision if some of those people
> would show up and say "I have reviewed this proposal and it looks {
> great | terrible | mediocre } for $TOOL because $REASON".

We *have* heard complaints from people, multiple times on various lists,
that they'd like to set up check_postgres, Nagios, $MONITORINGTOOL, with
a role that *isn't* a superuser. I'll ask Greg S-M if he would have
time to weigh in on this though, check_postgres was specifically one of
the tools which I was looking at when considering the pg_monitor role.

I'm not sure about the references you use above to Slony or pgBouncer or
pgPool as those aren't backup tools, to my mind.. I would expect barman
and other backup tools to also use pg_start/stop_backup and
pg_switch_xlog. I'm not sure that there's a way to cater to one backup
role when it comes to how filesystem-level backups are handled in PG,
but perhaps I've missed something there that barman uses and which isn't
included currently.

Of course, my reviewing barman or other tools wouldn't have the same
support as Simon weighing in, so I'll try and pursue that avenue as
well.

Thanks!

Stephen


From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: Noah Misch <noah(at)leadboat(dot)com>, Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, Amit Langote <Langote_Amit_f8(at)lab(dot)ntt(dot)co(dot)jp>, David Steele <david(at)pgmasters(dot)net>, Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, Gavin Flower <GavinFlower(at)archidevsys(dot)co(dot)nz>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>, Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2016-01-04 23:14:52
Message-ID: CA+TgmoZfg9gQvbOEbF8m0__+aWisRU0rJofBTWd1DhWWDJTpkQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Mon, Jan 4, 2016 at 4:56 PM, Stephen Frost <sfrost(at)snowman(dot)net> wrote:
>> First, it's not really going to matter to users very much whether the
>> command to enable one of these features is a single GRANT command or a
>> short sequence of GRANT commands executed one after another. So even
>> if we don't have roles that bundle together multiple permissions, you
>> will still be able to do this; you just might need more than one
>> command. Probably, I'm guessing, not very many commands, but more
>> than one.
>
> I disagree. I find that it does make a difference to users to be using
> a well documented and clear approach over one which involves fiddling
> with the individual pieces to get everything to work, and if a new
> function comes along that is useful for backup users, that would have to
> also be granted, even if it would clearly be useful to a backup role.

How is that a fair way to characterize the discussion here? Just
because you have to execute several SQL commands instead of one
doesn't turn a "well-documented and clear approach" into something
that involves "fiddling with individual pieces". Cutting and pasting
a sequence of 3 or 4 SQL commands into a psql window is not a lot
harder than copying and pasting a single one, and does not turn a good
approach into a shambles.

>> Second, I think it's really unlikely that you're going to maintain
>> perfect alignment between your predefined roles and the permissions
>> that third-party tools need over the course of multiple releases. I
>> think the chances of that working out are just about zero. Sure, you
>> can make the initial set of permissions granted to pg_backup match
>> exactly what pgbackrest needs, but it's a good bet that one of the six
>> or eight widely-used backup tools uses something that's not included
>> in that set.
>
> There may be something I've missed with the proposed pg_backup role, but
> I don't believe you're correct that there isn't a set of privileges
> which all of those backup tools need and which could be provided through
> the pg_backup role.

Well, there's certainly some set of privileges that will make them all
work. But it might include more than some of them want. If you done
any analysis of this, I have not seen it posted to this thread.

>> And even if not, it doesn't require very much
>> imagination to suppose that some tool, maybe pgbackrest or maybe
>> something else, that comes along over the next few releases will
>> require some extra permission. When that happens, will we include add
>> that permission to the pg_backup role, or not?
>
> As I pointed out previously, we've already been doing this with the
> replication role attribute and I don't recall any complaining about it.

1. This doesn't really seem like the same thing. You're introducing
something quite new here: these are not role attributes that apply
only to the role itself, but inheritable role attributes.

2. I believe that the discussion about what the replication role
should and should not allow involved considerably more people than
have discussed any of the specific roles you propose to add here.

3. It was clear from the outset that the replication role's basic
purpose was to be sufficient privilege for a streaming standby and no
more. The remit of these roles is a lot less clear, at least to me.

> I wasn't suggesting that we give everyone the same privileges to some
> default 'pgAdmin' role but rather that providing an abstraction of the
> set of privileges possible against the catalog objects, into sets that
> make sense together, is a useful simplification for users and that it'd
> be a better approach than asking users to figure out what sets make
> sense on their own.

I have no objection to that *in theory*. What's not clear to me is
that the way that you have broken it up actually meets the bona fide
needs of actual tools in a useful way.

> Adding pg_dump dump and restore support for catalog ACLs implies that
> we're supporting ACLs on all catalog objects- including tables.

Not to me it doesn't. I think we could support it just for functions,
and have it continue to be as weird as it is currently for other types
of objects until somebody gets around to straightening that out. If
we want to support it for more object types, great, but I don't think
that's a hard requirement.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: Noah Misch <noah(at)leadboat(dot)com>, Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, Amit Langote <Langote_Amit_f8(at)lab(dot)ntt(dot)co(dot)jp>, David Steele <david(at)pgmasters(dot)net>, Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, Gavin Flower <GavinFlower(at)archidevsys(dot)co(dot)nz>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>, Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2016-01-04 23:19:30
Message-ID: CA+TgmobPJC-CcZrQ9QLejtu1ZeG+ZF5xpDRRcas9o9bMFCuNKQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Mon, Jan 4, 2016 at 5:22 PM, Stephen Frost <sfrost(at)snowman(dot)net> wrote:
>> So, is this another case where the support is all in off-list fora and
>> thus invisible, or can you point to specific on-list discussions where
>> it was supported, and to the opinions offered in support? I don't
>> really remember many opinions that were any more positive than "I
>> wouldn't be strongly opposed to this" or "If we're going to do this
>> then we ought to do it in X way". I'm happy to be corrected if I'm
>> misrepresenting the record, but I'd characterize the overall reaction
>> to this proposal as tepid: nobody hated it, but nobody really loved it
>> either, and a bunch of mild concerns were offered.
>
> I agree that this has largely been the on-list reaction. To be fair,
> it's been largely the off-list reaction also, which I've expressly
> tried to seek out, as mentioned above. I'm not asking anyone to love
> it, I'm not entirely convinced it's lovable myself, but I do feel it's
> useful and worth making an effort for.

I think the question of whether the specific proposals on the table
are in fact useful is one that deserves more study. I am not
convinced of that. I believe something like this could be useful, but
I don't see a lot of evidence that the particular roles you're arguing
for actually are.

> I'd love to have folks from other companies involved in these
> discussions. I'll even reach out explicitly to seek their comment, as
> I've done with other hackers at conferences, and try to get them to
> voice their opinions here.

Great, thanks.

>> What really bothers me about this thread is that these predefined
>> roles are intended to be useful for third-party tools, but the people
>> who maintain those third-party tools have said basically nothing.
>
> For my 2c, I believe that to be, by-and-large, because they don't want
> to get their hopes up until they see something actually get committed.
> Following long and deep threads such as these are quite a committment.

Yep.

>> I
>> don't recall, for example, Dave Page weighing in on what pgAdmin
>> needs, or anybody commenting on to what degree any of these proposals
>> would meet the needs of Slony or pgBouncer or pgPool or any backup
>> tool (other than perhaps pgbackrest, which I assume your proposals
>> cater to) or any monitoring tool. Like, we've heard zip. Either
>> those people don't know this thread exists, or they can't understand
>> it, or they think it's so boring that they can't be bothered to write
>> in and say whether this is useful or not. I'd have a lot more
>> confidence that we are making a good decision if some of those people
>> would show up and say "I have reviewed this proposal and it looks {
>> great | terrible | mediocre } for $TOOL because $REASON".
>
> We *have* heard complaints from people, multiple times on various lists,
> that they'd like to set up check_postgres, Nagios, $MONITORINGTOOL, with
> a role that *isn't* a superuser.

True. But we should verify that this proposal actually meets those
needs, not just assume it does.

> I'll ask Greg S-M if he would have
> time to weigh in on this though, check_postgres was specifically one of
> the tools which I was looking at when considering the pg_monitor role.

OK, that sounds like a good idea.

> I'm not sure about the references you use above to Slony or pgBouncer or
> pgPool as those aren't backup tools, to my mind.. I would expect barman
> and other backup tools to also use pg_start/stop_backup and
> pg_switch_xlog. I'm not sure that there's a way to cater to one backup
> role when it comes to how filesystem-level backups are handled in PG,
> but perhaps I've missed something there that barman uses and which isn't
> included currently.

Oh, sure: they are not backup tools specifically. But anything that
might need elevated privileges deserves consideration here: what sort
of subdivision of the superuser role would make that need go away?

> Of course, my reviewing barman or other tools wouldn't have the same
> support as Simon weighing in, so I'll try and pursue that avenue as
> well.

Cool.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


From: Noah Misch <noah(at)leadboat(dot)com>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, Amit Langote <Langote_Amit_f8(at)lab(dot)ntt(dot)co(dot)jp>, Robert Haas <robertmhaas(at)gmail(dot)com>, David Steele <david(at)pgmasters(dot)net>, Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, Gavin Flower <GavinFlower(at)archidevsys(dot)co(dot)nz>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>, Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2016-01-06 06:33:34
Message-ID: 20160106063334.GB3142022@tornado.leadboat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Mon, Jan 04, 2016 at 12:55:16PM -0500, Stephen Frost wrote:
> * Noah Misch (noah(at)leadboat(dot)com) wrote:
> > On Tue, Dec 29, 2015 at 08:35:50AM -0500, Stephen Frost wrote:

> I'm approaching this largely from a 3rd-party application perspective.
> There are two examples off-hand which I'm considering:
>
> check_postgres
> pgbackrest
>
> I'd like to be able to include, in both of those, a simple set of
> instructions for granting the necessary rights to the user who is
> running those processes. A set of rights which an administrator can go
> look up and easily read and understand the result of those grants. For
> example:
>
> check_postgres:
>
> Most check_postgres sub-commands can be run without superuser
> privileges by granting the pg_monitor role to the monitoring user:
>
> GRANT pg_monitor TO monitor;
>
> For information regarding the pg_monitor role, see:
> http://www.postgresql.org/docs/current/static/roles/database-roles.html

Stop. Even if PostgreSQL introduces pg_monitor, check_postgres will do itself
a favor by not using it. The moment the two projects' sense of monitoring
privileges falls out of lockstep, benefits from using pg_monitor go negative.
check_postgres should instead furnish a script that creates a role holding
required privileges and/or SECURITY DEFINER helpers. If check_postgres starts
using an object, say pgstattuple, it will wish to use it in all versions.
Since PostgreSQL will change pg_monitor privileges in major releases only,
check_postgres would wait 6-18 months to use a privilege in just one of five
supported versions. If PostgreSQL hackers ever disagree with check_postgres
hackers about whether a privilege belongs in the pg_monitor role, then
check_postgres will wish it had never used pg_monitor. For a sample
controversy, some monitoring tool may well call pg_read_file, but that's
arguably too much power to be giving _every_ monitoring tool.

By the way, the pg_monitor role you were ready to commit does not cover
today's check_postgres needs. Among restricted objects, check_postgres uses
at least pg_ls_dir, pg_stats, pg_settings, and pg_stat_activity. Having said
that, it remains premature to design predefined roles. It would be a waste to
mobilize such a design effort with GRANT's limitation clouding the issue.

> and, to reiterate what I said above, I'd rather have one abstraction for
> these kinds of permissions instead of a mish-mash of instructions. The
> difference I can imagine being between:
>
> For backups and monitoring, you can use default roles:
>
> GRANT pg_backup,pg_monitor to new_admin;
>
> but for other regular privileges such as rotating logfiles, or sending
> signals to other processes, you have to explicitly GRANT permissions:
>
> GRANT EXECUTE ON FUNCTION pg_rotate_logfile() TO new_admin;
> GRANT EXECUTE ON FUNCTION pg_signal_backend() TO new_admin;

I don't mind having those two ways to transfer privilege. If I have to settle
for one or the other, I pick the latter.

> > > Further, I'm not convinced that adding support for dumping ACLs or, in
> > > general, encouraging users to define their own ACLs on catalog objects
> > > is a good idea. We certainly have no mechanism in place today for those
> > > ACLs to be respected by SysCache and encouraging their use when we won't
> > > actually respect them is likely to be confusing.
> >
> > What's this problem with syscache? It sounds important.
>
> CREATE TABLE and DROP TABLE aren't going to care one bit if you have
> access to pg_class or not. The same goes for basically everything else.
>
> If we really want to support ACLs on the catalog, we'd have to either
> caveat that none of the internal lookups will respect them or revamp
> SysCache and any other direct catalog access to do permission checks
> first, which I don't think we really want to do.

Oh, that. Having internal lookups ignore the ACLs is more good than bad, and
users have little cause to expect something different. You don't need INSERT
on pg_attribute to add a column, so why expect lack of SELECT on pg_attribute
to prevent dropping one? I might document it like so:

While GRANT can modify the privileges of a system catalog table, that
affects only queries that address the catalog as an SQL table. Internal,
system access to the same underlying data will proceed normally. For
example, "REVOKE SELECT ON pg_proc FROM PUBLIC" does not preclude calling
functions or even preclude passing them to pg_get_functiondef. It does
block queries that name pg_proc in a FROM clause.

> This entire discussion of privileges-on-catalog-objects should really
> also consider the ongoing discussion about providing policies for the
> catalog via RLS. If we start pg_dump'ing the ACLs of catalog objects
> then we'd, presumably, also want to pg_dump out any policies defined
> against catalog objects.

I would have no qualms supporting ACL changes while not supporting added
policies, indexes, triggers, rules, inheritance children, extra columns, etc.
Both Oracle and SQL Server invite system object GRANTs, but they don't invite
system object mutations generally.

nm


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Robert Haas <robertmhaas(at)gmail(dot)com>, Noah Misch <noah(at)leadboat(dot)com>
Cc: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, Amit Langote <Langote_Amit_f8(at)lab(dot)ntt(dot)co(dot)jp>, David Steele <david(at)pgmasters(dot)net>, Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, Gavin Flower <GavinFlower(at)archidevsys(dot)co(dot)nz>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>, Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2016-01-06 16:13:02
Message-ID: 20160106161302.GP3685@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Robert, Noah,

I just wanted to start off by saying thank you for taking the time read
and comment with your thoughts on this concept. I was a bit frustrated
about it feeling rather late, but appreciate the comments which have
been made as they've certainly been constructive.

* Robert Haas (robertmhaas(at)gmail(dot)com) wrote:
> On Mon, Jan 4, 2016 at 4:56 PM, Stephen Frost <sfrost(at)snowman(dot)net> wrote:
> >> First, it's not really going to matter to users very much whether the
> >> command to enable one of these features is a single GRANT command or a
> >> short sequence of GRANT commands executed one after another. So even
> >> if we don't have roles that bundle together multiple permissions, you
> >> will still be able to do this; you just might need more than one
> >> command. Probably, I'm guessing, not very many commands, but more
> >> than one.
> >
> > I disagree. I find that it does make a difference to users to be using
> > a well documented and clear approach over one which involves fiddling
> > with the individual pieces to get everything to work, and if a new
> > function comes along that is useful for backup users, that would have to
> > also be granted, even if it would clearly be useful to a backup role.
>
> How is that a fair way to characterize the discussion here? Just
> because you have to execute several SQL commands instead of one
> doesn't turn a "well-documented and clear approach" into something
> that involves "fiddling with individual pieces". Cutting and pasting
> a sequence of 3 or 4 SQL commands into a psql window is not a lot
> harder than copying and pasting a single one, and does not turn a good
> approach into a shambles.

I was looking at it from a perspective of what we have currently vs.
what the future state with default roles would be. That's not an
entirely fair characterization. If we supported ACLs on catalog objects
via pg_dump, then we could add documentation along the lines of "backups
generally need access to functions X, Y, Z, here's an example of how to
create such a role: blah, blah."

Of course, that documentation would likely have to be repeated in the
various backup tools, though it's possible they could tailor those, if
there was something different about their particular tool.

> >> Second, I think it's really unlikely that you're going to maintain
> >> perfect alignment between your predefined roles and the permissions
> >> that third-party tools need over the course of multiple releases. I
> >> think the chances of that working out are just about zero. Sure, you
> >> can make the initial set of permissions granted to pg_backup match
> >> exactly what pgbackrest needs, but it's a good bet that one of the six
> >> or eight widely-used backup tools uses something that's not included
> >> in that set.
> >
> > There may be something I've missed with the proposed pg_backup role, but
> > I don't believe you're correct that there isn't a set of privileges
> > which all of those backup tools need and which could be provided through
> > the pg_backup role.
>
> Well, there's certainly some set of privileges that will make them all
> work. But it might include more than some of them want. If you done
> any analysis of this, I have not seen it posted to this thread.

I can certainly work up a formal analysis and submit it for
consideration.

> >> And even if not, it doesn't require very much
> >> imagination to suppose that some tool, maybe pgbackrest or maybe
> >> something else, that comes along over the next few releases will
> >> require some extra permission. When that happens, will we include add
> >> that permission to the pg_backup role, or not?
> >
> > As I pointed out previously, we've already been doing this with the
> > replication role attribute and I don't recall any complaining about it.
>
> 1. This doesn't really seem like the same thing. You're introducing
> something quite new here: these are not role attributes that apply
> only to the role itself, but inheritable role attributes.

This approach started out by adding role attributes to handle these
kinds of rights, but in discussion with Tom and Magnus, iirc (no, I
don't have the specific links or threads, though I have asked Magnus to
take a look at this thread, as he has time), the idea of default roles
seemed better specifically because they would then be inheritable and
granting access could also be delegated.

> 2. I believe that the discussion about what the replication role
> should and should not allow involved considerably more people than
> have discussed any of the specific roles you propose to add here.

I didn't intend to dispute that, but...

> 3. It was clear from the outset that the replication role's basic
> purpose was to be sufficient privilege for a streaming standby and no
> more. The remit of these roles is a lot less clear, at least to me.

I've certainly intended the intention of these roles to be clear and
documented. The point I was trying to address above is that we
certainly appear fine to add additional privileges as new capabilities
are added to existing role attributes (the entire logical replication
system was added after the replication role attribute).

> > I wasn't suggesting that we give everyone the same privileges to some
> > default 'pgAdmin' role but rather that providing an abstraction of the
> > set of privileges possible against the catalog objects, into sets that
> > make sense together, is a useful simplification for users and that it'd
> > be a better approach than asking users to figure out what sets make
> > sense on their own.
>
> I have no objection to that *in theory*. What's not clear to me is
> that the way that you have broken it up actually meets the bona fide
> needs of actual tools in a useful way.

That's certainly been my goal, but I've not been as clear as I should
have been regarding the analysis and background work which I have done.

> > Adding pg_dump dump and restore support for catalog ACLs implies that
> > we're supporting ACLs on all catalog objects- including tables.
>
> Not to me it doesn't. I think we could support it just for functions,
> and have it continue to be as weird as it is currently for other types
> of objects until somebody gets around to straightening that out. If
> we want to support it for more object types, great, but I don't think
> that's a hard requirement.

Alright, that would certainly simplify things if we're talking about
only functions. The only concern which I have there is if there are any
non-function cases that we'll end up coming across, and I'm still a bit
nervous about the "old pg_dump / new database" restore concern, but
perhaps that's an acceptable issue.

* Robert Haas (robertmhaas(at)gmail(dot)com) wrote:
> On Mon, Jan 4, 2016 at 5:22 PM, Stephen Frost <sfrost(at)snowman(dot)net> wrote:
> >> So, is this another case where the support is all in off-list fora and
> >> thus invisible, or can you point to specific on-list discussions where
> >> it was supported, and to the opinions offered in support? I don't
> >> really remember many opinions that were any more positive than "I
> >> wouldn't be strongly opposed to this" or "If we're going to do this
> >> then we ought to do it in X way". I'm happy to be corrected if I'm
> >> misrepresenting the record, but I'd characterize the overall reaction
> >> to this proposal as tepid: nobody hated it, but nobody really loved it
> >> either, and a bunch of mild concerns were offered.
> >
> > I agree that this has largely been the on-list reaction. To be fair,
> > it's been largely the off-list reaction also, which I've expressly
> > tried to seek out, as mentioned above. I'm not asking anyone to love
> > it, I'm not entirely convinced it's lovable myself, but I do feel it's
> > useful and worth making an effort for.
>
> I think the question of whether the specific proposals on the table
> are in fact useful is one that deserves more study. I am not
> convinced of that. I believe something like this could be useful, but
> I don't see a lot of evidence that the particular roles you're arguing
> for actually are.

Based on Noah's response (which I respond to below), we seem to still
be debating the whole concept of default roles. I'm happy to provide
detailed analysis if we're able to agree on the concept.

> > I'd love to have folks from other companies involved in these
> > discussions. I'll even reach out explicitly to seek their comment, as
> > I've done with other hackers at conferences, and try to get them to
> > voice their opinions here.
>
> Great, thanks.

I've reached out to Magnus and Greg S-M so far. I've discussed this
quite a bit with David Steele already. I'll reach out to Marco
regarding barman.

> > I'm not sure about the references you use above to Slony or pgBouncer or
> > pgPool as those aren't backup tools, to my mind.. I would expect barman
> > and other backup tools to also use pg_start/stop_backup and
> > pg_switch_xlog. I'm not sure that there's a way to cater to one backup
> > role when it comes to how filesystem-level backups are handled in PG,
> > but perhaps I've missed something there that barman uses and which isn't
> > included currently.
>
> Oh, sure: they are not backup tools specifically. But anything that
> might need elevated privileges deserves consideration here: what sort
> of subdivision of the superuser role would make that need go away?

The general approach which I've been using for the default roles is that
they should grant rights which aren't able to be used to trivially make
oneself a superuser.

* Noah Misch (noah(at)leadboat(dot)com) wrote:
> On Mon, Jan 04, 2016 at 12:55:16PM -0500, Stephen Frost wrote:
> > * Noah Misch (noah(at)leadboat(dot)com) wrote:
> > > On Tue, Dec 29, 2015 at 08:35:50AM -0500, Stephen Frost wrote:
>
> > I'm approaching this largely from a 3rd-party application perspective.
> > There are two examples off-hand which I'm considering:
> >
> > check_postgres
> > pgbackrest
> >
> > I'd like to be able to include, in both of those, a simple set of
> > instructions for granting the necessary rights to the user who is
> > running those processes. A set of rights which an administrator can go
> > look up and easily read and understand the result of those grants. For
> > example:
> >
> > check_postgres:
> >
> > Most check_postgres sub-commands can be run without superuser
> > privileges by granting the pg_monitor role to the monitoring user:
> >
> > GRANT pg_monitor TO monitor;
> >
> > For information regarding the pg_monitor role, see:
> > http://www.postgresql.org/docs/current/static/roles/database-roles.html
>
> Stop. Even if PostgreSQL introduces pg_monitor, check_postgres will do itself
> a favor by not using it. The moment the two projects' sense of monitoring
> privileges falls out of lockstep, benefits from using pg_monitor go negative.
> check_postgres should instead furnish a script that creates a role holding
> required privileges and/or SECURITY DEFINER helpers. If check_postgres starts
> using an object, say pgstattuple, it will wish to use it in all versions.
> Since PostgreSQL will change pg_monitor privileges in major releases only,
> check_postgres would wait 6-18 months to use a privilege in just one of five
> supported versions. If PostgreSQL hackers ever disagree with check_postgres
> hackers about whether a privilege belongs in the pg_monitor role, then
> check_postgres will wish it had never used pg_monitor. For a sample
> controversy, some monitoring tool may well call pg_read_file, but that's
> arguably too much power to be giving _every_ monitoring tool.

Greg and I have chatted previously, and recently again yesterday, about
the idea of providing SECURITY DEFINER functions and neither of us care
for that approach. A role which is granted the necessary rights might
be alright, though I would still contend that a default role is better
and I don't particularly agree with the slow turn-around time-
check_postgres is quite mature and does not change very much any more.

> By the way, the pg_monitor role you were ready to commit does not cover
> today's check_postgres needs. Among restricted objects, check_postgres uses
> at least pg_ls_dir, pg_stats, pg_settings, and pg_stat_activity. Having said
> that, it remains premature to design predefined roles. It would be a waste to
> mobilize such a design effort with GRANT's limitation clouding the issue.

I reviewed check_postgres and wished to avoid functions that were overly
broad for what check_postgres actually needed and those which would
allow the monitoring role to be able to become superuser easily. That
is where the set of permissions actually granted to pg_monitor came
from. The checks of things like "number of WAL segments" are cases
where I'd rather we provide an explicit function that only provided that
information and then allow pg_monitor to use it rather than simply grant
pg_ls_dir access. I don't think that waiting until 9.7 or 10.0 for that
would be any problem at all for check_postgres, which is why I had
wished to get the basic default roles concept completed before moving on
to add such additional functions.

To put it another way, I'd rather *not* tell check_postgres users "sure,
just grant access to pg_ls_dir to the monitoring user" as that really
grants more access than the check_postgres check requires.

> > and, to reiterate what I said above, I'd rather have one abstraction for
> > these kinds of permissions instead of a mish-mash of instructions. The
> > difference I can imagine being between:
> >
> > For backups and monitoring, you can use default roles:
> >
> > GRANT pg_backup,pg_monitor to new_admin;
> >
> > but for other regular privileges such as rotating logfiles, or sending
> > signals to other processes, you have to explicitly GRANT permissions:
> >
> > GRANT EXECUTE ON FUNCTION pg_rotate_logfile() TO new_admin;
> > GRANT EXECUTE ON FUNCTION pg_signal_backend() TO new_admin;
>
> I don't mind having those two ways to transfer privilege. If I have to settle
> for one or the other, I pick the latter.

Of course, if we did provide both, then any difference might be able to
be addressed as a delta against what is provided by the default role.

> > > > Further, I'm not convinced that adding support for dumping ACLs or, in
> > > > general, encouraging users to define their own ACLs on catalog objects
> > > > is a good idea. We certainly have no mechanism in place today for those
> > > > ACLs to be respected by SysCache and encouraging their use when we won't
> > > > actually respect them is likely to be confusing.
> > >
> > > What's this problem with syscache? It sounds important.
> >
> > CREATE TABLE and DROP TABLE aren't going to care one bit if you have
> > access to pg_class or not. The same goes for basically everything else.
> >
> > If we really want to support ACLs on the catalog, we'd have to either
> > caveat that none of the internal lookups will respect them or revamp
> > SysCache and any other direct catalog access to do permission checks
> > first, which I don't think we really want to do.
>
> Oh, that. Having internal lookups ignore the ACLs is more good than bad, and
> users have little cause to expect something different. You don't need INSERT
> on pg_attribute to add a column, so why expect lack of SELECT on pg_attribute
> to prevent dropping one? I might document it like so:
>
> While GRANT can modify the privileges of a system catalog table, that
> affects only queries that address the catalog as an SQL table. Internal,
> system access to the same underlying data will proceed normally. For
> example, "REVOKE SELECT ON pg_proc FROM PUBLIC" does not preclude calling
> functions or even preclude passing them to pg_get_functiondef. It does
> block queries that name pg_proc in a FROM clause.

That's a particularly good example, as it is frequently requested that
prosrc be hidden. Though what is really desired is for users to be able
to see all functions they can call, but only see prosrc for the
functions they own. That kind of policy is where I believe we should be
taking CREATE POLICY, in the future. That's discussion for another
thread though, by and large.

> > This entire discussion of privileges-on-catalog-objects should really
> > also consider the ongoing discussion about providing policies for the
> > catalog via RLS. If we start pg_dump'ing the ACLs of catalog objects
> > then we'd, presumably, also want to pg_dump out any policies defined
> > against catalog objects.
>
> I would have no qualms supporting ACL changes while not supporting added
> policies, indexes, triggers, rules, inheritance children, extra columns, etc.

Alright.

> Both Oracle and SQL Server invite system object GRANTs, but they don't invite
> system object mutations generally.

Interesting. I hadn't assessed how system object GRANTs in those
systems were handled, so that's good to know.

Thanks!

Stephen


From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: Noah Misch <noah(at)leadboat(dot)com>, Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, Amit Langote <Langote_Amit_f8(at)lab(dot)ntt(dot)co(dot)jp>, David Steele <david(at)pgmasters(dot)net>, Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, Gavin Flower <GavinFlower(at)archidevsys(dot)co(dot)nz>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>, Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2016-01-06 17:29:14
Message-ID: CA+TgmoY2u=CqPKb07sWHhOYKb-aOu1RZ=odcZ2-dbZ4LoJyj1Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Wed, Jan 6, 2016 at 11:13 AM, Stephen Frost <sfrost(at)snowman(dot)net> wrote:
> I just wanted to start off by saying thank you for taking the time read
> and comment with your thoughts on this concept. I was a bit frustrated
> about it feeling rather late, but appreciate the comments which have
> been made as they've certainly been constructive.

Thanks.

>> Well, there's certainly some set of privileges that will make them all
>> work. But it might include more than some of them want. If you done
>> any analysis of this, I have not seen it posted to this thread.
>
> I can certainly work up a formal analysis and submit it for
> consideration.

I would be in favor of that.

>> 1. This doesn't really seem like the same thing. You're introducing
>> something quite new here: these are not role attributes that apply
>> only to the role itself, but inheritable role attributes.
>
> This approach started out by adding role attributes to handle these
> kinds of rights, but in discussion with Tom and Magnus, iirc (no, I
> don't have the specific links or threads, though I have asked Magnus to
> take a look at this thread, as he has time), the idea of default roles
> seemed better specifically because they would then be inheritable and
> granting access could also be delegated.

I agree that predefined roles are better than additional role
attributes. I don't agree that predefined roles are better than GRANT
EXECUTE ON FUNCTION pg_catalog.blah(). I think full support for GRANT
EXECUTE ON FUNCTION pg_catalog.blah() is undeniably useful and will be
a very clear improvement over what we have now. I think predefined
roles are a reasonable thing for somebody to want, but I don't think
it's nearly as clear-cut, and I'm very much unconvinced that we know
that the ones you're proposing are the right ones.

>> 3. It was clear from the outset that the replication role's basic
>> purpose was to be sufficient privilege for a streaming standby and no
>> more. The remit of these roles is a lot less clear, at least to me.
>
> I've certainly intended the intention of these roles to be clear and
> documented. The point I was trying to address above is that we
> certainly appear fine to add additional privileges as new capabilities
> are added to existing role attributes (the entire logical replication
> system was added after the replication role attribute).

Mmmph. I think we got lucky there as much as anything. replication
already allows sufficient privilege to extract all data in the
database, so allowing it to also request a logical change stream isn't
really a privilege escalation. That's not going to be true for what
you are proposing here.

>> > Adding pg_dump dump and restore support for catalog ACLs implies that
>> > we're supporting ACLs on all catalog objects- including tables.
>>
>> Not to me it doesn't. I think we could support it just for functions,
>> and have it continue to be as weird as it is currently for other types
>> of objects until somebody gets around to straightening that out. If
>> we want to support it for more object types, great, but I don't think
>> that's a hard requirement.
>
> Alright, that would certainly simplify things if we're talking about
> only functions. The only concern which I have there is if there are any
> non-function cases that we'll end up coming across, and I'm still a bit
> nervous about the "old pg_dump / new database" restore concern, but
> perhaps that's an acceptable issue.

I wouldn't worry about that a bit. We recommend that users always
pg_dump using the newest version of pg_dump, even if the dumped server
is older. That advice will be entirely satisfactory in this case
also.

> Based on Noah's response (which I respond to below), we seem to still
> be debating the whole concept of default roles. I'm happy to provide
> detailed analysis if we're able to agree on the concept.

I think you need to provide detailed analysis SO THAT we can agree on
the concept.

>> Oh, sure: they are not backup tools specifically. But anything that
>> might need elevated privileges deserves consideration here: what sort
>> of subdivision of the superuser role would make that need go away?
>
> The general approach which I've been using for the default roles is that
> they should grant rights which aren't able to be used to trivially make
> oneself a superuser.

That's a good principle, but not a sufficient guide.

>> Stop. Even if PostgreSQL introduces pg_monitor, check_postgres will do itself
>> a favor by not using it. The moment the two projects' sense of monitoring
>> privileges falls out of lockstep, benefits from using pg_monitor go negative.
>> check_postgres should instead furnish a script that creates a role holding
>> required privileges and/or SECURITY DEFINER helpers. If check_postgres starts
>> using an object, say pgstattuple, it will wish to use it in all versions.
>> Since PostgreSQL will change pg_monitor privileges in major releases only,
>> check_postgres would wait 6-18 months to use a privilege in just one of five
>> supported versions. If PostgreSQL hackers ever disagree with check_postgres
>> hackers about whether a privilege belongs in the pg_monitor role, then
>> check_postgres will wish it had never used pg_monitor. For a sample
>> controversy, some monitoring tool may well call pg_read_file, but that's
>> arguably too much power to be giving _every_ monitoring tool.
>
> Greg and I have chatted previously, and recently again yesterday, about
> the idea of providing SECURITY DEFINER functions and neither of us care
> for that approach. A role which is granted the necessary rights might
> be alright, though I would still contend that a default role is better
> and I don't particularly agree with the slow turn-around time-
> check_postgres is quite mature and does not change very much any more.

I am pretty much entirely in agreement with Noah's analysis here and I
think he put it better than I ever could have done. The rate of
change of check_postgres is utterly irrelevant. We are not going to
have a role called pg_check_postgres built into the database. We
would have, at most, a role called pg_monitor, which would be expected
to be generic across all monitoring tools. But all monitoring tools
will not have the same permissions needs. And they will certainly not
all develop equally quickly. EnterpriseDB has an entire team of
people working on our monitoring tool (PEM). Maybe it's not growing
any new features that require additional permissions at this point,
but that can change as fast as somebody can rewrite the roadmap.
Somebody could offer Greg a million dollars tomorrow to add a whole
bunch of new features to check_postgres.pl, and he might agree to take
on the work.

The point is that with the GRANT EXECUTE ON FUNCTION proposal, authors
of monitoring tools enjoy various really noteworthy advantages. They
can have monitoring roles which have *exactly* the privileges that
their tool needs, not whatever set of permissions (larger or smaller)
the core project has decide the pg_monitor role should have. They can
have optional features requiring extra permissions and those extra
permissions can be granted in precisely those shops where those extra
features are in use. They can deploy a new versions of their
monitoring tool that requires an extra privilege on an existing
PostgreSQL release without requiring any core modifications, which
shaves years of time off the deployment schedule and avoids
contentious arguments with the lovable folks who populate this mailing
list. That sounds *terrific* to me compared to the alternative you
are proposing.

> I don't think that waiting until 9.7 or 10.0 for that
> would be any problem at all for check_postgres,

I think it's nuts to design a solution on the theory that people won't
mind waiting 2 or 3 years to be able to enable a new feature in their
product. Maybe Greg won't mind personally, but if users don't mind
not having the feature for 2 or 3 years, it wasn't a very important
feature in the first place. No software product I've ever worked on
personally could afford to wait an extra 2 or 3 years to deploy a
feature that was truly needed, and most managers I've worked for would
pop a gasket.

> To put it another way, I'd rather *not* tell check_postgres users "sure,
> just grant access to pg_ls_dir to the monitoring user" as that really
> grants more access than the check_postgres check requires.

Sure, that's clearly right, but it doesn't making the pg_monitor
approach better than individual function grants. If you provide a
better alternative there, people can start granting access to that
instead, and in the meantime they can decide whether or not they want
to take the risk of granting access to pg_ls_dir().

> Of course, if we did provide both, then any difference might be able to
> be addressed as a delta against what is provided by the default role.

You can grant extra rights, but you can't revoke some of them away AFAIK.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: Noah Misch <noah(at)leadboat(dot)com>, Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, Amit Langote <Langote_Amit_f8(at)lab(dot)ntt(dot)co(dot)jp>, Robert Haas <robertmhaas(at)gmail(dot)com>, David Steele <david(at)pgmasters(dot)net>, Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, Gavin Flower <GavinFlower(at)archidevsys(dot)co(dot)nz>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>, Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2016-01-17 18:44:56
Message-ID: 20160117184456.GD16401@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Mon, Jan 4, 2016 at 12:55:16PM -0500, Stephen Frost wrote:
> I'd like to be able to include, in both of those, a simple set of
> instructions for granting the necessary rights to the user who is
> running those processes. A set of rights which an administrator can go
> look up and easily read and understand the result of those grants. For
> example:
>
...
> pgbackrest:
>
> To run pgbackrest as a non-superuser and not the 'postgres' system
> user, grant the pg_backup role to the backrest user and ensure the
> backrest system user has read access to the database files (eg: by
> having the system user be a member of the 'postgres' group):
------

Just to clarify, the 'postgres' OS user group cannot read the data
directory, e.g.

drwx------ 19 postgres staff 4096 Jan 17 12:19 data/
^^^group

I assume we don't want to change that.

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ As you are, so once was I. As I am, so you will be. +
+ Roman grave inscription +


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: Noah Misch <noah(at)leadboat(dot)com>, Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, Amit Langote <Langote_Amit_f8(at)lab(dot)ntt(dot)co(dot)jp>, Robert Haas <robertmhaas(at)gmail(dot)com>, David Steele <david(at)pgmasters(dot)net>, Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, Gavin Flower <GavinFlower(at)archidevsys(dot)co(dot)nz>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>, Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2016-01-17 18:49:19
Message-ID: 20160117184918.GE3685@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

* Bruce Momjian (bruce(at)momjian(dot)us) wrote:
> On Mon, Jan 4, 2016 at 12:55:16PM -0500, Stephen Frost wrote:
> > I'd like to be able to include, in both of those, a simple set of
> > instructions for granting the necessary rights to the user who is
> > running those processes. A set of rights which an administrator can go
> > look up and easily read and understand the result of those grants. For
> > example:
> >
> ...
> > pgbackrest:
> >
> > To run pgbackrest as a non-superuser and not the 'postgres' system
> > user, grant the pg_backup role to the backrest user and ensure the
> > backrest system user has read access to the database files (eg: by
> > having the system user be a member of the 'postgres' group):
> ------
>
> Just to clarify, the 'postgres' OS user group cannot read the data
> directory, e.g.
>
> drwx------ 19 postgres staff 4096 Jan 17 12:19 data/
> ^^^group
>
> I assume we don't want to change that.

This is going to be distribution dependent, unfortunately. On
Debian-based distributions, the group is 'postgres' and it'd be
perfectly reasonable to allow that group to read the data directory.

I don't recall offhand if that means we'd have to make changes to allow
that, but, for my 2c, I don't see why we wouldn't allow it to be an
option.

Thanks!

Stephen


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: Noah Misch <noah(at)leadboat(dot)com>, Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, Amit Langote <Langote_Amit_f8(at)lab(dot)ntt(dot)co(dot)jp>, Robert Haas <robertmhaas(at)gmail(dot)com>, David Steele <david(at)pgmasters(dot)net>, Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, Gavin Flower <GavinFlower(at)archidevsys(dot)co(dot)nz>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>, Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2016-01-17 18:55:49
Message-ID: 20160117185549.GE16401@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Sun, Jan 17, 2016 at 01:49:19PM -0500, Stephen Frost wrote:
> * Bruce Momjian (bruce(at)momjian(dot)us) wrote:
> > > pgbackrest:
> > >
> > > To run pgbackrest as a non-superuser and not the 'postgres' system
> > > user, grant the pg_backup role to the backrest user and ensure the
> > > backrest system user has read access to the database files (eg: by
> > > having the system user be a member of the 'postgres' group):
> > ------
> >
> > Just to clarify, the 'postgres' OS user group cannot read the data
> > directory, e.g.
> >
> > drwx------ 19 postgres staff 4096 Jan 17 12:19 data/
> > ^^^group
> >
> > I assume we don't want to change that.
>
> This is going to be distribution dependent, unfortunately. On
> Debian-based distributions, the group is 'postgres' and it'd be
> perfectly reasonable to allow that group to read the data directory.

Well, while the group name would be OS-dependent, the lack of any group
permisions in not OS-dependent and is forced by initdb:

umask(S_IRWXG | S_IRWXO);

create_data_directory();

> I don't recall offhand if that means we'd have to make changes to allow
> that, but, for my 2c, I don't see why we wouldn't allow it to be an
> option.

OK, that would be an initdb change then.

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ As you are, so once was I. As I am, so you will be. +
+ Roman grave inscription +


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: Noah Misch <noah(at)leadboat(dot)com>, Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, Amit Langote <Langote_Amit_f8(at)lab(dot)ntt(dot)co(dot)jp>, Robert Haas <robertmhaas(at)gmail(dot)com>, David Steele <david(at)pgmasters(dot)net>, Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, Gavin Flower <GavinFlower(at)archidevsys(dot)co(dot)nz>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>, Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2016-01-17 18:57:22
Message-ID: 20160117185722.GF3685@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

* Bruce Momjian (bruce(at)momjian(dot)us) wrote:
> On Sun, Jan 17, 2016 at 01:49:19PM -0500, Stephen Frost wrote:
> > * Bruce Momjian (bruce(at)momjian(dot)us) wrote:
> > > > pgbackrest:
> > > >
> > > > To run pgbackrest as a non-superuser and not the 'postgres' system
> > > > user, grant the pg_backup role to the backrest user and ensure the
> > > > backrest system user has read access to the database files (eg: by
> > > > having the system user be a member of the 'postgres' group):
> > > ------
> > >
> > > Just to clarify, the 'postgres' OS user group cannot read the data
> > > directory, e.g.
> > >
> > > drwx------ 19 postgres staff 4096 Jan 17 12:19 data/
> > > ^^^group
> > >
> > > I assume we don't want to change that.
> >
> > This is going to be distribution dependent, unfortunately. On
> > Debian-based distributions, the group is 'postgres' and it'd be
> > perfectly reasonable to allow that group to read the data directory.
>
> Well, while the group name would be OS-dependent, the lack of any group
> permisions in not OS-dependent and is forced by initdb:
>
> umask(S_IRWXG | S_IRWXO);
>
> create_data_directory();

Right, we also check in the backend on startup for certain permissions.
I don't recall offhand if that's forced to 700 or if we allow 750.

> > I don't recall offhand if that means we'd have to make changes to allow
> > that, but, for my 2c, I don't see why we wouldn't allow it to be an
> > option.
>
> OK, that would be an initdb change then.

It would need to be optional, so distributions and users could choose
which makes sense for their systems.

Thanks!

Stephen


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Stephen Frost <sfrost(at)snowman(dot)net>, Noah Misch <noah(at)leadboat(dot)com>, Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, Amit Langote <Langote_Amit_f8(at)lab(dot)ntt(dot)co(dot)jp>, David Steele <david(at)pgmasters(dot)net>, Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, Gavin Flower <GavinFlower(at)archidevsys(dot)co(dot)nz>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>, Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2016-01-17 19:22:42
Message-ID: 20160117192242.GF16401@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Wed, Jan 6, 2016 at 12:29:14PM -0500, Robert Haas wrote:
> The point is that with the GRANT EXECUTE ON FUNCTION proposal, authors
> of monitoring tools enjoy various really noteworthy advantages. They
> can have monitoring roles which have *exactly* the privileges that
> their tool needs, not whatever set of permissions (larger or smaller)
> the core project has decide the pg_monitor role should have. They can
> have optional features requiring extra permissions and those extra
> permissions can be granted in precisely those shops where those extra
> features are in use. They can deploy a new versions of their
> monitoring tool that requires an extra privilege on an existing
> PostgreSQL release without requiring any core modifications, which
> shaves years of time off the deployment schedule and avoids
> contentious arguments with the lovable folks who populate this mailing
> list. That sounds *terrific* to me compared to the alternative you
> are proposing.

I assume backup tools would either document the functions they want
access to via SQL commands, or supply a script. I assume they would
create a non-login role (group) with the desired permissions, and then
have users inherit from that. They would also need to be able to allow
upgrades where they would (conditionally?) add the role and then
add/revoke permissions as needed, e.g. they might not need all
permissions they needed in a previous release, or they might need new
ones.

That all seems very straight-forward to me.

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ As you are, so once was I. As I am, so you will be. +
+ Roman grave inscription +


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, Noah Misch <noah(at)leadboat(dot)com>, Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, Amit Langote <Langote_Amit_f8(at)lab(dot)ntt(dot)co(dot)jp>, David Steele <david(at)pgmasters(dot)net>, Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, Gavin Flower <GavinFlower(at)archidevsys(dot)co(dot)nz>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>, Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2016-01-17 23:58:25
Message-ID: 20160117235825.GG3685@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

* Bruce Momjian (bruce(at)momjian(dot)us) wrote:
> On Wed, Jan 6, 2016 at 12:29:14PM -0500, Robert Haas wrote:
> > The point is that with the GRANT EXECUTE ON FUNCTION proposal, authors
> > of monitoring tools enjoy various really noteworthy advantages. They
> > can have monitoring roles which have *exactly* the privileges that
> > their tool needs, not whatever set of permissions (larger or smaller)
> > the core project has decide the pg_monitor role should have. They can
> > have optional features requiring extra permissions and those extra
> > permissions can be granted in precisely those shops where those extra
> > features are in use. They can deploy a new versions of their
> > monitoring tool that requires an extra privilege on an existing
> > PostgreSQL release without requiring any core modifications, which
> > shaves years of time off the deployment schedule and avoids
> > contentious arguments with the lovable folks who populate this mailing
> > list. That sounds *terrific* to me compared to the alternative you
> > are proposing.
>
> I assume backup tools would either document the functions they want
> access to via SQL commands, or supply a script. I assume they would
> create a non-login role (group) with the desired permissions, and then
> have users inherit from that. They would also need to be able to allow
> upgrades where they would (conditionally?) add the role and then
> add/revoke permissions as needed, e.g. they might not need all
> permissions they needed in a previous release, or they might need new
> ones.
>
> That all seems very straight-forward to me.

I'm not against that idea, though I continue to feel that there are
common sets of privileges which backup tools could leverage.

The other issue that I'm running into, again, while considering how to
move back to ACL-based permissions for these objects is that we can't
grant out the actual permissions which currently exist. That means we
either need to break backwards compatibility, which would be pretty
ugly, in my view, or come up with new functions and then users will have
to know which functions to use when.

As I don't think we really want to break backwards compatibility or
remove existing functionality, the only approach which is going to make
sense is to add additional functions in some cases. In particular, we
will need alternate versions of pg_terminate_backend and
pg_cancel_backend. One thought I had was to make that
'pg_signal_backend', but that sounds like we'd allow any signal sent by
a user with that right, which seems a bit much to me...

Perhaps that's what I'll do though, barring other suggestions.

Thanks!

Stephen


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: Noah Misch <noah(at)leadboat(dot)com>, Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, Amit Langote <Langote_Amit_f8(at)lab(dot)ntt(dot)co(dot)jp>, Robert Haas <robertmhaas(at)gmail(dot)com>, David Steele <david(at)pgmasters(dot)net>, Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, Gavin Flower <GavinFlower(at)archidevsys(dot)co(dot)nz>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>, Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2016-01-18 01:01:09
Message-ID: 20160118010109.GA31450@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Sun, Jan 17, 2016 at 01:57:22PM -0500, Stephen Frost wrote:
> Right, we also check in the backend on startup for certain permissions.
> I don't recall offhand if that's forced to 700 or if we allow 750.
>
> > > I don't recall offhand if that means we'd have to make changes to allow
> > > that, but, for my 2c, I don't see why we wouldn't allow it to be an
> > > option.
> >
> > OK, that would be an initdb change then.
>
> It would need to be optional, so distributions and users could choose
> which makes sense for their systems.

While the group owner of the directory is a distributions question, the
permissions are usually a backup-method-specific requirement. I can see
us creating an SQL function that opens up group permissions on the data
directory for specific backup tools that need it, then granting
permissions on that function to the backup role. This is another
example where different backup tools need different permissions.

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ As you are, so once was I. As I am, so you will be. +
+ Roman grave inscription +


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, Noah Misch <noah(at)leadboat(dot)com>, Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, Amit Langote <Langote_Amit_f8(at)lab(dot)ntt(dot)co(dot)jp>, David Steele <david(at)pgmasters(dot)net>, Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, Gavin Flower <GavinFlower(at)archidevsys(dot)co(dot)nz>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>, Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2016-01-18 01:11:57
Message-ID: 20160118011157.GA31313@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Sun, Jan 17, 2016 at 06:58:25PM -0500, Stephen Frost wrote:
> I'm not against that idea, though I continue to feel that there are
> common sets of privileges which backup tools could leverage.
>
> The other issue that I'm running into, again, while considering how to
> move back to ACL-based permissions for these objects is that we can't
> grant out the actual permissions which currently exist. That means we

Is that because many of them are complex, e.g. you can kill only your
own sessions?

> either need to break backwards compatibility, which would be pretty
> ugly, in my view, or come up with new functions and then users will have
> to know which functions to use when.
>
> As I don't think we really want to break backwards compatibility or
> remove existing functionality, the only approach which is going to make
> sense is to add additional functions in some cases. In particular, we
> will need alternate versions of pg_terminate_backend and
> pg_cancel_backend. One thought I had was to make that

Like these? Could we define own-user-type rights?

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ As you are, so once was I. As I am, so you will be. +
+ Roman grave inscription +


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: Noah Misch <noah(at)leadboat(dot)com>, Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, Amit Langote <Langote_Amit_f8(at)lab(dot)ntt(dot)co(dot)jp>, Robert Haas <robertmhaas(at)gmail(dot)com>, David Steele <david(at)pgmasters(dot)net>, Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, Gavin Flower <GavinFlower(at)archidevsys(dot)co(dot)nz>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>, Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2016-01-18 02:10:23
Message-ID: 20160118021023.GH3685@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Bruce,

* Bruce Momjian (bruce(at)momjian(dot)us) wrote:
> On Sun, Jan 17, 2016 at 01:57:22PM -0500, Stephen Frost wrote:
> > Right, we also check in the backend on startup for certain permissions.
> > I don't recall offhand if that's forced to 700 or if we allow 750.
> >
> > > > I don't recall offhand if that means we'd have to make changes to allow
> > > > that, but, for my 2c, I don't see why we wouldn't allow it to be an
> > > > option.
> > >
> > > OK, that would be an initdb change then.
> >
> > It would need to be optional, so distributions and users could choose
> > which makes sense for their systems.
>
> While the group owner of the directory is a distributions question, the
> permissions are usually a backup-method-specific requirement. I can see
> us creating an SQL function that opens up group permissions on the data
> directory for specific backup tools that need it, then granting
> permissions on that function to the backup role. This is another
> example where different backup tools need different permissions.

I don't believe we can really consider group ownership and group
permissions independently. They really go hand-in-hand. On
RedHat-based system, where the group is set as 'staff', you probably
don't want group permissions to be allowed. On Debian-based systems,
where there is a dedicated 'postgres' group, group permissions are fine
to allow.

Group ownership and permissions aren't a backup-method-specific
requirement either, in my view. I'm happy to chat with Marco (who has
said he would be weighing in on this thread when he is able to)
regarding barman, and whomever would be appropriate for BART (perhaps
you could let me know..?), but if it's possible to do a backup without
being a superuser and with only read access to the data directory, I
would expect every backup soltuion to view that as a feature which they
want to support, as there are environments which will find it desirable,
at a minimum, and even some which will require it.

Lastly, I'm pretty sure this would have to be a postgresql.conf option
as we check the permissions on the data directory on startup. I don't
see how having an SQL function would work there as I certainly wouldn't
want to have the permissions changing on a running system. That strikes
me as being risky without any real benefit. Either it's safe and
acceptable to allow those rights to the group, or it isn't. A temproary
grant really isn't helping with anything that I can see, surely there
are numerous ways to exploit such a time-based grant.

Thanks!

Stephen


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, Noah Misch <noah(at)leadboat(dot)com>, Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, Amit Langote <Langote_Amit_f8(at)lab(dot)ntt(dot)co(dot)jp>, David Steele <david(at)pgmasters(dot)net>, Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, Gavin Flower <GavinFlower(at)archidevsys(dot)co(dot)nz>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>, Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2016-01-18 02:13:05
Message-ID: 20160118021305.GI3685@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

* Bruce Momjian (bruce(at)momjian(dot)us) wrote:
> On Sun, Jan 17, 2016 at 06:58:25PM -0500, Stephen Frost wrote:
> > I'm not against that idea, though I continue to feel that there are
> > common sets of privileges which backup tools could leverage.
> >
> > The other issue that I'm running into, again, while considering how to
> > move back to ACL-based permissions for these objects is that we can't
> > grant out the actual permissions which currently exist. That means we
>
> Is that because many of them are complex, e.g. you can kill only your
> own sessions?

Right.

> > either need to break backwards compatibility, which would be pretty
> > ugly, in my view, or come up with new functions and then users will have
> > to know which functions to use when.
> >
> > As I don't think we really want to break backwards compatibility or
> > remove existing functionality, the only approach which is going to make
> > sense is to add additional functions in some cases. In particular, we
> > will need alternate versions of pg_terminate_backend and
> > pg_cancel_backend. One thought I had was to make that
>
> Like these? Could we define own-user-type rights?

Interesting idea but I don't really see that being general enough that
we would want to burn a GRANT bit for it...

Thanks!

Stephen


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: Noah Misch <noah(at)leadboat(dot)com>, Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, Amit Langote <Langote_Amit_f8(at)lab(dot)ntt(dot)co(dot)jp>, Robert Haas <robertmhaas(at)gmail(dot)com>, David Steele <david(at)pgmasters(dot)net>, Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, Gavin Flower <GavinFlower(at)archidevsys(dot)co(dot)nz>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>, Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2016-01-18 02:20:44
Message-ID: 20160118022044.GD31313@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Sun, Jan 17, 2016 at 09:10:23PM -0500, Stephen Frost wrote:
> > While the group owner of the directory is a distributions question, the
> > permissions are usually a backup-method-specific requirement. I can see
> > us creating an SQL function that opens up group permissions on the data
> > directory for specific backup tools that need it, then granting
> > permissions on that function to the backup role. This is another
> > example where different backup tools need different permissions.
>
> I don't believe we can really consider group ownership and group
> permissions independently. They really go hand-in-hand. On
> RedHat-based system, where the group is set as 'staff', you probably
> don't want group permissions to be allowed. On Debian-based systems,
> where there is a dedicated 'postgres' group, group permissions are fine
> to allow.

Yes, I can see that as problematic. Seems it would have to be something
done by the administrator from the command-line.

> Group ownership and permissions aren't a backup-method-specific
> requirement either, in my view. I'm happy to chat with Marco (who has
> said he would be weighing in on this thread when he is able to)
> regarding barman, and whomever would be appropriate for BART (perhaps
> you could let me know..?), but if it's possible to do a backup without
> being a superuser and with only read access to the data directory, I
> would expect every backup soltuion to view that as a feature which they
> want to support, as there are environments which will find it desirable,
> at a minimum, and even some which will require it.

pg_dump doesn't need to read the PGDATA directory, and I thought this
permission was to be used by pg_dump users as well.

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ As you are, so once was I. As I am, so you will be. +
+ Roman grave inscription +


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: Noah Misch <noah(at)leadboat(dot)com>, Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, Amit Langote <Langote_Amit_f8(at)lab(dot)ntt(dot)co(dot)jp>, Robert Haas <robertmhaas(at)gmail(dot)com>, David Steele <david(at)pgmasters(dot)net>, Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, Gavin Flower <GavinFlower(at)archidevsys(dot)co(dot)nz>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>, Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2016-01-18 02:23:14
Message-ID: 20160118022314.GK3685@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

* Bruce Momjian (bruce(at)momjian(dot)us) wrote:
> On Sun, Jan 17, 2016 at 09:10:23PM -0500, Stephen Frost wrote:
> > > While the group owner of the directory is a distributions question, the
> > > permissions are usually a backup-method-specific requirement. I can see
> > > us creating an SQL function that opens up group permissions on the data
> > > directory for specific backup tools that need it, then granting
> > > permissions on that function to the backup role. This is another
> > > example where different backup tools need different permissions.
> >
> > I don't believe we can really consider group ownership and group
> > permissions independently. They really go hand-in-hand. On
> > RedHat-based system, where the group is set as 'staff', you probably
> > don't want group permissions to be allowed. On Debian-based systems,
> > where there is a dedicated 'postgres' group, group permissions are fine
> > to allow.
>
> Yes, I can see that as problematic. Seems it would have to be something
> done by the administrator from the command-line.

initdb on both RedHat and Debian-based systems is run, generally
speaking, from the packaging scripts. They would be able to pass the
correct options to initdb (or PG itself, if we decide that's
necessary..).

> > Group ownership and permissions aren't a backup-method-specific
> > requirement either, in my view. I'm happy to chat with Marco (who has
> > said he would be weighing in on this thread when he is able to)
> > regarding barman, and whomever would be appropriate for BART (perhaps
> > you could let me know..?), but if it's possible to do a backup without
> > being a superuser and with only read access to the data directory, I
> > would expect every backup soltuion to view that as a feature which they
> > want to support, as there are environments which will find it desirable,
> > at a minimum, and even some which will require it.
>
> pg_dump doesn't need to read the PGDATA directory, and I thought this
> permission was to be used by pg_dump users as well.

No. That has been a source of confusion, though I'm not quite sure how
or why, beyond the general assumption that anything 'backup' must
include 'pg_dump' (I don't generally consider that to be the case,
myself, but it seems others do...).

This is only for file-based backups.

Thanks!

Stephen


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: Noah Misch <noah(at)leadboat(dot)com>, Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, Amit Langote <Langote_Amit_f8(at)lab(dot)ntt(dot)co(dot)jp>, Robert Haas <robertmhaas(at)gmail(dot)com>, David Steele <david(at)pgmasters(dot)net>, Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, Gavin Flower <GavinFlower(at)archidevsys(dot)co(dot)nz>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>, Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2016-01-18 02:31:59
Message-ID: 20160118023159.GE31313@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Sun, Jan 17, 2016 at 09:23:14PM -0500, Stephen Frost wrote:
> > > Group ownership and permissions aren't a backup-method-specific
> > > requirement either, in my view. I'm happy to chat with Marco (who has
> > > said he would be weighing in on this thread when he is able to)
> > > regarding barman, and whomever would be appropriate for BART (perhaps
> > > you could let me know..?), but if it's possible to do a backup without
> > > being a superuser and with only read access to the data directory, I
> > > would expect every backup soltuion to view that as a feature which they
> > > want to support, as there are environments which will find it desirable,
> > > at a minimum, and even some which will require it.
> >
> > pg_dump doesn't need to read the PGDATA directory, and I thought this
> > permission was to be used by pg_dump users as well.
>
> No. That has been a source of confusion, though I'm not quite sure how
> or why, beyond the general assumption that anything 'backup' must
> include 'pg_dump' (I don't generally consider that to be the case,
> myself, but it seems others do...).

I think the source of that is that many people have asked for
backup-only uses, and I thought running pg_dump or pg_dumpall was one of
those cases.

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ As you are, so once was I. As I am, so you will be. +
+ Roman grave inscription +


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: Noah Misch <noah(at)leadboat(dot)com>, Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, Amit Langote <Langote_Amit_f8(at)lab(dot)ntt(dot)co(dot)jp>, Robert Haas <robertmhaas(at)gmail(dot)com>, David Steele <david(at)pgmasters(dot)net>, Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, Gavin Flower <GavinFlower(at)archidevsys(dot)co(dot)nz>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>, Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2016-01-18 02:33:44
Message-ID: 20160118023343.GL3685@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

* Bruce Momjian (bruce(at)momjian(dot)us) wrote:
> On Sun, Jan 17, 2016 at 09:23:14PM -0500, Stephen Frost wrote:
> > > > Group ownership and permissions aren't a backup-method-specific
> > > > requirement either, in my view. I'm happy to chat with Marco (who has
> > > > said he would be weighing in on this thread when he is able to)
> > > > regarding barman, and whomever would be appropriate for BART (perhaps
> > > > you could let me know..?), but if it's possible to do a backup without
> > > > being a superuser and with only read access to the data directory, I
> > > > would expect every backup soltuion to view that as a feature which they
> > > > want to support, as there are environments which will find it desirable,
> > > > at a minimum, and even some which will require it.
> > >
> > > pg_dump doesn't need to read the PGDATA directory, and I thought this
> > > permission was to be used by pg_dump users as well.
> >
> > No. That has been a source of confusion, though I'm not quite sure how
> > or why, beyond the general assumption that anything 'backup' must
> > include 'pg_dump' (I don't generally consider that to be the case,
> > myself, but it seems others do...).
>
> I think the source of that is that many people have asked for
> backup-only uses, and I thought running pg_dump or pg_dumpall was one of
> those cases.

I'd want that to be a seperate permission which would really be
something along the lines of "allowed to read everything through a DB
connection", which is what pg_dump/pg_dumpall need.

Thanks!

Stephen


From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: Bruce Momjian <bruce(at)momjian(dot)us>, Noah Misch <noah(at)leadboat(dot)com>, Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, Amit Langote <Langote_Amit_f8(at)lab(dot)ntt(dot)co(dot)jp>, David Steele <david(at)pgmasters(dot)net>, Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, Gavin Flower <GavinFlower(at)archidevsys(dot)co(dot)nz>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>, Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2016-01-18 18:04:24
Message-ID: CA+TgmoZqSMBec4igoan2pwCgcJbNzGwihxgWiJ2r76zx1ABtxA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Sun, Jan 17, 2016 at 6:58 PM, Stephen Frost <sfrost(at)snowman(dot)net> wrote:
> I'm not against that idea, though I continue to feel that there are
> common sets of privileges which backup tools could leverage.
>
> The other issue that I'm running into, again, while considering how to
> move back to ACL-based permissions for these objects is that we can't
> grant out the actual permissions which currently exist. That means we
> either need to break backwards compatibility, which would be pretty
> ugly, in my view, or come up with new functions and then users will have
> to know which functions to use when.
>
> As I don't think we really want to break backwards compatibility or
> remove existing functionality, the only approach which is going to make
> sense is to add additional functions in some cases. In particular, we
> will need alternate versions of pg_terminate_backend and
> pg_cancel_backend. One thought I had was to make that
> 'pg_signal_backend', but that sounds like we'd allow any signal sent by
> a user with that right, which seems a bit much to me...

So, this seems like a case where a built-in role would be
well-justified. I don't really believe in built-in roles as a way of
bundling related permissions; I know you do, but I don't. I'd rather
see the individual function permissions granted individually. But
here you are talking about a variable level of access to the same
function, depending on role. And for that it seems to me that a
built-in role has a lot more to recommend it in that case than it does
in the other. If you have been granted pg_whack, you can signal any
process on the system; otherwise just your own. Those checks are
internal to pg_terminate_backend/pg_cancel_backend so GRANT is not a
substitute.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


From: David Steele <david(at)pgmasters(dot)net>
To: Stephen Frost <sfrost(at)snowman(dot)net>, Bruce Momjian <bruce(at)momjian(dot)us>
Cc: Noah Misch <noah(at)leadboat(dot)com>, Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, Amit Langote <Langote_Amit_f8(at)lab(dot)ntt(dot)co(dot)jp>, Robert Haas <robertmhaas(at)gmail(dot)com>, Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, Gavin Flower <GavinFlower(at)archidevsys(dot)co(dot)nz>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>, Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2016-01-19 14:20:03
Message-ID: 569E4613.1010707@pgmasters.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 1/17/16 9:10 PM, Stephen Frost wrote:
> but if it's possible to do a backup without
> being a superuser and with only read access to the data directory, I
> would expect every backup soltuion to view that as a feature which they
> want to support, as there are environments which will find it desirable,
> at a minimum, and even some which will require it.

This would certainly be a desirable feature for pgBackRest. The fewer
processes running with the ability to alter the cluster the better.
Even if they are well-tested it's still one less thing to worry about.

--
-David
david(at)pgmasters(dot)net


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Bruce Momjian <bruce(at)momjian(dot)us>, Noah Misch <noah(at)leadboat(dot)com>, Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, Amit Langote <Langote_Amit_f8(at)lab(dot)ntt(dot)co(dot)jp>, David Steele <david(at)pgmasters(dot)net>, Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, Gavin Flower <GavinFlower(at)archidevsys(dot)co(dot)nz>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>, Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2016-01-28 16:04:30
Message-ID: 20160128160430.GR3331@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

* Robert Haas (robertmhaas(at)gmail(dot)com) wrote:
> On Sun, Jan 17, 2016 at 6:58 PM, Stephen Frost <sfrost(at)snowman(dot)net> wrote:
> > I'm not against that idea, though I continue to feel that there are
> > common sets of privileges which backup tools could leverage.
> >
> > The other issue that I'm running into, again, while considering how to
> > move back to ACL-based permissions for these objects is that we can't
> > grant out the actual permissions which currently exist. That means we
> > either need to break backwards compatibility, which would be pretty
> > ugly, in my view, or come up with new functions and then users will have
> > to know which functions to use when.
> >
> > As I don't think we really want to break backwards compatibility or
> > remove existing functionality, the only approach which is going to make
> > sense is to add additional functions in some cases. In particular, we
> > will need alternate versions of pg_terminate_backend and
> > pg_cancel_backend. One thought I had was to make that
> > 'pg_signal_backend', but that sounds like we'd allow any signal sent by
> > a user with that right, which seems a bit much to me...
>
> So, this seems like a case where a built-in role would be
> well-justified. I don't really believe in built-in roles as a way of
> bundling related permissions; I know you do, but I don't. I'd rather
> see the individual function permissions granted individually. But
> here you are talking about a variable level of access to the same
> function, depending on role. And for that it seems to me that a
> built-in role has a lot more to recommend it in that case than it does
> in the other. If you have been granted pg_whack, you can signal any
> process on the system; otherwise just your own. Those checks are
> internal to pg_terminate_backend/pg_cancel_backend so GRANT is not a
> substitute.

If we extend this into the future then it seems to potentially fall
afoul of Noah's concern that we're going to end up with two different
ways of saying GRANT EXECUTE X ON Y. Consider the more complicated case
of pg_stat_activity, where values are shown or hidden based on who the
current role is. The policy system only supports whole-row, today, but
the question has already come up, both on the lists and off, of support
for hiding individual column values for certain rows, exactly as we do
today for pg_stat_activity. Once we reach that point, we'll have a way
to GRANT out these rights and a default role which just has them.

Personally, I don't have any particular issue having both, but the
desire was stated that it would be better to have the regular
GRANT EXECUTE ON catalog_func() working before we consider having
default roles for same. That moves the goal posts awful far though, if
we're to stick with that and consider how we might extend the GRANT
system in the future.

What got me thinking along these lines was a question posed by Bruce
(Bruce, feel free to chime in if I've misunderstood) to me at SCALE
where we were chatting a bit about this, which was- how could we extend
GRANT to support the permissions that we actually wish
pg_terminate_backend() and pg_cancel_backend() to have, instead of using
a default role? I didn't think too much on it at the time as it strikes
me as a pretty narrow use-case and requiring quite a bit of complexity
to get right, but there again, I'd certainly view a system where the
user is allowed to have pg_start_backup() rights but not
pg_stop_backup() as being quite a small use-case also, yet that's the
direction we're largely going in with this discussion.

Thanks!

Stephen


From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: Bruce Momjian <bruce(at)momjian(dot)us>, Noah Misch <noah(at)leadboat(dot)com>, Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, Amit Langote <Langote_Amit_f8(at)lab(dot)ntt(dot)co(dot)jp>, David Steele <david(at)pgmasters(dot)net>, Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, Gavin Flower <GavinFlower(at)archidevsys(dot)co(dot)nz>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>, Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2016-01-28 16:17:42
Message-ID: CA+TgmobjgtUodMNSm0O64JrJwt9kbgtGS4j1E1sp=NWTeO_d7A@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Thu, Jan 28, 2016 at 11:04 AM, Stephen Frost <sfrost(at)snowman(dot)net> wrote:
>> So, this seems like a case where a built-in role would be
>> well-justified. I don't really believe in built-in roles as a way of
>> bundling related permissions; I know you do, but I don't. I'd rather
>> see the individual function permissions granted individually. But
>> here you are talking about a variable level of access to the same
>> function, depending on role. And for that it seems to me that a
>> built-in role has a lot more to recommend it in that case than it does
>> in the other. If you have been granted pg_whack, you can signal any
>> process on the system; otherwise just your own. Those checks are
>> internal to pg_terminate_backend/pg_cancel_backend so GRANT is not a
>> substitute.
>
> If we extend this into the future then it seems to potentially fall
> afoul of Noah's concern that we're going to end up with two different
> ways of saying GRANT EXECUTE X ON Y. Consider the more complicated case
> of pg_stat_activity, where values are shown or hidden based on who the
> current role is. The policy system only supports whole-row, today, but
> the question has already come up, both on the lists and off, of support
> for hiding individual column values for certain rows, exactly as we do
> today for pg_stat_activity. Once we reach that point, we'll have a way
> to GRANT out these rights and a default role which just has them.

Well, I'm not saying that predefined rolls are the *only* way to solve
a problem like this, but I think they're one way and I don't clearly
see that something else is better. However, my precise point is that
we should *not* have predefined rolls that precisely duplicate the
result of GRANT EXECUTE X ON Y. Having predefined rolls that change
the behavior of the system in other ways is a different thing. So I
don't see how this falls afoul of Noah's concern. (If it does,
perhaps he can clarify.)

> Personally, I don't have any particular issue having both, but the
> desire was stated that it would be better to have the regular
> GRANT EXECUTE ON catalog_func() working before we consider having
> default roles for same. That moves the goal posts awful far though, if
> we're to stick with that and consider how we might extend the GRANT
> system in the future.

I don't think it moves the goal posts all that far. Convincing
pg_dump to dump grants on system functions shouldn't be a crazy large
patch.

> What got me thinking along these lines was a question posed by Bruce
> (Bruce, feel free to chime in if I've misunderstood) to me at SCALE
> where we were chatting a bit about this, which was- how could we extend
> GRANT to support the permissions that we actually wish
> pg_terminate_backend() and pg_cancel_backend() to have, instead of using
> a default role? I didn't think too much on it at the time as it strikes
> me as a pretty narrow use-case and requiring quite a bit of complexity
> to get right, but there again, I'd certainly view a system where the
> user is allowed to have pg_start_backup() rights but not
> pg_stop_backup() as being quite a small use-case also, yet that's the
> direction we're largely going in with this discussion.

Well, sure, in that largely artificial example it's not hard to say
ha, ha, silly, but the actual examples we looked at upthread were much
less obviously silly. There was plenty of room for argument about the
precise contours of each predefined role.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Bruce Momjian <bruce(at)momjian(dot)us>, Noah Misch <noah(at)leadboat(dot)com>, Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, Amit Langote <Langote_Amit_f8(at)lab(dot)ntt(dot)co(dot)jp>, David Steele <david(at)pgmasters(dot)net>, Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, Gavin Flower <GavinFlower(at)archidevsys(dot)co(dot)nz>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>, Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2016-01-28 21:37:42
Message-ID: 20160128213742.GV3331@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

* Robert Haas (robertmhaas(at)gmail(dot)com) wrote:
> On Thu, Jan 28, 2016 at 11:04 AM, Stephen Frost <sfrost(at)snowman(dot)net> wrote:
> >> So, this seems like a case where a built-in role would be
> >> well-justified. I don't really believe in built-in roles as a way of
> >> bundling related permissions; I know you do, but I don't. I'd rather
> >> see the individual function permissions granted individually. But
> >> here you are talking about a variable level of access to the same
> >> function, depending on role. And for that it seems to me that a
> >> built-in role has a lot more to recommend it in that case than it does
> >> in the other. If you have been granted pg_whack, you can signal any
> >> process on the system; otherwise just your own. Those checks are
> >> internal to pg_terminate_backend/pg_cancel_backend so GRANT is not a
> >> substitute.
> >
> > If we extend this into the future then it seems to potentially fall
> > afoul of Noah's concern that we're going to end up with two different
> > ways of saying GRANT EXECUTE X ON Y. Consider the more complicated case
> > of pg_stat_activity, where values are shown or hidden based on who the
> > current role is. The policy system only supports whole-row, today, but
> > the question has already come up, both on the lists and off, of support
> > for hiding individual column values for certain rows, exactly as we do
> > today for pg_stat_activity. Once we reach that point, we'll have a way
> > to GRANT out these rights and a default role which just has them.
>
> Well, I'm not saying that predefined rolls are the *only* way to solve
> a problem like this, but I think they're one way and I don't clearly
> see that something else is better. However, my precise point is that
> we should *not* have predefined rolls that precisely duplicate the
> result of GRANT EXECUTE X ON Y. Having predefined rolls that change
> the behavior of the system in other ways is a different thing. So I
> don't see how this falls afoul of Noah's concern. (If it does,
> perhaps he can clarify.)

Apologies if it seems like what I'm getting at is obtuse but I'm trying
to generalize this, to provide guidance on how to handle the larger set
of privileges.

If I'm following correctly, having default roles for cases where the
role is specifically for something more than 'GRANT EXECUTE X ON Y' (or
a set of such commands..?) makes sense. Going back to the list of
roles, that would mean that default roles:

pg_monitor

Allows roles granted more information from pg_stat_activity. Can't be
just a regular non-default-role right as we don't, currently, have a
way to say "filter out the values of certain columns on certain rows,
but not on others."

(There's a question here though- for the privileges which will be
directly GRANT'able, should we GRANT those to pg_monitor, or have
pg_monitor only provide unfiltered access to pg_stat_activity, or..?
Further, if it's only for pg_stat_activity, should we name it
something else?)

pg_signal_backend

Allows roles to signal other backend processes beyond those backends
which are owned by a user they are a role member of. Can't be a
regular non-default-role right as we don't, currently, have any way to
GRANT rights to send signals only to backends you own or are a member
of.

pg_replication

Allows roles to use the various replication functions. Can't be a
regular non-default-role right as the REPLICATION role attribute
allows access to those functions and the GRANT system has no way of
saying "allow access to these functions if they have role attribute
X."

Make sense, as these are cases where we can't simply write GRANT
statements and get the same result, but we don't need (or at least,
shouldn't have without supporting GRANT on catalog objects and agreement
on what they're intended for):

pg_backup

pg_start_backup(), pg_stop_backup(), pg_switch_xlog(), and
pg_create_restore_point() will all be managed by the normal GRANT
system and therefore we don't need a default role for those use-cases.

pg_file_settings

pg_file_settings() function and pg_file_settings view will be managed
by the normal GRANT system and therefore we don't need a default role
for those use-cases.

pg_replay

pg_xlog_replay_pause(), and pg_xlog_replay_resume() will be managed
by the normal GRANT system and therefore we don't need a default role
for those use-cases.

pg_rotate_logfile

pg_rotate_logfile() will be managed by the normal GRANT system and
therefore we don't need a default role for that use-cases.

> > Personally, I don't have any particular issue having both, but the
> > desire was stated that it would be better to have the regular
> > GRANT EXECUTE ON catalog_func() working before we consider having
> > default roles for same. That moves the goal posts awful far though, if
> > we're to stick with that and consider how we might extend the GRANT
> > system in the future.
>
> I don't think it moves the goal posts all that far. Convincing
> pg_dump to dump grants on system functions shouldn't be a crazy large
> patch.

I wasn't clear as to what I was referring to here. I've already written
a patch to pg_dump to support grants on system objects and agree that
it's at least reasonable. When I was talking about moving goalposts, I
was saying that if we don't want default roles until the only thing
they're doing is being GRANT'd rights which administrators could GRANT
or create policies for themselves (which may one day be the case) then
that would imply a much larger amount of effort (support for hiding
columns based on policies, and perhaps even some way to GRANT access to
functions to operate only against other backends which are controlled by
a role of which you are a member).

> > What got me thinking along these lines was a question posed by Bruce
> > (Bruce, feel free to chime in if I've misunderstood) to me at SCALE
> > where we were chatting a bit about this, which was- how could we extend
> > GRANT to support the permissions that we actually wish
> > pg_terminate_backend() and pg_cancel_backend() to have, instead of using
> > a default role? I didn't think too much on it at the time as it strikes
> > me as a pretty narrow use-case and requiring quite a bit of complexity
> > to get right, but there again, I'd certainly view a system where the
> > user is allowed to have pg_start_backup() rights but not
> > pg_stop_backup() as being quite a small use-case also, yet that's the
> > direction we're largely going in with this discussion.
>
> Well, sure, in that largely artificial example it's not hard to say
> ha, ha, silly, but the actual examples we looked at upthread were much
> less obviously silly. There was plenty of room for argument about the
> precise contours of each predefined role.

I'm sure I'm looking at this through rosy colored goggles, but going
back over this thread, which started in October of 2014, and the other
one which I started, the questions which have come up around the rights
granted the default roles have been:

People would really like a default role that allowed pg_dump to always
work and maybe we should name 'pg_backup' something else, since it's
different from that.

Shouldn't we restrict access to the various pg_*_xlog_location()
functions? (I continue to agree that we should, but that's really an
independent discussion..)

The only specific discussions or questions about the permissions
included in the default roles, based on my ~1h review of the threads,
were from Michael regarding pg_switch_xlog(), who ultimately agreed that
it was fine as part of pg_backup, and from Fujii who suggested that
pg_monitor also have access to pgstattuple(), which is a contrib module
(and hence, I hadn't really thought about it, to be frank, tho it could
certainly be modified to work with a pg_monitor role). The other
concerns raised have not included specific issues or questions about the
privileges included but rather contended that there may be issues.

That's not to say that there couldn't be issues raised, but I guess I
don't see that many possible combinations for the sets of rights
included, which are the only ones sensible to consider based on my
review of the "if (!superuser()) ereport()" calls in the backend (from:
http://www.postgresql.org/message-id/20141015052259.GG28859@tamriel.snowman.net).

Thanks!

Stephen


From: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, Bruce Momjian <bruce(at)momjian(dot)us>, Noah Misch <noah(at)leadboat(dot)com>, Amit Langote <Langote_Amit_f8(at)lab(dot)ntt(dot)co(dot)jp>, David Steele <david(at)pgmasters(dot)net>, Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, Gavin Flower <GavinFlower(at)archidevsys(dot)co(dot)nz>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>, Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2016-01-29 05:14:49
Message-ID: CAB7nPqTWEgQxpQyXTXTp4XkRtvRWYF-Z+N0kK-Qsb-MTSCYPrg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Fri, Jan 29, 2016 at 6:37 AM, Stephen Frost <sfrost(at)snowman(dot)net> wrote:
> * Robert Haas (robertmhaas(at)gmail(dot)com) wrote:
>> On Thu, Jan 28, 2016 at 11:04 AM, Stephen Frost <sfrost(at)snowman(dot)net>
wrote:
>> > Personally, I don't have any particular issue having both, but the
>> > desire was stated that it would be better to have the regular
>> > GRANT EXECUTE ON catalog_func() working before we consider having
>> > default roles for same. That moves the goal posts awful far though, if
>> > we're to stick with that and consider how we might extend the GRANT
>> > system in the future.
>>
>> I don't think it moves the goal posts all that far. Convincing
>> pg_dump to dump grants on system functions shouldn't be a crazy large
>> patch.
>
> I wasn't clear as to what I was referring to here. I've already written
> a patch to pg_dump to support grants on system objects and agree that
> it's at least reasonable.

Is it already posted somewhere? I don't recall seeing it. Robert and Noah
have a point that this would be useful for users who would like to dump
GRANT/REVOKE rights on system functions & all, using a new option in
pg_dumpall, say --with-system-acl or --with-system-privileges. If at least
the three of you are agreeing here I think that we should try to move at
least toward this goal first. That seems a largely doable goal for 9.6. For
the set of default roles, there is clearly no clear consensus regarding
what each role should do or not, and under which limitation it should
operate.
--
Michael


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, Bruce Momjian <bruce(at)momjian(dot)us>, Noah Misch <noah(at)leadboat(dot)com>, Amit Langote <Langote_Amit_f8(at)lab(dot)ntt(dot)co(dot)jp>, David Steele <david(at)pgmasters(dot)net>, Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, Gavin Flower <GavinFlower(at)archidevsys(dot)co(dot)nz>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>, Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2016-01-29 14:41:20
Message-ID: 20160129144120.GA3331@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Michael,

* Michael Paquier (michael(dot)paquier(at)gmail(dot)com) wrote:
> On Fri, Jan 29, 2016 at 6:37 AM, Stephen Frost <sfrost(at)snowman(dot)net> wrote:
> > * Robert Haas (robertmhaas(at)gmail(dot)com) wrote:
> >> On Thu, Jan 28, 2016 at 11:04 AM, Stephen Frost <sfrost(at)snowman(dot)net>
> wrote:
> >> > Personally, I don't have any particular issue having both, but the
> >> > desire was stated that it would be better to have the regular
> >> > GRANT EXECUTE ON catalog_func() working before we consider having
> >> > default roles for same. That moves the goal posts awful far though, if
> >> > we're to stick with that and consider how we might extend the GRANT
> >> > system in the future.
> >>
> >> I don't think it moves the goal posts all that far. Convincing
> >> pg_dump to dump grants on system functions shouldn't be a crazy large
> >> patch.
> >
> > I wasn't clear as to what I was referring to here. I've already written
> > a patch to pg_dump to support grants on system objects and agree that
> > it's at least reasonable.
>
> Is it already posted somewhere? I don't recall seeing it. Robert and Noah
> have a point that this would be useful for users who would like to dump
> GRANT/REVOKE rights on system functions & all, using a new option in
> pg_dumpall, say --with-system-acl or --with-system-privileges.

Multiple versions were posted on this thread. I don't fault you for not
finding it, this thread is a bit long in the tooth. The one I'm
currently working from is:

http://www.postgresql.org/message-id/attachment/38049/catalog_function_acls_v4.patch

I'm going to split up the pg_dump changes and the backend changes, as
they can logically go in independently (though without both, we're not
moving the needle very far with regards to what administrators can do).

> If at least
> the three of you are agreeing here I think that we should try to move at
> least toward this goal first. That seems a largely doable goal for 9.6. For
> the set of default roles, there is clearly no clear consensus regarding
> what each role should do or not, and under which limitation it should
> operate.

I'm trying to work towards a consensus on the default roles, hence the
questions and discussion posed in the email you replied to.

Thanks!

Stephen


From: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, Bruce Momjian <bruce(at)momjian(dot)us>, Noah Misch <noah(at)leadboat(dot)com>, Amit Langote <Langote_Amit_f8(at)lab(dot)ntt(dot)co(dot)jp>, David Steele <david(at)pgmasters(dot)net>, Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, Gavin Flower <GavinFlower(at)archidevsys(dot)co(dot)nz>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>, Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2016-01-30 02:09:42
Message-ID: CAB7nPqSwm4_q2hAE3kN=j3Hoxhs6hYe5tj7M2dRSc3HU01v6Yg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Fri, Jan 29, 2016 at 11:41 PM, Stephen Frost <sfrost(at)snowman(dot)net> wrote:
> Michael,
>
> * Michael Paquier (michael(dot)paquier(at)gmail(dot)com) wrote:
>> On Fri, Jan 29, 2016 at 6:37 AM, Stephen Frost <sfrost(at)snowman(dot)net> wrote:
>> > * Robert Haas (robertmhaas(at)gmail(dot)com) wrote:
>> >> On Thu, Jan 28, 2016 at 11:04 AM, Stephen Frost <sfrost(at)snowman(dot)net>
>> wrote:
>> >> > Personally, I don't have any particular issue having both, but the
>> >> > desire was stated that it would be better to have the regular
>> >> > GRANT EXECUTE ON catalog_func() working before we consider having
>> >> > default roles for same. That moves the goal posts awful far though, if
>> >> > we're to stick with that and consider how we might extend the GRANT
>> >> > system in the future.
>> >>
>> >> I don't think it moves the goal posts all that far. Convincing
>> >> pg_dump to dump grants on system functions shouldn't be a crazy large
>> >> patch.
>> >
>> > I wasn't clear as to what I was referring to here. I've already written
>> > a patch to pg_dump to support grants on system objects and agree that
>> > it's at least reasonable.
>>
>> Is it already posted somewhere? I don't recall seeing it. Robert and Noah
>> have a point that this would be useful for users who would like to dump
>> GRANT/REVOKE rights on system functions & all, using a new option in
>> pg_dumpall, say --with-system-acl or --with-system-privileges.
>
> Multiple versions were posted on this thread. I don't fault you for not
> finding it, this thread is a bit long in the tooth. The one I'm
> currently working from is:
>
> http://www.postgresql.org/message-id/attachment/38049/catalog_function_acls_v4.patch
>
> I'm going to split up the pg_dump changes and the backend changes, as
> they can logically go in independently (though without both, we're not
> moving the needle very far with regards to what administrators can do).

OK. Looks like a good way to move forward to me.

>> If at least
>> the three of you are agreeing here I think that we should try to move at
>> least toward this goal first. That seems a largely doable goal for 9.6. For
>> the set of default roles, there is clearly no clear consensus regarding
>> what each role should do or not, and under which limitation it should
>> operate.
>
> I'm trying to work towards a consensus on the default roles, hence the
> questions and discussion posed in the email you replied to.

So the current CF entry should be marked as returned with feedback
perhaps? What do you think? Once patches are ready for the default
roles in backend and for pg_dump, we could then work on reviewing them
separately.
--
Michael


From: Craig Ringer <craig(at)2ndquadrant(dot)com>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, Bruce Momjian <bruce(at)momjian(dot)us>, Noah Misch <noah(at)leadboat(dot)com>, Amit Langote <Langote_Amit_f8(at)lab(dot)ntt(dot)co(dot)jp>, David Steele <david(at)pgmasters(dot)net>, Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, Gavin Flower <GavinFlower(at)archidevsys(dot)co(dot)nz>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>, Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2016-01-30 20:32:13
Message-ID: CAMsr+YEqgvT8K0DDsAVa8QGagkvtf7JdXiWAb3PZMQqpY93RaA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 29 January 2016 at 22:41, Stephen Frost <sfrost(at)snowman(dot)net> wrote:

> Michael,
>
> * Michael Paquier (michael(dot)paquier(at)gmail(dot)com) wrote:
> > On Fri, Jan 29, 2016 at 6:37 AM, Stephen Frost <sfrost(at)snowman(dot)net>
> wrote:
> > > * Robert Haas (robertmhaas(at)gmail(dot)com) wrote:
> > >> On Thu, Jan 28, 2016 at 11:04 AM, Stephen Frost <sfrost(at)snowman(dot)net>
> > wrote:
> > >> > Personally, I don't have any particular issue having both, but the
> > >> > desire was stated that it would be better to have the regular
> > >> > GRANT EXECUTE ON catalog_func() working before we consider having
> > >> > default roles for same. That moves the goal posts awful far
> though, if
> > >> > we're to stick with that and consider how we might extend the GRANT
> > >> > system in the future.
> > >>
> > >> I don't think it moves the goal posts all that far. Convincing
> > >> pg_dump to dump grants on system functions shouldn't be a crazy large
> > >> patch.
> > >
> > > I wasn't clear as to what I was referring to here. I've already
> written
> > > a patch to pg_dump to support grants on system objects and agree that
> > > it's at least reasonable.
> >
> > Is it already posted somewhere? I don't recall seeing it. Robert and Noah
> > have a point that this would be useful for users who would like to dump
> > GRANT/REVOKE rights on system functions & all, using a new option in
> > pg_dumpall, say --with-system-acl or --with-system-privileges.
>
> Multiple versions were posted on this thread. I don't fault you for not
> finding it, this thread is a bit long in the tooth. The one I'm
> currently working from is
>
>
It strikes me that this thread would possibly benefit from a wiki page
outlining the permissions, overall concepts, etc, as it's getting awfully
hard to follow.

--
Craig Ringer http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services


From: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
To: Craig Ringer <craig(at)2ndquadrant(dot)com>
Cc: Stephen Frost <sfrost(at)snowman(dot)net>, Robert Haas <robertmhaas(at)gmail(dot)com>, Bruce Momjian <bruce(at)momjian(dot)us>, Noah Misch <noah(at)leadboat(dot)com>, Amit Langote <Langote_Amit_f8(at)lab(dot)ntt(dot)co(dot)jp>, David Steele <david(at)pgmasters(dot)net>, Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, Gavin Flower <GavinFlower(at)archidevsys(dot)co(dot)nz>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>, Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2016-01-30 22:55:26
Message-ID: CAB7nPqTb-iPpHccwvimg4bR1_jxwjppQL23Kx137FRhyE-7mCw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Sun, Jan 31, 2016 at 5:32 AM, Craig Ringer <craig(at)2ndquadrant(dot)com> wrote:
> On 29 January 2016 at 22:41, Stephen Frost <sfrost(at)snowman(dot)net> wrote:
>>
>> Michael,
>>
>> * Michael Paquier (michael(dot)paquier(at)gmail(dot)com) wrote:
>> > On Fri, Jan 29, 2016 at 6:37 AM, Stephen Frost <sfrost(at)snowman(dot)net>
>> > wrote:
>> > > * Robert Haas (robertmhaas(at)gmail(dot)com) wrote:
>> > >> On Thu, Jan 28, 2016 at 11:04 AM, Stephen Frost <sfrost(at)snowman(dot)net>
>> > wrote:
>> > >> > Personally, I don't have any particular issue having both, but the
>> > >> > desire was stated that it would be better to have the regular
>> > >> > GRANT EXECUTE ON catalog_func() working before we consider having
>> > >> > default roles for same. That moves the goal posts awful far
>> > >> > though, if
>> > >> > we're to stick with that and consider how we might extend the GRANT
>> > >> > system in the future.
>> > >>
>> > >> I don't think it moves the goal posts all that far. Convincing
>> > >> pg_dump to dump grants on system functions shouldn't be a crazy large
>> > >> patch.
>> > >
>> > > I wasn't clear as to what I was referring to here. I've already
>> > > written
>> > > a patch to pg_dump to support grants on system objects and agree that
>> > > it's at least reasonable.
>> >
>> > Is it already posted somewhere? I don't recall seeing it. Robert and
>> > Noah
>> > have a point that this would be useful for users who would like to dump
>> > GRANT/REVOKE rights on system functions & all, using a new option in
>> > pg_dumpall, say --with-system-acl or --with-system-privileges.
>>
>> Multiple versions were posted on this thread. I don't fault you for not
>> finding it, this thread is a bit long in the tooth. The one I'm
>> currently working from is
>>
>
> It strikes me that this thread would possibly benefit from a wiki page
> outlining the permissions, overall concepts, etc, as it's getting awfully
> hard to follow.

+1. This has proved to be very beneficial for UPSERT.
--
Michael


From: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
To: Craig Ringer <craig(at)2ndquadrant(dot)com>
Cc: Stephen Frost <sfrost(at)snowman(dot)net>, Robert Haas <robertmhaas(at)gmail(dot)com>, Bruce Momjian <bruce(at)momjian(dot)us>, Noah Misch <noah(at)leadboat(dot)com>, Amit Langote <Langote_Amit_f8(at)lab(dot)ntt(dot)co(dot)jp>, David Steele <david(at)pgmasters(dot)net>, Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, Gavin Flower <GavinFlower(at)archidevsys(dot)co(dot)nz>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>, Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2016-01-31 12:30:54
Message-ID: CAB7nPqTRZJxrvQR16qK3kgNWeZhMgCAY7AKbo+UuLJG+9B1u6A@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Sun, Jan 31, 2016 at 7:55 AM, Michael Paquier
<michael(dot)paquier(at)gmail(dot)com> wrote:
> On Sun, Jan 31, 2016 at 5:32 AM, Craig Ringer <craig(at)2ndquadrant(dot)com> wrote:
>> On 29 January 2016 at 22:41, Stephen Frost <sfrost(at)snowman(dot)net> wrote:
>>>
>>> Michael,
>>>
>>> * Michael Paquier (michael(dot)paquier(at)gmail(dot)com) wrote:
>>> > On Fri, Jan 29, 2016 at 6:37 AM, Stephen Frost <sfrost(at)snowman(dot)net>
>>> > wrote:
>>> > > * Robert Haas (robertmhaas(at)gmail(dot)com) wrote:
>>> > >> On Thu, Jan 28, 2016 at 11:04 AM, Stephen Frost <sfrost(at)snowman(dot)net>
>>> > wrote:
>>> > >> > Personally, I don't have any particular issue having both, but the
>>> > >> > desire was stated that it would be better to have the regular
>>> > >> > GRANT EXECUTE ON catalog_func() working before we consider having
>>> > >> > default roles for same. That moves the goal posts awful far
>>> > >> > though, if
>>> > >> > we're to stick with that and consider how we might extend the GRANT
>>> > >> > system in the future.
>>> > >>
>>> > >> I don't think it moves the goal posts all that far. Convincing
>>> > >> pg_dump to dump grants on system functions shouldn't be a crazy large
>>> > >> patch.
>>> > >
>>> > > I wasn't clear as to what I was referring to here. I've already
>>> > > written
>>> > > a patch to pg_dump to support grants on system objects and agree that
>>> > > it's at least reasonable.
>>> >
>>> > Is it already posted somewhere? I don't recall seeing it. Robert and
>>> > Noah
>>> > have a point that this would be useful for users who would like to dump
>>> > GRANT/REVOKE rights on system functions & all, using a new option in
>>> > pg_dumpall, say --with-system-acl or --with-system-privileges.
>>>
>>> Multiple versions were posted on this thread. I don't fault you for not
>>> finding it, this thread is a bit long in the tooth. The one I'm
>>> currently working from is
>>>
>>
>> It strikes me that this thread would possibly benefit from a wiki page
>> outlining the permissions, overall concepts, etc, as it's getting awfully
>> hard to follow.
>
> +1. This has proved to be very beneficial for UPSERT.

I am marking this patch as returned with feedback per the current
status of this thread.
--
Michael


From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: Bruce Momjian <bruce(at)momjian(dot)us>, Noah Misch <noah(at)leadboat(dot)com>, Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, Amit Langote <Langote_Amit_f8(at)lab(dot)ntt(dot)co(dot)jp>, David Steele <david(at)pgmasters(dot)net>, Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, Gavin Flower <GavinFlower(at)archidevsys(dot)co(dot)nz>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>, Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2016-02-03 18:44:28
Message-ID: CA+TgmoZQXD0tQtvoFq03ui1_dhpdmpk_fNGC3YUtutN9iHc=Bg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Thu, Jan 28, 2016 at 4:37 PM, Stephen Frost <sfrost(at)snowman(dot)net> wrote:
> pg_monitor
>
> Allows roles granted more information from pg_stat_activity. Can't be
> just a regular non-default-role right as we don't, currently, have a
> way to say "filter out the values of certain columns on certain rows,
> but not on others."
>
> (There's a question here though- for the privileges which will be
> directly GRANT'able, should we GRANT those to pg_monitor, or have
> pg_monitor only provide unfiltered access to pg_stat_activity, or..?
> Further, if it's only for pg_stat_activity, should we name it
> something else?)

I endorse this proposed role. I'd have it just grant access to
pg_stat_activity but keep the name pg_monitor so that it could apply
to other similar things in the future, but there might be other good
alternatives too.

> pg_signal_backend
>
> Allows roles to signal other backend processes beyond those backends
> which are owned by a user they are a role member of. Can't be a
> regular non-default-role right as we don't, currently, have any way to
> GRANT rights to send signals only to backends you own or are a member
> of.

I also endorse this.

> pg_replication
>
> Allows roles to use the various replication functions. Can't be a
> regular non-default-role right as the REPLICATION role attribute
> allows access to those functions and the GRANT system has no way of
> saying "allow access to these functions if they have role attribute
> X."
>
> Make sense, as these are cases where we can't simply write GRANT
> statements and get the same result, but we don't need (or at least,
> shouldn't have without supporting GRANT on catalog objects and agreement
> on what they're intended for):

This seems like it could be reshuffled so that it can be done with
GRANT. Therefore, I don't endorse this.

> pg_backup
>
> pg_start_backup(), pg_stop_backup(), pg_switch_xlog(), and
> pg_create_restore_point() will all be managed by the normal GRANT
> system and therefore we don't need a default role for those use-cases.

Agreed.

> pg_file_settings
>
> pg_file_settings() function and pg_file_settings view will be managed
> by the normal GRANT system and therefore we don't need a default role
> for those use-cases.

Agreed.

> pg_replay
>
> pg_xlog_replay_pause(), and pg_xlog_replay_resume() will be managed
> by the normal GRANT system and therefore we don't need a default role
> for those use-cases.

Agreed.

> pg_rotate_logfile
>
> pg_rotate_logfile() will be managed by the normal GRANT system and
> therefore we don't need a default role for that use-cases.

Agreed.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


From: Noah Misch <noah(at)leadboat(dot)com>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Stephen Frost <sfrost(at)snowman(dot)net>, Bruce Momjian <bruce(at)momjian(dot)us>, Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, Amit Langote <Langote_Amit_f8(at)lab(dot)ntt(dot)co(dot)jp>, David Steele <david(at)pgmasters(dot)net>, Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, Gavin Flower <GavinFlower(at)archidevsys(dot)co(dot)nz>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>, Adam Brightwell <adam(dot)brightwell(at)crunchydatasolutions(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Petr Jelinek <petr(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Additional role attributes && superuser review
Date: 2016-02-21 02:26:39
Message-ID: 20160221022639.GA486055@tornado.leadboat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Wed, Feb 03, 2016 at 01:44:28PM -0500, Robert Haas wrote:
> On Thu, Jan 28, 2016 at 4:37 PM, Stephen Frost <sfrost(at)snowman(dot)net> wrote:
> > pg_monitor
> >
> > Allows roles granted more information from pg_stat_activity. Can't be
> > just a regular non-default-role right as we don't, currently, have a
> > way to say "filter out the values of certain columns on certain rows,
> > but not on others."
> >
> > (There's a question here though- for the privileges which will be
> > directly GRANT'able, should we GRANT those to pg_monitor, or have
> > pg_monitor only provide unfiltered access to pg_stat_activity, or..?
> > Further, if it's only for pg_stat_activity, should we name it
> > something else?)
>
> I endorse this proposed role. I'd have it just grant access to
> pg_stat_activity but keep the name pg_monitor so that it could apply
> to other similar things in the future, but there might be other good
> alternatives too.

-1 for adding any pg_monitor role. That name belongs to a role allowing, from
inception, more than just full pg_stat_activity access. The last, vigorous
effort to define its scope failed; there may not exist one notion of
"monitoring" operations qualified to claim this name. At least, the community
lacks the ability to design it in the foreseeable future.

> > pg_signal_backend
> >
> > Allows roles to signal other backend processes beyond those backends
> > which are owned by a user they are a role member of. Can't be a
> > regular non-default-role right as we don't, currently, have any way to
> > GRANT rights to send signals only to backends you own or are a member
> > of.
>
> I also endorse this.

+1. This role has a clear scope and a name denoting that scope, so it's a
sound way to introduce built-in role infrastructure. I like the concept of
built-in roles. One can inherit them via user-defined roles and use NOINHERIT
to regulate that. One can grant WITH ADMIN OPTION, something role options
like REPLICATION don't offer. It feels more scalable than defining role
options, and it's a technique non-core code can imitate.

I haven't decided whether it's a problem that members of built-in roles can
create objects owned by those roles.