pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #6264: Superuser does not have inherent Replication permission
15+ messages / 7 participants
[nested] [flat]

* BUG #6264: Superuser does not have inherent Replication permission
@ 2011-10-21 21:54  Keith Fiske <keith@omniti.com>
  0 siblings, 1 reply; 15+ messages in thread

From: Keith Fiske @ 2011-10-21 21:54 UTC (permalink / raw)
  To: pgsql-bugs


The following bug has been logged online:

Bug reference:      6264
Logged by:          Keith Fiske
Email address:      keith@omniti.com
PostgreSQL version: 9.1.1
Operating system:   Debian
Description:        Superuser does not have inherent Replication permission
Details: 

Was testing out an upgrade from 9.0.4 to 9.1.1 and ran across either some
lack of clarity in the documentation or a bug in the superuser privilege.
I had a streaming replication setup and after the upgrade and setting up the
new slave, the slave would no longer connect to the master for SR. Looking
into this more, I saw that 9.1 has a new Replication permission to allow
non-superusers the ability to be replication users. 
The documentation says replication is inherent to a superuser. After testing
several times, I can assure you it is not. The old replication user from
9.0.4 which was carried through the upgrade kept its superuser privileges,
but was unable to be used for replication until I explicitly granted it the
Replication permission. 
Brand new roles created initially as superusers are explicitly given the
separate replication permission. If you create a user as a NONsuperuser,
then later ALTER them to be one, they will NOT have the replication
permission and cannot be used as a replication user until you explicitly
grant that permission.



^ permalink  raw  reply  [nested|flat] 15+ messages in thread

* Re: BUG #6264: Superuser does not have inherent Replication permission
@ 2011-10-22 15:49  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Keith Fiske <keith@omniti.com>
  0 siblings, 1 reply; 15+ messages in thread

From: Tom Lane @ 2011-10-22 15:49 UTC (permalink / raw)
  To: Keith Fiske <keith@omniti.com>; +Cc: pgsql-bugs

"Keith Fiske" <keith@omniti.com> writes:
> The documentation says replication is inherent to a superuser.

What it actually says is that superusers get the replication privilege
by default --- but you can create a superuser without that.  If you
see a place that says something different, please point it out
specifically so we can improve it.

> After testing
> several times, I can assure you it is not.

Please show your test case.  It looks to me like it works as expected:

regression=# create user foo superuser;
CREATE ROLE
regression=# create user foo2 superuser noreplication;
CREATE ROLE
regression=# select rolname,rolsuper,rolreplication from pg_authid ;
 rolname  | rolsuper | rolreplication 
----------+----------+----------------
 postgres | t        | t
 foo      | t        | t
 foo2     | t        | f
(3 rows)


> If you create a user as a NONsuperuser,
> then later ALTER them to be one, they will NOT have the replication
> permission and cannot be used as a replication user until you explicitly
> grant that permission.

That doesn't sound to me like a bug.  These flags are independent, we
just provide a certain default at role creation time.

			regards, tom lane



^ permalink  raw  reply  [nested|flat] 15+ messages in thread

* Re: BUG #6264: Superuser does not have inherent Replication permission
@ 2011-10-24 14:37  Keith Fiske <keith@omniti.com>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 15+ messages in thread

From: Keith Fiske @ 2011-10-24 14:37 UTC (permalink / raw)
  To: pgsql-bugs

On Sat, Oct 22, 2011 at 11:49 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> "Keith Fiske" <keith@omniti.com> writes:
>> The documentation says replication is inherent to a superuser.
>
> What it actually says is that superusers get the replication privilege
> by default --- but you can create a superuser without that.  If you
> see a place that says something different, please point it out
> specifically so we can improve it.



^ permalink  raw  reply  [nested|flat] 15+ messages in thread

* Re: BUG #6264: Superuser does not have inherent Replication permission
@ 2011-10-25 12:39  Magnus Hagander <magnus@hagander.net>
  parent: Keith Fiske <keith@omniti.com>
  0 siblings, 2 replies; 15+ messages in thread

From: Magnus Hagander @ 2011-10-25 12:39 UTC (permalink / raw)
  To: Keith Fiske <keith@omniti.com>; +Cc: pgsql-bugs

On Mon, Oct 24, 2011 at 16:37, Keith Fiske <keith@omniti.com> wrote:
> On Sat, Oct 22, 2011 at 11:49 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> "Keith Fiske" <keith@omniti.com> writes:
>
>>> If you create a user as a NONsuperuser,
>>> then later ALTER them to be one, they will NOT have the replication
>>> permission and cannot be used as a replication user until you explicitly
>>> grant that permission.
>>
>> That doesn't sound to me like a bug.  These flags are independent, we
>> just provide a certain default at role creation time.
>>
>
> That is not what the documentation as read would lead people to
> believe. I'd be more than happy to help with clarifying the
> documentation myself if needed. Just let me know how.

This part I agree with - it makes sense for ALTER to set both flags
when it enables superuser. It seems inconsistent now - even if it may
be technically correct.

If we don't change it, we should definitely accept a docs patch to
clarify what happens, because I agree it's confusing.

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



^ permalink  raw  reply  [nested|flat] 15+ messages in thread

* Re: BUG #6264: Superuser does not have inherent Replication permission
@ 2011-10-25 12:58  Simon Riggs <simon@2ndQuadrant.com>
  parent: Magnus Hagander <magnus@hagander.net>
  1 sibling, 0 replies; 15+ messages in thread

