Re: DROP OWNED BY fails to clean out pg_init_privs grants

2024-09-19 Thread Marina Polyakova
Hello! IIUC the regression test test_pg_dump [1] fails, see the attached regression.diffs: diff -U3 /Users/test/Work/postgrespro/src/test/modules/test_pg_dump/expected/test_pg_dump.out /Users/test/Work/postgrespro/build/testrun/test_pg_dump-running/regress/results/test_pg_dump.out --- /User

Re: DROP OWNED BY fails to clean out pg_init_privs grants

2024-09-17 Thread Tom Lane
=?UTF-8?B?0JXQs9C+0YAg0KfQuNC90LTRj9GB0LrQuNC9?= writes: > This query does not expect that test database may already contain some > information about custom user that ran test_pg_dump-running. I'm perfectly content to reject this as being an abuse of the test case. Our TAP tests are built on th

Re: DROP OWNED BY fails to clean out pg_init_privs grants

2024-09-17 Thread Егор Чиндяскин
  >On Thu, Jun 20, 2024 at 3:43PM Hannu Krosing < han...@google.com > wrote: >> Still it would be nice to have some public support for users of >> non-managed PostgreSQL databases as well >+1. > >-- >Robert Haas >EDB: http://www.enterprisedb.com Hello! I have recently been researching postgres bu

Re: DROP OWNED BY fails to clean out pg_init_privs grants

2024-06-20 Thread Robert Haas
On Thu, Jun 20, 2024 at 3:43 PM Hannu Krosing wrote: > Still it would be nice to have some public support for users of > non-managed PostgreSQL databases as well +1. -- Robert Haas EDB: http://www.enterprisedb.com

Re: DROP OWNED BY fails to clean out pg_init_privs grants

2024-06-20 Thread Hannu Krosing
It does happen with some regularity. At least one large cloud database provider I know of saw this more than once a month until the mitigations were integrated in the major version upgrade process. It is possible that making database upgrades easier via better automation is what made this turn up

Re: DROP OWNED BY fails to clean out pg_init_privs grants

2024-06-20 Thread Tom Lane
Hannu Krosing writes: > Or perhaps we should still also patch pg_dump to ignore the aclentries > which refer to roles that do not exist in the database ? I didn't want to do that before, and I still don't. Given that this issue has existed since pg_init_privs was invented (9.6) without prior rep

Re: DROP OWNED BY fails to clean out pg_init_privs grants

2024-06-20 Thread Robert Haas
On Thu, Jun 20, 2024 at 2:25 PM Tom Lane wrote: > Hannu Krosing writes: > > Or perhaps we should still also patch pg_dump to ignore the aclentries > > which refer to roles that do not exist in the database ? > > I didn't want to do that before, and I still don't. Given that this > issue has exis

Re: DROP OWNED BY fails to clean out pg_init_privs grants

2024-06-20 Thread Hannu Krosing
Or perhaps we should still also patch pg_dump to ignore the aclentries which refer to roles that do not exist in the database ? On Thu, Jun 20, 2024 at 7:41 PM Hannu Krosing wrote: > > Then maybe we should put a query / function in the release notes to > clean up the existing mess. > > Thinking o

Re: DROP OWNED BY fails to clean out pg_init_privs grants

2024-06-20 Thread Hannu Krosing
Then maybe we should put a query / function in the release notes to clean up the existing mess. Thinking of it we should do it anyway, as the patch only prevents new messiness from happening and does not fix existing issues. I could share a query to update the pg_init_privs with non-existent role

Re: DROP OWNED BY fails to clean out pg_init_privs grants

2024-06-20 Thread Tom Lane
Hannu Krosing writes: > Is there anything that could be back-patched with reasonable effort ? Afraid not. The whole thing is dependent on pg_shdepend entries that won't exist in older branches. regards, tom lane

Re: DROP OWNED BY fails to clean out pg_init_privs grants

2024-06-20 Thread Hannu Krosing
Hi Tom, Is there anything that could be back-patched with reasonable effort ? -- Hannu On Mon, Jun 17, 2024 at 6:37 PM Daniel Gustafsson wrote: > > > On 17 Jun 2024, at 16:56, Tom Lane wrote: > > Daniel Gustafsson writes: > > >> I wonder if this will break any tools/scripts in prod which reli

Re: DROP OWNED BY fails to clean out pg_init_privs grants

2024-06-17 Thread Daniel Gustafsson
> On 17 Jun 2024, at 16:56, Tom Lane wrote: > Daniel Gustafsson writes: >> I wonder if this will break any tools/scripts in prod which relies on the >> previous (faulty) behaviour. It will be interesting to see if anything shows >> up on -bugs. Off the cuff it seems like a good idea judging by

Re: DROP OWNED BY fails to clean out pg_init_privs grants

2024-06-17 Thread Tom Lane
Daniel Gustafsson writes: > On 15 Jun 2024, at 01:46, Tom Lane wrote: >> The core change is to install SHARED_DEPENDENCY_INITACL entries in >> pg_shdepend for all references to non-pinned roles in pg_init_privs, >> whether they are the object's owner or not. Doing that ensures that >> we can't d

Re: DROP OWNED BY fails to clean out pg_init_privs grants

2024-06-17 Thread Daniel Gustafsson
> On 15 Jun 2024, at 01:46, Tom Lane wrote: > > Robert Haas writes: >> I think the only thing we absolutely have to fix here is the dangling >> ACL references. > > Here's a draft patch that takes care of Hannu's example, and I think > it fixes other potential dangling-reference scenarios too. >

Re: DROP OWNED BY fails to clean out pg_init_privs grants

2024-06-15 Thread Tom Lane
I wrote: > The semantics I've implemented on top of that are: > * ALTER OWNER does not touch pg_init_privs entries. > * REASSIGN OWNED replaces pg_init_privs references with the new > role, whether the references are as grantor or grantee. > * DROP OWNED removes pg_init_privs mentions of the doomed

Re: DROP OWNED BY fails to clean out pg_init_privs grants

2024-06-14 Thread Tom Lane
Robert Haas writes: > I think the only thing we absolutely have to fix here is the dangling > ACL references. Here's a draft patch that takes care of Hannu's example, and I think it fixes other potential dangling-reference scenarios too. I'm not sure whether I like the direction this is going, b

Re: DROP OWNED BY fails to clean out pg_init_privs grants

2024-06-04 Thread Robert Haas
On Fri, May 24, 2024 at 4:00 PM Tom Lane wrote: > > Oh! That does seem like it would make what I said wrong, but how would > > it even know who the original owner was? Shouldn't we be recreating > > the object with the owner it had at dump time? > > Keep in mind that the whole point here is for th

Re: DROP OWNED BY fails to clean out pg_init_privs grants

2024-06-04 Thread Robert Haas
On Tue, May 28, 2024 at 9:06 PM Hannu Krosing wrote: > We should definitely also fix pg_dump, likely just checking that the > role exists when generating REVOKE commands (may be a good practice > for other cases too so instead of casting to ::regrole do the actual > join) > > ## here is the fix f

Re: DROP OWNED BY fails to clean out pg_init_privs grants

2024-05-28 Thread Hannu Krosing
Hi Daniel, pg_upgrade is just one important user of pg_dump which is the one that generates REVOKE for a non-existent role. We should definitely also fix pg_dump, likely just checking that the role exists when generating REVOKE commands (may be a good practice for other cases too so instead of ca

Re: DROP OWNED BY fails to clean out pg_init_privs grants

2024-05-26 Thread Daniel Gustafsson
> On 26 May 2024, at 23:25, Tom Lane wrote: > > Hannu Krosing writes: >> Attached is a minimal patch to allow missing roles in REVOKE command > > FTR, I think this is a very bad idea. Agreed, this is papering over a bug. If we are worried about pg_upgrade it would be better to add a check to

Re: DROP OWNED BY fails to clean out pg_init_privs grants

2024-05-26 Thread Tom Lane
Hannu Krosing writes: > Attached is a minimal patch to allow missing roles in REVOKE command FTR, I think this is a very bad idea. It might be OK if we added some kind of IF EXISTS option, but I'm not eager about that concept either. The right thing here is to fix the backend so that pg_dump do

Re: DROP OWNED BY fails to clean out pg_init_privs grants

2024-05-26 Thread Hannu Krosing
Attached is a minimal patch to allow missing roles in REVOKE command This should fix the pg_upgrade issue and also a case where somebody has dropped a role you are trying to revoke privileges from : smalltest=# create table revoketest(); CREATE TABLE smalltest=# revoke select on revoketest from b

Re: DROP OWNED BY fails to clean out pg_init_privs grants

2024-05-25 Thread Hannu Krosing
On Sat, May 25, 2024 at 4:48 PM Tom Lane wrote: > > Hannu Krosing writes: > > Having an pg_init_privs entry referencing a non-existing user is > > certainly of no practical use. > > Sure, that's not up for debate. What I think we're discussing > right now is > > 1. What other cases are badly han

Re: DROP OWNED BY fails to clean out pg_init_privs grants

2024-05-25 Thread Tom Lane
Hannu Krosing writes: > Having an pg_init_privs entry referencing a non-existing user is > certainly of no practical use. Sure, that's not up for debate. What I think we're discussing right now is 1. What other cases are badly handled by the pg_init_privs mechanisms. 2. How much of that is pra

Re: DROP OWNED BY fails to clean out pg_init_privs grants

2024-05-25 Thread Hannu Krosing
On Fri, May 24, 2024 at 10:00 PM Tom Lane wrote: > > Robert Haas writes: > > On Fri, May 24, 2024 at 2:57 PM Tom Lane wrote: > >> Doesn't seem right to me. That will give pg_dump the wrong idea > >> of what the initial privileges actually were, and I don't see how > >> it can construct correct

Re: DROP OWNED BY fails to clean out pg_init_privs grants

2024-05-24 Thread Tom Lane
Robert Haas writes: > On Fri, May 24, 2024 at 2:57 PM Tom Lane wrote: >> Doesn't seem right to me. That will give pg_dump the wrong idea >> of what the initial privileges actually were, and I don't see how >> it can construct correct delta GRANT/REVOKE on the basis of false >> information. Duri

Re: DROP OWNED BY fails to clean out pg_init_privs grants

2024-05-24 Thread Robert Haas
On Fri, May 24, 2024 at 2:57 PM Tom Lane wrote: > Doesn't seem right to me. That will give pg_dump the wrong idea > of what the initial privileges actually were, and I don't see how > it can construct correct delta GRANT/REVOKE on the basis of false > information. During the dump reload, the ext

Re: DROP OWNED BY fails to clean out pg_init_privs grants

2024-05-24 Thread Tom Lane
Robert Haas writes: > On Fri, May 24, 2024 at 11:59 AM Tom Lane wrote: >> So this goal seems to >> mean that neither ALTER OWNER nor REASSIGN OWNED should touch >> pg_init_privs at all, as that would break its function of recording >> a historical state. Only DROP OWNED should get rid of pg_init

Re: DROP OWNED BY fails to clean out pg_init_privs grants

2024-05-24 Thread Robert Haas
On Fri, May 24, 2024 at 11:59 AM Tom Lane wrote: > Thinking about this some more: the point of pg_init_privs is to record > an object's privileges as they stood at the end of CREATE EXTENSION > (or extension update), with the goal that pg_dump should be able to > compute the delta between that and

Re: DROP OWNED BY fails to clean out pg_init_privs grants

2024-05-24 Thread Tom Lane
Daniel Gustafsson writes: > On 24 May 2024, at 16:20, Tom Lane wrote: >> Another point: shdepReassignOwned explicitly does not touch grants >> or default ACLs. It feels like the same should be true of >> pg_init_privs entries, > Agreed, I can't see why pg_init_privs should be treated differentl

Re: DROP OWNED BY fails to clean out pg_init_privs grants

2024-05-24 Thread Daniel Gustafsson
> On 24 May 2024, at 16:20, Tom Lane wrote: > 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. +1, in light of this

Re: DROP OWNED BY fails to clean out pg_init_privs grants

2024-05-24 Thread Tom Lane
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 simpler > case). Should REASSIGN OWNED alter the rows in pg_shdepend matching init > privs > from SHARED_DEPENDENCY_OWNER

Re: DROP OWNED BY fails to clean out pg_init_privs grants

2024-05-24 Thread Daniel Gustafsson
> On 24 May 2024, at 01:01, Tom Lane wrote: > > Hannu Krosing writes: >> While the 'DROP OWNED BY fails to clean out pg_init_privs grants' >> issue is now fixed,we have a similar issue with REASSIGN OWNED BY that >> is still there: > > Ugh, how embarrassing. I'll take a look tomorrow, if no on

Re: DROP OWNED BY fails to clean out pg_init_privs grants

2024-05-23 Thread Tom Lane
Hannu Krosing writes: > While the 'DROP OWNED BY fails to clean out pg_init_privs grants' > issue is now fixed,we have a similar issue with REASSIGN OWNED BY that > is still there: Ugh, how embarrassing. I'll take a look tomorrow, if no one beats me to it. regards, tom l

Re: DROP OWNED BY fails to clean out pg_init_privs grants

2024-05-23 Thread Hannu Krosing
While the 'DROP OWNED BY fails to clean out pg_init_privs grants' issue is now fixed,we have a similar issue with REASSIGN OWNED BY that is still there: Tested on fresh git checkout om May 20th test=# create user privtestuser superuser; CREATE ROLE test=# set role privtestuser; SET test=# create

Re: DROP OWNED BY fails to clean out pg_init_privs grants

2024-04-29 Thread David G. Johnston
On Monday, April 29, 2024, Tom Lane wrote: > "David G. Johnston" writes: > > My solution to this was to rely on the fact that the bootstrap superuser > is > > assigned OID 10 regardless of its name. > > Yeah, I wrote it that way to start with too, but reconsidered > because > > (1) I don't like

Re: DROP OWNED BY fails to clean out pg_init_privs grants

2024-04-29 Thread Tom Lane
"David G. Johnston" writes: > My solution to this was to rely on the fact that the bootstrap superuser is > assigned OID 10 regardless of its name. Yeah, I wrote it that way to start with too, but reconsidered because (1) I don't like hard-coding numeric OIDs. We can avoid that in C code but it

Re: DROP OWNED BY fails to clean out pg_init_privs grants

2024-04-29 Thread David G. Johnston
On Monday, April 29, 2024, Tom Lane wrote: > Daniel Gustafsson writes: > >> On 28 Apr 2024, at 20:52, Tom Lane wrote: > > > >> This is of course not bulletproof: with a sufficiently weird > >> bootstrap superuser name, we could get false matches to parts > >> of "regress_dump_test_role" or to p

Re: DROP OWNED BY fails to clean out pg_init_privs grants

2024-04-29 Thread Tom Lane
I wrote: > Pushed, thanks for reviewing! Argh, I forgot I'd meant to push b0c5b215d first not second. Oh well, it was only neatnik-ism that made me want to see those other animals fail --- and a lot of the buildfarm is red right now for $other_reasons anyway. regards, tom

Re: DROP OWNED BY fails to clean out pg_init_privs grants

2024-04-29 Thread Tom Lane
Daniel Gustafsson writes: > On 29 Apr 2024, at 21:15, Tom Lane wrote: >> v3 attached also has a bit more work on code comments. > LGTM. Pushed, thanks for reviewing! regards, tom lane

Re: DROP OWNED BY fails to clean out pg_init_privs grants

2024-04-29 Thread Daniel Gustafsson
> On 29 Apr 2024, at 21:15, Tom Lane wrote: > It occurred to me to use "aclexplode" to expand the initprivs, and > then we can substitute names with simple equality tests. The test > query is a bit more complicated, but I feel better about it. Nice, I didn't even remember that function existed.

Re: DROP OWNED BY fails to clean out pg_init_privs grants

2024-04-29 Thread Tom Lane
Daniel Gustafsson writes: >> On 28 Apr 2024, at 20:52, Tom Lane wrote: >> ... It's a little bit >> nasty to look at the ACL column of pg_init_privs, because that text >> involves the bootstrap superuser's name which is site-dependent. >> What I did to try to make the test stable is >> replace(ini

Re: DROP OWNED BY fails to clean out pg_init_privs grants

2024-04-29 Thread Daniel Gustafsson
> On 28 Apr 2024, at 20:52, Tom Lane wrote: > > I wrote: >> Here's a draft patch that attacks that. It seems to fix the >> problem with test_pg_dump: no dangling pg_init_privs grants >> are left behind. Reading this I can't find any sharp edges, and I prefer your changes to recordExtensionInitP

Re: DROP OWNED BY fails to clean out pg_init_privs grants

2024-04-28 Thread Tom Lane
I wrote: > Here's a draft patch that attacks that. It seems to fix the > problem with test_pg_dump: no dangling pg_init_privs grants > are left behind. Here's a v2 that attempts to add some queries to test_pg_dump.sql to provide visual verification that pg_shdepend and pg_init_privs are updated c

Re: DROP OWNED BY fails to clean out pg_init_privs grants

2024-04-27 Thread Tom Lane
I wrote: > A bigger problem though is that I think you are addressing the > original complaint from the older thread, which while it's a fine > thing to fix seems orthogonal to the failure we're seeing in the > buildfarm. The buildfarm's problem is not that we're recording > incorrect pg_init_priv

Re: DROP OWNED BY fails to clean out pg_init_privs grants

2024-04-26 Thread Tom Lane
Daniel Gustafsson writes: > On 21 Apr 2024, at 23:08, Tom Lane wrote: >> So the meson animals are not running the test that sets up the >> problematic data. > I took a look at this, reading code and the linked thread. My gut feeling is > that Stephen is right in that the underlying bug is these

Re: DROP OWNED BY fails to clean out pg_init_privs grants

2024-04-26 Thread Daniel Gustafsson
> On 21 Apr 2024, at 23:08, Tom Lane wrote: > > Daniel Gustafsson writes: >>> On 6 Apr 2024, at 01:10, Tom Lane wrote: >>> (So now I'm wondering why *only* copperhead has shown this so far. >>> Are our other cross-version-upgrade testing animals AWOL?) > >> Clicking around searching for Xversi

Re: DROP OWNED BY fails to clean out pg_init_privs grants

2024-04-22 Thread Daniel Gustafsson
> On 21 Apr 2024, at 23:08, Tom Lane wrote: > ... were you going to look at it? I can take a whack if it's too far down > your priority list. Yeah, I’m working on a patchset right now. ./daniel

Re: DROP OWNED BY fails to clean out pg_init_privs grants

2024-04-21 Thread Tom Lane
Daniel Gustafsson writes: >> On 6 Apr 2024, at 01:10, Tom Lane wrote: >> (So now I'm wondering why *only* copperhead has shown this so far. >> Are our other cross-version-upgrade testing animals AWOL?) > Clicking around searching for Xversion animals I didn't spot any, but without > access to th

Re: DROP OWNED BY fails to clean out pg_init_privs grants

2024-04-06 Thread Daniel Gustafsson
> On 6 Apr 2024, at 01:10, Tom Lane wrote: > (So now I'm wondering why *only* copperhead has shown this so far. > Are our other cross-version-upgrade testing animals AWOL?) Clicking around searching for Xversion animals I didn't spot any, but without access to the database it's nontrivial to kno

Re: DROP OWNED BY fails to clean out pg_init_privs grants

2024-04-05 Thread Tom Lane
Noah Misch writes: > On Fri, Apr 05, 2024 at 07:10:59PM -0400, Tom Lane wrote: >> The fact that the DROP ROLE added by 936e3fa37 succeeded indicates >> that these role references weren't captured in pg_shdepend. >> I imagine that we also lack code that would allow DROP OWNED BY to >> follow up on

Re: DROP OWNED BY fails to clean out pg_init_privs grants

2024-04-05 Thread Noah Misch
On Fri, Apr 05, 2024 at 07:10:59PM -0400, Tom Lane wrote: > I wondered why buildfarm member copperhead has started to fail > xversion-upgrade-HEAD-HEAD tests. I soon reproduced the problem here: > > pg_restore: creating ACL "regress_pg_dump_schema.TYPE "test_type"" > pg_restore: while PROCESSING