Skip to content

[Bug]: Cross-account account snapshot restore leaves table grants bound to source object IDs #26640

Closed

Description

@Ariznawlll

What happened

RESTORE ACCOUNT <source>{snapshot="..."} TO ACCOUNT <target> restores users, roles, and table data, but table-level privileges retain the source account table object ID. The restored target table has a new object ID, so the restored non-admin user can connect and has the expected current role but cannot read the table.

This makes a cross-account account snapshot restore incomplete for ordinary application users: the data is present, but the restored table permissions no longer authorize access to it.

Environment

  • MatrixOne main: b18cdee19bad80a51ea54789a727aa1753fd0b08
  • Fresh isolated two-CN deployment
  • Reproduced independently: 3/3

Steps to reproduce

-- In source_account as account admin
CREATE DATABASE snapshot_account_source_db;
CREATE TABLE snapshot_account_source_db.orders (
  id INT PRIMARY KEY,
  note VARCHAR(32)
);
INSERT INTO snapshot_account_source_db.orders VALUES (1, 'snapshotted');

CREATE ROLE snapshot_reader;
CREATE USER source_reader IDENTIFIED BY '<password>' DEFAULT ROLE snapshot_reader;
GRANT CONNECT ON ACCOUNT * TO snapshot_reader;
GRANT SELECT ON TABLE snapshot_account_source_db.orders TO snapshot_reader;
GRANT snapshot_reader TO source_reader;

-- A fresh source_reader session can read `orders` here.

-- As sys
CREATE SNAPSHOT snapshot_account_before_mutation FOR ACCOUNT source_account;
RESTORE ACCOUNT source_account{snapshot="snapshot_account_before_mutation"}
  TO ACCOUNT target_account;

Connect as target_account#source_reader using the restored password and run:

SELECT current_role();
SELECT COUNT(*) FROM snapshot_account_source_db.orders;

Actual behavior

The connection succeeds and current_role() returns snapshot_reader, but the SELECT fails with:

internal error: do not have privilege to execute the statement

The issue is reproducible with the following catalog relationship in every run:

source mo_role_privs.obj_id (SELECT on orders) = source orders rel_id = A
target restored mo_role_privs.obj_id           = A
target restored orders rel_id                  = B

A and B are different. The privilege row was copied with the source table object ID instead of being rebound to the restored target table object ID.

Expected behavior

After cross-account account snapshot restore, roles and table-level grants should authorize the restored users against the restored target tables. The restore path should remap table-scoped privilege object IDs to the corresponding target objects, or otherwise preserve equivalent access semantics.

Control checks

  • The source reader can read the source table before snapshot creation.
  • A new source reader connection after snapshot creation can still read the source table.
  • The restored target account contains the snapshotted table data.
  • The restored user and role exist and the restored session selects snapshot_reader as its current role.
  • A target-only user and target-only table are removed by the account restore as expected.

These controls isolate the failure to the table-grant object mapping during cross-account account snapshot restore.

Activity

  1. added this to the MO-202608 milestone on Aug 3, 2026
  2. added
    kind/bug
    on Aug 3, 2026
  3. added theissue type on Aug 3, 2026
  4. assigned and unassigned on Aug 5, 2026
  5. Ariznawlll commented on Aug 9, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 分支:main
    • commit:08770e1beeb23239c91165492f2fe85243a3c66a
    • 部署方式:本地隔离单 CN/单 TN/LogService;两个非 sys 账号的 account snapshot restore
    • 测试日期:2026-08-09

    原问题验证

    源账号中创建带表级 SELECT grant 的 reader,创建 account snapshot 后恢复到已存在目标账号。恢复后的目标 reader 连续 3/3 保持 snapshot_reader,并可读取订单表的 COUNT=1,SUM(id)=1。

    Happy Path 覆盖

    1. snapshot 前源 reader 可读取授予的表。
    2. cross-account restore 后目标账号 admin 看到相同 1,1 数据。
    3. 恢复后的普通 reader 直接读取全限定表成功,证明表级 privilege 已绑定到目标对象。

    Unhappy Path 覆盖

    1. 目标账号恢复前预置 target_only_db 与用户;恢复后该数据库查询返回 1049 Unknown database,证明 restore 覆盖了目标账号旧状态。
    2. 每轮清理 snapshot、两个账号及所有连接;未观察到残留账号或 session。

    白盒验证

    不适用:问题本身是跨账号控制面和目录对象映射,使用真实 snapshot/restore 验证比 mock 更合适。

    回归测试

    已加入 motr PR #85:suites/04_snapshot_pitr/t/issue_26640_restore_table_grants.test。该 suite 已配置独占执行;新 case 3 轮通过,完整 snapshot suite 为 92/92 成功。

    测试证据

    • 黑盒原始与覆盖路径:3/3 成功。
    • 新 motr case:3/3、84 条语句成功。
    • ./motr --suite 04_snapshot_pitr:92/92 成功。

    测试结论

    测试通过。

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

Metadata

Metadata

Assignees

Labels

kind/bug

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions