Skip to content

Check the UNDROP TABLE grant on the undropped table instead of *.* - #131892

Merged
PedroTadim merged 7 commits into
ClickHouse:masterfrom
lazerg:fix/issue-131853-undrop-table-grant
Nov 17, 2026
Merged

PedroTadim merged 7 commits into
ClickHouse:masterfrom
lazerg:fix/issue-131853-undrop-table-grant

Conversation

@lazerg

@lazerg lazerg commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Closes: #131853

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):

UNDROP TABLE now works with an UNDROP TABLE grant on the database or the table. Before, it always required the grant ON *.*.

Description

InterpreterUndropQuery::execute called checkAccess(AccessType::UNDROP_TABLE) without a database or table, so a grant like GRANT UNDROP TABLE ON db.* was never enough. The check now runs in executeToTable against the target table, after an unqualified name is resolved to the current database, the same as DROP TABLE. ON CLUSTER queries already check the scoped grant through getRequiredAccessForDDLOnCluster. Since a grant on one table is now enough, UNDROP TABLE t2 UUID '...' with the UUID of another dropped table t1 is now rejected: it used to bring back t1, which would let a grant on t2 restore t1. The error for such a mismatch no longer names the other table or database. UNDROP TABLE is also now rejected under readonly and allow_ddl = 0, like DROP TABLE, and the UUID form with ON CLUSTER still needs the grant on *.*, because older replicas do not check the name. With ON CLUSTER the grant is checked before the database is looked at, and _temporary_and_external_tables is rejected like in DatabaseCatalog. The new test fails on master.


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

Version info

  • Merged into: 26.11.1.2557-master (included in 26.11 and later)

@clickhouse-gh clickhouse-gh Bot added comp-rbac Authorization: roles, grants, quotas, row-level security, access checks. external Author is not a member of the ClickHouse organization labels Nov 16, 2026
@PedroTadim PedroTadim self-assigned this Nov 16, 2026
@PedroTadim PedroTadim added the can be tested Allows running workflows for external contributors label Nov 16, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [07f6601]

Summary: ✅


AI Review

⚠️ Review sessions stopped as a cybersecurity risk

The model provider stopped these review sessions as a possible cybersecurity risk:

  • attempt 1: gpt-6.1-sol

This summary comes from a session with gpt-5.4. A session is typically stopped when it reaches a memory-safety finding, and the finding is lost with it, so this review can miss a real defect. Please review the change in detail, and run the review internally with a model that has cyber access.

Summary

This PR moves UNDROP TABLE authorization onto the actual target table/database, restores the expected readonly and allow_ddl protections, hardens UUID-based undrops and ON CLUSTER routing against cross-object disclosure, and adds focused stateless coverage for those regressions. I re-checked the current head against the prior review threads and do not see a remaining correctness, privilege, or mixed-version issue in the diff.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Nov 16, 2026
Comment thread src/Interpreters/DatabaseCatalog.cpp Resolved
@PedroTadim

Copy link
Copy Markdown
Member

@lazerg please address the blocker threads

@lazerg

lazerg commented Nov 16, 2026

Copy link
Copy Markdown
Contributor Author

Fast test failed on 02681_undrop_query_uuid because of my change: with only the global grant for ON CLUSTER ... UUID, the current database was no longer added to the query, so the replica looked in default. Fixed in 2b83403 by keeping the scoped element next to the global one.

@clickhouse-gh

clickhouse-gh Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 07f660199 with master aed311f51 (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

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

Job report

jkartseva pushed a commit to lazerg/ClickHouse that referenced this pull request Nov 19, 2026
…eadonly mode

`readonly` and `allow_ddl` are enforced in `ContextAccess::checkAccessImplHelper`
by a deny-list of requested access types. Three statements that change
persistent state were missing from it:

- `ALTER DATABASE ... MODIFY COMMENT` / `MODIFY SETTING` request the children
  of `ALTER_DATABASE`, which `table_ddl` did not contain, so they ran at
  `readonly = 1`, `readonly = 2`, over HTTP GET and with `allow_ddl = 0`.
  `ALTER_DATABASE` is now part of `table_ddl`, like `ALTER_TABLE` and
  `ALTER_VIEW`.
- `KILL TRANSACTION` requests `KILL_TRANSACTION`, which was not in
  `not_readonly_flags` (`KILL_QUERY` is), so a read-only session could roll
  back another user's transaction.
- `INSERT INTO FUNCTION` never requests `INSERT`; its only gated flag is
  `CREATE_TEMPORARY_TABLE` (forced for inserts by ClickHouse#44290), which `readonly = 2`
  allows on purpose for session temporary tables. So at `readonly = 2`, which is
  what HTTP GET runs with, `file()` wrote and overwrote files and `url()` sent
  the POST. The source `WRITE` flag is not added to the deny-list because it is
  also requested by `BACKUP` destinations (documented as not restricted by
  `readonly`), by `SELECT` from a `DatabaseS3` table and by `file()` reads with
  `rename_files_after_processing`, and a filtered `WRITE` grant does not reach
  the gate at all. Instead `InterpreterInsertQuery::getTable` refuses a table
  function insert under any `readonly`, with the gate's error text, before
  anything is resolved or written. Every table function insert (synchronous,
  asynchronous, parallel replicas) goes through it.

The English documentation of these settings is updated, including two stale
sentences (named collection management and `UNDROP TABLE` have been gated
since ClickHouse#130952 and ClickHouse#131892).

Related: ClickHouse#132330

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-rbac Authorization: roles, grants, quotas, row-level security, access checks. external Author is not a member of the ClickHouse organization pr-bugfix Pull request with bugfix, not backported by default 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.

UNDROP TABLE ignores a database- or table-level UNDROP TABLE grant and always requires it ON *.*

3 participants