Skip to content

remove secondary role - #26734

Merged
mergify[bot] merged 6 commits into
matrixorigin:mainfrom
daviszhen:0805-fix-second-role
Aug 6, 2026
Merged

mergify[bot] merged 6 commits into
matrixorigin:mainfrom
daviszhen:0805-fix-second-role

Conversation

@daviszhen

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:

issue #25465

What this PR does / why we need it:

此分支将 secondary role 功能改为兼容性 no-op:

  • SET SECONDARY ROLE ALL/NONE 保留语法并成功执行,但不改变会话状态。
  • 用户始终只有一个有效角色;secondary role 的权限不会自动合并。
  • 删除启用 secondary role 时查询、加载角色的执行逻辑。
  • 避免 no-op 语句触发权限缓存失效。
  • 保留 SET ROLE ,用户可显式切换到另一个单独角色。
  • 更新前端 UT 和新增 BVT,覆盖 no-op 后角色不变、secondary 权限不生效、显式切换角色后权限生效。

@daviszhen
daviszhen requested a review from XuPeng-SH as a code owner August 5, 2026 13:33
@daviszhen
daviszhen requested a review from a user August 5, 2026 13:33
@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 commented Aug 6, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-08-06 06:59 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • ✅ Checks passed · in-place
  • ✅ Merged — 2026-08-06 08:24 UTC · at 4c62db04595692c831d54479c31431ce1da6ef8f · squash

This pull request spent 1 hour 24 minutes 45 seconds in the queue, including 45 minutes 44 seconds running CI.

Required conditions to merge
  • #review-threads-unresolved = 0 [🛡 GitHub branch protection]
  • github-review-approved [🛡 GitHub branch protection]
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-neutral = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-skipped = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI / UT Test on Ubuntu/x86
    • check-neutral = Matrixone CI / UT Test on Ubuntu/x86
    • check-skipped = Matrixone CI / UT Test on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI / SCA Test on Linux/arm64
    • check-neutral = Matrixone CI / SCA Test on Linux/arm64
    • check-skipped = Matrixone CI / SCA Test on Linux/arm64
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Utils CI / Coverage
    • check-neutral = Matrixone Utils CI / Coverage
    • check-skipped = Matrixone Utils CI / Coverage
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
    • check-neutral = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
    • check-skipped = Matrixone UT Coverage / UT Coverage on Ubuntu/x86

@mergify
mergify Bot merged commit 09b361f into matrixorigin:main Aug 6, 2026
26 of 27 checks passed
@mergify mergify Bot removed the queued label Aug 6, 2026
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
此分支将 secondary role 功能改为兼容性 no-op:

- SET SECONDARY ROLE ALL/NONE 保留语法并成功执行,但不改变会话状态。
- 用户始终只有一个有效角色;secondary role 的权限不会自动合并。
- 删除启用 secondary role 时查询、加载角色的执行逻辑。
- 避免 no-op 语句触发权限缓存失效。
- 保留 SET ROLE <role>,用户可显式切换到另一个单独角色。
- 更新前端 UT 和新增 BVT,覆盖 no-op 后角色不变、secondary 权限不生效、显式切换角色后权限生效。

Approved by: @XuPeng-SH, @heni02
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
此分支将 secondary role 功能改为兼容性 no-op:

- SET SECONDARY ROLE ALL/NONE 保留语法并成功执行,但不改变会话状态。
- 用户始终只有一个有效角色;secondary role 的权限不会自动合并。
- 删除启用 secondary role 时查询、加载角色的执行逻辑。
- 避免 no-op 语句触发权限缓存失效。
- 保留 SET ROLE <role>,用户可显式切换到另一个单独角色。
- 更新前端 UT 和新增 BVT,覆盖 no-op 后角色不变、secondary 权限不生效、显式切换角色后权限生效。

Approved by: @XuPeng-SH, @heni02
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
此分支将 secondary role 功能改为兼容性 no-op:

- SET SECONDARY ROLE ALL/NONE 保留语法并成功执行,但不改变会话状态。
- 用户始终只有一个有效角色;secondary role 的权限不会自动合并。
- 删除启用 secondary role 时查询、加载角色的执行逻辑。
- 避免 no-op 语句触发权限缓存失效。
- 保留 SET ROLE <role>,用户可显式切换到另一个单独角色。
- 更新前端 UT 和新增 BVT,覆盖 no-op 后角色不变、secondary 权限不生效、显式切换角色后权限生效。

Approved by: @XuPeng-SH, @heni02
XuPeng-SH added a commit that referenced this pull request Dec 3, 2026
…3692)

## What type of PR is this?

- [ ] API-change
- [x] 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](#26734) ·
[4.2-dev role
selection](https://github.com/matrixorigin/matrixone/blob/355a64c9bf9bd657d366f366e0aec05d85511012/pkg/frontend/authenticate.go#L3653-L3681)

### 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](https://github.com/matrixorigin/matrixone/blob/82ef44b94f8cd54dfd7a495529f1549c87104f7f/pkg/proxy/migration_principal_integration_test.go#L121-L154)

<details>
<summary>Two-CN test command and terminal output</summary>

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

```sh
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
```

```text
82ef44b
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
```

</details>

- 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 #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.

This branch was previously deployed

1 inactive deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/enhancement kind/feature size/L Denotes a PR that changes [500,999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants