Skip to content

fix(proxy): preserve the active SQL role during session migration - #33692

Merged
XuPeng-SH merged 6 commits into
matrixorigin:mainfrom
XuPeng-SH:codex/main-migration-role-principal
Dec 3, 2026
Merged

XuPeng-SH merged 6 commits into
matrixorigin:mainfrom
XuPeng-SH:codex/main-migration-role-principal

Conversation

@XuPeng-SH

@XuPeng-SH XuPeng-SH commented Dec 2, 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 #33696.

Related to #33377 (4.2-dev active-role enforcement) and #29148 (prepared-statement authorization).

What this PR does / why we need it:

Proxy opens a fresh authenticated connection on the destination CN. On main at faafdf4fef03 and on #33568 at 89068bb76c96, a session that had run SET ROLE could move under the login default role. The 4.2-dev fix in #33389 already kept the source connection when its active role differed from the target login.

The source adds the active role ID and name to the existing account and user identity. The destination compares this identity at preflight and again before importing session state. A mismatch keeps the client on its source CN. Checking both role fields preserves CURRENT_ROLE_ID() and CURRENT_ROLE() across a rename and prevents a different role from matching a reused name. Export action 0 and PrincipalVerified field 2 retain their existing wire numbers.

Main gives each session one active role. SET SECONDARY ROLE ALL/NONE leaves that role unchanged. The main protocol carries the role ID in field 3 and its name in field 5. Tag 4 is reserved. The 4.2-dev role snapshot uses tag 4 for its enabled secondary-role mode. Main role semantics · 4.2-dev role selection

Validation on 5dbde1d75806

Local PR SCA selected ./... because of proto/query.proto. Both molint and golangci-lint passed with the repository configuration. All 11 targeted race tests across four packages passed, including authenticated session migration between two CNs. A separate arm64 check with GOEXPERIMENT=simd reproduced the same checkunsafe warning in distance_func_narrow_arm64.go:40 on clean main at 4a3e5182a6e3 and on this commit.

Validation on 82ef44b94f8c

The full PR patch is identical before and after the rebase onto main at c13851c20654 (#33635). The tests below ran with the updated dependency.

One authenticated client connected through Proxy to two CNs. Each of three race-detector runs checked four transfers. A different login default, a renamed role with the same ID, and a reused role name with a different ID kept the source connection. Matching role ID and name moved the same connection to the other CN. Every attempt checked the backend address, role ID, role name, one allowed table read and one denied table read. Two-CN assertions

Two-CN test command and terminal output

The checkout was clean, with the repository's CPU native libraries on Darwin/arm64. The sandbox isolates an unrelated local HAKeeper listener.

git rev-parse HEAD
go version
export GOWORK=off GOEXPERIMENT=simd GOMAXPROCS=4 GOMEMLIMIT=5GiB
export TMPDIR="$(mktemp -d)"
printf '%s\n' '(version 1)' '(allow default)' '(deny network-outbound (remote ip "localhost:32001"))' > "$TMPDIR/hakeeper.sb"
.agents/skills/mo-dev/scripts/mo-cgo-test -mod=readonly -p=2 -race -timeout=12m \
  -exec "/usr/bin/sandbox-exec -f $TMPDIR/hakeeper.sb" \
  -count=3 -v -run '^TestRenameUserProxyMigrationPrincipal$' ./pkg/proxy
82ef44b94f8cd54dfd7a495529f1549c87104f7f
go version go1.27.1 darwin/arm64
=== RUN   TestRenameUserProxyMigrationPrincipal
    migration_principal_integration_test.go:142: different login default: backend 127.0.0.1:10120 -> 127.0.0.1:10120, role 3/migration_rb, allowed read on b and denied read on a
    migration_principal_integration_test.go:145: matching active role: backend 127.0.0.1:10120 -> 127.0.0.1:10160, role 3/migration_rb, allowed read on b and denied read on a
    migration_principal_integration_test.go:148: same role ID, renamed role: backend 127.0.0.1:10160 -> 127.0.0.1:10160, role 3/migration_rb, allowed read on b and denied read on a
    migration_principal_integration_test.go:151: same role name, different ID: backend 127.0.0.1:10160 -> 127.0.0.1:10160, role 3/migration_rb, allowed read on b and denied read on a
--- PASS: TestRenameUserProxyMigrationPrincipal (16.21s)
=== RUN   TestRenameUserProxyMigrationPrincipal
    migration_principal_integration_test.go:142: different login default: backend 127.0.0.1:10120 -> 127.0.0.1:10120, role 10002/migration_rb, allowed read on b and denied read on a
    migration_principal_integration_test.go:145: matching active role: backend 127.0.0.1:10120 -> 127.0.0.1:10160, role 10002/migration_rb, allowed read on b and denied read on a
    migration_principal_integration_test.go:148: same role ID, renamed role: backend 127.0.0.1:10160 -> 127.0.0.1:10160, role 10002/migration_rb, allowed read on b and denied read on a
    migration_principal_integration_test.go:151: same role name, different ID: backend 127.0.0.1:10160 -> 127.0.0.1:10160, role 10002/migration_rb, allowed read on b and denied read on a
--- PASS: TestRenameUserProxyMigrationPrincipal (21.01s)
=== RUN   TestRenameUserProxyMigrationPrincipal
    migration_principal_integration_test.go:142: different login default: backend 127.0.0.1:10120 -> 127.0.0.1:10120, role 10002/migration_rb, allowed read on b and denied read on a
    migration_principal_integration_test.go:145: matching active role: backend 127.0.0.1:10120 -> 127.0.0.1:10160, role 10002/migration_rb, allowed read on b and denied read on a
    migration_principal_integration_test.go:148: same role ID, renamed role: backend 127.0.0.1:10160 -> 127.0.0.1:10160, role 10002/migration_rb, allowed read on b and denied read on a
    migration_principal_integration_test.go:151: same role name, different ID: backend 127.0.0.1:10160 -> 127.0.0.1:10160, role 10002/migration_rb, allowed read on b and denied read on a
--- PASS: TestRenameUserProxyMigrationPrincipal (18.84s)
PASS
ok  	github.com/matrixorigin/matrixone/pkg/proxy	59.630s
exit 0
  • 336 top-level Proxy tests, 59 frontend migration tests and 5 wire and prepared-statement regressions passed under the race detector. The prepared-statement cases include revoking SELECT between preflight and replay.
  • The combined tree with fix(proxy): migrate sessions from obsolete CN routes #33568 at 89068bb76c96 (2c94a66d3aaf) passed six migration and routing tests three times each under the race detector.
  • Go vet, molint and incremental golangci-lint passed. The generator reproduced the main binding byte for byte. The protobuf descriptor differs from main only in the two added fields and the reserved tag.

@mergify

mergify Bot commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

This pull request is merged.

@matrix-meow matrix-meow added the size/M Denotes a PR that changes [100,499] lines label Dec 2, 2026
@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 Dec 2, 2026 •

Copy link
Copy Markdown
Contributor Author

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

Commit: a670157a9ddace35f9955991e88b0ae0e99ea7b0

linked issue or PR description changed before publication

@XuPeng-SH

XuPeng-SH commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor Author

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

Commit: a670157a9ddace35f9955991e88b0ae0e99ea7b0

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

Assessment: request_changes

The role comparison appropriately extends the existing principal verifier and repeats the check before import. The new old-peer handshake conflicts with the pinned shutdown-upgrade policy, and the supplied evidence does not include a verifiable terminal result for the required two-CN role regression.

Model: gpt-6.1-terra / max

Session: 01a237df-a073-7910-ac2c-836d2d273b8a · slot 1 · generation 43

  • P2 proto/query.proto:666: Connection migration now requires a new export action and a newly numbered principal-verification acknowledgement to distinguish older Proxy and CN peers.
    Impact: This adds permanent producer, consumer, and wire-contract distinctions for a mixed-version deployment that the pinned repository policy does not support. This is a policy and design finding, not an observed production failure.
    Evidence: The pinned .agents/skills/mo-dev/references/upgrade-compatibility.md:3-6,94-109 specifies full-cluster shutdown upgrades and prohibits new older-peer capability or fallback mechanisms. The baseline used export action 0 and acknowledgement field 2; this change rejects action 0 in pkg/frontend/routine.go:826 and moves the acknowledgement to field 3 at proto/query.proto:786. Preserve the full role verification while reusing the existing action and acknowledgement for same-version peers; leave unrelated existing compatibility checks alone.

  • P2 pkg/proxy/migration_principal_integration_test.go:124: A client changes its active role and then migrates through Proxy between authenticated CNs.
    Impact: The required public-path evidence for both rejected and successful transfers, including the allowed and denied reads, cannot be verified from the supplied results. This is a validation gap, not a demonstrated product failure.
    Evidence: The PR description reports exact-head race and two-CN passes, but local_validation is empty and the supplied evidence has no command or terminal output for that run; the relevant CI jobs were still in progress in the frozen snapshot. The local Go test could not compile with the installed toolchain. Make the already-reported exact-head command and terminal result accessible, or complete the focused TestRenameUserProxyMigrationPrincipal test in a supported environment.

Validation:

  • The isolation preflight, git diff --check, gofmt check, and generated protobuf descriptor check completed successfully on the assigned head. Their commands, source fingerprints, exits, and retained logs are mapped in validation-reconciliation.json.

  • The source review traced SET ROLE, the migration operation lease, source export, target preflight and final import, Proxy handoff, and the two-CN test assertions.

  • The complete discussion was assessed in discussion-assessment.json; its four entries are informational notices.

Limitations:

  • The focused Go wire test stopped before compilation because the installed Go 1.26.6 is older than the required Go 1.27.1. A bounded attempt to obtain the required toolchain timed out; neither result is a product-test failure or pass.

  • The author also reports exact-head frontend, Proxy, race, and Connector/J checks. Their terminal logs were not included in the supplied evidence, so they were not independently verified.

@XuPeng-SH

XuPeng-SH commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor Author

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

Commit: 586a9ae89ff47a62ca16400957b81038e436da24

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: 586a9ae89ff47a62ca16400957b81038e436da24

Assessment: approve

The prior concerns are resolved: the change retains the existing export action and acknowledgement, and the supplied exact-head evidence covers authenticated two-CN migration. The fix extends the existing principal verifier and repeats the role check before import.

Model: gpt-6.1-terra / max

Session: 01a237df-a073-7910-ac2c-836d2d273b8a · slot 1 · generation 43

Validation:

  • The PR body supplies the exact-head command and terminal output for TestRenameUserProxyMigrationPrincipal: three passing race-detector runs through Proxy and two CNs, with backend, active-role, allowed-read, and denied-read assertions.

  • Independent bounded checks passed for diff whitespace, formatting, and the generated protobuf descriptor. The descriptor comparison found only the three intended principal fields changed from the base. Receipts and logs are mapped in validation-reconciliation.json.

  • The review traced authenticated role selection, operation leases, export, preflight, final import, failure handling, and the changed prepared-statement test oracles.

Limitations:

  • The additional package, prepared-statement, and lint runs are author-reported without detailed terminal output in the supplied evidence.

  • Relevant CI jobs were still in progress in the frozen snapshot.

@XuPeng-SH

XuPeng-SH commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor Author

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

Commit: 1ce9b5ed8eec903112f794408839953177c6023e

Review completed. Read the assessment.

@XuPeng-SH

XuPeng-SH commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor Author

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

Commit: 82ef44b94f8cd54dfd7a495529f1549c87104f7f

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: 82ef44b94f8cd54dfd7a495529f1549c87104f7f

Assessment: approve

The change preserves the authenticated active role by extending the existing migration principal check. The earlier wire-format and two-CN validation concerns remain resolved.

Model: gpt-6.1-terra / max

Session: 01a237df-a073-7910-ac2c-836d2d273b8a · slot 1 · generation 43

Validation:

  • The PR supplies exact-head terminal output for three passing race-detector runs through Proxy and two CNs, covering matching roles, changed defaults, renamed roles, reused names, and allowed and denied reads.

  • Independent bounded checks passed for the generated protobuf descriptor, diff whitespace, formatting, and comparison with the previously reviewed PR patch. The patch is byte-for-byte identical across the rebase; the base update changes dependency files.

  • The review traced role selection, operation leases, source export, target preflight and final import, and the changed prepared-statement authorization tests. Receipts and logs are mapped in validation-reconciliation.json.

Limitations:

  • Relevant CI jobs were still in progress in the frozen snapshot.

  • Additional package and lint runs are author-reported without detailed terminal output in the supplied evidence.

@XuPeng-SH XuPeng-SH closed this Dec 3, 2026
@XuPeng-SH XuPeng-SH reopened this Dec 3, 2026
@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 Dec 3, 2026 •

Copy link
Copy Markdown
Contributor Author

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

Commit: 5dbde1d758062e2b0c8d57a4016a7640ef220ad2

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: 5dbde1d758062e2b0c8d57a4016a7640ef220ad2

Assessment: approve

The change preserves the active role by extending the existing migration principal check before replay and final import. The earlier handshake and public-path validation concerns are resolved; no actionable findings remain.

Model: gpt-6.1-terra / max

Session: 01a237df-a073-7910-ac2c-836d2d273b8a · slot 1 · generation 43

Validation:

  • The complete pkg/pb/query test package passed on the assigned head. An independent descriptor comparison found only the intended role fields and reserved tag; logs and receipts are recorded in validation-reconciliation.json.

  • Isolation preflight, diff whitespace and Go formatting checks passed.

  • The PR supplies three passing race-detector runs through Proxy and two CNs at 82ef44b, covering role matches, mismatches, renames and authorization. The later change in the affected migration code is a receiver rename.

Limitations:

  • The two-CN test was not repeated locally on the assigned head.

  • Relevant CI checks were pending in the supplied snapshot. Other exact-head race and lint results are author-reported without terminal logs.

@XuPeng-SH
XuPeng-SH merged commit 2305687 into matrixorigin:main Dec 3, 2026
4 of 6 checks passed
@XuPeng-SH
XuPeng-SH deleted the codex/main-migration-role-principal branch December 3, 2026 01:27
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]: Proxy session migration can change the active SQL role on main

2 participants