Re: incorrect pg_dump output due to not handling dropped roles correctly

Stephen Frost <[email protected]>
Newsgroups gmane.comp.db.postgresql.bugs
Message-ID <[email protected]>
Greetings,

* Floris Van Nee ([email protected]) wrote:
> I noticed I wasn't able to apply my usual pg_dump schema output without errors anymore after I dropped some roles. After some digging, I found it has to do with Postgres not correctly updating the pg_init_privs table upon dropping roles. I can reproduce a similar scenario with the following steps (output from v13devel, but AFAIK all versions affected, I ran into the issue on v11.2):

Ok, this is ... interesting.

> postgres=# create role test;
> CREATE ROLE
> postgres=# alter default privileges in schema public grant all privileges on tables to test;
> ALTER DEFAULT PRIVILEGES
> postgres=# create extension pg_stat_statements;
> CREATE EXTENSION

So- in this case, the 'test' role is being granted these privileges
because it was given default privs in the public schema for objects that
are created by the superuser, even though the 'test' role never shows up
in the actual pg_stat_statements sql script.

I'm on the fence about if all of the objects which are created by an
extension should actually be subject to default privileges or not, but I
definitely don't think that the pg_init_privs system should be treating
those privileges that come from default privileges, instead of from the
extension's sql script, as being part of the 'initial privileges' for
the extension.

In short, I don't think any of the downthread discussion about how to
fix this is at all correct- the problem, as I view it, is that these
entries are getting into pg_init_privs in the first place and they
really shouldn't be because these privileges aren't coming from the
*extension* which is what pg_init_privs is trying to track.

Another way to view this is that I think the way we should be thinking
about the order of operations here is:

create role test;
alter default privs;
create extension;
  -- extension .sql runs WITHOUT any default privs being applied
  -- ACLs are recorded into pg_init_privs from the .sql script
  -- default privs are applied to the objects from the extension

Maybe we implement it that way, maybe we don't, but the above is my
feeling as to what the perception should be.

This would also mean that pg_dump would automatically figure out that
these privileges have been added AFTER the extension was created (and
aren't part of the extension's .sql script) and therefore there should
be some independent GRANT commands to add those privileges back included
in the pg_dump file.

Maybe something else to point out is that if we keep these entries in
pg_init_privs the way the downthread discussion seems to be assuming,
then pg_dump would *not* include the GRANT commands to add them back and
therefore you'd have to imagine re-ordering things in pg_dump so that
the default privileges are installed before the extension gets created,
and I'm hoping everyone here agress that'd be pretty crazy to try and
do.

Thanks,

Stephen
signature.asc (application/pgp-signature, 819 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1

iQIcBAEBCgAGBQJd5sVBAAoJEO1sijiDR2RVZ+sQALksC3KTelIWANIfQiOqKdXp
orhaDbvSlXAdlmN8nDbl4vZMQ3ufwtXdC/PfAEqQC9800BsWG+gJe9n+EHMNH5rh
c12Vhbnz2M35skoEwIrHdgN73yVO2aGbqSmVEJiiy3RfGp+lPLfsepZYoQwhdB8z
VljdyNQqh4kluoEJvu/A2q2KuaxtolXdyjl12PnWldxvlWo/C/gMiHrUlJduAksa
vMnoEAvbWLH1xbk5YdhSSsYyyICYHX5XwGh99yGcE+kV4ie+euPhQK7LmADrnA8z
eKkVAGlYN6iM9H60iErQz3ilAM4T+uHnRcjfV0pPVrBquJ6PHeO9O/9xcrSs8JLK
YjMiKJbhsqIfcabbgZeoV0cdplRUP14pgHmJSPFQ4vYl0onQHKPbNWikUu7OTplb
vC3LrNQQ6mnrk2arzs7zG25BVS2N5SmS7Rj+bV/FUMRZQWrD/TUhiqcoqrzlzB8h
A1u4SYDPzzK3ATfPioOC99TTz+nZJw5AcNp+jHe6kLWcMONQxO31SgFUrrTP4RDy
n8uvv/+lgdbSKYUymSUsCN/P2iOQlDIiwrgBr2eowEwO/krcUQYR03rv5/jVI5UO
bEWq91oW8sup/0vYIa5BWzwWyLh9fUMjVtVMMXb3xHXR/MvQX+V2qzcfAxZFygu3
wFo4C+v6uzHL+F2tRKK3
=B/2P
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.