Skip to content

[4.2-dev] fix: enforce mandatory role rules on client queries - #33389

Merged
XuPeng-SH merged 13 commits into
4.2-devfrom
codex/33377-mandatory-role-rules
Nov 28, 2026
Merged

XuPeng-SH merged 13 commits into
4.2-devfrom
codex/33377-mandatory-role-rules

Conversation

@XuPeng-SH

@XuPeng-SH XuPeng-SH commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

Fixes #33377. Backport of #29236.

What this PR does / why we need it:

Apply the active role’s row and column rules to client queries and both MySQL prepare paths. Keep session and inline rewrites optional. Preserve mandatory rules while binding optional rewrite layers, and reject statement forms that cannot apply them. Keep the existing object-privilege checks.

Refresh mandatory policy after a role change within a request. Check the retained policy before reusing a prepared plan and require a new prepare when the active policy differs. Preserve 4.2’s SQL-mode staging, SQL source classification, and prepared-statement invalidation behavior.

Built the service on Linux/amd64 with Go 1.26.4. On a loopback-only synthetic database, 29 MySQL-protocol assertions passed for row filtering, column projection, object-privilege denial, relational and full-text reads, vector search, new connections, prepared execution, and role and session state changes. Focused frontend, parser, and planner tests also passed.

Physical IVFFlat verification on e2dfe3392fed4583914c7dd26cf6e7bd6993afbe used a loopback-only synthetic database. All six restricted cases (pre, post, and include with optional rewriting enabled and disabled) showed ivf_search in EXPLAIN. The pre and post plans retained the role predicate on the base-table scan. The include plan pushed the predicate into the index reader. All six executions returned the same two authorized rows in rank order (synthetic IDs 12 and 14), matching the exact-scan control. Wildcard projection returned only the role-projected columns. Both execution and EXPLAIN rejected queries when object privileges were missing or the rule omitted the embedding column.

Distributed BVT was outside the local verification.

Review follow-up

Mandatory role rules now reach INSERT assignment and source binding contexts. Rule caches validate the policy and role-grant catalogs against the authorized read snapshot. A committed rule change refreshes the remaining statements in the same request. Connections with prepared statements stay on the source CN, and the destination rejects unverified prepared state. A policy catalog read failure permits normal handling of a standalone transaction end while data statements fail closed.

On a1b738479207667cb99ca76c8a2df08dd48b319d, the maintained two-CN MySQL regression passed first-rule publication, policy tightening on an existing connection, stale native and text prepared-plan denial, and role changes. It also checked relational and full-text results, the physical IVFFlat plan, column projection, and the role predicate in a conflict-assignment subquery. Focused frontend, parser, and planner tests passed, including injected catalog failure with transaction rollback and migration refusal at both ends.

The four frontend cases reported by the old x86 coverage job and both combined rounds of TestRewritePolicySavedResult passed locally. The frontend mocks now supply the expected role-catalog rows. The saved-result checks assert authorization for both live and persisted rows. The embedded test used a local TCP-only listener setting. Old x86 coverage job

Distributed BVT and end-to-end proxy migration were outside this local follow-up.

Statement authorization review follow-up

The active role policy and object authorization now share one view for each client statement, including statements in a batch and nested expressions. Views inherit the caller’s mandatory rules. Unsupported data reads and protected-target INSERT RETURNING fail closed. Restricted users can replay saved rows only when the saved policy and principal match, and existing object authorization still applies. Policy catalog errors follow the transaction rollback setting. The test for an invalid policy under the current SQL mode also verifies that authorized table cleanup remains available.

Local validation of bb66239ab6e76129ac406395874ce66f8ac7679f passed with Go 1.26.4 on Linux/amd64.

  • The two-CN MySQL fixture verified row and column results through relational, full-text and nested-view reads, confirmed ivf_search in the physical IVFFlat plan, and verified object-denial controls, policy changes, prepared-plan invalidation, and the expected counts in INSERT conflict assignments and SET expressions.
  • Frontend tests verified a controlled policy and object-authorization snapshot interleaving, transaction rollback for both settings on text query and native prepare errors, and migration refusal for unverified plans. Test_mce, TestKill, TestMysqlResultSet and TestSession_Migrate/ok passed.
  • Both combined rounds of TestRewritePolicySavedResult passed using the local TCP-only test configuration. The test accepted authorized saved rows and rejected a result after its policy changed. Focused parser, view, INSERT and RETURNING tests also passed.

Hosted distributed BVT and end-to-end proxy migration remain separate from these local results. The previous head’s Proxy BVT reported two cleanup failures in the role-rule fixture. The new head's hosted result will establish the distributed outcome. Previous Proxy BVT

Prepared migration and cancellation follow-up

The source and destination both verify prepared replay. The supported path rebuilds ordinary prepared SQL when the authenticated principal, preparation settings and client-visible metadata agree and neither CN has an active role rule. Other prepared state stays on the source. The proxy checks the source before dialing and defers session-level transfer refusals until client activity. A standalone KILL reaches the usual authorization and cancellation handler during a role-catalog read failure. Data requests continue to fail closed.

The old x86 Coverage timeout occurred because the authorization reader moved its first cancellation check behind a mutex held by the waiting test. The current head restores the baseline check before the wait and retains the check after acquisition. The fixture now reports a bounded failure if it cannot observe that order. Old x86 Coverage log

Go 1.26.4 on Linux/amd64 validated 3f32c488748aee4d91e17fa19014decc348e4a26, tree ff72501b166f4b90c588439687dd5e88851e61fb, from 11:59:08 to 11:59:51 UTC on 2026-11-27. The focused runner exited 0 across frontend, proxy, isolated integration, embed, parser and planner. The retained validation record contains the command, tested tree, exit status and Go test events.

  • TestMandatoryRoleRulesAcrossConnections passed in 14.06 s. Two real CNs exported and replayed text- and native-prepared handles through the query-service RPCs. The destination executed both retained handles and returned the expected synthetic row. Source export and destination replay refused the same prepared state after the mandatory policy was published. The existing restricted-user fixture also verified views, full text, physical IVFFlat, projection and object-privilege denial.
  • TestAuthorizationWaitHonorsCancellation/authorization, TestRoleRuleAndObjectPrivilegesShareStatementSnapshot and TestKill passed. The SQL protocol fixture cancelled queries and connections during the injected catalog fault and rejected queries that could access data.
  • TestMigrateConnSourceRefusalStopsBeforeRouting, TestTransferSync_SkipCachePopOnMigration and the tunnel delivery regression passed. Both TestRewritePolicySavedResult combined rounds passed with the local TCP-only embed listener setting.

The local run covered two-CN RPC replay and proxy retry tests. A live proxy handoff and hosted distributed BVT remain pending. New head CI

Saved-result replay, historical reads and proxy drain

2f553ddd3b0981fdb738f68e111559c400bea4d9 keeps the released saved-result metadata format and expiry. A saved payload and a rule-text fingerprint cannot establish whether the effective policy still authorizes the materialized rows and columns. Both result_scan and meta_scan refuse replay while a role rule is active. With an empty effective role policy, reads retain the existing object-privilege checks for old, new and restored results. Live queries continue to apply the current filters and projection. No metadata migration or rewrite is needed.

The binder rejects MO snapshot and Iceberg history qualifiers when a role-rule rewrite would replace the qualified table reference. A two-CN SQL fixture verified the no-rule historical rows against a different set of current rows and verified refusal for the restricted reader. The Iceberg qualifier is covered at the planner boundary.

The destination compares the authenticated account, user, primary role and secondary-role mode before replaying client settings. The proxy records activity after sending a command. A native statement close has no acknowledgement, so in-flight or unreplayable prepared state uses the existing 10-second migration cooldown. The source copies prepared metadata only outside an active command.

  • The real TCP proxy with two CNs preserved the connection ID and session variable on an ordinary handoff, and refused both primary-role and secondary-role-mode mismatches. After a native COM_STMT_CLOSE, the previously refused idle session reached the target within 15.249 seconds with the same connection ID and returned the authorized row. A separate prepared session recovered after a rule change with only PING traffic in 15.243 seconds. Proxy runner and service shutdown both exited 0.
  • Six focused Go packages passed on Linux/amd64 with Go 1.26.4. Both saved-result rounds verified an unchanged rule whose dependency change moved the live authorized result from row 1 to row 2, and verified that both replay entry points refused the old result. The run also covered native snapshots, the earlier x86 Coverage fixture, statement authorization and cancellation, two-CN prepared replay, physical IVFFlat, full text, projection and object privileges. A local listener overlay substituted TCP in two existing fixtures.
  • The synchronized CLOSE-forwarding test passed 100 repetitions under -race. A whole-package proxy -race run stopped when local socket policy blocked six Unix-listener fixtures. Hosted x86 Coverage and distributed BVT remain separate. GitHub checks

v4.2.9 shutdown-upgrade receipt (2f553dd)

Official Linux x86_64 asset for tag v4.2.9, source commit 6c05e42f9f660a207077b050b8ec285ccf3f8103. The downloaded archive SHA-256 matched the digest in the GitHub release metadata. The candidate was built and tested from local commit 8b55c3fc049b1e30c39fb052ed703fc7aedbb17b, with identical tree db6b13f46daa6ebdb346ebf90a8d8e91cd8c20d2 to the then-current PR head 2f553ddd3b0981fdb738f68e111559c400bea4d9. Both binaries used the same isolated data directory in sequence. Separate backup and restore and the later v4.2.8 hotfix binaries were outside this run. Official archive · Release metadata

SHA256 archive    7d567c88cdcc1ea610e122df67340941865a8116ea876f17eb775855dd072737  sha256sum -c: OK
SHA256 v4.2.9 bin d76fcc947ee73bc8a6ada94c437910c40a12d52af1a67d55ad0d2708f51d79e4
SHA256 candidate  b3fc56c11d3094f1ef5e82c4421ccedfa16ea5eb28d0c60e8c8373939f5b73a2

2026-11-27T14:15:31Z v4.2.9   mo-service -launch etc/launch/launch.toml
2026-11-27T14:15:44Z seed     two authorized saved fixtures, columns=[id], rows=[[1]]
2026-11-27T14:15:45Z v4.2.9   SIGTERM; all services stopped, exit=0; seed_exit=0
2026-11-27T14:19:27Z build    GOFLAGS=-buildvcs=false make ARCHSIMD=0 build-with-prebuilt-native
2026-11-27T14:19:56Z build    exit=0
2026-11-27T14:19:57Z candidate mo-service -launch etc/launch/launch.toml (same stopped data directory)
2026-11-27T14:20:01Z legacy   active-rule read refused; no-rule read columns=[id], rows=[[1]]
2026-11-27T14:20:01Z new      active-rule result_scan and meta_scan both refused (20301)
2026-11-27T14:20:01Z new      no-rule write/read columns=[id], rows=[[1]]
2026-11-27T14:20:02Z candidate SIGTERM; all services stopped, exit=0; upgrade_exit=0

