From: Tom Lane <tgl@sss.pgh.pa.us>
To: Daniel Gustafsson <daniel@yesql.se>
Cc: Hannu Krosing <hannuk@google.com>
Cc: David G. Johnston <david.g.johnston@gmail.com>
Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Cc: Stephen Frost <sfrost@snowman.net>
Cc: Andres Freund <andres@anarazel.de>
Cc: Noah Misch <nmisch@google.com>
Subject: Re: DROP OWNED BY fails to clean out pg_init_privs grants
Date: Fri, 24 May 2024 10:20:00 -0400
Message-ID: <651419.1716560400@sss.pgh.pa.us> (raw)
In-Reply-To: <C253EA83-0133-4336-B993-F52762BF6624@yesql.se>
References: <1745535.1712358659@sss.pgh.pa.us>
<78CCD91B-99DC-4B0F-B65E-AD46E67CBC0B@yesql.se>
<2857513.1713733688@sss.pgh.pa.us>
<F27F3F6F-A052-4EEF-9A11-3D10A867843F@yesql.se>
<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>
<CAKFQuwajB+mm5zK9JGzqoGdZmm+1D5PWoqcd83Rs2g3Dn9b9=g@mail.gmail.com>
<1562011.1714450202@sss.pgh.pa.us>
<CAKFQuwYyhx01CMxmtupuMGiRwQbWTsDrDc2S88W4woaW3P=NyQ@mail.gmail.com>
<CAMT0RQSVgv48G5GArUvOVhottWqZLrvC5wBzBa4HrUdXe9VRXw@mail.gmail.com>
<537173.1716505303@sss.pgh.pa.us>
<C253EA83-0133-4336-B993-F52762BF6624@yesql.se>
Daniel Gustafsson <daniel@yesql.se> 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 simpler
> case). Should REASSIGN OWNED alter the rows in pg_shdepend matching init 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-hackers@postgresql.org
Cc: tgl@sss.pgh.pa.us, daniel@yesql.se, hannuk@google.com, david.g.johnston@gmail.com, sfrost@snowman.net, andres@anarazel.de, nmisch@google.com
Subject: Re: DROP OWNED BY fails to clean out pg_init_privs grants
In-Reply-To: <651419.1716560400@sss.pgh.pa.us>
References: <1745535.1712358659@sss.pgh.pa.us> <78CCD91B-99DC-4B0F-B65E-AD46E67CBC0B@yesql.se> <2857513.1713733688@sss.pgh.pa.us> <F27F3F6F-A052-4EEF-9A11-3D10A867843F@yesql.se> <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> <CAKFQuwajB+mm5zK9JGzqoGdZmm+1D5PWoqcd83Rs2g3Dn9b9=g@mail.gmail.com> <1562011.1714450202@sss.pgh.pa.us> <CAKFQuwYyhx01CMxmtupuMGiRwQbWTsDrDc2S88W4woaW3P=NyQ@mail.gmail.com> <CAMT0RQSVgv48G5GArUvOVhottWqZLrvC5wBzBa4HrUdXe9VRXw@mail.gmail.com> <537173.1716505303@sss.pgh.pa.us> <C253EA83-0133-4336-B993-F52762BF6624@yesql.se> <651419.1716560400@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox