pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Stephen Frost <sfrost@snowman.net>
To: Jeff Davis <pgsql@j-davis.com>
Cc: Andres Freund <andres@anarazel.de>
Cc: Robert Haas <robertmhaas@gmail.com>
Cc: Bossart, Nathan <bossartn@amazon.com>
Cc: Alvaro Herrera <alvherre@alvh.no-ip.org>
Cc: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
Cc: PostgreSQL-development <pgsql-hackers@postgresql.org>
Subject: Re: Predefined role pg_maintenance for VACUUM, ANALYZE, CHECKPOINT.
Date: Tue, 9 Nov 2021 11:29:38 -0500
Message-ID: <20211109162938.GS20998@tamriel.snowman.net> (raw)
In-Reply-To: <c5d7045507b0ccac7d9421f52bf3b59b60e1150b.camel@j-davis.com>
References: <20211101165025.GS20998@tamriel.snowman.net>
	<5e7a618de1b49ba1ceede54ee1b1d073bd57f1f4.camel@j-davis.com>
	<20211104224204.ee5673h3qlzblh7e@alap3.anarazel.de>
	<ae70a6ff7700a821849be0da6cd0da69e0e4b05e.camel@j-davis.com>
	<CA+Tgmob9TxDV3X4+=eG9E+o80MW_qoJjTvvHhRt252OO=X9FbA@mail.gmail.com>
	<20211107184649.mpncdezkzfq2v4pb@alap3.anarazel.de>
	<20211108172318.GF20998@tamriel.snowman.net>
	<20211108173325.6ury6xflvxq7yqbn@alap3.anarazel.de>
	<20211108174723.GI20998@tamriel.snowman.net>
	<c5d7045507b0ccac7d9421f52bf3b59b60e1150b.camel@j-davis.com>

Greetings,

* Jeff Davis (pgsql@j-davis.com) wrote:
> On Mon, 2021-11-08 at 12:47 -0500, Stephen Frost wrote:
> > 
> > I don't feel as strongly as others apparently do on this point
> > though,
> > and I'd rather have non-superusers able to run CHECKPOINT *somehow*
> > than not, so if the others feel like a predefined role is a better
> > approach then I'm alright with that.  Seems a bit overkill to me but
> > it's also not like it's actually all that much code or work to do.
> 
> +1. It seems like the pg_checkpointer predefined role is the most
> acceptable to everyone (even if not universally liked).
> 
> Attached a rebased version of that patch.

Thanks.  Quick review-

> diff --git a/src/backend/tcop/utility.c b/src/backend/tcop/utility.c
> index bf085aa93b2..0ff832a62c2 100644
> --- a/src/backend/tcop/utility.c
> +++ b/src/backend/tcop/utility.c
> @@ -24,6 +24,7 @@
>  #include "catalog/catalog.h"
>  #include "catalog/index.h"
>  #include "catalog/namespace.h"
> +#include "catalog/pg_authid.h"
>  #include "catalog/pg_inherits.h"
>  #include "catalog/toasting.h"
>  #include "commands/alter.h"
> @@ -939,10 +940,10 @@ standard_ProcessUtility(PlannedStmt *pstmt,
>  			break;
>  
>  		case T_CheckPointStmt:
> -			if (!superuser())
> +			if (!has_privs_of_role(GetUserId(), ROLE_PG_CHECKPOINTER))
>  				ereport(ERROR,
>  						(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
> -						 errmsg("must be superuser to do CHECKPOINT")));
> +						 errmsg("must be member of pg_checkpointer to do CHECKPOINT")));

Most such error messages say 'superuser or '...  Also, note the recent
thread about trying to ensure that places are using has_privs_of_role()
as you're doing here but also say that in the error message
consistently, rather than 'member of' it should really be 'has
privileges of' as the two are not necessarily always the same.  You can
be a member of a role but not actively have the privileges of that role.

Otherwise, looks pretty good to me.  I'll note that has_privs_of_role()
will first call superuser_arg(member), just the same as the prior
superuser() check did, so this doesn't change the catalog accesses in
that case from today.

Thanks,

Stephen

Attachments:

  signature.asc (application/pgp-signature, 818B) download

view thread (65+ messages)

Message-ID: <20211109162938.GS20998@tamriel.snowman.net>
Permalink:  ../20211109162938.GS20998@tamriel.snowman.net/
Also on:    postgresql.org/message-id/20211109162938.GS20998@tamriel.snowman.net

 · 

reply

Reply instructions:

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

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

  To: pgsql-hackers@postgresql.org
  Cc: sfrost@snowman.net, pgsql@j-davis.com, andres@anarazel.de, robertmhaas@gmail.com, bossartn@amazon.com, alvherre@alvh.no-ip.org, bharath.rupireddyforpostgres@gmail.com
  Subject: Re: Predefined role pg_maintenance for VACUUM, ANALYZE, CHECKPOINT.
  In-Reply-To: <20211109162938.GS20998@tamriel.snowman.net>
  References: <20211101165025.GS20998@tamriel.snowman.net> <5e7a618de1b49ba1ceede54ee1b1d073bd57f1f4.camel@j-davis.com> <20211104224204.ee5673h3qlzblh7e@alap3.anarazel.de> <ae70a6ff7700a821849be0da6cd0da69e0e4b05e.camel@j-davis.com> <CA+Tgmob9TxDV3X4+=eG9E+o80MW_qoJjTvvHhRt252OO=X9FbA@mail.gmail.com> <20211107184649.mpncdezkzfq2v4pb@alap3.anarazel.de> <20211108172318.GF20998@tamriel.snowman.net> <20211108173325.6ury6xflvxq7yqbn@alap3.anarazel.de> <20211108174723.GI20998@tamriel.snowman.net> <c5d7045507b0ccac7d9421f52bf3b59b60e1150b.camel@j-davis.com> <20211109162938.GS20998@tamriel.snowman.net>

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

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