Table and role identity (d3931b6)

The role catalog and planner now share physical relation identity in all three table-name modes. The derived binding exposes the same column qualifier as an ordinary scan. An ambiguous historical folded key prevents the affected read and leaves authorized rule DDL available. Before replaying session state, migration compares the SQL-visible primary role name and table-name mode in addition to the existing role and principal IDs.

Rebased to 4.2-dev at 78fe31d619. Local incremental SCA passed. Race validation covered frontend, proxy, parser and planner, the two-CN role-policy fixture, and saved-result replay. The proxy cancellation case passed 30 race repetitions with cancellation triggered after request receipt. Shutdown upgrade verification from the published v4.2.9 build covered retained lower-case role data on the same store.

For the final build, a paired local benchmark of warmed SQL reads against the rebased pre-fix build measured median block latency of 181.88 vs 188.77 µs with an active rule and 195.84 vs 199.50 µs for the no-rule control. The active-rule median decreased in the reverse-order pair.

Directory proof and bounded role retry (a71450c)

Case-preserving sessions accept a folded legacy policy key only when the statement authorization snapshot proves a unique exact lowercase database and relation and the planner resolves the same physical relation. Both ambiguous spellings are denied. Changes to the directory invalidate the proof, and prepared statements whose proof has changed require a fresh prepare. The persisted rule format is unchanged.

The destination requires role equivalence before replay. A recoverable primary-role name or ID mismatch uses the existing 10-second per-tunnel cooldown and drain scheduler. The destination still rejects migration while roles are unequal.

At a71450cc69a2dfbbd77be2136ff27868883d823d, the tested local commit 459b45db8d1b6913add6fa7d4d0c56c09accf6b9 has identical tree 63e15f8eda5d02bc0678caad5a67454ab03945dc. Six focused Linux/amd64 Go 1.26.4 package suites passed (frontend, proxy, sql/parsers, sql/plan, tests/issues/isolated, embed), including case-sensitive binding, a new case sibling invalidating a prepared plan, saved results, and proxy retry classification. A test-only overlay substituted TCP listeners for two local fixtures. git diff --check passed.

Current v4.2.9 shutdown-upgrade receipt

This receipt covers the exact tree of the earlier head a71450cc69a2dfbbd77be2136ff27868883d823d.

The released Linux x86_64 binary (source commit 6c05e42f9f660a207077b050b8ec285ccf3f8103) and the candidate ran sequentially against the same stopped synthetic data directory. Official archive · Published asset digest

2026-11-27 UTC | Linux/amd64, synthetic fixtures
SHA256 archive   7d567c88cdcc1ea610e122df67340941865a8116ea876f17eb775855dd072737  (sha256sum -c: OK)
SHA256 v4.2.9    d76fcc947ee73bc8a6ada94c437910c40a12d52af1a67d55ad0d2708f51d79e4
SHA256 candidate 3d3b69e7964ca8dd5d9810a73ecdde400b18748ddc75115f8b3a640af67952f3
20:42:19Z  GOFLAGS=-buildvcs=false make ARCHSIMD=0 build-with-prebuilt-native
20:43:07Z  build exit=0
20:43:08Z  v4.2.9: mo-service -launch etc/launch/launch.toml
20:43:22Z  fixture setup exit=0, v4.2.9 SIGTERM exit=0
20:43:22Z  candidate: mo-service -launch etc/launch/launch.toml
20:43:27Z  unique legacy key: columns=[id] rows=[[1]]
           ambiguous group: both spellings denied
           unruled saved results: legacy and new rows=[[1]]
           active policy: result_scan and meta_scan denied
           candidate SIGTERM exit=0, upgrade runner exit=0
20:43:28Z  candidate: mo-service -launch etc/launch-with-proxy/launch.toml -with-proxy
20:43:54Z  ordinary two-CN handoff passed, renamed-role connection stayed on source
20:44:09Z  original role restored, PING-only client migrated in 15.044s
           connection ID preserved, authorized rows=[[1]]
20:44:11Z  candidate SIGTERM exit=0, proxy runner exit=0

Backup/restore and upgrades from other releases were outside this run. Distributed BVT is tracked in hosted CI.

Physical exports, ordinary writes and table-name mode retry

With active role rules, physical table export and SQL backup are refused before their handlers can emit data. Row-local UPDATE and DELETE still use ordinary object authorization when the planner resolves one unprotected base table. Protected or uncertain targets, foreign-key access to other tables, and unsupported expressions or multi-source forms are refused.

A recoverable mismatch in the destination's table-name mode uses the existing 10-second per-tunnel retry cooldown. Migration still requires equivalent session identity and table-name mode before replay.

Validation for fc2af632a8b4afd2dc10c0b574319b7eacea1f9f used local commit 5bcfae1bfb53b493ea4874dd4e820f60ef62ad35 with identical tree 43305cde43e60b90b1301fa0b8ed409446d94a59.

  • Six focused Linux/amd64 Go 1.26.4 package suites passed across frontend, proxy, sql/parsers, sql/plan, tests/issues/isolated and embed. The saved-result test used a local TCP-only listener overlay because Unix sockets were unavailable. Existing table-export privilege and handler controls also passed.
  • The two-CN MySQL regression verified committed ordinary writes on an unprotected table, denial without mutations on a protected table, refusal of a subquery write, and denial of an administrator's physical dump before manifest creation.
  • The exact candidate built via make ARCHSIMD=0 build-with-prebuilt-native (exit 0, binary SHA-256 aed0027d37eedde368fa0843ef70cead1d0547444b8032af303ac1d10af2fdc6). A synthetic two-CN cluster with a real TCP proxy ran mo-service -launch etc/launch-with-proxy/launch.toml -with-proxy. On 2026-11-27 at 21:43:52 UTC a mode mismatch retained the source connection. At 21:44:07 UTC the same client migrated after mode restoration with PING as its only client traffic while waiting (15.054 s, same connection ID and authorized id projection with row [1]). Service and runner exited 0.

This revision did not rerun the release-to-release shutdown-upgrade or backup/restore exercises. Distributed BVT is tracked in hosted CI.

CDC admission and row-local write functions

When mandatory role rules apply, CREATE CDC is refused before task creation. The background reader cannot maintain the creating statement's authorization policy. Without mandatory role rules, the existing CDC authorization and configuration checks apply.

The ordinary UPDATE and DELETE path accepts a small set of registered data-only scalar built-ins with recursively row-local arguments. The planner still proves the unprotected single-table target and applies existing object permissions. A missing built-in overload cannot fall back to a UDF on this path. Unknown forms remain fail-closed.

Validation for b93a41bac6907e414c919f01690a9b6e1a1c043a used local commit cfc77844d0d476350d4e16a75e474778d2b17948 with identical tree 0f11e188fd8b9ebceba72c5392921cbb6e60226f. Five focused Linux/amd64 Go 1.26.4 packages passed at 22:19 UTC on 2026-11-27 (frontend, proxy, sql/plan, sql/plan/function and tests/issues/isolated), including the existing CDC create handler and policy regressions. git diff --check passed.

The synthetic two-CN MySQL regression verified that the unruled administrator reached the normal CDC configuration validator, the same request under an active rule was refused, and no task was recorded. No CDC sink was configured. On the unprotected table, the restricted client's row-local built-in UPDATE committed the expected value and its DELETE removed only the expected row. Unknown and subquery expressions were refused. Distributed BVT is tracked in hosted CI.

CDC lifecycle admission

The existing statement role-policy gate refuses CREATE CDC, resume and restart before dispatch to the CDC task service when mandatory role rules apply. All three can activate background reads that lack the caller's continuous authorization policy. SHOW, PAUSE and DROP retain their existing administrator checks and behavior.

Validation for 8477faa346c8b93876959977bbe3a3cdfe68f541 used local commit add15063dbd3d0b95e8af165ecec907fa464ede9 with identical tree e8117c4e5e57529db50fcc4b8d0032f15694ff49. Focused Linux/amd64 Go 1.26.4 suites for frontend, taskservice and tests/issues/isolated passed on 2026-11-27 at 22:58 UTC. The frontend protocol test refused resume and restart before any task-service call and left the synthetic paused task unchanged. Existing task-service tests verified lifecycle transitions on test doubles.

In the two-CN MySQL fixture, the unruled administrator reached the normal task lookup for resume and restart. With an active rule, both were refused at authorization, as was create. PAUSE and idempotent DROP were accepted and no fixture task was created. The tests used no real CDC sink. git diff --check passed. Distributed BVT is tracked in hosted CI.

Prepared policy principal

SQL and binary prepared execution now compare the authorization principal from the rule lookup along with the effective rules, directory proof and SQL mode. The snapshot retains its principal even when the catalog is unable to provide reusable version evidence. A change of principal under an active policy requires a fresh prepare. Statements in sessions without rules and equivalent policies for the same principal retain normal reuse. Proxy migration keeps its existing identity and replay checks.

Validation for 78da203ee89eebf367720c39fc7cb5cca7b54633 used local commit 5b043676105cabc48dd8fd988e66eb072ce8c257 with identical tree 3a8edd52d392adb21191a8490acde74f5bf9b951. The synthetic two-CN MySQL test used matching static policies and verified that SQL and binary prepared execution both requested a fresh prepare after a role change. Fresh handles returned the expected authorized rows. The same fixture verified reuse between unruled roles and after restoring the original principal, and exercised two-CN prepared migration. Focused frontend, proxy, tests/issues/isolated and embed tests passed on Linux/amd64 Go 1.26.4 on 2026-11-28 at 03:00 UTC, including secondary-role rule discovery and saved results. The saved-result fixture used a TCP-only listener overlay.

Git's three-way merge check against 4.2-dev at 57cd85573cd1d4e1297642010f06094cbfb92320 was clean. Runtime tests used the published candidate tree. The prior IVF Coverage attribution is unchanged and this round contains no IVF changes. Earlier Coverage run · Current hosted 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 →

@mergify mergify Bot added the kind/bug Something isn't working label Nov 27, 2026
@mergify

mergify Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

This pull request is merged.

@XuPeng-SH

XuPeng-SH commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor Author

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

Commit: e2dfe3392fed4583914c7dd26cf6e7bd6993afbe

Review completed. Read the assessment.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor Author

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: e2dfe3392fed4583914c7dd26cf6e7bd6993afbe

Assessment: request_changes

The design appropriately extends the existing policy snapshot and planner rewrite machinery, but mandatory enforcement is incomplete across conflict-update subqueries, prepared-statement migration, and policy refresh. Policy-load failures also block transaction recovery. The required restricted-user regression coverage is not present in the change. The discussion contains no substantive prior review concerns.

Model: gpt-6.1-terra / max

Session: 01a21c25-08ff-7481-8807-238741372da4 · slot 2 · generation 9

  • P1 pkg/frontend/rewrite_rule.go:459: An INSERT has an ON DUPLICATE KEY UPDATE expression containing a subquery that reads a table protected by an active role rule.
    Impact: The subquery can read rows or columns excluded by the role rule and write its result to the insert target.
    Evidence: The new classification accepts every Insert, but pkg/sql/parsers/sqlparse.go:603 attaches the rewrite option only to the INSERT source. The conflict-update binder uses the parent context at pkg/sql/plan/bind_insert.go:1628, so its subqueries do not inherit that option. pkg/sql/plan/numeric_assignment_context_test.go:1517 confirms that this subquery form is supported. Propagate the mandatory policy to that context or reject the unsupported form.

  • P1 pkg/frontend/mysql_cmd_executor.go:2042: A connection with optional rewriting disabled has a protected prepared statement and is transparently migrated to another CN.
    Impact: The destination can rebuild the statement without its mandatory rule and subsequently execute the unprotected plan.
    Evidence: pkg/frontend/routine.go:653 transfers only the prepared SQL and parameter types; pkg/frontend/session.go:2307 replays it with no rewritePolicy. With the default switch off, the hint is not installed during replay, roleRules remains nil here, and pkg/frontend/rewrite_rule.go:517 accepts that nil policy at execution. Capture and enforce the active policy during migration replay, or fail the migration safely, and cover the migrated execution path.

  • P1 pkg/frontend/rewrite_rule.go:88: An administrator adds or tightens a rule after another session has cached an empty or older policy.
    Impact: That live session continues to use the stale policy for subsequent reads, including prepared statements, until a local invalidation or reconnect occurs.
    Evidence: captureRoleRuleCache returns any non-nil cache indefinitely. The rule writer explicitly invalidates only its own session at pkg/frontend/rewrite_rule.go:1464. This limitation already existed for opt-in rewriting, but this PR now uses the cache for mandatory enforcement in default sessions. Make rule changes visible across live sessions and refresh the request snapshot after an in-request rule change.

  • P2 pkg/frontend/mysql_cmd_executor.go:5276: A session has an open transaction, its rule cache has been invalidated, and loading the role catalog fails.
    Impact: ROLLBACK and COMMIT fail before reaching transaction handling, leaving the transaction open until policy loading recovers or the connection is closed.
    Evidence: COM_QUERY now loads policy before dispatch and returns immediately on a load error. The existing recovery exceptions in pkg/frontend/rewrite_rule.go:296 only handle rule interpretation errors after loading. Permit safe transaction-control recovery when policy loading fails while continuing to reject data-reading statements.

  • P2 pkg/frontend/mysql_cmd_executor_test.go:2757: The new mandatory-enforcement behavior is delivered without maintained restricted-user coverage of its public paths.
    Impact: The changed default behavior, returned rows and projections, prepare and role transitions, and relational, full-text, and vector reads lack the public regression proof required by issue 33377 and the repository testing contract.
    Evidence: The changed test checks injected SQL and deliberately stops before execution; the existing role-rule BVT enables optional rewriting before its reads. The PR describes local assertions, but the evidence bundle contains no matching retained commands or logs. Extend an existing isolated restricted-user fixture with the required public-path cases and retain their results.

Validation:

  • Reviewed the complete frozen patch, relevant frontend, parser, planner, migration and cache consumers, the linked issue, and all three discussion entries.

  • Private /tmp and loopback preflight passed; receipt checks/1795768742712789349-3.json and preflight.log.

  • The focused parser test on the assigned head timed out after 360 seconds during dependency downloads, before any test result; receipt checks/1795769231116431046-2.json and parser-tests.log. This is neither a pass nor a product-test failure.

Limitations:

  • The supplied evidence contains no retained local validation logs for the PR's reported MySQL-protocol assertions, and the relevant CI jobs were pending in the frozen snapshot.

  • No public restricted-user or multi-CN migration test was executed during this review.

@XuPeng-SH

XuPeng-SH commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor Author

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

Commit: a1b738479207667cb99ca76c8a2df08dd48b319d

"interrupted"

@XuPeng-SH

XuPeng-SH commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor Author

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

Commit: d3931b68ccc5c9d4b0bc6bbf68372bff814717f0

Review completed. Read the assessment.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor Author

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: d3931b68ccc5c9d4b0bc6bbf68372bff814717f0

Assessment: request_changes

Two correctness issues remain in legacy rule identity and proxy migration retry. The design otherwise reuses the existing authorization, planner, and migration owners; the catalog proofs and replay checks address policy freshness and safe handoff. The earlier direct mixed-case lookup and role-rename concerns have guards, but related edge cases remain.

