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 1tafQR-003zgD-4J for pgsql-hackers@arkaria.postgresql.org; Wed, 22 Jan 2025 18:26:03 +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 1tafQP-003ZsD-Ul for pgsql-hackers@arkaria.postgresql.org; Wed, 22 Jan 2025 18:26:01 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tafQP-003Zs4-Kg for pgsql-hackers@lists.postgresql.org; Wed, 22 Jan 2025 18:26:01 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1tafQM-000xEY-2V for pgsql-hackers@lists.postgresql.org; Wed, 22 Jan 2025 18:26:01 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 50MIPtme3944970; Wed, 22 Jan 2025 13:25:55 -0500 From: Tom Lane To: Laurenz Albe cc: Pavel Stehule , pgsql-hackers@lists.postgresql.org Subject: Re: Wrong security context for deferred triggers? In-reply-to: <51386e72c47d922ef68eaa67451a52dc3f569843.camel@cybertec.at> References: <77ee784cf248e842f74588418f55c2931e47bd78.camel@cybertec.at> <6f27f51bc98354d7254bbde1c171fa13aca03f28.camel@cybertec.at> <77b89e609f21380785865542609fbc14010021c8.camel@cybertec.at> <3f0a08f3e3d445137ae287125bc8c1a007045db8.camel@cybertec.at> <66021ca9d81c4e1a22b6c417659b05424e130f27.camel@cybertec.at> <6bca669972ef0d4a665fa83c5b751ab116324f8f.camel@cybertec.at> <2653121.1730737337@sss.pgh.pa.us> <51386e72c47d922ef68eaa67451a52dc3f569843.camel@cybertec.at> Comments: In-reply-to Laurenz Albe message dated "Mon, 04 Nov 2024 18:25:51 +0100" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3944968.1737570355.1@sss.pgh.pa.us> Date: Wed, 22 Jan 2025 13:25:55 -0500 Message-ID: <3944969.1737570355@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Laurenz Albe writes: > [ v4-0001-Make-AFTER-triggers-run-with-the-correct-user.patch ] I started to look at this and got distracted by wondering why afterTriggerAddEvent's scanning loop wasn't checking ats_modifiedcols. That led to ea68ea632, which means this now needs a minor rebase. I have a couple other thoughts: * It's kind of sad that we have to add yet another field to AfterTriggerSharedData, especially since this one will cost 8 bytes thanks to alignment considerations. I'm not sure if there's another way, but it seems like ats_relid, ats_rolid, and ats_modifiedcols are all going to be extremely redundant in typical scenarios. Maybe it's worth rethinking that data structure a bit? Or maybe I'm worried over nothing; perhaps normal situations have only a few AfterTriggerSharedDatas anyway. It might be worth trying to gather some statistics about that. * I don't buy the bit about "We have to check if the role still exists"; I think that's just a waste of cycles. There is no check that prevents dropping the role a session is currently running as, so why do we need one here? Moreover, the role could still get dropped immediately after you look. Or for that matter, save_rolid could be invalid by the time you restore it. None of this bothers me, because if a session is running as a dropped role it will still function pretty normally. It will find that it has no privileges beyond those granted to PUBLIC, and if it tries to inspect current_user or related functions those will fail, but there's no compromise to system integrity. So I'd just remove that test. regards, tom lane