Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qQWX3-000BEl-A7 for pgsql-hackers@arkaria.postgresql.org; Mon, 31 Jul 2023 17:18:10 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1qQWX0-001C0d-RL for pgsql-hackers@arkaria.postgresql.org; Mon, 31 Jul 2023 17:18:08 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qQWX0-001C0V-4w for pgsql-hackers@lists.postgresql.org; Mon, 31 Jul 2023 17:18:07 +0000 Received: from mail-yw1-x112a.google.com ([2607:f8b0:4864:20::112a]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1qQWWv-0001xW-Ap for pgsql-hackers@postgresql.org; Mon, 31 Jul 2023 17:18:06 +0000 Received: by mail-yw1-x112a.google.com with SMTP id 00721157ae682-583a8596e2aso45270947b3.1 for ; Mon, 31 Jul 2023 10:18:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joeconway.com; s=google; t=1690823880; x=1691428680; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=jS3WmhHle/izoLmtSokRYXTFS/mLIfc0KCTlKRLWQac=; b=W5wMHzVOr+YLhVPhsscJpB+zEIQebQJDfF24Wo/BdclKtu0R1l/v1NIUjC/i2drC3e PhD/me28BYAm4KKcL8S5+UJeKXoLIRDGWTjkBfCeCx7c1yg6Nj+jUTvVFGREknk2in2H QPElBYx9dwzAdpWWaw2I3F9BEl3ovuXHNAkJ1eH6wD4XmvMiWkJsKq2zlp0NfB0Gv+bA 0bQGCnfiDXeQMa8692eAT3jcbzMAPGsW1KfHleAMKlnWtA8EQAx/4W+7ZsPqdHGhwswN OcCaTGnkaey4GOl3Mo3yfgLh/GYrlj7nkyT0MXg4KUf8Fv7IF3xg8tVAvnr6RjcwGJvy 6u0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690823880; x=1691428680; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=jS3WmhHle/izoLmtSokRYXTFS/mLIfc0KCTlKRLWQac=; b=IfMIgV2/g+o1uuUEQINTM7DiK56dHYLVOvOee/H6tjC2vxvzV2LcQ2pSOHWFxFb5J1 tMujI8OJ/GT9Vscvf95c0JXMaxgx8ilkIS59KIdGnYciPfKPaNtmKbHV0Ty7E6xE4lwH 08tIpVUh5M2aN8jIYMIQDpWohYCpiLzp5ZrPK1OzhAPPYbR1WJyVAfFxPEe2frbYtNcU 9n7X8FsRzatG8IobKjqYkCarenYtV/x1YqIMwS8Nac4S5tFrReiS/YhunDxq1JuCRJvc 6c/DoJXIryaf/Cr/d4kRFV2DFlvdtHXsjnBHWNzr1cAaEoxiyzcTQGybSzLMhrYZtx3X x3tw== X-Gm-Message-State: ABy/qLYa8nT8ufKUStOKqe8La4v4fSZtZ5//JNL629LT2jXk7VzVxxcD LpmNloTGFr/GLK12D2clMQstiQ== X-Google-Smtp-Source: APBJJlHzAcjwXqgcqI09hpiTuTp5ufia3EVGKca2Tx3OZwKVsQll85O3I5q6WP/Q1qStGobylQf4bA== X-Received: by 2002:a0d:cad2:0:b0:583:fa48:1625 with SMTP id m201-20020a0dcad2000000b00583fa481625mr7787068ywd.1.1690823880100; Mon, 31 Jul 2023 10:18:00 -0700 (PDT) Received: from [192.168.4.41] (162-239-31-113.lightspeed.dybhfl.sbcglobal.net. [162.239.31.113]) by smtp.gmail.com with ESMTPSA id q206-20020a8175d7000000b005772646629csm3114087ywc.144.2023.07.31.10.17.59 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 31 Jul 2023 10:17:59 -0700 (PDT) Message-ID: Date: Mon, 31 Jul 2023 13:17:59 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Subject: Re: pgsql: Fix search_path to a safe value during maintenance operations. To: Robert Haas , Jeff Davis Cc: Tom Lane , Noah Misch , "pgsql-hackers@postgresql.org" , Nathan Bossart 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-Language: en-US From: Joe Conway In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 7/31/23 12:53, Robert Haas wrote: > On Fri, Jun 30, 2023 at 3:41 AM Jeff Davis wrote: >> 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=pg_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. > > I agree. I think there are actually two interrelated problems here. > > One is that virtually all code needs to run with the originally > intended search_path rather than some search_path chosen at another > time and maybe by a different user. If not, it's going to break, or > compromise security, depending on the situation. The other is that > running arbitrary code written by somebody else as yourself is > basically instant death, from a security perspective. I agree too. But the analysis of the issue needs to go one step further. Even if the search_path does not change from the originally intended one, a newly created function can shadow the intended one based on argument coercion rules. -- Joe Conway PostgreSQL Contributors Team RDS Open Source Databases Amazon Web Services: https://aws.amazon.com