Model: gpt-6.1-terra / max

Session: 01a21ea6-2de2-71f3-b7d7-f3fe6df56dd8 · slot 0 · generation 27

  • P2 pkg/sql/plan/bind_context.go:46: A v4.2.9 store with case-sensitive names contains a legacy rule created for a mixed-case table and also contains a distinct lowercase table with the same folded name.
    Impact: A query for the lowercase table can be rewritten using the rule intended for the mixed-case table and return rows from the wrong relation.
    Evidence: The v4.2.9 role-rule grammar folds both identifiers before storing the key. The new exact-match branch treats that folded key as authoritative before checking ambiguity, and the planner then binds the stored rule body. Distinguish legacy identities or fail closed for both ambiguous spellings, and cover case-distinct tables using released catalog data.

  • P2 pkg/proxy/tunnel.go:687: A destination refuses migration because an administrator renamed the session's role, then the administrator restores the original name while the client is idle or sends only PINGs.
    Impact: The connection remains excluded from migration after the role identities match again, potentially keeping it on a draining CN indefinitely.
    Evidence: The destination's role comparison returns OkExpectedNotSafeToStartTransfer, which this function records with a zero retry deadline. Only non-PING client activity clears that latch; catalog changes do not. Give externally changeable identity refusals a bounded retry or invalidation path while retaining protection against busy retries.

Validation:

  • Reconciled all 16 discussion keys and the claimed command, source, exit, and log evidence in attempt-3/reconciliation.log.

  • The current-head saved-result regression and focused parser and planner tests passed under -race, using a test-only TCP-listener overlay: attempt-3/checks/1795811145469112038-3.json and attempt-3/saved-case-tests.log.

  • Reused same-head passing focused frontend/proxy race tests and the two-CN role-policy integration test from attempt 1: checks/1795810286317849487-2.json and checks/1795810287564845604-2.json, with their retained logs.

  • Private /tmp and loopback preflight and git diff --check passed: attempt-3/checks/1795810951077310273-3.json and attempt-3/checks/1795811192973542445-3.json.

Limitations:

  • The two findings are based on source tracing and were not reproduced through a live service or proxy in this review.

  • The detailed v4.2.9 upgrade receipt in the PR describes an earlier candidate tree, before the rebase and case-identity changes; a current-head release upgrade was not independently run.

  • The linked upstream PR's contents were not included in the supplied evidence.

@XuPeng-SH

XuPeng-SH commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor Author

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

Commit: a71450cc69a2dfbbd77be2136ff27868883d823d

Review completed. Read the assessment.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor Author

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: a71450cc69a2dfbbd77be2136ff27868883d823d

Assessment: request_changes

The change appropriately extends the existing authorization, planner, and migration owners; the directory proof addresses the ambiguity in released folded rule keys. Three issues remain: an admin-role physical dump bypasses its active policy, unrelated writes are rejected whenever any role rule is active, and a recoverable table-name-mode mismatch can indefinitely defer proxy migration. The prior folded-key and primary-role retry concerns have corresponding guards.

Model: gpt-6.1-terra / max

Session: 01a21ed9-be28-74f1-bfa3-45a1440e0eaa · slot 1 · generation 29

  • P2 pkg/frontend/rewrite_rule.go:567: An administrator whose active role has a row or column rule runs DUMP TABLE for the protected table.
    Impact: The dump exports complete physical objects, including rows and columns excluded by the active policy. This path is limited to administrator roles, but it violates the requested mandatory-policy behavior.
    Evidence: DumpTable is classified as QueryTypeOth and accepted by the default branch, while pkg/frontend/table_dump.go:819 copies the unfiltered objects. The public SQL probe in attempt-2/public-control.log restored both original rows and the hidden column after the dump. Reject full physical dumps under an active policy, or export data through a path that enforces the policy.

  • P2 pkg/frontend/rewrite_rule.go:567: A role has a rule on one table and issues a literal UPDATE or DELETE against a different, unprotected table.
    Impact: Ordinary authorized writes fail with 'statement cannot enforce active role rules', even though they do not read or modify the protected table. This also affects roles using the default disabled optional-rewrite setting.
    Evidence: The default branch rejects every DML statement other than explicitly handled INSERT whenever any role rule exists. In attempt-2/public-control.log, the same UPDATE and DELETE succeed before the rule is installed and fail afterward. Preserve safe writes whose targets and expressions cannot access protected data, while applying the rules or rejecting shapes that can.

  • P2 pkg/frontend/session.go:2294: A session retains its original lower_case_table_names value, the global value changes, and a proxy migration is refused; the global value is then restored while the client is idle or sends only PINGs.
    Impact: The connection remains excluded from migration after the source and destination modes match again, potentially retaining it on a draining CN indefinitely.
    Evidence: The mode mismatch returns OkExpectedNotSafeToStartTransfer, which pkg/proxy/tunnel.go:687 records without a retry deadline. Only non-PING client activity clears that refusal. The exact-head frontend and proxy probes in attempt-1/review-probes.log confirm the classification and latch. Treat this externally changeable mismatch as retryable with a bounded cooldown, and cover restoration without client SQL.

