Skip to content

Validate access to underlying tables for Merge engine - #78339

Merged
GrigoryPervakov merged 2 commits into
masterfrom
merge-access-validation
Apr 8, 2025
Merged

GrigoryPervakov merged 2 commits into
masterfrom
merge-access-validation

Conversation

@GrigoryPervakov

@GrigoryPervakov GrigoryPervakov commented Mar 26, 2025 •

Copy link
Copy Markdown
Member

Use the same validation as in the table function Merge before, but move logic inside StorageMerge to provide consistent behaviour

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 to CHANGELOG.md):

Validate access to underlying tables for the Merge engine

@clickhouse-gh

clickhouse-gh Bot commented Mar 26, 2025 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [04c76a2]

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Mar 26, 2025
@GrigoryPervakov
GrigoryPervakov force-pushed the merge-access-validation branch 6 times, most recently from a6a7c20 to 745d719 Compare March 31, 2025 17:44
@GrigoryPervakov
GrigoryPervakov marked this pull request as ready for review April 1, 2025 11:02
@divanik divanik self-assigned this Apr 2, 2025
@@ -1,195 +1,195 @@
CREATE TABLE t_merge as 01902_db.t ENGINE=Merge(REGEXP(^01902_db), ^t)

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.

There is a neighbour test 01902_table_function_merge_db_params.sql that creates a db that matches that prefix, and in case of failure, it doesn't cleanup, so it affects this test run

Comment thread src/Storages/StorageMerge.cpp Resolved
Comment thread src/Storages/StorageMerge.cpp Resolved
Comment thread src/Storages/StorageMerge.cpp Resolved
Comment thread src/Storages/StorageMerge.cpp Resolved
Comment thread src/Storages/StorageMerge.cpp Resolved

@divanik divanik left a comment

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.

Some minor issues and an explanation request

@GrigoryPervakov
GrigoryPervakov force-pushed the merge-access-validation branch from 745d719 to 04c76a2 Compare April 7, 2025 14:04
@GrigoryPervakov
GrigoryPervakov requested a review from divanik April 7, 2025 15:35
@GrigoryPervakov
GrigoryPervakov added this pull request to the merge queue Apr 7, 2025
@GrigoryPervakov
GrigoryPervakov removed this pull request from the merge queue due to a manual request Apr 7, 2025
@GrigoryPervakov
GrigoryPervakov added this pull request to the merge queue Apr 8, 2025
robot-clickhouse added a commit that referenced this pull request Apr 10, 2025
Backport #78339 to 25.2: Validate access to underlying tables for Merge engine
GrigoryPervakov added a commit that referenced this pull request Apr 14, 2025
Backport #78339 to 25.3: Validate access to underlying tables for Merge engine
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Apr 14, 2025
GrigoryPervakov added a commit that referenced this pull request Apr 15, 2025
Backport #78339 to 25.1: Validate access to underlying tables for Merge engine
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-backports-created-cloud deprecated label, NOOP label Apr 22, 2025
GrigoryPervakov added a commit that referenced this pull request Apr 29, 2025
Backport #78339 to 24.8: Validate access to underlying tables for Merge engine
@robot-clickhouse robot-clickhouse added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Jul 2, 2025
alexey-milovidov pushed a commit to zvonand/ClickHouse that referenced this pull request Nov 10, 2026
A `Merge` table or `merge()` reads only the matched tables the user has
`SHOW TABLES` on (ClickHouse#78339), but its metadata-only answers walked every
matched table: the trivial count (`SELECT count()` with
`apply_patch_parts = 0, apply_mutations_on_fly = 0`), `system.tables`
`total_rows`/`total_bytes` and `system.columns` sizes included the rows
and on-disk size of a table the user holds no privilege on, and the
trivial count answered for a visible child the user cannot read.

`totalRows`/`totalBytes`, `supportsTrivialCountOptimization` and
`tryGetColumnSizes` now enumerate the children with the query context
and skip those without `SHOW TABLES`, like `getSelectedTables` does. The
trivial count is also declined for a visible child with no `SELECT` on
any column, so the read path raises its `ACCESS_DENIED`.
`tryGetColumnSizes` takes the query context (its only caller is
`system.columns`), and the Merge sums each visible child's own
context-aware sizes, so a nested `Merge` or an `Alias` over a `Merge`
filters its own children too. `Alias`, `StorageProxy` and
`StorageTableFunctionProxy` forward the context.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
alexey-milovidov pushed a commit to amosbird/ClickHouse that referenced this pull request Nov 10, 2026
…ble function

A `Merge` table and `merge` read only the matched tables that the current
user can see (has `SHOW TABLES` on), and check `SELECT` only on those; a
matched table the user cannot see is skipped without an error. Structure
inference uses the same visibility filter and requires `SHOW COLUMNS`.
The rule comes from ClickHouse#78339 and is asserted by
`03400_merge_storage_underlying_tables_access_validation`. The owner chose
to document it on ClickHouse#129597 instead of changing the behaviour.

Add an `Access rights` section to both registration doc strings. The
reference pages `docs/reference/engines/table-engines/special/merge.mdx`
and `docs/reference/functions/table-functions/merge.mdx` are generated from
these strings by the nightly docs autogeneration, so they are not edited
here.

Closes ClickHouse#129597

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

pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-backports-created-cloud deprecated label, NOOP 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.

7 participants