Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mkU0E-0007zE-KX for pgsql-hackers@arkaria.postgresql.org; Tue, 09 Nov 2021 16:29:42 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mkU0D-00040O-FD for pgsql-hackers@arkaria.postgresql.org; Tue, 09 Nov 2021 16:29:41 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mkU0D-0003z7-5X for pgsql-hackers@lists.postgresql.org; Tue, 09 Nov 2021 16:29:41 +0000 Received: from tamriel.snowman.net ([2001:470:e38f::11]) by makus.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mkU0A-0003a1-TU for pgsql-hackers@postgresql.org; Tue, 09 Nov 2021 16:29:40 +0000 Received: by tamriel.snowman.net (Postfix, from userid 1000) id 9724E5F7A2; Tue, 9 Nov 2021 11:29:38 -0500 (EST) Date: Tue, 9 Nov 2021 11:29:38 -0500 From: Stephen Frost To: Jeff Davis Cc: Andres Freund , Robert Haas , "Bossart, Nathan" , Alvaro Herrera , Bharath Rupireddy , PostgreSQL-development Subject: Re: Predefined role pg_maintenance for VACUUM, ANALYZE, CHECKPOINT. Message-ID: <20211109162938.GS20998@tamriel.snowman.net> References: <20211101165025.GS20998@tamriel.snowman.net> <5e7a618de1b49ba1ceede54ee1b1d073bd57f1f4.camel@j-davis.com> <20211104224204.ee5673h3qlzblh7e@alap3.anarazel.de> <20211107184649.mpncdezkzfq2v4pb@alap3.anarazel.de> <20211108172318.GF20998@tamriel.snowman.net> <20211108173325.6ury6xflvxq7yqbn@alap3.anarazel.de> <20211108174723.GI20998@tamriel.snowman.net> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="F1+38+k2Q3ZvY9Bb" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --F1+38+k2Q3ZvY9Bb Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Greetings, * Jeff Davis (pgsql@j-davis.com) wrote: > On Mon, 2021-11-08 at 12:47 -0500, Stephen Frost wrote: > >=20 > > 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. >=20 > +1. It seems like the pg_checkpointer predefined role is the most > acceptable to everyone (even if not universally liked). >=20 > 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; > =20 > 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 --F1+38+k2Q3ZvY9Bb Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBCgAGBQJhiqHyAAoJEO1sijiDR2RVX2MP/jD0kUBjgXkklRlKj1qzcnAE njOPW26rEpPnGbe0KSFoQBLbb9TzyW5EbBriT/Mqy6ZyMnMQcAWYs1YKFNSw1nQj zjxe5PagrpYczm0WOW34Sm/MLzLdP/QX7FPxMMugdWJTkPN7BZujhc0NY/DYMCfV XY4t9FnEg8zzgRr4NrBdeLX+MJJjRDIAfaCziau0ABP7h94iuknZWPWa34bT0YMe Xs0RTA7DERjpf4CbbyU3kSMzOYMaqmCljtvmDp9A2N1tGRca2d7LpNAeu0Yk47sA 1hD0pJsp+R+CXP2weDgnpr+E/UC34+iD7hIesIjYLgWePYWHybY9iMZXQeqIr1B5 uWG5rcQctiEmDHLBDjwSUeFBKjFs3zW2iFZgZIMZn3B76DbMj1/lpTWn9PNV1AAU R0pAWsO/sACz3w4I1YCVvJduHkPCErKbSFlJ8OWONALtdBU7h4SowVziTJE2WjaT WQKaB4UZqYF1A8mahoDMN48KNOiUgZMG4VoyPYzCRyULUVMwhnYmDJs+6YqgZLz+ 8BjVP2c7a7TjozqIRULkwI/FDZ5u9kTFPzzPl5Wiq/UjJxsCoLZZ82z2ikl5Lb1d rztPjIcpOn1Rb1UCEZAt6MXdvM65Wf7FWBZvLG9F301QSzHT0gyH/zDcprm2xvUG 29xBUYJLappLQ3ValtCg =mNFo -----END PGP SIGNATURE----- --F1+38+k2Q3ZvY9Bb--