Validation:

  • Private /tmp and loopback preflight passed: attempt-2/checks/1795814136709014079-4.json and attempt-2/preflight.log.

  • The existing two-CN role-policy regression passed: attempt-2/checks/1795814345606792403-2.json and attempt-2/two-cn.log.

  • Selected frontend, proxy, parser, and planner tests passed: attempt-2/checks/1795814341831396231-2.json and attempt-2/focused.log.

  • The controlled MySQL-protocol probe completed with failing assertions for the two reproduced policy issues; its no-rule write controls succeeded: attempt-2/checks/1795814682002287773-2.json and attempt-2/public-control.log. The earlier migration classification probe also completed with the expected failing retry assertion: attempt-1/checks/1795813884634590007-2.json and attempt-1/review-probes.log.

  • The exact-head diff check passed. All 18 discussion keys and claimed check receipts were reconciled in attempt-2/reconciliation.log.

  • Official release metadata confirms v4.2.9 and later v4.2.8 hotfixes; the PR supplies a v4.2.9 shutdown-upgrade receipt for an identical candidate tree.

Limitations:

  • The table-name-mode migration sequence was established by source tracing and focused probes, not a live proxy handoff.

  • The reported release upgrade was not independently rerun; no separate hotfix upgrade or backup/restore test was run.

  • Relevant hosted CI jobs were still in progress or skipped in the frozen evidence.

@XuPeng-SH

XuPeng-SH commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor Author

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

Commit: fc2af632a8b4afd2dc10c0b574319b7eacea1f9f

Review completed. Read the assessment.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor Author

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: fc2af632a8b4afd2dc10c0b574319b7eacea1f9f

Assessment: request_changes

The change reuses the existing authorization, planner, and migration owners, and addresses the prior dump and migration-retry concerns. Two gaps remain: CDC creation can start an unfiltered physical export under an active role policy, and the earlier unrelated-write regression remains for ordinary scalar expressions.

Model: gpt-6.1-terra / max

Session: 01a21f04-073f-77d1-8630-a593fb7859fd · slot 0 · generation 28

  • P2 pkg/frontend/rewrite_rule.go:587: An administrator whose active role has a rule creates a CDC task for a protected table.
    Impact: The task can send rows and columns excluded by the active policy to its sink. This path is limited to administrator roles.
    Evidence: CreateCDC is classified as QueryTypeOth and passes this default branch, while DumpTable and BackupStart are explicitly refused. CDC task options retain the account and user but no role policy, and pkg/cdc/table_change_stream.go:1242 collects physical changes for the sink without policy-aware planning. Refuse task creation under an active policy unless the CDC path can enforce that policy throughout the task lifecycle.

  • P2 pkg/frontend/rewrite_rule.go:525: A role has a rule on one table and updates an unrelated table using a row-local builtin, such as ABS(value), in an assignment.
    Impact: The authorized write fails before target validation, even though the expression does not read the protected table. This leaves the previous unrelated-write concern only partly resolved.
    Evidence: rowLocalExpr rejects every FuncExpr in its default branch. The retained parser probe confirms that ABS(value) is a FuncExpr, while a simple arithmetic assignment is a BinaryExpr and is admitted. Support demonstrably row-local builtins with safe arguments, or validate them through a policy-aware planning path, while continuing to reject expressions that can read protected data.

Validation:

  • Private /tmp and loopback preflight passed: checks/1795816983472115024-3.json and preflight.log.

  • git diff --check passed for the assigned range: checks/1795816983503718110-3.json and diff-check.log.

  • The same-head case-mode parser tests passed in attempt 1: attempt-1/checks/1795816689203459376-3.json and attempt-1/parser-tests.log.

  • A test-only parser overlay confirmed the unrelated-write expression shapes: checks/1795817079011124269-3.json and parser-probe.log. It did not execute the frontend guard.

  • All 20 discussion keys and the claimed receipts were reconciled: checks/1795817304095703539-3.json and reconciliation.log.

Limitations:

  • Both findings are based on source tracing; neither was reproduced through a live service.

  • The author reports current-tree focused and two-CN tests and a proxy handoff; these were not independently rerun. Relevant hosted UT and proxy jobs were still in progress in the frozen evidence.

  • The reported v4.2.9 shutdown upgrade used the preceding head; the saved-result and legacy-identity paths it exercised were not materially changed by this head and were not independently rerun.

@XuPeng-SH

XuPeng-SH commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor Author

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

Commit: b93a41bac6907e414c919f01690a9b6e1a1c043a

Review completed. Read the assessment.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor Author

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: b93a41bac6907e414c919f01690a9b6e1a1c043a

Assessment: request_changes

The change extends the existing authorization, planner and migration owners, and addresses the prior CREATE CDC and unrelated-write findings. One related CDC lifecycle path remains open: a policy-bearing administrator can resume or restart an existing unfiltered task.

Model: gpt-6.1-terra / max

Session: 01a21f04-073f-77d1-8630-a593fb7859fd · slot 0 · generation 28

  • P2 pkg/frontend/rewrite_rule.go:537: An administrator with an active role rule resumes or restarts an existing paused CDC task targeting a protected table. The task may have been created before the rule was attached or by an unruled administrator.
    Impact: The task can send rows and columns excluded by the administrator’s active policy to its sink. CDC operations require administrator privileges, but the resumed reader does not enforce the mandatory role rule.
    Evidence: The guard rejects CreateCDC, while ResumeCDC and RestartCDC are classified as QueryTypeOth and pass the default branch. The handlers in pkg/frontend/cdc_handle.go:171 request task resumption or restart, and pkg/taskservice/daemon_task.go:270 resumes the existing routine; its reader collects physical changes without role-rule filtering. A test-only admission probe confirms both statements are accepted. Reject resume and restart under active rules, or enforce those rules throughout the resulting task.

