Fix DefaultPrivileges Observe to filter by target role and schema - #459
Open
shashankvarma499 wants to merge 1 commit into
Open
shashankvarma499 wants to merge 1 commit into
shashankvarma499 wants to merge 1 commit into
Conversation
The Observe SELECT query only filtered by object type and grantee role, so default privileges for a different target role or schema that happen to grant the same privileges to the same grantee were mistaken for this resource's grants. Observe then reported the resource as up-to-date and Create (which issues the ALTER DEFAULT PRIVILEGES) was never called, leaving the privileges unapplied while the resource showed Ready/Synced. Filter by defaclrole (FOR ROLE target) and defaclnamespace (IN SCHEMA, or the database-wide namespace oid 0 when objectType is schema). Signed-off-by: Shashank Varma <324153016+shashankvarma499@users.noreply.github.com>
2 tasks
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.
Description of your changes
The
DefaultPrivilegesObserveSELECT query only filtered by object type and grantee role. It ignored the target role (FOR ROLE) and the schema (IN SCHEMA), so default privileges belonging to a different target role or schema that happen to grant the same privileges to the same grantee were mistaken for this resource's grants.Observethen reported the resource as up-to-date andCreate(which issues theALTER DEFAULT PRIVILEGES) was never called — the privileges were never applied, yet the resource showedReady/Synced.This fixes the "DefaultPrivileges except the first one are not applied but show ready/synced" symptom: once any unrelated default privilege matched, every subsequent
DefaultPrivilegesthat overlapped on grantee + object type was silently skipped.The fix adds two filters to
selectDefaultPrivilegesQuery, applied to both the namespaced and cluster controllers:defaclrole= the target role (FOR ROLE), resolved via apg_rolesjoin.defaclnamespace= the schema (IN SCHEMA), resolved viapg_namespace; forobjectType: schema(which has noIN SCHEMAclause) it filters the database-wide namespace (defaclnamespace = 0).Fixes #458
I have:
make reviewableto ensure this PR is ready for review.How has this code been tested
Added
TestSelectDefaultPrivilegesQueryto both the namespaced and cluster controller test suites, asserting the generated SQL filters by target role and schema (and by the database-wide namespace forobjectType: schema), and that the parameter list carries the object type, role, target role and schema.go testpasses for both packages andgofmt/go vetare clean.