Report
pg_dumpall emits role grants with ADMIN OPTION in an order that cannot be restored when grantors form a cycle
- Severity
- 30
- Blamed commit
- ce6b672e4455820a0348214be0da1a024c3f619f
On 5 branches
REL_16_STABLE, REL_17_STABLE, REL_18_STABLE, REL_19_STABLE, master
Summary
pg_dumpall writes role grants that carry ADMIN OPTION in an order that cannot be restored when the grantors form a cycle. One GRANT runs before its grantor holds ADMIN OPTION, so the restore fails with
ERROR: ADMIN option cannot be granted back to your own grantor
pg_upgrade fails the same way. The reporter reproduced it on 19.0.
Reproduction
CREATE ROLE r1; CREATE ROLE r2; CREATE ROLE r3;
GRANT r1 TO r3 WITH ADMIN OPTION;
GRANT r1 TO r2 WITH ADMIN OPTION GRANTED BY r3;
GRANT r1 TO r2 WITH ADMIN OPTION GRANTED BY CURRENT_USER;
GRANT r1 TO r3 WITH ADMIN OPTION GRANTED BY r2;
REVOKE r1 FROM r2 GRANTED BY CURRENT_USER;
Then dump with pg_dumpall and restore the output into a new cluster. The restore fails with the error above.
Analysis
After the REVOKE, the remaining grants are r1 to r3 by the bootstrap superuser, r1 to r2 by r3, and r1 to r3 by r2. All of them are valid in the source cluster, but pg_dumpall emits them in a sequence where a grant is issued before its grantor has been given ADMIN OPTION in the target cluster.
The reporter attributes this to ce6b672e4455820a0348214be0da1a024c3f619f ("Make role grant system more consistent with other privileges"), which introduced grantor tracking for role grants. That commit is in REL_16_STABLE and later.
An older thread with patches for role-grant dump ordering, which do not cover this case: https://postgr.es/m/CALdSSPiJUAO2VsWy3hvWghgThT%3DAwK5-HVrCp-%2BRYAiYiDjr4Q%40mail.gmail.com
Notes
Reported on pgsql-bugs: https://postgr.es/m/19962-530e0c11d39d12e3@postgresql.org. Not independently reproduced by the bots yet.