Validation:

  • Private /tmp and loopback preflight and the assigned-range git diff check passed; receipts checks/1795819026420843952-3.json and checks/1795819026476506997-3.json, with retained logs.

  • The focused frontend statement-support test and two-CN role-policy regression passed; receipt checks/1795819615068599540-3.json and focused.log.

  • Test-only frontend probes confirmed the selected builtin admission behavior and acceptance of ResumeCDC and RestartCDC; receipt checks/1795819675834332454-2.json and admission-probes.log.

  • All 22 discussion keys and the claimed check receipts were reconciled; receipt checks/1795819727885200809-2.json and reconciliation.log. The initial native setup failure was recovered by initializing the build directories and rebuilding.

Limitations:

  • The CDC lifecycle finding is supported by source tracing and an admission-classifier probe; it was not exercised against a live CDC sink.

  • The reported v4.2.9 shutdown upgrade and proxy handoff were not independently rerun. Relevant hosted checks were incomplete in the frozen evidence.

@XuPeng-SH

XuPeng-SH commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor Author

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

Commit: 8477faa346c8b93876959977bbe3a3cdfe68f541

Review completed. Read the assessment.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor Author

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: 8477faa346c8b93876959977bbe3a3cdfe68f541

Assessment: request_changes

The change reuses the existing authorization, rewrite, and migration owners, and the earlier CDC lifecycle concern is addressed. Prepared plans can still retain a policy result from a previous role when the two roles have identical rule text. The cache, policy checks, and migration safeguards serve distinct purposes, but this remaining identity check is needed for mandatory enforcement.

Model: gpt-6.1-terra / max

Session: 01a22009-ffda-7582-8f3a-5d2b1b110027 · slot 0 · generation 33

  • P1 pkg/frontend/rewrite_rule.go:676: A session changes roles after preparing a statement, and both roles have identical rule text whose result depends on the current role.
    Impact: The prepared plan can return rows authorized for the previous role instead of applying the current role’s policy. Both native and text prepared execution are affected.
    Evidence: The equality check compares rule text and folded-target proofs without comparing the prepare-time principal. The retained exact-head two-CN test in attempt-3/role-policy-probe.log shows a fresh query reflecting the new role while both prepared protocols return the previous role’s result; checks/1795822202212209924-2.json records its exit 1. Record and validate the policy-relevant principal, or otherwise ensure the policy is reevaluated safely, and retain regression coverage for both protocols.

Validation:

  • Reused the exact-head focused frontend CDC checks and two-CN role-policy regression: attempt-1/checks/1795821480851469719-2.json and attempt-1/focused.log record exit 0.

  • Reused the test-only prepared-role counterexample: attempt-3/checks/1795822202212209924-2.json and attempt-3/role-policy-probe.log record exit 1 with the differing results.

  • Both retained private /tmp and loopback preflights passed. The assigned-range diff check passed in attempt 1.

  • Reconciled all 24 discussion keys and the reused command, source, exit, and log evidence: attempt-8/checks/1795834244940238390-2.json and attempt-8/reconciliation.log.

Limitations:

  • The author-reported v4.2.9 shutdown upgrade and live proxy handoff were not independently rerun in this attempt.

  • Relevant hosted checks were incomplete in the frozen evidence. The target base is newer than the merge-base, so the retained executions do not cover a combined merge.

@XuPeng-SH

XuPeng-SH commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor Author

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

Commit: 78da203ee89eebf367720c39fc7cb5cca7b54633

Review completed. Read the assessment.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor Author

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: 78da203ee89eebf367720c39fc7cb5cca7b54633

Assessment: approve

The new principal comparison resolves the prior prepared-role finding, including when catalog-version proof is unavailable. The change extends the existing authorization, rewrite, and migration owners; the cache proof, prepared-plan check, and bounded migration retry address distinct responsibilities. No actionable findings remain.

Model: gpt-6.1-terra / max

Session: 01a22009-ffda-7582-8f3a-5d2b1b110027 · slot 0 · generation 33

Validation:

  • The selected frontend tests and TestMandatoryRoleRulesAcrossConnections passed on the assigned head with Go 1.26.6 on Linux/amd64. Receipt: model-switch-1795835832222089299/checks/1795836634885851743-2.json; log: model-switch-1795835832222089299/focused.log.

  • The private /tmp and loopback preflight passed, and the assigned-range git diff check passed. Receipts and logs are retained in attempt-1 and model-switch-1795835832222089299.

  • All 26 discussion keys and the claimed check evidence were reconciled: model-switch-1795835832222089299/checks/1795836654475383827-2.json and reconciliation.log.

Limitations:

  • The author-reported v4.2.9 shutdown upgrade and live proxy handoff were not independently rerun.

  • Relevant hosted checks were incomplete in the frozen evidence. Local runtime tests exercised the assigned head, not a combined merge with the newer target base.

  • Earlier dependency-download attempts were interrupted before tests began; the successful retry used the same task caches and an alternate module proxy.

This branch was successfully deployed

No deployments
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/XXL Denotes a PR that changes 2000+ lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants