Repository navigation
Revoke privileges per grantor, revoke depended-on grant options with CASCADE, report grants of other roles - #366
Merged
Merged
Conversation
…d under SET ROLE before, revoke grant options other grants depend on with CASCADE and give back the grants kept, report grants of other roles in pull and diff.
This was referenced Nov 21, 2026
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #339
Fixes #362
PostgreSQL records a grantor for each privilege, and a plain
REVOKEonly takes away the grants of the role it runs as (of the owner, for the owner, a role with its privileges or a superuser). A grant that another role made, underSET ROLEor withGRANT ... GRANTED BYon 19, was revoked on every diff and stayed.Revokes per grantor (#339)
SET ROLEto.REVOKE ... GRANTED BY <grantor>on 19 when the connecting role is a superuser or has the grantor's privileges (19 requires inheriting them, checked), otherwiseSET ROLE <grantor>; REVOKE ...; RESET ROLE;when it maySET ROLEto it (15 to 18 rejectGRANTED BYanother role with "grantor must be current user", even for a superuser). Grants it can do neither for are left out with anot_ownerwarning that gives the statement to run.SET ROLErevokes go ahead of the plan's other revokes, as running as the grantor needs itsUSAGEon the schema.REVOKE ... GRANTED BYfrompublicgets thepublic_revokewarning too.REVOKEas before.Grant options other grants depend on (#362)
CASCADE, and the dependent grants the block doesn't revoke are granted again.Reporting
pgy pullwarns about the grants a role other than the owner and the connecting role made, andpgy diffabout those a grants block keeps: grants blocks don't record grantors, so a rebuilt database gets those privileges from the owner or the connecting role.Not done: writing the grantor into the YAML and planning
GRANT ... GRANTED BYwould need a new YAML construct, not a small change to the grants model. That is left for a follow-up.Tests: unit tests in
internal/diff/grantors_test.goandinternal/pull/grantors_test.go. Integration testsTestIntegrationGrantorRevokesConvergeandTestIntegrationGrantorCascadeKeepsGrantspass on 15, 16, 18 and 19, and so do the fullinternal/cliandinternal/integrationsuites. The probe fixtures (f15_base+f15_drifton 19,f15_drift18on 15/16/18) now converge with matching pg_dump output.