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 1qF8lj-0002Ad-1B for pgsql-hackers@arkaria.postgresql.org; Fri, 30 Jun 2023 07:42:15 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1qF8kj-0001kC-0p for pgsql-hackers@arkaria.postgresql.org; Fri, 30 Jun 2023 07:41:13 +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 1qF8ki-0001k3-Is for pgsql-hackers@lists.postgresql.org; Fri, 30 Jun 2023 07:41:12 +0000 Received: from mail-qk1-x72f.google.com ([2607:f8b0:4864:20::72f]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1qF8kd-001K2p-4E for pgsql-hackers@postgresql.org; Fri, 30 Jun 2023 07:41:11 +0000 Received: by mail-qk1-x72f.google.com with SMTP id af79cd13be357-7658430eb5dso160529585a.2 for ; Fri, 30 Jun 2023 00:41:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=j-davis-com.20221208.gappssmtp.com; s=20221208; t=1688110865; x=1690702865; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:from:to:cc:subject :date:message-id:reply-to; bh=etLSju8yH2XNoJmrlbZjHZDGhXV1ADRxeQ6v2Xv5lEY=; b=0pN9eMQYYee5XZlP4zdyHdXmE19colB5JeeJWI0Jt0yzETjNUZeaJ/GogmUvZaN0Ll j0wvEoSs9guPHcobB4DU/QMq3upQJVWqDDJsmP11xRWagVS6H+YUhcVidanTpwDapfyo wq1xgDCWLFxFQ4couLMkNUyx/GXwKVaewy15c/XmPbmgcrfLcesXKecscz1ritlqvYl9 2BH3at/d0G8suwCc8Ya4VwwkHU5OJL0A0O4Plhtt5idE7PYLk9BF8hAzUoZw2BOYohAa 9AZILU6ptqa378aijouHxwjIUEkbAHMjDK6YmH4ETVBI7ySSlD3ihl7ja+SndWOQjgJj jtiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688110865; x=1690702865; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=etLSju8yH2XNoJmrlbZjHZDGhXV1ADRxeQ6v2Xv5lEY=; b=D7O9ECQ0zw3bOKkD+Qiow2DQBIVXfnx+h9kxIZa0o3iRjPrRcu9vdx4M4YUykZ5i91 71owfBhR8tjUHADp0ZJ2sAoH3yXaIVB2tXqBck+U1O8q6nZRepm/kJwyZ97hWr5LgcwA x0nem4D6Kh/st8RIn6DqG2GctYuBBtYVSKKoUgOffNQnpul/CqaifOvrmEkqoRnFRkEE qT3qONvGNXBOq7yHTNNwarLQrK0CryaJKIPdHVlJ8FC7c5Nf9muKbn9DCuyb2prQ4KXs djmhr7/dOH1KAYP1sFUcGj6l/nKeMggBTCqoFzUSRv/52yhJ8im2xCmXFRFbnS1hG3Ah HyYA== X-Gm-Message-State: ABy/qLZi4qZDc8AdHs0RCy6FO3MJ0RyTLrBLBFiLtX7tNsm737lM5xiD dNN4bDLffLaX0rwfWZveYbXGiQ== X-Google-Smtp-Source: APBJJlF4HgaoLz7uBgAQTKH1lH+qcZoAdSHd0tXwPXMJe70gnOhJiRPv41XD5CK0LAWx5nlym4gBRg== X-Received: by 2002:a05:620a:1a07:b0:767:39c5:652d with SMTP id bk7-20020a05620a1a0700b0076739c5652dmr2043442qkb.64.1688110865594; Fri, 30 Jun 2023 00:41:05 -0700 (PDT) Received: from jeff-laptop.lan (c-73-170-46-202.hsd1.ca.comcast.net. [73.170.46.202]) by smtp.gmail.com with ESMTPSA id y10-20020aa7804a000000b00669c99d05fasm9447536pfm.150.2023.06.30.00.41.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Jun 2023 00:41:04 -0700 (PDT) Message-ID: Subject: Re: pgsql: Fix search_path to a safe value during maintenance operations. From: Jeff Davis To: Tom Lane Cc: Robert Haas , Noah Misch , "pgsql-hackers@postgresql.org" , Nathan Bossart Date: Fri, 30 Jun 2023 00:41:02 -0700 In-Reply-To: <1659699.1688086436@sss.pgh.pa.us> References: <89a415b86d5421941e4281ba5bf6288934078624.camel@j-davis.com> <573014.1686375211@sss.pgh.pa.us> <20230612170510.GA201972@gust.leadboat.com> <20230613182920.GA259321@gust.leadboat.com> <1799839.1686687804@sss.pgh.pa.us> <4df537f5a0d8c0ceac3eec3809d1144880b8e76d.camel@j-davis.com> <578fb4be80247570e6a05924908765a0b345971e.camel@j-davis.com> <43bbc9f7318057f51552d5986830908cb018dadf.camel@j-davis.com> <1659699.1688086436@sss.pgh.pa.us> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.44.4-0ubuntu1 MIME-Version: 1.0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Thu, 2023-06-29 at 20:53 -0400, Tom Lane wrote: > I think that's a seriously awful kluge.=C2=A0 It will mean that things > behave > differently for the owner than for MAINTAIN grantees, which pretty > much > destroys the use-case for that privilege, as well as being very > confusing > and hard to debug. In version 15, try this: CREATE USER foo; CREATE SCHEMA foo AUTHORIZATION foo; CREATE USER bar; CREATE SCHEMA bar AUTHORIZATION bar; \c - foo CREATE FUNCTION foo.mod10(INT) RETURNS INT IMMUTABLE LANGUAGE plpgsql AS $$ BEGIN RETURN mod($1,10); END; $$; CREATE TABLE t(i INT); -- units digit must be unique CREATE UNIQUE INDEX t_idx ON t (foo.mod10(i)); INSERT INTO t VALUES(7); -- success INSERT INTO t VALUES(17); -- fails GRANT USAGE ON SCHEMA foo TO bar; GRANT INSERT ON t TO bar; \c - bar CREATE FUNCTION bar.mod(INT, INT) RETURNS INT IMMUTABLE LANGUAGE plpgsql AS $$ BEGIN RETURN $1 + 1000000; END; $$; SET search_path =3D bar, pg_catalog; INSERT INTO foo.t VALUES(7); -- succeeds \c - foo SELECT * FROM t; i=20 --- 7 7 (2 rows) I'm not sure that everyone in this thread realizes just how broken it is to depend on search_path in a functional index at all. And doubly so if it depends on a schema other than pg_catalog in the search_path. Let's also not forget that logical replication always uses search_path=3Dpg_catalog, so if you depend on a different search_path for any function attached to the table (not just functional indexes, also functions inside expressions or trigger functions), then those are already broken in version 15. And if a superuser is executing maintenance commands, there's little reason to think they'll have the same search path as the user that created the table. At some point in the very near future (though I realize that point may come after version 16), we need to lock down the search path in a lot of cases (not just maintenance commands), and I don't see any way around that. Regards, Jeff Davis