Skip to content

Check the TABLE ENGINE grant before ATTACH ... AS [NOT] REPLICATED converts a table - #128995

Merged
kolsha merged 3 commits into
masterfrom
attach-as-replicated-engine-grant
Nov 10, 2026
Merged

kolsha merged 3 commits into
masterfrom
attach-as-replicated-engine-grant

Conversation

@kolsha

@kolsha kolsha commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

A short ATTACH TABLE ... AS [NOT] REPLICATED carries no engine, so only CREATE TABLE was required up front. The TABLE ENGINE grant on the converted engine was checked only after convertMergeTreeTableIfPossible had rewritten the stored definition of the detached table and, for AS REPLICATED, removed the transaction metadata files of its parts. A query refused for that grant therefore still changed the engine that a later plain ATTACH TABLE loaded.

Check that the converted engine exists and that the TABLE ENGINE grant on it is held before any of these changes. The converted name comes from the new DatabaseOrdinary::getConvertedMergeTreeEngineName, which setMergeTreeEngine uses as well, so the checked name and the stored one cannot diverge.

The first commit adds the test, the second contains the fix.

🤖 Generated with Claude Code

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

ATTACH TABLE ... AS REPLICATED and ATTACH TABLE ... AS NOT REPLICATED now check the TABLE ENGINE grant on the engine the table is converted to before changing anything. Previously a query refused for this grant had already rewritten the stored definition of the detached table, so a later ATTACH TABLE loaded it with the new engine.


Workflow [PR]
Sync PR [sync-upstream/pr/128995]

Version info

  • Merged into: 26.11.1.1861-master (included in 26.11 and later)
  • Backported to: 26.9.32.10, 26.8.40.10, 26.3.67.18

kolsha and others added 2 commits November 3, 2026 14:12
…PLICATED`

A user with only `CREATE TABLE` runs `ATTACH TABLE ... AS REPLICATED` and
`ATTACH TABLE ... AS NOT REPLICATED` on detached tables. Each query is refused
for the missing `TABLE ENGINE` grant on the engine the table would be converted
to, and a later plain `ATTACH TABLE` must load every table with the engine it
had before.

With the grant on the converted engine, the conversion succeeds in both
directions and keeps the data.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…CATED` changes anything

A short `ATTACH` carries no engine, so `getRequiredAccess` requires only
`CREATE TABLE`. The `TABLE ENGINE` grant on the converted engine was checked
only after `convertMergeTreeTableIfPossible` had rewritten the stored metadata
of the detached table and, for `AS REPLICATED`, removed the transaction metadata
files of its parts. A refused query still changed the engine that a later plain
`ATTACH TABLE` used.

Check that the converted engine exists and that the grant on it is held before
any of these changes. The converted name comes from the new
`DatabaseOrdinary::getConvertedMergeTreeEngineName`, which `setMergeTreeEngine`
uses as well, so the checked name and the stored one are the same.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [72e6937]

Summary: ✅


AI Review

Summary

ATTACH TABLE ... AS [NOT] REPLICATED now validates the destination engine and its TABLE ENGINE grant before rewriting stored metadata or deleting transaction metadata. Reviewed head 72e6937869525bea489d926ce79c57bcf6c85c39; no actionable findings.

Missing context / blind spots
  • ⚠️ Latest-head stateless CI was still pending, and no local ClickHouse binary was available. The added regression passed all 50 targeted ASan/UBSan runs at the preceding implementation commit, 36fabe7732e192ba5cdff279232a641559cce11a (CI report). The subsequent commit adds only a precondition assertion and explanatory comments; latest-head CI completion would close this validation gap.
Final Verdict

Status: ✅ Approve.

