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 1oEaPr-0002Lt-LL for pgsql-hackers@arkaria.postgresql.org; Thu, 21 Jul 2022 17:56:51 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oEaPq-0005ou-Gt for pgsql-hackers@arkaria.postgresql.org; Thu, 21 Jul 2022 17:56:50 +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 1oEaPq-0005ob-7O for pgsql-hackers@lists.postgresql.org; Thu, 21 Jul 2022 17:56:50 +0000 Received: from mail-pj1-x1033.google.com ([2607:f8b0:4864:20::1033]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1oEaPn-0005nk-Cw for pgsql-hackers@postgresql.org; Thu, 21 Jul 2022 17:56:49 +0000 Received: by mail-pj1-x1033.google.com with SMTP id x24-20020a17090ab01800b001f21556cf48so5971374pjq.4 for ; Thu, 21 Jul 2022 10:56:47 -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=V+rsvqVJNwRBnAvl2HEOgyQ4PlKa0eV7YlPKiER77rk=; b=NvdB9And32TEJI4gH8WJiaV8Miue/v4M8ZE6wnWRwSKgFHtN2QUxjVMwH55V8zklVZ 7wokoppVSWp1yYrE972EMpHsWIKzGwDyLN5ZGhsMQIKuKEn2hkts31lEadFUjFqSxRnr XO9lW0xDOCA5pW2P6wD3kswdSQKycLO6rjdMN+mk2xcxd5YeZxdluOQ8lg27o06k7tsu gdy2AP0aZto3CxoDZDpZK+Mknr52Gn693tcQ9mZPxWkgxUhQw4GG+1MKeFYx64sIaBDk GuLjfdvukKXV+0Ufuj28KQwuDBHNQEk8wD0Ckex8nLUwN6KfhG+p80Ygh7Qx5oO8Ugv9 3pzg== 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=V+rsvqVJNwRBnAvl2HEOgyQ4PlKa0eV7YlPKiER77rk=; b=At2uLFluMMe59/KAawJT/t6m6bD1sJ83OLZe4Jtp13cYSS7vlTe/DvHxQbs72yKT6v aaZrUMJOqfyVoyYgAAP4092pZLFkz6fks/1XC22aVIR1RzxySq9omHqNN0nPvVAOWqZ4 ooeHWW/aizLGvz+8x25RuMfD1bDW6WLs8h6/nmxdLeqeBoLfr6JiICevQqq6CI2QRQuj KrouCu1027aWll9N1/VdR+jXrEewTdtmd4Jk2nEG1rYa5ownw1f1j1ugpjSGlW4P+YmP ODw5PQH9NmAjOlENkEuXwh6x1czMiHff+RUj+b7twHzIzrs2woIFGtQIb+ehyhYSgegr Od7Q== X-Gm-Message-State: AJIora8AjBq9/qkVjuOpqOX+RlcCyDasqmz0ix0resIuFJooTzKdsnfn FQXKW96w/pF7aA3lmO8Esmg= X-Google-Smtp-Source: AGRyM1uWooMvAEg49zbSsfeBq/T308hx4M2tAwFi8Ohec1xJ2f7KgtglJGSUVmWmruuQiU6fTVEPfw== X-Received: by 2002:a17:90b:4f47:b0:1f0:4785:b9be with SMTP id pj7-20020a17090b4f4700b001f04785b9bemr12533640pjb.131.1658426204463; Thu, 21 Jul 2022 10:56:44 -0700 (PDT) Received: from nathanxps13 ([50.54.155.70]) by smtp.gmail.com with ESMTPSA id n11-20020a170902d2cb00b0016bdf2220desm2018569plc.263.2022.07.21.10.56.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Jul 2022 10:56:43 -0700 (PDT) Date: Thu, 21 Jul 2022 10:56:41 -0700 From: Nathan Bossart To: Tom Lane Cc: Kyotaro Horiguchi , steve@supabase.io, pgsql-hackers@postgresql.org Subject: Re: Allow placeholders in ALTER ROLE w/o superuser Message-ID: <20220721175641.GB3779763@nathanxps13> References: <20220719000305.GA3714057@nathanxps13> <20220719165339.GB3716275@nathanxps13> <20220720.152836.1442103646840823302.horikyota.ntt@gmail.com> <1732511.1658332210@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1732511.1658332210@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Wed, Jul 20, 2022 at 11:50:10AM -0400, Tom Lane wrote: > I think that 13d838815 has completely changed the terms that this > discussion needs to be conducted under. It seems clear to me now > that if you want to relax this only-superusers restriction, what > you have to do is store the OID of the role that issued ALTER ROLE/DB SET, > and then apply the same checks that would be used in the ordinary case > where a placeholder is being filled in after being set intra-session. > That is, we'd no longer assume that a value coming from pg_db_role_setting > was set with superuser privileges, but we'd know exactly who did set it. I was imagining that the permissions checks would apply at ALTER ROLE/DB SET time, not at login time. Otherwise, changing a role's privileges might impact other roles' parameters, and it's not clear (at least to me) what should happen when the role is dropped. Another reason I imagined it this way is because that's basically how it works today. We assume that the pg_db_role_setting entry was added by a superuser, but we don't check that the user that ran ALTER ROLE/DB SET is still superuser every time you log in. > This might also tie into Nathan's question in another thread about > exactly what permissions should be required to issue ALTER ROLE/DB SET. > In particular I'm wondering if different permissions should be needed to > override an existing entry than if there is no existing entry. If not, > we could find ourselves downgrading a superuser-set entry to a > non-superuser-set entry, which might have bad consequences later > (eg, by rendering the entry nonfunctional because when we actually > load the extension we find out the GUC is SUSET). Yeah, this is why I suggested storing something that equates to PGC_SUSET any time a role is superuser or has grantable GUC permissions. > Possibly related to this: I felt while working on 13d838815 that > PGC_SUSET and PGC_SU_BACKEND should be usable as GucContext > values for GUC variables, indicating that the GUC requires special > privileges to be set, but we should no longer use them as passed-in > GucContext values. That is, we should remove privilege tests from > the call sites, like this: > > (void) set_config_option(stmt->name, > ExtractSetVariableArgs(stmt), > - (superuser() ? PGC_SUSET : PGC_USERSET), > + PGC_USERSET, > PGC_S_SESSION, > action, true, 0, false); > > and instead put that behavior inside set_config_option_ext, which > would want to look at superuser_arg(srole) instead, and indeed might > not need to do anything because pg_parameter_aclcheck would subsume > the test. I didn't pursue this further because it wasn't essential > to fixing the bug. But it seems relevant here, because that line of > thought leads to the conclusion that storing PGC_SUSET vs PGC_USERSET > is entirely the wrong approach. Couldn't ProcessGUCArray() use set_config_option_ext() with the context indicated by pg_db_role_setting? Also, instead of using PGC_USERSET in all the set_config_option() call sites, shouldn't we remove the "context" argument altogether? I am likely misunderstanding your proposal, but while I think simplifying set_config_option() is worthwhile, I don't see why it would preclude storing the context in pg_db_role_setting. -- Nathan Bossart Amazon Web Services: https://aws.amazon.com