Skip to content

fix(frontend): scope role-rule invalidation to owning account - #30358

Merged
XuPeng-SH merged 2 commits into
mainfrom
fix/30347-tenant-role-invalidation
Oct 16, 2026
Merged

XuPeng-SH merged 2 commits into
mainfrom
fix/30347-tenant-role-invalidation

Conversation

@LeftHandCold

Copy link
Copy Markdown
Collaborator

What type of PR is this?

  • BUG

Which issue(s) this PR fixes:

Fixes #30347

What this PR does / why we need it:

Scope role-rule invalidation to the owning account, and do not broadcast an absent-role DROP ROLE IF EXISTS.

Root cause and reproduction

#29186 introduced an all-session CN broadcast after successful DROP ROLE and ALTER ROLE ADD/DROP RULE. It invokes the prepared-policy invalidation introduced by #29195, without checking account identity. Even an absent-role DROP commits successfully and invalidates another tenant's existing SQL/binary prepared handles.

Reproduced on host50 at unfixed main b24d1b311555e0b6f3d56eb37f9a2e9617e9a5b7 using the real embedded frontend and independently authenticated accounts on one CN:

  1. Account B prepares and successfully queries its one-row table using a binary handle.
  2. Sys executes DROP ROLE IF EXISTS issue30347_absent.
  3. B reuses its original handle and gets 1615 / Prepared statement needs to be re-prepared.

The same black-box test passes with this patch. The no-op DROP unit counterexample also fails on unfixed main. This is not a TPCC retry/Runner workaround. Attribution to #29186 is from the exact source diff and nightly evidence; the local runtime A/B is current unfixed main versus this patch.

Minimal fix / security boundary

  • Carry the source account ID through the existing notification path. Check recipient identity under the session mutex before touching its cache, generation or prepared handles. Closed/nil-tenant sessions are not sys account zero.
  • Notify after DROP ROLE only when at least one role was deleted and the transaction committed. Mixed absent/present roles still notify; statement/commit errors do not.
  • Avoid notifying the source twice when it is also in SessionManager.
  • Retain conservative account-wide invalidation for real mutations, including ADD/DROP RULE. Do not introduce role-dependency tracking, retries, background work or protocol/catalog changes.
  • Preserve the security control: affected old handles fail with 1615; newly prepared handles return the exact new filtered rows. Existing prepared-role and disabled-remap protections remain enabled.

This fixes unrelated-account interference on the existing same-CN broadcast path; it does not introduce a new cross-CN invalidation protocol.

Validation on host50 (Go 1.27.1)

  • Focused frontend controls: committed/no-op/error DROP, cross-account isolation, in-flight cache reload, existing prepared-policy checks: PASS.
  • Full pkg/frontend: PASS; full pkg/frontend -race: PASS.
  • TestInvalidateRoleRuleCachesConcurrentAccounts and TestCaptureRewritePolicyReloadsAfterInFlightInvalidation: each 100 race repetitions PASS, selected after a single measured race run.
  • Native SQL/binary TestPreparedRoleInvalidationAccountIsolation plus existing TestNativePreparedRoleRuleSurvivesDisabledRemapHint: PASS, including same-instance repeated execution and final delivery rerun.
  • Extended existing zz_accesscontrol/role_rule_prepared.sql: normal mo-tester comparison 51/51 twice, with explicit account/role/user/database teardown checks between runs. Also 51/51 twice with result metadata comparison enabled. No new skipped assertions or generated-result acceptance.
  • Changed-package go vet, repository-pinned golangci-lint v2.14.0, gofmt and diff checks: PASS.

Self-review

Audit Result
Q1 ownership PASS: mark handles only; existing Close remains cleanup owner. Test connections, statements and accounts are cleaned.
Q2 waits PASS: release source/manager locks before recipient locks; no SQL/RPC/wait is added under recipient locks. Existing lock order is preserved.
Q3 growth PASS: bounded existing session snapshot/prepared maps; no new persistent state, goroutine, queue or retry.

Production changes are limited to the role-DDL notification closure. Tests reuse existing fixtures and the existing BVT case. Remote CI is separate from these completed local checks.

@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@XuPeng-SH

XuPeng-SH commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-local · done

Commit: 54e3b3ebd999f964b6e6f094327f0737d9319edc

Review completed. Read the assessment.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mo-bot review · mo-bot-local · review

Commit: 54e3b3ebd999f964b6e6f094327f0737d9319edc

Assessment: approve

Reviewed the complete eight-file delta, transaction boundaries, session lifecycle and prepared-policy consumers. The design appropriately reuses the existing invalidation owner, checks account identity under the recipient lock, and suppresses absent-role DROP broadcasts. Same-account stale handles still fail closed. Real mutations retain the existing session scan but avoid unrelated cache and prepared-handle traversal; no query-path work is added. No actionable defects remain.

Model: gpt-6-astra / xhigh

Session: 01a13dcf-1517-7f90-b3f9-c5f9f9e7031b · slot 0 · generation 1

Validation:

  • Verified the frozen head, complete patch and unchanged source. Commands, source fingerprints, exits and logs are reconciled in /home/xupeng/.local/state/mo-bot/jobs/b21caff4ecbf1bbcccebff5b/attempt-1/review-evidence.json. Final audit receipt: 1792128477702759819-4.json.

  • Isolation preflight passed; independently verified 192 current native inputs and 19 retained build artifacts.

  • Full frontend suite passed normally and under race instrumentation: 2,459 and 2,458 top-level passes respectively.

  • Concurrent-account invalidation and in-flight cache reload each passed 100 race repetitions after measured runs.

  • Both live SQL/binary prepared-role tests passed twice on the same instance, including unrelated-account isolation, error 1615 and exact fresh-policy results.

  • The exact role_rule_prepared.sql BVT passed 51/51 assertions four times: twice normally and twice with metadata comparison. Explicit account, user, role and database teardown checks passed between runs.

  • The no-op regression test failed as expected with the exact merge-base DROP implementation overlaid. Candidate tests passed.

  • Changed-package go vet, gofmt and git diff --check passed.

Limitations:

  • Scope remains same-CN broadcast invalidation. Preexisting local privilege-cache invalidation in the initiating DDL session remains unchanged.

  • One existing test skipped itself; an existing allocation test is excluded under race instrumentation and passed normally.

  • The linked issue body was absent from frozen evidence; the PR supplied the reproduction and contract. Author-reported executions without retained receipts were not counted as independently verified.

  • No performance benchmark was run; the cost assessment follows the changed notification path.

@mergify mergify Bot added the queued label Oct 16, 2026
@mergify

mergify Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-10-16 05:29 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • 🟠 Checks running · in-place
  • 🚫 Left the queue — 2026-10-16 08:11 UTC · at 06616bf66f7fc8f9c5bee3cdb92021f917aad095

This pull request spent 2 hours 41 minutes 52 seconds in the queue, with no time running CI.

Reason

Pull request #30358 has been merged manually at 61e8b45

Hint

You were too fast!

Waiting for any of
  • check-neutral = CI Required
  • check-skipped = CI Required
  • check-success = CI Required
All conditions

Tick the box to put this pull request back in the merge queue (same as @mergifyio queue).

  • Requeue this pull request

This branch was previously deployed

1 inactive deployment
ci — 06616bf6 Deployed Oct 16, 2026 by mergify[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Something isn't working size/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: DROP ROLE IF EXISTS invalidates unrelated tenants’ prepared statements on the same CN after #29186

3 participants