Skip to content

[Bug]: REVOKE role does not invalidate the role in an existing active session #27650

Closed

Description

@Ariznawlll

Description

After an administrator revokes the currently active role from a user, the existing user session continues to use that role for subsequent statements. Clearing the session privilege cache does not remove the revoked active role. Both fresh text SQL and an existing binary prepared statement remain authorized.

Environment

  • Branch: main
  • Commit: a53f5a3b757c5b21a36e539e4471533fe1d091a8
  • Deployment: local mo-service, 1 Log / 1 TN / 1 CN
  • Client: MySQL Connector/J 8.4.0, server-side prepared statements enabled
  • enable_privilege_cache: on; the user session explicitly runs SET SESSION clear_privilege_cache=ON after revoke
  • Test date: 2026-08-26 (Asia/Shanghai)

Steps to reproduce

  1. Create role reader, user u with default role reader, and a table containing one row.
  2. Grant table SELECT to reader, then grant reader to u.
  3. Connect as u with reader active and prepare a parameterized SELECT.
  4. Confirm both text SQL and the prepared statement can read the row.
  5. From an administrator session, run REVOKE reader FROM u.
  6. In the existing user session, run SET SESSION clear_privilege_cache=ON.
  7. Execute the equivalent fresh text query and the existing binary prepared statement.
  8. Run SET ROLE public, then try SET ROLE reader again as a control.

Actual behavior

  • The fresh text query still succeeds after role revoke and cache clear.
  • The existing binary prepared statement also still succeeds.
  • After switching to public, SET ROLE reader is rejected because the role is no longer granted. This confirms the catalog revoke succeeded while the already active session retained stale authorization.

Observed in 3/3 fresh rounds:

round=1 text=allowed prepared=allowed switch-back=denied
round=2 text=allowed prepared=allowed switch-back=denied
round=3 text=allowed prepared=allowed switch-back=denied

Expected behavior

Revoking an active role should adjust the privileges of current sessions for the next statement. Fresh text and prepared execution should both be rejected after the revoke.

Controls

  • Direct REVOKE SELECT ... FROM reader plus session privilege-cache clear correctly denies both text/prepared access on this commit, confirming the [Bug]: prepared statements bypass revoked table SELECT privilege after cache clear #26891 fix remains effective.
  • A fresh connection explicitly requesting the revoked role is rejected in 3/3 rounds.
  • MySQL 8.0.46 control: the existing session loses the role privilege on the first statement after revoke.
  • No data mutation is involved. Cleanup succeeded after every round.

Code analysis

doRevokeRole removes the mo_user_grant row, but the existing session keeps its role ID/name in TenantInfo. Privilege cache invalidation only clears cached privilege results; it does not revalidate whether the active role is still granted to the user.

Regression recommendation

Add a multi-session access-control regression covering text SQL and binary prepared execution after role membership revoke, cache clear, switch-away/switch-back, and re-grant recovery.

Activity

  1. added this to the MO-202608 milestone on Aug 26, 2026
  2. added
    kind/bug
    on Aug 26, 2026
  3. added theissue type on Aug 26, 2026
  4. added a commit that references this issue on Aug 28, 2026
    958a4ce
  5. reopened this on Sep 4, 2026
  6. Ariznawlll commented on Sep 5, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 分支:main
    • commit:fa829e5c505520e4bd429d283c78157781b4de72
    • 部署方式:129 TKE,3 CN / 1 TN / 3 LogService / 2 Proxy
    • 测试日期:2026-09-05

    原问题验证

    3 轮隔离租户复测:已建立连接的用户在角色被撤销后,文本 PREPARE/EXECUTE 不能继续读取原授权对象。

    Happy Path 覆盖

    1. 授权后文本 prepared 查询和普通查询均成功。
    2. 撤销无关角色不影响 reader;重新授权后,既有 prepared statement 与新连接恢复可用。

    Unhappy Path 覆盖

    1. 撤销 reader 后,活动连接、文本 prepared statement、SET ROLE reader 和显式 reader 登录均被拒绝。
    2. 新连接回退到 public;拒绝后连接健康、目标表数据不变。

    白盒验证

    不适用:以 MySQL 协议黑盒验证权限缓存失效。

    回归测试

    已加入 MOTR:suites/14_issue_regression/t/issue_27650_27651_revoked_roles.test 与 binary 协议补充 issue_27650_binary_role_revoke.test。PR:https://github.com/matrixorigin/motr/pull/145 。该仓库当前没有可触发的 PR 回归 workflow,状态检查为空。

    测试证据

    隔离账号在每轮均删除;文本与 binary prepared 变体各 3/3 通过。

    测试结论

    测试通过。

  7. added 3 commits that reference this issue on Sep 17, 2026
    bdbe312
    6f6b748
    aa650c2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/bugphase/testing

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions