Skip to content

Fix DefaultPrivileges Observe to filter by target role and schema - #459

Open
shashankvarma499 wants to merge 1 commit into
crossplane-contrib:masterfrom
shashankvarma499:fix/defaultprivileges-observe-filter
Open

shashankvarma499 wants to merge 1 commit into
crossplane-contrib:masterfrom
shashankvarma499:fix/defaultprivileges-observe-filter

Conversation

@shashankvarma499

Copy link
Copy Markdown

Description of your changes

The DefaultPrivileges Observe SELECT 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. Observe then reported the resource as up-to-date and Create (which issues the ALTER DEFAULT PRIVILEGES) was never called — the privileges were never applied, yet the resource showed Ready/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 DefaultPrivileges that 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 a pg_roles join.
  • defaclnamespace = the schema (IN SCHEMA), resolved via pg_namespace; for objectType: schema (which has no IN SCHEMA clause) it filters the database-wide namespace (defaclnamespace = 0).

Fixes #458

I have:

  • Read and followed Crossplane's contribution process.
  • Run make reviewable to ensure this PR is ready for review.

How has this code been tested

Added TestSelectDefaultPrivilegesQuery to both the namespaced and cluster controller test suites, asserting the generated SQL filters by target role and schema (and by the database-wide namespace for objectType: schema), and that the parameter list carries the object type, role, target role and schema. go test passes for both packages and gofmt/go vet are clean.

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DefaultPrivileges except the first one are not applied but show ready/synced

1 participant