Repository navigation
Declare the grants of roles other than the owner in grantedBy blocks - #371
Merged
Merged
Conversation
… made GRANTED BY the grantor on PostgreSQL 19 and under SET ROLE before, and pull them.
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 #367
Since #366 pgy revokes per grantor, but a grants block can't say who granted a privilege. A rebuilt database got every grant from the owner or the connecting role, so
pg_dumpof the source and of the rebuild differed (p19_reader=r/p19_adminvsr/pgy). This adds agrantedBy:block that declares those grants.YAML
grants:block now also takesgrantedBy:: tables, foreign tables, columns, views, materialized views, sequences, functions, procedures, aggregates, types, domains, schemas (schema x:blocks andschemas:entries), servers, foreign-data wrappers and languages. A view's columns takecolumnGrantedBy:. The shape is grantor → grantee → privileges, spelled as in a grants block (with grant optionandallincluded).schemas/pgy.schema.jsonhas a newgrantedBydefinition and accepts the key in all of these places. Alanguages:entry now needsgrantsorgrantedBy.Semantics
grantor: {}revokes all of that grantor's grants.grantedByblock doesn't list. It no longer sees privileges that only listed grantors gave, so it never revokes or regrants them (no flapping). A privilege a grantee holds from both the owner and a listed grantor appears in both blocks.pgy validatewarns about it.grantedByblock lists.REVOKE ... GRANTED BY galso takes away g's grants on the table's columns. A column'sgrantedBymakes those grants again. I found this on real servers, andafterTableRevokeshandles it.Emission
GRANT ... GRANTED BY gwhen the connecting role is a superuser or inherits g's privileges.SET ROLE g; GRANT ...; RESET ROLE;when the connecting role is a superuser or maySET ROLEto g. On these versionsGRANTED BYmust name the current user, even for a superuser (checked on 18).GRANT.not_ownerwarning that gives the statement to run.--from-emptyplans theSET ROLEform, which runs on every version.REVOKE ... CASCADEtakes away are made again.SimulateappliesgrantedByblocks to the simulated grantors and ACLs, so split plans converge.ALLis expanded ingrantedByblocks too.pull
pgy pullwritesgrantedByfor grants whose grantor is neither the owner nor the connecting role, and takes them out of the grants block unless the owner granted the same privilege. Before, it warned about these grants.validate
Decided against / left open
GRANTrecords the owner as the grantor. That grant is left out with a warning. Pull keeps writing such grants to the grants block, as before.maintain-before-17 version warning still looks only at grants blocks, not atgrantedByblocks.Tests
internal/schema/granted_by_test.go).internal/diff/granted_by_test.go):not_ownerfallback with hintsGRANTED BY/SET ROLEALLexpansioninternal/pull/grantors_test.go) and validate tests (internal/validate/granted_by_test.go).internal/integration/testdata/pull/granted_by.sql. It covers grantor chains, PUBLIC granted by a non-owner, a column, a view, a sequence, a function, a type, the schema andplpgsql, and is checked with the pg_dump comparison.internal/integration/grantedby_test.go: a superuser converge, drift revoke and pull round trip, plus a non-superuser member of the grantor, with anot_ownerwarning for a grantor it isn't a member of.TestIntegrationGrantorRevokesConvergenow expectsgrantedByblocks instead of pull warnings.internal/cliandinternal/integrationsuites pass on PostgreSQL 15, 16, 18 and 19 (PGY_TEST_REQUIRE_PL=1, pg_dump comparison on).make test,go vetandgolangci-lintare clean.f14_grants(19) andf14b_grants18(15/16/18) now produce matching dumps with--roles. Before this change, 19 differed only in the grantor.f15_base+f15_drift/f15_drift18with driftcmp match on all four versions, and so does the reverse direction (pull the drifted database, apply it to the base one).