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 1oC7mE-0002eV-S6 for pgsql-hackers@arkaria.postgresql.org; Thu, 14 Jul 2022 22:57:46 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oC7mD-0004EQ-OZ for pgsql-hackers@arkaria.postgresql.org; Thu, 14 Jul 2022 22:57:45 +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 1oC7mD-00049J-DM for pgsql-hackers@lists.postgresql.org; Thu, 14 Jul 2022 22:57:45 +0000 Received: from mail-pj1-x102a.google.com ([2607:f8b0:4864:20::102a]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1oC7m6-0005ot-Kl for pgsql-hackers@postgresql.org; Thu, 14 Jul 2022 22:57:44 +0000 Received: by mail-pj1-x102a.google.com with SMTP id g16-20020a17090a7d1000b001ea9f820449so9942270pjl.5 for ; Thu, 14 Jul 2022 15:57:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=0v/yB2VQQLH/PXg8dPVzRtqjjnFxHbSIU1oG5FIz7zo=; b=V9kcVVYPwNCZ0Ev6UpP9IRXxZK++Pn3OTotxQdt0QxDV63mAr+hNU31IJpZC7Hi5T9 rUHiimNwgphorBiZ+KXGPw0z25I/NOtQoxzRTUdypRX+soa8X7W8xOpdwEx16GwLIyS5 O/MfX4H7UcjtlB0HUuwUyqYCGaCEDYaYe2hYNBXj8I75K8gijlAWqTxsv0CGTbKPhSBx 6/3O50thn/LFv/pWwHel2vH7pjfVsHpkSbBHI6wES3xxdIvFa7FU9n3E8VFH5+LwbNPx uns1wTF2qN5RYdyy95hBeD/bGvsl9vDv/5FtMNXkgBe1zv0xToMAJKAwB2YmkhH0GCvN Codg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=0v/yB2VQQLH/PXg8dPVzRtqjjnFxHbSIU1oG5FIz7zo=; b=k++Qdkj6RZiKtfZywqGL5lIEL4kjx32vQOQmC5+TlNbGBIk9quLMX8UYXUnmLwi0Mz ou3QkIl0Av03tzTXkPpmxXpbs8Y3Rhcp0aMNRPO71yOUKBBYKZrvLYhM7tyHky+8Psp6 fKwJuaUiLx1G+tDB6+lsLt7mfSZ7UU1IITCs7EpYlFACZge/VNF9kAVK4lM3/WF8UHK6 hK8UGY0N8/1+c4BiY+/GDyBh8E8+jXg3qMJBSqwxuVhIiE8TZi+ZGYMHg+Jl6u7FywsZ Ahdw6a8lmNN3vqUWWd5HavALeAHtATH/oQqHsfNdj4evAaXeZYaMaYxze50kjwVygm/6 5EoQ== X-Gm-Message-State: AJIora9Wr8Ttfx2Secim2NlL8E52kdUNMOTs3sblRSYQY32CE4toTD5f /UUJF98l94rsUp5fBzM74m7C/F+1nPg= X-Google-Smtp-Source: AGRyM1uRJFePGg3d/X5xGEN43sWCLBKg0VgU1M2tiIbc5/KFGgjp0SJ19ygAmL7gxsQVgGu0E94tfA== X-Received: by 2002:a17:902:ebd2:b0:16c:2607:acbe with SMTP id p18-20020a170902ebd200b0016c2607acbemr10589358plg.14.1657839457649; Thu, 14 Jul 2022 15:57:37 -0700 (PDT) Received: from nathanxps13 ([50.54.155.70]) by smtp.gmail.com with ESMTPSA id q126-20020a634384000000b0040ca587fe0fsm1902968pga.63.2022.07.14.15.57.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Jul 2022 15:57:36 -0700 (PDT) Date: Thu, 14 Jul 2022 15:57:35 -0700 From: Nathan Bossart To: Tom Lane Cc: Michael Paquier , pgsql-hackers@postgresql.org Subject: Re: pg_parameter_aclcheck() and trusted extensions Message-ID: <20220714225735.GB3173833@nathanxps13> References: <20220706224727.GA2158260@nathanxps13> <2995921.1657212060@sss.pgh.pa.us> <3126292.1657828950@sss.pgh.pa.us> <20220714215225.GA3173833@nathanxps13> <3159281.1657836225@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <3159281.1657836225@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Thu, Jul 14, 2022 at 06:03:45PM -0400, Tom Lane wrote: > Nathan Bossart writes: >> On Thu, Jul 14, 2022 at 04:02:30PM -0400, Tom Lane wrote: >>> I noted something that ought to be looked at separately: >>> validate_option_array_item() seems like it needs to be taught about >>> grantable permissions on GUCs. I think that right now it may report >>> permissions failures in some cases where it should succeed. > >> Which cases do you think might be inappropriately reporting permissions >> failures? It looked to me like this stuff was mostly used for >> pg_db_role_setting, which wouldn't be impacted by the current set of >> grantable GUC permissions. Is the idea that you should be able to do ALTER >> ROLE SET for GUCs that you have SET permissions for? > > Well, that's what I'm wondering. Obviously that wouldn't *alone* be > enough permissions, but it seems like it could be a component of it. > Specifically, this bit: > > /* manual permissions check so we can avoid an error being thrown */ > if (gconf->context == PGC_USERSET) > /* ok */ ; > else if (gconf->context == PGC_SUSET && superuser()) > /* ok */ ; > else if (skipIfNoPermissions) > return false; > > seems like it's trying to duplicate what set_config_option would do, > and it's now missing a component of that. If it shouldn't check > per-GUC permissions along with superuser(), we should add a comment > explaining why not. I looked into this a bit closer. I found that having SET permissions on a GUC seems to allow you to ALTER ROLE SET it to others. postgres=# CREATE ROLE test CREATEROLE; CREATE ROLE postgres=# CREATE ROLE other; CREATE ROLE postgres=# GRANT SET ON PARAMETER zero_damaged_pages TO test; GRANT postgres=# SET ROLE test; SET postgres=> ALTER ROLE other SET zero_damaged_pages = 'on'; ALTER ROLE postgres=> SELECT * FROM pg_db_role_setting; setdatabase | setrole | setconfig -------------+---------+------------------------- 0 | 16385 | {zero_damaged_pages=on} (1 row) However, ALTER ROLE RESET ALL will be blocked, while resetting only the individual GUC will go through. postgres=> ALTER ROLE other RESET ALL; ALTER ROLE postgres=> SELECT * FROM pg_db_role_setting; setdatabase | setrole | setconfig -------------+---------+------------------------- 0 | 16385 | {zero_damaged_pages=on} (1 row) postgres=> ALTER ROLE other RESET zero_damaged_pages; ALTER ROLE postgres=> SELECT * FROM pg_db_role_setting; setdatabase | setrole | setconfig -------------+---------+----------- (0 rows) I think this is because GUCArrayReset() is the only caller of validate_option_array_item() that sets skipIfNoPermissions to true. The others fall through to set_config_option(), which does a pg_parameter_aclcheck(). So, you are right. Regarding whether SET privileges should be enough to allow ALTER ROLE SET, I'm not sure I have an opinion yet. You would need WITH GRANT OPTION to be able to grant SET to that role, but that's a bit different than altering the setting for the role. You'll already have privileges to alter the role (e.g., CREATEROLE), so requiring extra permissions to set GUCs on roles feels like it might be excessive. But there might be a good argument for it. -- Nathan Bossart Amazon Web Services: https://aws.amazon.com