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 1sAVmE-00AMZv-29 for pgsql-hackers@arkaria.postgresql.org; Fri, 24 May 2024 14:20:11 +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 1sAVmE-0064WX-10 for pgsql-hackers@arkaria.postgresql.org; Fri, 24 May 2024 14:20:10 +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 1sAVmD-0064WP-Nv for pgsql-hackers@lists.postgresql.org; Fri, 24 May 2024 14:20:09 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sAVmB-001n1v-9b for pgsql-hackers@lists.postgresql.org; Fri, 24 May 2024 14:20:08 +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 44OEK0T1651420; Fri, 24 May 2024 10:20:00 -0400 From: Tom Lane To: Daniel Gustafsson cc: Hannu Krosing , "David G. Johnston" , PostgreSQL Hackers , Stephen Frost , Andres Freund , Noah Misch Subject: Re: DROP OWNED BY fails to clean out pg_init_privs grants In-reply-to: References: <1745535.1712358659@sss.pgh.pa.us> <78CCD91B-99DC-4B0F-B65E-AD46E67CBC0B@yesql.se> <2857513.1713733688@sss.pgh.pa.us> <32556.1714165429@sss.pgh.pa.us> <378162.1714257933@sss.pgh.pa.us> <772627.1714330360@sss.pgh.pa.us> <33E80863-5516-45A1-93D1-00F1A166EC7C@yesql.se> <1372432.1714418108@sss.pgh.pa.us> <1562011.1714450202@sss.pgh.pa.us> <537173.1716505303@sss.pgh.pa.us> Comments: In-reply-to Daniel Gustafsson message dated "Fri, 24 May 2024 13:27:18 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <651418.1716560400.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Fri, 24 May 2024 10:20:00 -0400 Message-ID: <651419.1716560400@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Daniel Gustafsson writes: > I had a look, but I didn't beat you to a fix since it's not immediately = clear > to me how this should work for REASSING OWNED (DROP OWNED seems a simple= r > case). Should REASSIGN OWNED alter the rows in pg_shdepend matching ini= t privs > from SHARED_DEPENDENCY_OWNER to SHARED_DEPENDENCY_INITACL, so that these= can be > mopped up with a later DROP OWNED? Trying this in a POC patch it fails = with > RemoveRoleFromInitPriv not removing the rows, shortcircuiting that for a= test > seems to make it work but is it the right approach? I've tentatively concluded that I shouldn't have modeled SHARED_DEPENDENCY_INITACL so closely on SHARED_DEPENDENCY_ACL, in particular the decision that we don't need such an entry if there's also SHARED_DEPENDENCY_OWNER. I think one reason we can get away with omitting a SHARED_DEPENDENCY_ACL entry for the owner is that the object's normal ACL is part of its primary catalog row, so it goes away automatically if the object is dropped. But obviously that's not true for a pg_init_privs entry. I can see two routes to a solution: 1. Create SHARED_DEPENDENCY_INITACL, if applicable, whether the role is the object's owner or not. Then, clearing out the pg_shdepend entry cues us to go delete the pg_init_privs entry. 2. Just always search pg_init_privs for relevant entries when dropping an object. I don't especially like #2 on performance grounds, but it has a lot fewer moving parts than #1. In particular, there's some handwaving in changeDependencyOnOwner() about why we should drop SHARED_DEPENDENCY_ACL when changing owner, and I've not wrapped my head around how those concerns map to INITACL if we treat it in this different way. Another point: shdepReassignOwned explicitly does not touch grants or default ACLs. It feels like the same should be true of pg_init_privs entries, or at least if not, why not? In that case there's nothing to be done in shdepReassignOwned (although maybe its comments should be adjusted to mention this explicitly). The bug is just that DROP OWNED isn't getting rid of the entries because there's no INITACL entry to cue it to do so. Another thing I'm wondering about right now is privileges on global objects (roles, databases, tablespaces). The fine manual says "Although an extension script is not prohibited from creating such objects, if it does so they will not be tracked as part of the extension". Presumably, that also means that no pg_init_privs entries are made; but do we do that correctly? Anyway, -ENOCAFFEINE for the moment. I'll look more later. regards, tom lane