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 1oDaho-0005xt-2s for pgsql-hackers@arkaria.postgresql.org; Tue, 19 Jul 2022 00:03:16 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oDahm-0002kX-7c for pgsql-hackers@arkaria.postgresql.org; Tue, 19 Jul 2022 00:03:14 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oDahl-0002kO-Tk for pgsql-hackers@lists.postgresql.org; Tue, 19 Jul 2022 00:03:13 +0000 Received: from mail-pg1-x52a.google.com ([2607:f8b0:4864:20::52a]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1oDahh-0002Ry-Sl for pgsql-hackers@postgresql.org; Tue, 19 Jul 2022 00:03:12 +0000 Received: by mail-pg1-x52a.google.com with SMTP id r186so12046960pgr.2 for ; Mon, 18 Jul 2022 17:03:09 -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=pAKYfxnAaA9B4e4fd3g5kCu7DATqv9SfDpy1UMIAEW8=; b=OjWfPtTD+qgFUFJgpWeEMvBMwDly4H0mvx6Q05J9z8ZL7gBXeGkz8PZd2UY15wp4Cd MGIa31WaLdNwZZ/nKOIUKfaiOCac8vcj/0oJbtWR4a1tEU7kHDwgTn7mqxXb3uF9ltAu a56uDp4VYrIZi726KtqR2PxhXMNm8w0JAMLsiWsTHXOIt/GXZYnAsbYsMKk2s90ELaDe PU6UDtYTbWhMRzkvgpc9IbZrzp92uaOKKdKP5pznymIiUegubbKmpLQpuIm67OLCJhnI 4kpA35D3pSyzHQqcLK/V6Z+6GKPfJc+ux+K63eWWqNWpifrAzB/ayEYbtxfG/XaEBtp8 i1Wg== 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=pAKYfxnAaA9B4e4fd3g5kCu7DATqv9SfDpy1UMIAEW8=; b=2706hLC0yjm7S7+2liVUCeui1snZp9QO+xgeERuSDL+6c//np8YLLSxU5dl2NukOe0 hRvj5PITdPBEFvtyKCRsIzeANMRxxUevPue/xv0ghI2mj2xpfYu2+Dfeg/+Hf7SP2eoA tj6jIhFljKdduRl9007BjJVyrL7V4rIKxJwnCBSGAUT4dSlAyRL0IH7kthLzzTZV005X T6MZ5WwvCHvQZ1c5qbN7WbqrpMssWPmUj+7MZ2PiwnmRPdGkXMZlVkixwxxcbEQqGdM/ zxg8th53tbbqpQyLVmkFTWghVa9NGMoS6RUFnm9vXRfo0X12fXYVsMh43mhr6nXXfTMP O1HA== X-Gm-Message-State: AJIora9xBM+L4Y7x2cWerVaHRnojm+5jewiBFmYw+5sQzMbETrACSdQA I+lZQ2NMs6T7vqmlhEHsgb8= X-Google-Smtp-Source: AGRyM1sWrdokkvoOlEz4n2XSzIGQmqlwlsuKxuJeOGsxR/D5v5r090WtEeXBQMttJVNUq3buRGqk+Q== X-Received: by 2002:a63:4903:0:b0:416:97f:6115 with SMTP id w3-20020a634903000000b00416097f6115mr27448267pga.198.1658188987563; Mon, 18 Jul 2022 17:03:07 -0700 (PDT) Received: from nathanxps13 ([50.54.155.70]) by smtp.gmail.com with ESMTPSA id a10-20020aa7970a000000b0052513b5d078sm9949422pfg.31.2022.07.18.17.03.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Jul 2022 17:03:07 -0700 (PDT) Date: Mon, 18 Jul 2022 17:03:05 -0700 From: Nathan Bossart To: Steve Chavez Cc: pgsql-hackers@postgresql.org Subject: Re: Allow placeholders in ALTER ROLE w/o superuser Message-ID: <20220719000305.GA3714057@nathanxps13> References: <20220701234027.GA637814@nathanxps13> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220701234027.GA637814@nathanxps13> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Fri, Jul 01, 2022 at 04:40:27PM -0700, Nathan Bossart wrote: > On Sun, Jun 05, 2022 at 11:20:38PM -0500, Steve Chavez wrote: >> However, defining placeholders at the role level require superuser: >> >> alter role myrole set my.username to 'tomas'; >> ERROR: permission denied to set parameter "my.username" >> >> Which is inconsistent and surprising behavior. I think it doesn't make >> sense since you can already set them at the session or transaction >> level(SET LOCAL my.username = 'tomas'). Enabling this would allow sidecar >> services to store metadata scoped to its pertaining role. >> >> I've attached a patch that removes this restriction. From my testing, this >> doesn't affect permission checking when an extension defines its custom GUC >> variables. >> >> DefineCustomStringVariable("my.custom", NULL, NULL, &my_custom, NULL, >> PGC_SUSET, ..); >> >> Using PGC_SUSET or PGC_SIGHUP will fail accordingly. Also no tests fail >> when doing "make installcheck". > > IIUC you are basically proposing to revert a6dcd19 [0], but it is not clear > to me why that is safe. Am I missing something? I spent some more time looking into this, and I think I've constructed a simple example that demonstrates the problem with removing this restriction. postgres=# CREATE ROLE test CREATEROLE; CREATE ROLE postgres=# CREATE ROLE other LOGIN; CREATE ROLE postgres=# GRANT CREATE ON DATABASE postgres TO other; GRANT postgres=# SET ROLE test; SET postgres=> ALTER ROLE other SET plperl.on_plperl_init = 'test'; ALTER ROLE postgres=> \c postgres other You are now connected to database "postgres" as user "other". postgres=> CREATE EXTENSION plperl; CREATE EXTENSION postgres=> SHOW plperl.on_plperl_init; plperl.on_plperl_init ----------------------- test (1 row) In this example, the non-superuser role sets a placeholder GUC for another role. This GUC becomes a PGC_SUSET GUC when plperl is loaded, so a non-superuser role will have successfully set a PGC_SUSET GUC. If we had a record of who ran ALTER ROLE, we might be able to apply appropriate permissions checking when the module is loaded, but this information doesn't exist in pg_db_role_setting. IIUC we have the following options: 1. Store information about who ran ALTER ROLE. I think there are a couple of problems with this. For example, what happens if the grantor was dropped or its privileges were altered? Should we instead store the context of the user (i.e., PGC_USERSET or PGC_SUSET)? Do we need to add entries to pg_depend? 2. Ignore or ERROR for any ALTER ROLE settings for custom GUCs. Since we don't know who ran ALTER ROLE, we can't trust the value. 3. Require superuser to use ALTER ROLE for a placeholder. This is what we do today. Since we know a superuser set the value, we can always apply it when the custom GUC is finally defined. If this is an accurate representation of the options, it seems clear why the superuser restriction is in place. -- Nathan Bossart Amazon Web Services: https://aws.amazon.com