@clickhouse-gh clickhouse-gh Bot added pr-bugfix Pull request with bugfix, not backported by default comp-rbac Authorization: roles, grants, quotas, row-level security, access checks. labels Nov 3, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 72e693786 with master 4f752f7e6 (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

38 translation units recompiled, 329 s compile time in total, 38 of them have a recent master baseline.

Job report

@kolsha
kolsha marked this pull request as ready for review November 4, 2026 08:19
@kolsha
kolsha requested a review from Algunenano November 4, 2026 08:19
…the conversion precondition

A grant such as `TABLE ENGINE ON *` covers an engine name that is not registered, so the registered-engine check
before the `TABLE ENGINE` check is what keeps a conversion from writing a definition that cannot be attached; say
so in the comment. `DatabaseOrdinary::getConvertedMergeTreeEngineName` now asserts that the name it strips starts
with `Replicated`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Algunenano Algunenano self-assigned this Nov 4, 2026
ylw510 pushed a commit to ylw510/ClickHouse that referenced this pull request Nov 6, 2026
The parallel-INSERT section compared the entries of the newest manifest list
(by file mtime) with the APPEND rows of system.iceberg_history. The insert
streams commit their snapshots about 1 ms apart, so the current manifest list
and its parent can share one coarse-clock mtime; `sort -n` then orders the
tie by the path, which carries the random snapshot id, and `tail -1` can
return the parent's list (one entry fewer), printing `0 1 1` instead of
`1 1 1`. CI query_log of both failures (ClickHouse#125897, ClickHouse#128995) shows the test
reading the parent snapshot's list.

Find the list the way a reader does: the newest v<N>.metadata.json, the
snapshot whose snapshot-id is current-snapshot-id, its manifest-list.
Forcing every manifest list to one mtime, the old helper picked a wrong list
in 23/40 trials and the new one in 0/40.

05496 and 05229 use the same mtime heuristic but write each snapshot from a
separate client call, so they are not changed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@kolsha
kolsha added this pull request to the merge queue Nov 7, 2026
@kolsha
kolsha removed this pull request from the merge queue due to a manual request Nov 7, 2026
@kolsha
kolsha added this pull request to the merge queue Nov 10, 2026
Merged via the queue into master with commit ca02742 Nov 10, 2026
365 of 368 checks passed
@kolsha
kolsha deleted the attach-as-replicated-engine-grant branch November 10, 2026 14:36
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 10, 2026
@nikitamikhaylov nikitamikhaylov added the pr-must-backport Pull request should be backported intentionally. Use this label with great care! label Nov 11, 2026
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Nov 11, 2026
clickhouse-gh Bot added a commit that referenced this pull request Nov 11, 2026
Backport #128995 to 26.10: Check the `TABLE ENGINE` grant before `ATTACH ... AS [NOT] REPLICATED` converts a table
groeneai pushed a commit to groeneai/ClickHouse that referenced this pull request Nov 12, 2026
…efore `ATTACH ... AS [NOT] REPLICATED` converts a table
leshikus pushed a commit that referenced this pull request Nov 13, 2026
…ACH ... AS [NOT] REPLICATED` converts a table
kolsha added a commit that referenced this pull request Nov 18, 2026
Keep the release branch side and apply only the fix of #128995: check the
`TABLE ENGINE` grant on the converted engine in `convertMergeTreeTableIfPossible`
before the side effects of `ATTACH ... AS [NOT] REPLICATED`.

The master-only code next to the fix is not carried over: `isTableReadonlyAsReplicated`
(#119224) and the `temporary_uuid` / `ordinary_znode_info` handling of `Ordinary`
databases, none of which exist on 26.9, where the conversion supports `Atomic` only.
Because of that the test is tagged `no-ordinary-database`, as `03169_attach_as_replicated`.
robot-ch-test-poll3 added a commit that referenced this pull request Nov 18, 2026
Cherry pick #128995 to 26.8: Check the `TABLE ENGINE` grant before `ATTACH ... AS [NOT] REPLICATED` converts a table
robot-clickhouse added a commit that referenced this pull request Nov 18, 2026
…CH ... AS [NOT] REPLICATED` converts a table
robot-ch-test-poll3 added a commit that referenced this pull request Nov 18, 2026
Cherry pick #128995 to 26.9: Check the `TABLE ENGINE` grant before `ATTACH ... AS [NOT] REPLICATED` converts a table
kolsha added a commit that referenced this pull request Nov 18, 2026
Keep the release branch side and apply only the fix of #128995: check the
`TABLE ENGINE` grant on the converted engine in `convertMergeTreeTableIfPossible`
before the side effects of `ATTACH ... AS [NOT] REPLICATED`.

The master-only code next to the fix is not carried over: `isTableReadonlyAsReplicated`
(#119224) and the `temporary_uuid` / `ordinary_znode_info` handling of `Ordinary`
databases, none of which exist on 26.8, where the conversion supports `Atomic` only.
Because of that the test is tagged `no-ordinary-database`, as `03169_attach_as_replicated`.
robot-clickhouse added a commit that referenced this pull request Nov 18, 2026
…CH ... AS [NOT] REPLICATED` converts a table
kolsha added a commit that referenced this pull request Nov 18, 2026
Keep the release branch side and apply only the fix of #128995: check the
`TABLE ENGINE` grant on the converted engine in `convertMergeTreeTableIfPossible`
before the side effects of `ATTACH ... AS [NOT] REPLICATED`.

The master-only code next to the fix is not carried over: `isTableReadonlyAsReplicated`
(#119224) and the `temporary_uuid` / `ordinary_znode_info` handling of `Ordinary`
databases, none of which exist on 26.3, where the conversion supports `Atomic` only.
Because of that the test is tagged `no-ordinary-database`, as `03169_attach_as_replicated`.
robot-ch-test-poll4 added a commit that referenced this pull request Nov 18, 2026
Cherry pick #128995 to 26.3: Check the `TABLE ENGINE` grant before `ATTACH ... AS [NOT] REPLICATED` converts a table
robot-clickhouse added a commit that referenced this pull request Nov 18, 2026
…CH ... AS [NOT] REPLICATED` converts a table
@robot-ch-test-poll robot-ch-test-poll added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Nov 18, 2026
clickhouse-gh Bot added a commit that referenced this pull request Nov 18, 2026
Backport #128995 to 26.9: Check the `TABLE ENGINE` grant before `ATTACH ... AS [NOT] REPLICATED` converts a table
clickhouse-gh Bot added a commit that referenced this pull request Nov 18, 2026
Backport #128995 to 26.8: Check the `TABLE ENGINE` grant before `ATTACH ... AS [NOT] REPLICATED` converts a table
@kolsha kolsha self-assigned this Nov 18, 2026
kolsha added a commit that referenced this pull request Nov 18, 2026
Backport #128995 to 26.3: Check the `TABLE ENGINE` grant before `ATTACH ... AS [NOT] REPLICATED` converts a table
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-rbac Authorization: roles, grants, quotas, row-level security, access checks. pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-bugfix Pull request with bugfix, not backported by default pr-must-backport Pull request should be backported intentionally. Use this label with great care! pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants