ACL dump ordering broken as well for tablespaces - Mailing list pgsql-hackers

From Michael Paquier
Subject ACL dump ordering broken as well for tablespaces
Date
Msg-id 20190522071555.GB1278@paquier.xyz
Whole thread Raw
Responses Re: ACL dump ordering broken as well for tablespaces
List pgsql-hackers
Hi all,

As some may have noticed, I have been looking at the ACL dump ordering
for databases, and I have noticed the same issue with tablespaces:
https://www.postgresql.org/message-id/20190522062626.GC1486@paquier.xyz

For the sake of avoiding looking at the other email, here is how to
reproduce the issue:
1) First issue those SQLs:
\! rm -rf /tmp/tbspc/
\! mkdir -p /tmp/tbspc/
CREATE ROLE a_user;
CREATE ROLE b_user WITH SUPERUSER;
CREATE ROLE c_user;
CREATE TABLESPACE poo LOCATION '/tmp/tbspc/';
SET SESSION AUTHORIZATION b_user;
REVOKE ALL ON TABLESPACE poo FROM public;
GRANT CREATE ON TABLESPACE poo TO c_user WITH GRANT OPTION;
SET SESSION AUTHORIZATION c_user;
GRANT CREATE ON TABLESPACE poo TO a_user
2) Use pg_dumpall -g, where you would notice the following set of
GRANT queries:
CREATE TABLESPACE poo OWNER postgres LOCATION '/tmp/tbspc';
SET SESSION AUTHORIZATION c_user;
GRANT ALL ON TABLESPACE poo TO a_user;
RESET SESSION AUTHORIZATION;
GRANT ALL ON TABLESPACE poo TO c_user WITH GRANT OPTION;
3) Trying to restore results in a failure for the first GRANT query,
as the second one has not set yet the authorizations for c_user.

Attached is a patch to fix that, so as pg_dumpall does not complain
when piling up GRANT commands using WITH GRANT OPTION.  Are there any
complains to apply that down to 9.6?

When applying the patch, the set of GRANT queries is reordered:
 CREATE TABLESPACE poo OWNER postgres LOCATION '/tmp/tbspc';
+GRANT ALL ON TABLESPACE poo TO c_user WITH GRANT OPTION;
 SET SESSION AUTHORIZATION c_user;
 GRANT ALL ON TABLESPACE poo TO a_user;
 RESET SESSION AUTHORIZATION;
-GRANT ALL ON TABLESPACE poo TO c_user WITH GRANT OPTION;

As the problem is kind of different than the database case, I wanted
to spawn anyway a new thread, but I got a bonus question: what would
it take to support pg_init_privs for databases and tablespaces?  If we
could get that to work, then all the ACL-related queries built for all
objects could make use of buildACLQueries(), which would avoid extra
diffs in the dump code for dbs and tbspaces.

Thoughts?
--
Michael

Attachment

pgsql-hackers by date:

Previous
From: Amit Langote
Date:
Subject: Re: PostgreSQL 12 Beta 1 press release draft
Next
From: Michael Paquier
Date:
Subject: Re: PG 12 draft release notes