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 1lql4e-0002en-7g for pgsql-hackers@arkaria.postgresql.org; Tue, 08 Jun 2021 23:23:56 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lql4c-0003wA-4O for pgsql-hackers@arkaria.postgresql.org; Tue, 08 Jun 2021 23:23:54 +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 1lql4b-0003tE-O6 for pgsql-hackers@lists.postgresql.org; Tue, 08 Jun 2021 23:23:53 +0000 Received: from mail-pl1-x62f.google.com ([2607:f8b0:4864:20::62f]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1lql4Y-0005dr-4Q for pgsql-hackers@lists.postgresql.org; Tue, 08 Jun 2021 23:23:52 +0000 Received: by mail-pl1-x62f.google.com with SMTP id h1so3892585plt.1 for ; Tue, 08 Jun 2021 16:23:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb-com.20150623.gappssmtp.com; s=20150623; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=v1kAPO9bIsXLZ2PH6ql3XFWgb37+Dcmc4K3WLvSJs7w=; b=I3itZ+uwkfjYTpftPsJUmfFDo0UPJ9P1EofQh0tbNcgWm79aggXoJkHTVPvKP2HQ8T FX4cIz8iuHFXQa3PdHBgH9+AWQwWICtK8aoPEqnXLLMLkN/uPtxfToVVJJSImZih1cF4 RjRID8pwR37WlbPRRkl4MfWHb3FGM9mpsqyLNnl/VHj1sFcft3iNgOyn90jBkszvObTr GxiLCla7RlIa24Og9slzQFxvZXx9LfK1RANx20fBQv49EF+FMT4CQA/qyJGTwDVa68wU HXP3+4VeJrw8uW9svNTpguHHBiYWjLpAOg9+1XDUK3NaReZUiiPy9hsXPnplz5bnsjcd FG/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=v1kAPO9bIsXLZ2PH6ql3XFWgb37+Dcmc4K3WLvSJs7w=; b=scqiTXxgx2+1p8RQOSNfvRGSdPQ1tiM7ZZmxtAg8ExBXdjZNxEVeB1DsazetBwjjpH 42AuLpcLl63vRohXUQ3g9ceFI5/TjBQve198xH4oWqMa0882WrMoDBk7TRMqP5khcpI+ lf0BGPGKZOUXM3AcE77egkN/k1cSQxaWg/ZAB0Y9brkCXataC8oMjyumhJ3Qu4p9Jn+R wRpPm4bQEJ98mqk4Q4OgIMh5sArMdgpl6Vg8eKcTfQVrnR5W6L/zl30094RVbriMHpCy fT3ic9sx7s0QZSaE2TjvwhOGR56WTIezhnId5kwJZOuJd8dLRjgeLeKhk/bxHpeyej2F h8hw== X-Gm-Message-State: AOAM533fZ2KxXeSRiVU0IZiT5uca0Vu/6jV8STzPqborpVf7DLqOIWgL 4ZdOEGkjWiSOKtK0WGop0Xsig+zooTvG1bD1oL5orOLM6KEesLEuaQdRfu4bKAEdgmS3Ons47qA 1fst/3VjVeQ4aghKOrb7ywDQC8ZGHSCGotWm3+RmVWOQQXSUd6SjW9hI3ccotN3QQNYP86dgDWV BkdM16R3x5rV1c5Ks88WVx331C+wm+537sPkHZxgO8Pbb3BlY362Ph X-Google-Smtp-Source: ABdhPJw8CTJKAszUxl13E2SYCV988zEZgflYFnYjydzE/tzlqAEwBgqCoez/ahS2greP4nayZ6N7Zw== X-Received: by 2002:a17:902:562:b029:10e:eadc:41a4 with SMTP id 89-20020a1709020562b029010eeadc41a4mr2493196plf.45.1623194628672; Tue, 08 Jun 2021 16:23:48 -0700 (PDT) Received: from laptop280-ma-us.hitronhub.home (24-113-193-150.wavecable.com. [24.113.193.150]) by smtp.gmail.com with ESMTPSA id lw3sm8416244pjb.1.2021.06.08.16.23.47 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 08 Jun 2021 16:23:48 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.120.23.2.4\)) Subject: Re: logical replication of truncate command with trigger causes Assert From: Mark Dilger In-Reply-To: <1250962.1623192946@sss.pgh.pa.us> Date: Tue, 8 Jun 2021 16:23:47 -0700 Cc: PostgreSQL Hackers , Peter Eisentraut , Simon Riggs Content-Transfer-Encoding: quoted-printable Message-Id: References: <1250962.1623192946@sss.pgh.pa.us> To: Tom Lane X-Mailer: Apple Mail (2.3608.120.23.2.4) X-CLOUD-SEC-AV-Info: enterprisedb,google_mail,monitor X-CLOUD-SEC-AV-Sent: true X-Gm-Spam: 0 X-Gm-Phishy: 0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > On Jun 8, 2021, at 3:55 PM, Tom Lane wrote: >=20 > The right way to say that is "commit 84f5c2908da exposed the = pre-existing > unsafe behavior of this code". It's not okay to run arbitrary user = code > without holding a snapshot to protect TOAST dereference operations. Sure, I didn't expect that you'd broken things so much as we now have an = Assert where, at least for simple commands, things were working back in = April. Those things may not have been working correctly -- I'll have to = do some more test development to see if I can get the pre-84f5c2908da to = misbehave -- but this may appear to be a regression in version 14 if we = don't do something. Calling ExecuteTruncateGuts from within the logical replication worker = was introduced in commit 039eb6e92f2, "Logical replication support for = TRUNCATE", back in April 2018. So whatever we do will likely need to be = backpatched. > I suppose that either apply_dispatch or LogicalRepApplyLoop needs to > grow some more snapshot management logic, but I've not looked at that > code much, so I don't have an opinion on just where to add it. I was looking at those for other reasons prior to hitting this bug. My = purpose was to figure out how to get the code to respect privileges. = Perhaps the solution to these two issues is related. I don't know yet. As it stands, a subscription can only be created by a superuser, and the = replication happens under that user's current_user and session_user. I = naively thought that adding a built-in role pg_logical_replication which = could create subscriptions would be of some use. I implemented that = but, but now if I create a user named "replication_manager" with = membership in pg_logical_replication but not superuser, it turns out = that even though the apply worker runs as replication_manager, the = insert/update/delete commands work without checking privileges. (They = can insert/update/delete tables and execute functions owned by a = database superuser for which "replication_manager" has no privileges.) = So I need to go a bit further to get acl checks called from this code = path. > There's a reasonable case to be made that running user code outside > a Portal is a just-plain-bad idea, so we should fix the logical > apply worker to make it create a suitable Portal. I speculated about > that in the commit message for 84f5c2908da, but I don't feel like > taking point on such work. I'll dig into this a bit more. =E2=80=94 Mark Dilger EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company