fix(grants): experimental fix for cross-namespace role revocation#349
Draft
fix(grants): experimental fix for cross-namespace role revocation#349
Conversation
When the same PostgreSQL user has PostgreSQLUser resources in multiple namespaces pointing to the same host, each reconciliation revokes roles granted by other namespaces because it only computes expected roles from its own namespace's databases. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Merge sibling-namespace accesses before diffing so rolesDiff sees the full expected role set across all namespaces sharing the same PostgreSQL username and host. Without this, each namespace independently revokes roles granted by the others. Changes: - kube.PostgreSQLUsers: cluster-wide user listing - Granter.AllUsers: drop namespace param (always cluster-wide) - SyncUser: call mergeSiblingAccesses after groupAccesses - mergeSiblingAccesses: expand accesses with sibling namespaces, but only for hosts the current namespace already connects to - Wire AllUsers in cmd/main.go - Anonymise test fixtures (no real hostnames, usernames, or db names) - Add TestCrossNamespaceRevocation_MergeFixPreventsRevocation WIP: experimental — needs discussion before merging. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.
Problem
When the same PostgreSQL username has
PostgreSQLUserresources in multiple namespaces that share a host, each namespace reconciles independently and revokes roles granted by the others. The result is intermittent access loss — whichever namespace reconciled last wins.Root cause:
SyncUsercomputesaccessesfrom the current namespace only, then passes those torolesDiff, which revokes any_read/_readwriterole not in that list.The bug is reproduced (and documented) in:
pkg/postgres/cross_namespace_revoke_test.go— provesrolesDiffrevokes cross-namespace rolespkg/grants/cross_namespace_revoke_test.go— provesgroupAccessesproduces disjoint role sets per namespaceApproach
Before calling
setRolesOnHosts, merge database schemas from all otherPostgreSQLUserresources with the samespec.name(but different namespace) that target the same host. This expands the expected role set seen byrolesDiffto include all namespaces — so nothing gets revoked.Constraint: only merge for hosts the current namespace already connects to. No new connections are opened.
Changes
pkg/kube/kube.go—PostgreSQLUsers: cluster-wide user listingpkg/grants/grants.go—AllUsers: drop namespace param (always cluster-wide)pkg/grants/sync.go—mergeSiblingAccesses+ call fromSyncUsercmd/main.go— wireAllUsersTestCrossNamespaceRevocation_MergeFixPreventsRevocationverifies the fixDiscussion points
AllUserslisting block the reconciliation rather than proceeding silently?listRBAC onpostgresqlusers— RBAC manifests not updated yetSyncUsercall now issues an extra cluster-wide list; acceptable?🤖 Generated with Claude Code