From: Simon Riggs @ 2011-10-25 12:58 UTC (permalink / raw)
  To: Magnus Hagander <magnus@hagander.net>; +Cc: Keith Fiske <keith@omniti.com>; pgsql-bugs

On Tue, Oct 25, 2011 at 1:39 PM, Magnus Hagander <magnus@hagander.net> wrote:
> On Mon, Oct 24, 2011 at 16:37, Keith Fiske <keith@omniti.com> wrote:
>> On Sat, Oct 22, 2011 at 11:49 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>>> "Keith Fiske" <keith@omniti.com> writes:
>>
>>>> If you create a user as a NONsuperuser,
>>>> then later ALTER them to be one, they will NOT have the replication
>>>> permission and cannot be used as a replication user until you explicitly
>>>> grant that permission.
>>>
>>> That doesn't sound to me like a bug.  These flags are independent, we
>>> just provide a certain default at role creation time.
>>>
>>
>> That is not what the documentation as read would lead people to
>> believe. I'd be more than happy to help with clarifying the
>> documentation myself if needed. Just let me know how.
>
> This part I agree with - it makes sense for ALTER to set both flags
> when it enables superuser.

+1

Change the behaviour to match the docs makes most sense to me.


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



^ permalink  raw  reply  [nested|flat] 15+ messages in thread

* Re: BUG #6264: Superuser does not have inherent Replication permission
@ 2011-10-27 17:45  Robert Haas <robertmhaas@gmail.com>
  parent: Magnus Hagander <magnus@hagander.net>
  1 sibling, 2 replies; 15+ messages in thread

From: Robert Haas @ 2011-10-27 17:45 UTC (permalink / raw)
  To: Magnus Hagander <magnus@hagander.net>; +Cc: Keith Fiske <keith@omniti.com>; pgsql-bugs

On Tue, Oct 25, 2011 at 8:39 AM, Magnus Hagander <magnus@hagander.net> wrote:
> On Mon, Oct 24, 2011 at 16:37, Keith Fiske <keith@omniti.com> wrote:
>> On Sat, Oct 22, 2011 at 11:49 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>>> "Keith Fiske" <keith@omniti.com> writes:
>>
>>>> If you create a user as a NONsuperuser,
>>>> then later ALTER them to be one, they will NOT have the replication
>>>> permission and cannot be used as a replication user until you explicitly
>>>> grant that permission.
>>>
>>> That doesn't sound to me like a bug.  These flags are independent, we
>>> just provide a certain default at role creation time.
>>>
>>
>> That is not what the documentation as read would lead people to
>> believe. I'd be more than happy to help with clarifying the
>> documentation myself if needed. Just let me know how.
>
> This part I agree with - it makes sense for ALTER to set both flags
> when it enables superuser. It seems inconsistent now - even if it may
> be technically correct.
>
> If we don't change it, we should definitely accept a docs patch to
> clarify what happens, because I agree it's confusing.

There's a pre-existing catalog flag called rolcatupdate that works a
little bit like this, and we discussed making rolreplication behave
similarly.  But we ended up with different semantics:

rhaas=# create user bob nosuperuser;
CREATE ROLE
rhaas=# create user fred nosuperuser;
CREATE ROLE
rhaas=# alter role fred superuser;
ALTER ROLE
rhaas=# create user harry superuser;
CREATE ROLE
rhaas=# select * from pg_authid where rolname in ('bob', 'fred',
'harry') order by rolname;
 rolname | rolsuper | rolinherit | rolcreaterole | rolcreatedb |
rolcatupdate | rolcanlogin | rolreplication | rolconnlimit |
rolpassword | rolvaliduntil
---------+----------+------------+---------------+-------------+--------------+-------------+----------------+--------------+-------------+---------------
 bob     | f        | t          | f             | f           | f
       | t           | f              |           -1 |             |
 fred    | t        | t          | f             | f           | t
       | t           | f              |           -1 |             |
 harry   | t        | t          | f             | f           | t
       | t           | t              |           -1 |             |
(3 rows)

One difference is that, AFAIK, there's no DDL command to change
rolcatupdate separately from rolsuper.  If we do decide to change the
behavior, we'd better carefully document that if you want to make
someone a superuser without giving them replication privileges (or
revoke their superuser status without revoking replication
privileges), you need to specify both ALTER TABLE options.

All in all I'm somewhat inclined to think we should just patch the
docs.  9.1 hasn't been out for very long, so maybe expectations aren't
too settled yet, but changing security-critical behavior in back
branches doesn't seem like a wonderful idea; and I think I mildly
prefer the current semantics to the proposed ones.

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



^ permalink  raw  reply  [nested|flat] 15+ messages in thread

* Re: BUG #6264: Superuser does not have inherent Replication permission
@ 2011-10-27 18:18  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Robert Haas <robertmhaas@gmail.com>
  1 sibling, 0 replies; 15+ messages in thread

From: Tom Lane @ 2011-10-27 18:18 UTC (permalink / raw)
  To: Robert Haas <robertmhaas@gmail.com>; +Cc: Magnus Hagander <magnus@hagander.net>; Keith Fiske <keith@omniti.com>; pgsql-bugs

Robert Haas <robertmhaas@gmail.com> writes:
> ...  If we do decide to change the
> behavior, we'd better carefully document that if you want to make
> someone a superuser without giving them replication privileges (or
> revoke their superuser status without revoking replication
> privileges), you need to specify both ALTER TABLE options.

You'd also have to be careful about processing-order dependencies;
consider
	ALTER USER joe NOREPLICATION SUPERUSER;
which would do the wrong thing with a naive implementation.

> All in all I'm somewhat inclined to think we should just patch the
> docs.  9.1 hasn't been out for very long, so maybe expectations aren't
> too settled yet, but changing security-critical behavior in back
> branches doesn't seem like a wonderful idea; and I think I mildly
> prefer the current semantics to the proposed ones.

+1

			regards, tom lane



^ permalink  raw  reply  [nested|flat] 15+ messages in thread

* Re: BUG #6264: Superuser does not have inherent Replication permission
@ 2011-10-27 21:01  Noah Misch <noah@leadboat.com>
  parent: Robert Haas <robertmhaas@gmail.com>
  1 sibling, 1 reply; 15+ messages in thread

From: Noah Misch @ 2011-10-27 21:01 UTC (permalink / raw)
  To: Robert Haas <robertmhaas@gmail.com>; +Cc: Magnus Hagander <magnus@hagander.net>; Keith Fiske <keith@omniti.com>; pgsql-bugs

On Thu, Oct 27, 2011 at 01:45:34PM -0400, Robert Haas wrote:
> On Tue, Oct 25, 2011 at 8:39 AM, Magnus Hagander <magnus@hagander.net> wrote:
> > On Mon, Oct 24, 2011 at 16:37, Keith Fiske <keith@omniti.com> wrote:
> >> On Sat, Oct 22, 2011 at 11:49 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> >>> "Keith Fiske" <keith@omniti.com> writes:
> >>
> >>>> If you create a user as a NONsuperuser,
> >>>> then later ALTER them to be one, they will NOT have the replication
> >>>> permission and cannot be used as a replication user until you explicitly
> >>>> grant that permission.
> >>>
> >>> That doesn't sound to me like a bug. ?These flags are independent, we
> >>> just provide a certain default at role creation time.
> >>>
> >>
> >> That is not what the documentation as read would lead people to
> >> believe. I'd be more than happy to help with clarifying the
> >> documentation myself if needed. Just let me know how.
> >
> > This part I agree with - it makes sense for ALTER to set both flags
> > when it enables superuser. It seems inconsistent now - even if it may
> > be technically correct.
> >
> > If we don't change it, we should definitely accept a docs patch to
> > clarify what happens, because I agree it's confusing.
> 
> There's a pre-existing catalog flag called rolcatupdate that works a
> little bit like this, and we discussed making rolreplication behave
> similarly.  But we ended up with different semantics:

[ALTER ROLE sets rolcatupdate = rolsuper when changing rolsuper.]

> One difference is that, AFAIK, there's no DDL command to change
> rolcatupdate separately from rolsuper.  If we do decide to change the
> behavior, we'd better carefully document that if you want to make
> someone a superuser without giving them replication privileges (or
> revoke their superuser status without revoking replication
> privileges), you need to specify both ALTER TABLE options.

Let's look at the behavior of DDL-exposed access constraints for precedent.  We
currently have three paradigms for applying access control to superusers:

1. Settings that affect superusers and regular users identically.  These include
ALTER ROLE ... LOGIN | VALID UNTIL.

2. Rights that superusers possess implicitly and irrevocably; the actual setting
recorded in pg_authid or elsewhere has no effect.  These include GRANT ... ON
TABLE and ALTER ROLE ... CREATEDB | CREATEROLE.

3. ALTER ROLE ... REPLICATION is very similar to #1, except that CREATE ROLE
... SUPERUSER implies CREATE ROLE ... SUPERUSER REPLICATION.

I think we should merge #3 into #2; nothing about the REPLICATION setting
justifies a distinct paradigm.  On a clean slate, #1 might be an equally
suitable fit.  However, #2 provides better backward compatibility with 9.0.

> All in all I'm somewhat inclined to think we should just patch the
> docs.  9.1 hasn't been out for very long, so maybe expectations aren't
> too settled yet, but changing security-critical behavior in back
> branches doesn't seem like a wonderful idea; and I think I mildly
> prefer the current semantics to the proposed ones.

The implication of my proposal is to remove the possibility of creating a
superuser that cannot connect for replication; users so restricted under 9.1.1
would suddenly be able to make replication connections in 9.1.2.  Of course,
they could already "ALTER ROLE myself REPLICATION".  On that account, no secure
system would quietly become insecure following such an upgrade.

nm



^ permalink  raw  reply  [nested|flat] 15+ messages in thread

* Re: Re: BUG #6264: Superuser does not have inherent Replication permission
@ 2011-10-27 22:15  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Noah Misch <noah@leadboat.com>
  0 siblings, 1 reply; 15+ messages in thread

From: Tom Lane @ 2011-10-27 22:15 UTC (permalink / raw)
  To: Noah Misch <noah@leadboat.com>; +Cc: Robert Haas <robertmhaas@gmail.com>; Magnus Hagander <magnus@hagander.net>; Keith Fiske <keith@omniti.com>; pgsql-bugs

Noah Misch <noah@leadboat.com> writes:
> Let's look at the behavior of DDL-exposed access constraints for precedent.  We
> currently have three paradigms for applying access control to superusers:

> 1. Settings that affect superusers and regular users identically.  These include
> ALTER ROLE ... LOGIN | VALID UNTIL.

> 2. Rights that superusers possess implicitly and irrevocably; the actual setting
> recorded in pg_authid or elsewhere has no effect.  These include GRANT ... ON
> TABLE and ALTER ROLE ... CREATEDB | CREATEROLE.

> 3. ALTER ROLE ... REPLICATION is very similar to #1, except that CREATE ROLE
> ... SUPERUSER implies CREATE ROLE ... SUPERUSER REPLICATION.

> I think we should merge #3 into #2; nothing about the REPLICATION setting
> justifies a distinct paradigm.

Yeah, there's much to be said for that.  I thought the notion of a
privilege that superusers might not have was pretty bogus to start with.

rolcatupdate isn't a very good precedent to rely on because it's never
been documented or used to any noticeable extent, so there's no reason
to think that it provides a tested-and-accepted behavior.

			regards, tom lane



^ permalink  raw  reply  [nested|flat] 15+ messages in thread

* Re: Re: BUG #6264: Superuser does not have inherent Replication permission
@ 2011-10-28 13:32  Robert Haas <robertmhaas@gmail.com>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 2 replies; 15+ messages in thread

From: Robert Haas @ 2011-10-28 13:32 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Noah Misch <noah@leadboat.com>; Magnus Hagander <magnus@hagander.net>; Keith Fiske <keith@omniti.com>; pgsql-bugs

On Thu, Oct 27, 2011 at 6:15 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> Noah Misch <noah@leadboat.com> writes:
>> Let's look at the behavior of DDL-exposed access constraints for precedent.  We
>> currently have three paradigms for applying access control to superusers:
>
>> 1. Settings that affect superusers and regular users identically.  These include
>> ALTER ROLE ... LOGIN | VALID UNTIL.
>
>> 2. Rights that superusers possess implicitly and irrevocably; the actual setting
>> recorded in pg_authid or elsewhere has no effect.  These include GRANT ... ON
>> TABLE and ALTER ROLE ... CREATEDB | CREATEROLE.
>
>> 3. ALTER ROLE ... REPLICATION is very similar to #1, except that CREATE ROLE
>> ... SUPERUSER implies CREATE ROLE ... SUPERUSER REPLICATION.
>
>> I think we should merge #3 into #2; nothing about the REPLICATION setting
>> justifies a distinct paradigm.
>
> Yeah, there's much to be said for that.  I thought the notion of a
> privilege that superusers might not have was pretty bogus to start with.
>
> rolcatupdate isn't a very good precedent to rely on because it's never
> been documented or used to any noticeable extent, so there's no reason
> to think that it provides a tested-and-accepted behavior.

That seems fine for 9.2, but I am still not in favor of changing the
behavior in back branches.  This is not such a confusing behavior that
we can't document our way out of it.

(Hey, if SELECT .. ORDER BY .. FOR UPDATE can return rows out of order
and we can document our way out of that, this is small potatoes by
comparison.)

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



^ permalink  raw  reply  [nested|flat] 15+ messages in thread

* Re: Re: BUG #6264: Superuser does not have inherent Replication permission
@ 2011-10-28 14:03  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Robert Haas <robertmhaas@gmail.com>
  1 sibling, 0 replies; 15+ messages in thread

From: Tom Lane @ 2011-10-28 14:03 UTC (permalink / raw)
  To: Robert Haas <robertmhaas@gmail.com>; +Cc: Noah Misch <noah@leadboat.com>; Magnus Hagander <magnus@hagander.net>; Keith Fiske <keith@omniti.com>; pgsql-bugs

Robert Haas <robertmhaas@gmail.com> writes:
> On Thu, Oct 27, 2011 at 6:15 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> Noah Misch <noah@leadboat.com> writes:
>>> I think we should merge #3 into #2; nothing about the REPLICATION setting
>>> justifies a distinct paradigm.

>> Yeah, there's much to be said for that.  I thought the notion of a
>> privilege that superusers might not have was pretty bogus to start with.

> That seems fine for 9.2, but I am still not in favor of changing the
> behavior in back branches.  This is not such a confusing behavior that
> we can't document our way out of it.

Agreed, changing it in a minor release would be a bad idea.

			regards, tom lane



^ permalink  raw  reply  [nested|flat] 15+ messages in thread

* Re: Re: BUG #6264: Superuser does not have inherent Replication permission
@ 2011-10-28 15:42  Noah Misch <noah@leadboat.com>
  parent: Robert Haas <robertmhaas@gmail.com>
  1 sibling, 1 reply; 15+ messages in thread

From: Noah Misch @ 2011-10-28 15:42 UTC (permalink / raw)
  To: Robert Haas <robertmhaas@gmail.com>; +Cc: Tom Lane <tgl@sss.pgh.pa.us>; Magnus Hagander <magnus@hagander.net>; Keith Fiske <keith@omniti.com>; pgsql-bugs

