Skip to content

Fix CREATE OR REPLACE bypassing the drop privilege of the replaced table via Replicated databases and ON CLUSTER - #122272

Merged
evillique merged 2 commits into
ClickHouse:masterfrom
evillique:create-or-replace-remote-drop-privilege
Oct 1, 2026
Merged

evillique merged 2 commits into
ClickHouse:masterfrom
evillique:create-or-replace-remote-drop-privilege

Conversation

@evillique

@evillique evillique commented Sep 25, 2026 •

Copy link
Copy Markdown
Member

CREATE OR REPLACE sent to a Replicated database or with ON CLUSTER is replayed with full access, so the drop privilege for the kind of the replaced table was never checked and a user with only CREATE VIEW and DROP VIEW could replace a dictionary with a view. The privilege is now required in getRequiredAccess, which every path checks on the initiator as the real user.

Changelog category (leave one):

  • Critical Bug Fix (crash, data loss, RBAC)

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

CREATE OR REPLACE in a Replicated database or with ON CLUSTER now requires the drop privilege for the kind of the table it replaces, so a user without DROP DICTIONARY can no longer replace a dictionary.


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

Version info

  • Merged into: 26.10.1.1221-master (included in 26.10 and later)
  • Backported to: 26.9.9.13, 26.8.16.19, 26.7.20.12, 26.3.40.16

@clickhouse-gh

clickhouse-gh Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [f6058a3]

Summary: ✅


AI Review

Summary

This PR moves the replacement-time DROP_* check into InterpreterCreateQuery::getRequiredAccess so replicated database and ON CLUSTER replays are authorized before workers run with full access. The local synchronized case is covered, but the ON CLUSTER path still derives the extra drop grant only from the initiator's local catalog, so the RBAC bypass remains when the replaced object exists only on a remote host or under another shard default database.

Findings
  • ❌ [src/Interpreters/InterpreterCreateQuery.cpp:3773-3776] The new DROP_* requirement is computed only from DatabaseCatalog::instance().tryGetDatabase(database_name) on the initiator. executeDDLQueryOnCluster later expands empty database names to each host's default database, and createTable already notes that an ON CLUSTER database may be absent on the initiator. In those cases this block adds no DROP_DICTIONARY/DROP_TABLE grant, but the remote worker still replays the replacement with full access, so an unprivileged user can still replace a remote dictionary or table.
    Suggested fix: derive the extra drop grant from the same per-host target set used by distributed DDL, or re-check the concrete remote object kind under the original user on the worker before the swap.
Tests
  • ⚠️ The new stateless test covers only the synchronized local-catalog case. Add a regression where the initiator cannot see the replaced object (ON CLUSTER remote-only database, or a bare table name resolved via a shard default database), because that is the path still left open by the current patch.
Final Verdict

Changes requested.

LLVM Coverage Report

Measured on commit f6058a3.

Metric Baseline Current Δ
Lines 88.10% 88.20% +0.10%
Functions 91.70% 91.70% +0.00%
Branches 79.40% 79.50% +0.10%

Changed lines: Changed C/C++ lines covered: 16/16 (100.00%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added pr-critical-bugfix pr-must-backport Pull request should be backported intentionally. Use this label with great care! comp-rbac Authorization: roles, grants, quotas, row-level security, access checks. labels Sep 25, 2026
Comment on lines +3773 to +3776
String database_name = getContext()->resolveDatabase(create.getDatabase());
if (auto database = DatabaseCatalog::instance().tryGetDatabase(database_name))
if (auto table = database->tryGetTable(create.getTable(), getContext()))
required_access.emplace_back(getDropAccessType(*table), database_name, create.getTable());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This still authorizes only against the initiator's local catalog. For ON CLUSTER, executeDDLQueryOnCluster later expands empty database names to each host's default DB, and createTable already documents that the target database may be absent on the initiator. In both cases this block can add no DROP_DICTIONARY/DROP_TABLE requirement even though a remote worker will still replay the replacement with full access, so the RBAC bypass remains for remote-only or default-db-mismatched targets.

Please derive the extra drop grant from the same per-host target set that distributed DDL uses, or re-check the concrete remote object kind under the original user on the worker before the swap.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The initiator can only authorize against objects it can see, as with every ON CLUSTER check. It cannot learn the kind of a remote-only object. For that case, distributed_ddl_use_initial_user_and_roles already makes each worker run this check as the initiating user.

@clickhouse-gh

clickhouse-gh Bot commented Sep 25, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing f6058a3b2 with master 58a1b24cb (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of e00c1a0cc; 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

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

Job report

@thevar1able thevar1able self-assigned this Oct 1, 2026
@evillique
evillique added this pull request to the merge queue Oct 1, 2026
Merged via the queue into ClickHouse:master with commit 6caf070 Oct 1, 2026
349 of 350 checks passed
@evillique
evillique deleted the create-or-replace-remote-drop-privilege branch October 1, 2026 22:37
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 1, 2026
@robot-clickhouse robot-clickhouse added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Oct 1, 2026
clickhouse-gh Bot added a commit that referenced this pull request Oct 2, 2026
Backport #122272 to 26.9: Fix `CREATE OR REPLACE` bypassing the drop privilege of the replaced table via `Replicated` databases and `ON CLUSTER`
clickhouse-gh Bot added a commit that referenced this pull request Oct 2, 2026
Backport #122272 to 26.8: Fix `CREATE OR REPLACE` bypassing the drop privilege of the replaced table via `Replicated` databases and `ON CLUSTER`
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Oct 2, 2026
… the drop privilege of the replaced table via `Replicated` databases and `ON CLUSTER`
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Oct 2, 2026
… the drop privilege of the replaced table via `Replicated` databases and `ON CLUSTER`
PedroTadim added a commit that referenced this pull request Oct 2, 2026
Backport #122272 to 26.7: Fix `CREATE OR REPLACE` bypassing the drop privilege of the replaced table via `Replicated` databases and `ON CLUSTER`
robot-clickhouse-ci-2 added a commit that referenced this pull request Oct 2, 2026
Cherry pick #122272 to 26.3: Fix `CREATE OR REPLACE` bypassing the drop privilege of the replaced table via `Replicated` databases and `ON CLUSTER`
robot-clickhouse added a commit that referenced this pull request Oct 2, 2026
…privilege of the replaced table via `Replicated` databases and `ON CLUSTER`
@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 Oct 2, 2026
evillique added a commit that referenced this pull request Oct 3, 2026
Backport #122272 to 26.3: Fix `CREATE OR REPLACE` bypassing the drop privilege of the replaced table via `Replicated` databases and `ON CLUSTER`
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Oct 9, 2026
… the drop privilege of the replaced table via `Replicated` databases and `ON CLUSTER`
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-critical-bugfix 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.

4 participants