fix(frontend): align role rule merge semantics#24929
Conversation
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
XuPeng-SH
left a comment
There was a problem hiding this comment.
I found two blocking regressions in the frontend changes.
-
pkg/frontend/rewrite_rule.go:428-446narrows mergeable rewrite rules to bare column /*projections only. That makes identical row-preserving projections likeselect a + 1 as b from db1.t1 where ...stop merging, so the later role silently overwrites the earlier one instead of unioning both roles' visibility. The new expectation inpkg/frontend/rewrite_rule_test.go:777-779already demonstrates this regression. -
pkg/frontend/authenticate.go:3503-3531stops rebinding the current role duringSET SECONDARY ROLE ALL, but the privilege/rule loaders still seed fromtenant.GetDefaultRoleID()unconditionally (pkg/frontend/rewrite_rule.go:223-239,pkg/frontend/authenticate.go:7273-7287,8688-8704). If the session's current primary role was revoked after login,SET SECONDARY ROLE ALLnow keeps that stale role active and reloads caches with it, which is a privilege-revocation regression. Please either validate/fallback the primary role here or stop treatingDefaultRoleIDas implicitly valid downstream.
感谢指出这个问题。如果这里的目标是保持旧的 我重新确认后,这个 PR 现在明确采用的是另一层语义:多 role rewrite rule 合并表示“基础行可见性并集”。也就是说,只要任意一个 active 例如两条不同的基础行都投影成 我已经更新了 PR 来明确这一点:
所以我没有把 OR 合并限制到 |
Merge Queue Status
This pull request spent 1 hour 36 minutes 15 seconds in the queue, including 1 hour 2 minutes 51 seconds running CI. Required conditions to merge
|
What type of PR is this?
Which issue(s) this PR fixes:
issue #23271
What this PR does / why we need it:
This PR ports the latest role rewrite-rule and SET ROLE behavior from #24792 to the current branch.
Changes:
WHERE (...) OR (...).UNION DISTINCToptimization for partial projections. If two visible base rows project to the same value, both rows remain visible.select a + 1 as b ..., while aggregate/window/table-function and other non-compatible shapes still fall back to the later rule.SET SECONDARY ROLE ALL; it only enables secondary roles.SET ROLE, switch the current role to the target role and invalidate the privilege/rule cache so subsequent privilege checks use the new role.Review note:
a = 1and expectscount(*) = 2afterSET SECONDARY ROLE ALL.Validation:
gofmt -w pkg/frontend/rewrite_rule.go pkg/frontend/rewrite_rule_test.gogit diff --checkgo test ./pkg/frontend -run 'TestMergeRewriteRules|TestRewriteRuleMergeShapeForRule|TestLoadRuleCacheIncludesSecondaryRoles|TestRewriteSQLPropagatesRuleCacheLoadError|TestValidateRewriteRuleSQL'could not complete locally because vendor metadata is inconsistent withgo.mod.go test -mod=mod ./pkg/frontend -run 'TestMergeRewriteRules|TestRewriteRuleMergeShapeForRule|TestLoadRuleCacheIncludesSecondaryRoles|TestRewriteSQLPropagatesRuleCacheLoadError|TestValidateRewriteRuleSQL'reached CGO compilation but could not complete locally becauseusearch.handxxhash.hare missing.role_rule.sqlmo-tester case was updated, but not run locally because no MatrixOne server is listening on the configured127.0.0.1:6001.