On Fri, Oct 28, 2011 at 09:32:30AM -0400, Robert Haas wrote:
> On Thu, Oct 27, 2011 at 6:15 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> > Noah Misch <noah@leadboat.com> writes:
> >> Let's look at the behavior of DDL-exposed access constraints for precedent. ?We
> >> currently have three paradigms for applying access control to superusers:
> >
> >> 1. Settings that affect superusers and regular users identically. ?These include
> >> ALTER ROLE ... LOGIN | VALID UNTIL.
> >
> >> 2. Rights that superusers possess implicitly and irrevocably; the actual setting
> >> recorded in pg_authid or elsewhere has no effect. ?These include GRANT ... ON
> >> TABLE and ALTER ROLE ... CREATEDB | CREATEROLE.
> >
> >> 3. ALTER ROLE ... REPLICATION is very similar to #1, except that CREATE ROLE
> >> ... SUPERUSER implies CREATE ROLE ... SUPERUSER REPLICATION.
> >
> >> I think we should merge #3 into #2; nothing about the REPLICATION setting
> >> justifies a distinct paradigm.
> >
> > Yeah, there's much to be said for that. ?I thought the notion of a
> > privilege that superusers might not have was pretty bogus to start with.

> That seems fine for 9.2, but I am still not in favor of changing the
> behavior in back branches.  This is not such a confusing behavior that
> we can't document our way out of it.
> 
> (Hey, if SELECT .. ORDER BY .. FOR UPDATE can return rows out of order
> and we can document our way out of that, this is small potatoes by
> comparison.)

Quite so.  Let's do it that way.

^ permalink  raw  reply  [nested|flat] 15+ messages in thread

* Re: Re: BUG #6264: Superuser does not have inherent Replication permission
@ 2012-01-02 19:46  Noah Misch <noah@leadboat.com>
  parent: Noah Misch <noah@leadboat.com>
  0 siblings, 1 reply; 15+ messages in thread

From: Noah Misch @ 2012-01-02 19:46 UTC (permalink / raw)
  To: Robert Haas <robertmhaas@gmail.com>; +Cc: Tom Lane <tgl@sss.pgh.pa.us>; Magnus Hagander <magnus@hagander.net>; Keith Fiske <keith@omniti.com>; pgsql-bugs

On Fri, Oct 28, 2011 at 11:42:38AM -0400, Noah Misch wrote:
> On Fri, Oct 28, 2011 at 09:32:30AM -0400, Robert Haas wrote:
> > On Thu, Oct 27, 2011 at 6:15 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> > > Noah Misch <noah@leadboat.com> writes:
> > >> Let's look at the behavior of DDL-exposed access constraints for precedent. ?We
> > >> currently have three paradigms for applying access control to superusers:
> > >
> > >> 1. Settings that affect superusers and regular users identically. ?These include
> > >> ALTER ROLE ... LOGIN | VALID UNTIL.
> > >
> > >> 2. Rights that superusers possess implicitly and irrevocably; the actual setting
> > >> recorded in pg_authid or elsewhere has no effect. ?These include GRANT ... ON
> > >> TABLE and ALTER ROLE ... CREATEDB | CREATEROLE.
> > >
> > >> 3. ALTER ROLE ... REPLICATION is very similar to #1, except that CREATE ROLE
> > >> ... SUPERUSER implies CREATE ROLE ... SUPERUSER REPLICATION.
> > >
> > >> I think we should merge #3 into #2; nothing about the REPLICATION setting
> > >> justifies a distinct paradigm.
> > >
> > > Yeah, there's much to be said for that. ?I thought the notion of a
> > > privilege that superusers might not have was pretty bogus to start with.
> 
> > That seems fine for 9.2, but I am still not in favor of changing the
> > behavior in back branches.  This is not such a confusing behavior that
> > we can't document our way out of it.
> > 
> > (Hey, if SELECT .. ORDER BY .. FOR UPDATE can return rows out of order
> > and we can document our way out of that, this is small potatoes by
> > comparison.)
> 
> Quite so.  Let's do it that way.

Patch attached.

Attachments:

superuser-replication-v1.patch (text/plain, 11.4K) download diff --git a/doc/src/sgml/high-availability.sgml b/doc/src/sgml/high-availability.sgml index 86c2729..c5db6ef 100644 *** a/doc/src/sgml/high-availability.sgml --- b/doc/src/sgml/high-availability.sgml *************** *** 797,819 **** archive_cleanup_command = 'pg_archivecleanup /path/to/archive %r' It is very important that the access privileges for replication be set up so that only trusted users can read the WAL stream, because it is easy to extract privileged information from it. Standby servers must ! authenticate to the primary as an account that has the ! <literal>REPLICATION</> privilege. So a role with the ! <literal>REPLICATION</> and <literal>LOGIN</> privileges needs to be ! created on the primary. </para> - <note> - <para> - It is recommended that a dedicated user account is used for replication. - While the <literal>REPLICATION</> privilege is granted to superuser - accounts by default, it is not recommended to use superuser accounts - for replication. While <literal>REPLICATION</> privilege gives very high - permissions, it does not allow the user to modify any data on the - primary system, which the <literal>SUPERUSER</> privilege does. - </para> - </note> - <para> Client authentication for replication is controlled by a <filename>pg_hba.conf</> record specifying <literal>replication</> in the --- 797,810 ---- It is very important that the access privileges for replication be set up so that only trusted users can read the WAL stream, because it is easy to extract privileged information from it. Standby servers must ! authenticate to the primary as a superuser or an account that has the ! <literal>REPLICATION</> privilege. It is recommended to create a ! dedicated user account with <literal>REPLICATION</> and <literal>LOGIN</> ! privileges for replication. While <literal>REPLICATION</> privilege gives ! very high permissions, it does not allow the user to modify any data on ! the primary system, which the <literal>SUPERUSER</> privilege does. </para> <para> Client authentication for replication is controlled by a <filename>pg_hba.conf</> record specifying <literal>replication</> in the diff --git a/doc/src/sgml/recovery-config.index 8647024..7e39c0d 100644 *** a/doc/src/sgml/recovery-config.sgml --- b/doc/src/sgml/recovery-config.sgml *************** *** 325,333 **** restore_command = 'copy "C:\\server\\archivedir\\%f" "%p"' # Windows The connection string should specify the host name (or address) of the primary server, as well as the port number if it is not the same as the standby server's default. ! Also specify a user name corresponding to a role that has the ! <literal>REPLICATION</> and <literal>LOGIN</> privileges on the ! primary (see <xref linkend="streaming-replication-authentication">). A password needs to be provided too, if the primary demands password authentication. It can be provided in the --- 325,332 ---- The connection string should specify the host name (or address) of the primary server, as well as the port number if it is not the same as the standby server's default. ! Also specify a user name corresponding to a suitably-privileged role ! on the primary (see <xref linkend="streaming-replication-authentication">). A password needs to be provided too, if the primary demands password authentication. It can be provided in the diff --git a/doc/src/sgml/ref/create_rolindex 4953df6..7ec4d0a 100644 *** a/doc/src/sgml/ref/create_role.sgml --- b/doc/src/sgml/ref/create_role.sgml *************** *** 185,192 **** CREATE ROLE <replaceable class="PARAMETER">name</replaceable> [ [ WITH ] <replac A role having the <literal>REPLICATION</> attribute is a very highly privileged role, and should only be used on roles actually used for replication. If not specified, ! <literal>NOREPLICATION</literal> is the default for all roles except ! superusers. </para> </listitem> </varlistentry> --- 185,191 ---- A role having the <literal>REPLICATION</> attribute is a very highly privileged role, and should only be used on roles actually used for replication. If not specified, ! <literal>NOREPLICATION</literal> is the default. </para> </listitem> </varlistentry> diff --git a/doc/src/sgml/ref/pg_basebacindex 8c8c78f..05d5bed 100644 *** a/doc/src/sgml/ref/pg_basebackup.sgml --- b/doc/src/sgml/ref/pg_basebackup.sgml *************** *** 50,61 **** PostgreSQL documentation <para> The backup is made over a regular <productname>PostgreSQL</productname> ! connection, and uses the replication protocol. The connection must be ! made with a user having <literal>REPLICATION</literal> permissions (see ! <xref linkend="role-attributes">), and the user must be granted explicit ! permissions in <filename>pg_hba.conf</filename>. The server must also ! be configured with <xref linkend="guc-max-wal-senders"> set high enough ! to leave at least one session available for the backup. </para> <para> --- 50,62 ---- <para> The backup is made over a regular <productname>PostgreSQL</productname> ! connection, and uses the replication protocol. The connection must be made ! with a superuser or a user having <literal>REPLICATION</literal> ! permissions (see <xref linkend="role-attributes">), ! and <filename>pg_hba.conf</filename> must explicitly permit the replication ! connection. The server must also be configured ! with <xref linkend="guc-max-wal-senders"> set high enough to leave at least ! one session available for the backup. </para> <para> diff --git a/doc/src/sgml/ref/pg_receivexlindex 9a2a24b..fad7470 100644 *** a/doc/src/sgml/ref/pg_receivexlog.sgml --- b/doc/src/sgml/ref/pg_receivexlog.sgml *************** *** 50,62 **** PostgreSQL documentation <para> The transaction log is streamed over a regular ! <productname>PostgreSQL</productname> connection, and uses the ! replication protocol. The connection must be ! made with a user having <literal>REPLICATION</literal> permissions (see ! <xref linkend="role-attributes">), and the user must be granted explicit ! permissions in <filename>pg_hba.conf</filename>. The server must also ! be configured with <xref linkend="guc-max-wal-senders"> set high enough ! to leave at least one session available for the stream. </para> </refsect1> --- 50,62 ---- <para> The transaction log is streamed over a regular ! <productname>PostgreSQL</productname> connection, and uses the replication ! protocol. The connection must be made with a superuser or a user ! having <literal>REPLICATION</literal> permissions (see ! <xref linkend="role-attributes">), and <filename>pg_hba.conf</filename> ! must explicitly permit the replication connection. The server must also be ! configured with <xref linkend="guc-max-wal-senders"> set high enough to ! leave at least one session available for the stream. </para> </refsect1> diff --git a/doc/src/sgml/user-manag.sgml bindex 0a4f82d..177ac7a 100644 *** a/doc/src/sgml/user-manag.sgml --- b/doc/src/sgml/user-manag.sgml *************** *** 169,184 **** CREATE USER <replaceable>name</replaceable>; <listitem> <para> A database superuser bypasses all permission checks, except the right ! to log in or the right to initiate replication. This is a ! dangerous privilege and should not be used carelessly; it is best ! to do most of your work as a role that is not a superuser. ! To create a new database superuser, use <literal>CREATE ROLE ! <replaceable>name</replaceable> SUPERUSER</literal>. You must do ! this as a role that is already a superuser. Creating a superuser ! will by default also grant permissions to initiate streaming ! replication. For increased security this can be disallowed using ! <literal>CREATE ROLE <replaceable>name</replaceable> SUPERUSER ! NOREPLICATION</literal>. </para> </listitem> </varlistentry> --- 169,179 ---- <listitem> <para> A database superuser bypasses all permission checks, except the right ! to log in. This is a dangerous privilege and should not be used ! carelessly; it is best to do most of your work as a role that is not a ! superuser. To create a new database superuser, use <literal>CREATE ! ROLE <replaceable>name</replaceable> SUPERUSER</literal>. You must do ! this as a role that is already a superuser. </para> </listitem> </varlistentry> *************** *** 217,223 **** CREATE USER <replaceable>name</replaceable>; <listitem> <para> A role must explicitly be given permission to initiate streaming ! replication. A role used for streaming replication must always have <literal>LOGIN</> permission as well. To create such a role, use <literal>CREATE ROLE <replaceable>name</replaceable> REPLICATION LOGIN</literal>. --- 212,219 ---- <listitem> <para> A role must explicitly be given permission to initiate streaming ! replication (except for superusers, since those bypass all permission ! checks). A role used for streaming replication must always have <literal>LOGIN</> permission as well. To create such a role, use <literal>CREATE ROLE <replaceable>name</replaceable> REPLICATION LOGIN</literal>. diff --git a/src/backend/commands/uindex fa312cb..797e957 100644 *** a/src/backend/commands/user.c --- b/src/backend/commands/user.c *************** *** 239,254 **** CreateRole(CreateRoleStmt *stmt) if (dpassword && dpassword->arg) password = strVal(dpassword->arg); if (dissuper) - { issuper = intVal(dissuper->arg) != 0; - - /* - * Superusers get replication by default, but only if NOREPLICATION - * wasn't explicitly mentioned - */ - if (issuper && !(disreplication && intVal(disreplication->arg) == 0)) - isreplication = 1; - } if (dinherit) inherit = intVal(dinherit->arg) != 0; if (dcreaterole) --- 239,245 ---- diff --git a/src/backend/utils/iniindex 94f92dd..37696c2 100644 *** a/src/backend/utils/init/postinit.c --- b/src/backend/utils/init/postinit.c *************** *** 659,669 **** InitPostgres(const char *in_dbname, Oid dboid, const char *username, { Assert(!bootstrap); ! /* must have authenticated as a replication role */ ! if (!is_authenticated_user_replication_role()) ereport(FATAL, (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), ! errmsg("must be replication role to start walsender"))); /* process any options passed in the startup packet */ if (MyProcPort != NULL) --- 659,668 ---- { Assert(!bootstrap); ! if (!superuser() && !is_authenticated_user_replication_role()) ereport(FATAL, (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), ! errmsg("must be superuser or replication role to start walsender"))); /* process any options passed in the startup packet */ if (MyProcPort != NULL)
^ permalink raw reply [nested|flat] 15+ messages in thread

* Re: Re: BUG #6264: Superuser does not have inherent Replication permission
@ 2012-01-14 16:34  Heikki Linnakangas <heikki.linnakangas@enterprisedb.com>
  parent: Noah Misch <noah@leadboat.com>
  0 siblings, 1 reply; 15+ messages in thread

From: Heikki Linnakangas @ 2012-01-14 16:34 UTC (permalink / raw)
  To: Noah Misch <noah@leadboat.com>; +Cc: Robert Haas <robertmhaas@gmail.com>; Tom Lane <tgl@sss.pgh.pa.us>; Magnus Hagander <magnus@hagander.net>; Keith Fiske <keith@omniti.com>; pgsql-bugs

On 02.01.2012 21:46, Noah Misch wrote:
> On Fri, Oct 28, 2011 at 11:42:38AM -0400, Noah Misch wrote:
>> On Fri, Oct 28, 2011 at 09:32:30AM -0400, Robert Haas wrote:
>>> On Thu, Oct 27, 2011 at 6:15 PM, Tom Lane<tgl@sss.pgh.pa.us>  wrote:
>>>> Noah Misch<noah@leadboat.com>  writes:
>>>>> Let's look at the behavior of DDL-exposed access constraints for precedent. ?We
>>>>> currently have three paradigms for applying access control to superusers:
>>>>
>>>>> 1. Settings that affect superusers and regular users identically. ?These include
>>>>> ALTER ROLE ... LOGIN | VALID UNTIL.
>>>>
>>>>> 2. Rights that superusers possess implicitly and irrevocably; the actual setting
>>>>> recorded in pg_authid or elsewhere has no effect. ?These include GRANT ... ON
>>>>> TABLE and ALTER ROLE ... CREATEDB | CREATEROLE.
>>>>
>>>>> 3. ALTER ROLE ... REPLICATION is very similar to #1, except that CREATE ROLE
>>>>> ... SUPERUSER implies CREATE ROLE ... SUPERUSER REPLICATION.
>>>>
>>>>> I think we should merge #3 into #2; nothing about the REPLICATION setting
>>>>> justifies a distinct paradigm.
>>>>
>>>> Yeah, there's much to be said for that. ?I thought the notion of a
>>>> privilege that superusers might not have was pretty bogus to start with.
>>
>>> That seems fine for 9.2, but I am still not in favor of changing the
>>> behavior in back branches.  This is not such a confusing behavior that
>>> we can't document our way out of it.
>>>
>>> (Hey, if SELECT .. ORDER BY .. FOR UPDATE can return rows out of order
>>> and we can document our way out of that, this is small potatoes by
>>> comparison.)
>>
>> Quite so.  Let's do it that way.
>
> Patch attached.

Thanks, committed to master.

Was there something that still needed to be done for the 9.1 docs? I'm 
not sure what the conclusion on that was in the discussions back in October.

-- 
   Heikki Linnakangas
   EnterpriseDB   http://www.enterprisedb.com



^ permalink  raw  reply  [nested|flat] 15+ messages in thread

* Re: Re: BUG #6264: Superuser does not have inherent Replication permission
@ 2012-01-15 00:27  Noah Misch <noah@leadboat.com>
  parent: Heikki Linnakangas <heikki.linnakangas@enterprisedb.com>
  0 siblings, 0 replies; 15+ messages in thread

From: Noah Misch @ 2012-01-15 00:27 UTC (permalink / raw)
  To: Heikki Linnakangas <heikki.linnakangas@enterprisedb.com>; +Cc: Robert Haas <robertmhaas@gmail.com>; Tom Lane <tgl@sss.pgh.pa.us>; Magnus Hagander <magnus@hagander.net>; Keith Fiske <keith@omniti.com>; pgsql-bugs

On Sat, Jan 14, 2012 at 06:34:25PM +0200, Heikki Linnakangas wrote:
> On 02.01.2012 21:46, Noah Misch wrote:
>> On Fri, Oct 28, 2011 at 11:42:38AM -0400, Noah Misch wrote:
>>> On Fri, Oct 28, 2011 at 09:32:30AM -0400, Robert Haas wrote:
>>>> On Thu, Oct 27, 2011 at 6:15 PM, Tom Lane<tgl@sss.pgh.pa.us>  wrote:
>>>>> Noah Misch<noah@leadboat.com>  writes:
>>>>>> Let's look at the behavior of DDL-exposed access constraints for precedent. ?We
>>>>>> currently have three paradigms for applying access control to superusers:
>>>>>
>>>>>> 1. Settings that affect superusers and regular users identically. ?These include
>>>>>> ALTER ROLE ... LOGIN | VALID UNTIL.
>>>>>
>>>>>> 2. Rights that superusers possess implicitly and irrevocably; the actual setting
>>>>>> recorded in pg_authid or elsewhere has no effect. ?These include GRANT ... ON
>>>>>> TABLE and ALTER ROLE ... CREATEDB | CREATEROLE.
>>>>>
>>>>>> 3. ALTER ROLE ... REPLICATION is very similar to #1, except that CREATE ROLE
>>>>>> ... SUPERUSER implies CREATE ROLE ... SUPERUSER REPLICATION.
>>>>>
>>>>>> I think we should merge #3 into #2; nothing about the REPLICATION setting
>>>>>> justifies a distinct paradigm.
>>>>>
>>>>> Yeah, there's much to be said for that. ?I thought the notion of a
>>>>> privilege that superusers might not have was pretty bogus to start with.
>>>
>>>> That seems fine for 9.2, but I am still not in favor of changing the
>>>> behavior in back branches.  This is not such a confusing behavior that
>>>> we can't document our way out of it.
>>>>
>>>> (Hey, if SELECT .. ORDER BY .. FOR UPDATE can return rows out of order
>>>> and we can document our way out of that, this is small potatoes by
>>>> comparison.)
>>>
>>> Quite so.  Let's do it that way.
>>
>> Patch attached.
>
> Thanks, committed to master.

Thanks.

> Was there something that still needed to be done for the 9.1 docs? I'm  
> not sure what the conclusion on that was in the discussions back in 
> October.

Not that I noted.  The former docs describe the 9.1 behavior thoroughly.



^ permalink  raw  reply  [nested|flat] 15+ messages in thread


end of thread, other threads:[~2012-01-15 00:27 UTC | newest]

Thread overview: 15+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2011-10-21 21:54 BUG #6264: Superuser does not have inherent Replication permission Keith Fiske <keith@omniti.com>
2011-10-22 15:49 ` Tom Lane <tgl@sss.pgh.pa.us>
2011-10-24 14:37   ` Keith Fiske <keith@omniti.com>
2011-10-25 12:39     ` Magnus Hagander <magnus@hagander.net>
2011-10-25 12:58       ` Simon Riggs <simon@2ndQuadrant.com>
2011-10-27 17:45       ` Robert Haas <robertmhaas@gmail.com>
2011-10-27 18:18         ` Tom Lane <tgl@sss.pgh.pa.us>
2011-10-27 21:01         ` Noah Misch <noah@leadboat.com>
2011-10-27 22:15           ` Tom Lane <tgl@sss.pgh.pa.us>
2011-10-28 13:32             ` Robert Haas <robertmhaas@gmail.com>
2011-10-28 14:03               ` Tom Lane <tgl@sss.pgh.pa.us>
2011-10-28 15:42               ` Noah Misch <noah@leadboat.com>
2012-01-02 19:46                 ` Noah Misch <noah@leadboat.com>
2012-01-14 16:34                   ` Heikki Linnakangas <heikki.linnakangas@enterprisedb.com>
2012-01-15 00:27                     ` Noah Misch <noah@leadboat.com>

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