Skip to content

Fix target access checks for the Alias engine - #114596

Merged
hanfei1991 merged 14 commits into
ClickHouse:masterfrom
nauu:fix_alias
Aug 24, 2026
Merged

hanfei1991 merged 14 commits into
ClickHouse:masterfrom
nauu:fix_alias

Conversation

@nauu

@nauu nauu commented Aug 13, 2026 •

Copy link
Copy Markdown
Member

Alias table now requires SHOW COLUMNS on its target when a new definition is submitted. This prevents users from using Alias to reveal a target table's schema.

The trivial count optimization is disabled when the user has no SELECT privilege on the target, allowing the normal read path to enforce access checks.
rows and bytes statistics are also hidden unless the user has SHOW TABLES on the target.

Closes: #114511

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

Fixed an RBAC bypass in the Alias table engine that allowed users without privileges on the target table to reveal its schema, row count, size, and existence.


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

Version info

  • Merged into: 26.9.1.43 (included in 26.9 and later)
  • Backported to: 26.8.1.1994

@nauu nauu added the can be tested Allows running workflows for external contributors label Aug 13, 2026
@clickhouse-gh clickhouse-gh Bot closed this Aug 13, 2026
@clickhouse-gh clickhouse-gh Bot reopened this Aug 13, 2026
@clickhouse-gh

clickhouse-gh Bot commented Aug 13, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [a8691e5]

Summary: ✅


AI Review

Summary

This PR closes several obvious Alias metadata leaks, but the RBAC fix is still incomplete. The current head still leaves one hidden-target oracle in the SELECT analysis path, and Alias reads still ignore row policies defined only on the target table, so I would not merge this as the claimed access-control fix yet.

Findings

❌ Blockers

  • [src/Storages/StorageAlias.cpp:426-491, src/Interpreters/InterpreterSelectQuery.cpp:661-674, src/Interpreters/InterpreterSelectQuery.cpp:952-970, src/Interpreters/InterpreterSelectQuery.cpp:1115-1120, src/Planner/CollectTableExpressionData.cpp:314-323] The new target-side SELECT check still runs after Alias has already resolved the target for getStorageSnapshot and capability probes. That means an existing alias whose target is now hidden can still distinguish ACCESS_DENIED from UNKNOWN_TABLE, and SAMPLE / FINAL / PREWHERE still disclose target capabilities before the access denial happens. Suggested fix: make the remaining advisory Alias probes fail closed, or move the target-side access gate ahead of any target resolution in query analysis.
  • [src/Interpreters/InterpreterSelectQuery.cpp:788-792, src/Planner/PlannerJoinTree.cpp:526-535, src/Storages/StorageAlias.cpp:233-241] [dismissed by author -- https://github.com/Fix target access checks for the Alias engine #114596#discussion_r3774320998] Alias reads still build row-policy state from the alias StorageID and then forward query_info unchanged to the target, so policies defined only on the target table are still bypassed. Suggested fix: derive row-policy state from the target table as part of alias reads, or reject alias reads while the target has row policies.
Tests
  • ⚠️ The new stateless coverage does not exercise the remaining hidden-target oracle on plain SELECT / SAMPLE / PREWHERE / FINAL, nor a target protected only by a row policy. Please add one focused regression for each case.
Final Verdict

Status: ⚠️ Request changes

Minimum required actions:

  1. Fail close every pre-access target resolution / capability probe that Alias still performs during SELECT analysis.
  2. Ensure Alias reads apply the target table's row policies, or explicitly reject that configuration until it is implemented.
  3. Add focused regressions for both paths.

LLVM Coverage Report

Metric Baseline Current Δ
Lines 87.00% 87.00% +0.00%
Functions 91.90% 91.90% +0.00%
Branches 79.30% 79.30% +0.00%

Changed lines: Changed C/C++ lines covered: 223/237 (94.09%) · 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! labels Aug 13, 2026
Comment thread src/Storages/StorageAlias.cpp Resolved
Comment thread src/Storages/StorageAlias.cpp Resolved
Comment thread src/Storages/StorageAlias.cpp Resolved
@PedroTadim

Copy link
Copy Markdown
Member

@nauu did you also test the alias engine with row policies? The target table row policies should be applied when querying the alias table.

@clickhouse-gh

clickhouse-gh Bot commented Aug 13, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing a8691e574 with master 4faa0468e (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
Binary Master PR Δ
programs/clickhouse-stripped 706.02 MiB 703.00 MiB -3.03 MiB (-0.43%)

Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction.

Compile time of recompiled translation units

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

Job report

@nauu

nauu commented Aug 13, 2026

Copy link
Copy Markdown
Member Author

@nauu did you also test the alias engine with row policies? The target table row policies should be applied when querying the alias table.

@PedroTadim It currently uses the row policy defined on the Alias.
If row policies are both defined on the Alias and the target table, which one takes precedence?

@PedroTadim

Copy link
Copy Markdown
Member

@nauu did you also test the alias engine with row policies? The target table row policies should be applied when querying the alias table.

@PedroTadim It currently uses the row policy defined on the Alias. If row policies are both defined on the Alias and the target table, which one takes precedence?

For me, it should always take the row policies on the target. Creating row policies in the alias doesn't seem right to me.

@nauu

nauu commented Aug 13, 2026

Copy link
Copy Markdown
Member Author

@nauu did you also test the alias engine with row policies? The target table row policies should be applied when querying the alias table.

@PedroTadim It currently uses the row policy defined on the Alias. If row policies are both defined on the Alias and the target table, which one takes precedence?

For me, it should always take the row policies on the target. Creating row policies in the alias doesn't seem right to me.

it make sense, let's use a separate PR to resolve this.

Comment thread src/Storages/StorageAlias.cpp Outdated
return access->isGranted(access_check.access_type, target_database, target_table, access_check.column_names);
}

bool StorageAlias::isGrantedToExposeMetadata(ContextPtr query_context, AccessType access_type, const String & column_name) const

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.

The new target-side metadata checks still leave row-level security out of Alias reads. Both planners derive the row-policy filter from storage->getStorageID() (InterpreterSelectQuery.cpp:780-785, PlannerJoinTree.cpp:361-368), which for Alias is the alias name, and StorageAlias::read() then forwards that filter unchanged to the target (StorageAlias.cpp:221-247).

So a query through alias_t applies policies defined on alias_t itself (or none at all), but never policies defined on the target t. If the target is protected only by row policies, reading it through an alias still bypasses them. Sibling proxy paths already preserve child-table policies explicitly (StorageMerge::RowPolicyData, view inlining in QueryAnalyzer), so Alias needs analogous propagation or an explicit refusal.

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.

row policy will use a separate PR.

@nauu
nauu requested a review from hanfei1991 August 14, 2026 02:41
@hanfei1991 hanfei1991 self-assigned this Aug 17, 2026

@hanfei1991 hanfei1991 left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

After this change we have to check isGrantedToExposeMetadata everywhere. It's a kind of burden for us. Can we change inside Context::checkAccess and get StoragePtr by DatabaseCatalog::instance().tryGetTable(table_id, context); and check if the table is alias storage?

Comment thread src/Storages/IStorage.h Outdated
return metadata.get();
}

/// Some metadata accessors, such as `totalBytesUncompressed`, do not accept a `ContextPtr` and cannot check

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think we can remove these trivial comments but explain what isGrantedToExposeMetadata is

Comment thread src/Storages/StorageAlias.cpp Outdated
return DatabaseCatalog::instance().getTable(StorageID(target_database, target_table), getContext());
}

bool StorageAlias::isTargetAccessGranted(const TargetAccess & access_check) const

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This function is only used by isGrantedToExposeMetadata. Does it make sense to make it an independent function?

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.

Let me remove it

@nauu

nauu commented Aug 19, 2026

Copy link
Copy Markdown
Member Author

After this change we have to check isGrantedToExposeMetadata everywhere. It's a kind of burden for us. Can we change inside Context::checkAccess and get StoragePtr by DatabaseCatalog::instance().tryGetTable(table_id, context); and check if the table is alias storage?

the interfaces such as totalBytesUncompressed ,getColumnSizes do not have the ContextPtr and therefore cannot identify the current user. Without the hook in IStorage, we would need to add a context parameter to all such interfaces and update every implementation and call site, which would be a much larger change.

@hanfei1991

Copy link
Copy Markdown
Member

@nauu before this change, the guard before totalBytesUncompressed , getColumnSizes is context->checkAccess and access->isGranted. If we check alias storage context->checkAccess and replace access->isGranted, the problem will be resolved

@ramazanpolat

Copy link
Copy Markdown
Contributor

This sounds a new feature to be implemented later.

@PedroTadim Here it is: #116125

@hanfei1991
hanfei1991 added this pull request to the merge queue Aug 24, 2026
Merged via the queue into ClickHouse:master with commit 977ba7e Aug 24, 2026
178 checks passed
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Aug 24, 2026
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 24, 2026
clickhouse-gh Bot added a commit that referenced this pull request Aug 24, 2026
Backport #114596 to 26.8: Fix target access checks for the Alias 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 Aug 25, 2026
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Aug 25, 2026
Master gained an access check in `registerStorageAlias` (ClickHouse#114596) in the same
place this branch moved the self-reference and Alias-to-Alias rejections to.
Both are kept. The access check runs first so that a caller without access to
the target cannot learn from the rejection message whether the target exists
and which engine it uses.
pull Bot pushed a commit to AnotherGenZ/ClickHouse that referenced this pull request Aug 28, 2026
…Alias

PR ClickHouse#114596 added an Alias target-access check to
InterpreterShowCreateQuery::executeImpl(). It runs after create_query has
already been produced, and opens the storage object unconditionally just to
learn whether the object is a StorageAlias.

DatabaseCatalog::tryGetTable is only non-throwing for a missing table: with
exception == nullptr it delegates to the database's own tryGetTable with no
try/catch, so an exception raised in there propagates.
DatabaseDataLake::tryGetTableImpl raises one for a table the catalog reports as
unreadable, while getCreateTableQueryImpl never opens the table and answers
from catalog metadata with the placeholder engine Other. So SHOW CREATE TABLE
on such a table failed where it used to return the create query, and since the
object is not an Alias the check had nothing to say about it anyway. The
comment at line 132 already documents this trap for the dictionary path.

Gate the block on the engine name of the create query instead. That is a
narrowing, not a behaviour change: StorageAlias has exactly one construction
site, the factory lambda registered under the literal "Alias", getName()
returns that literal, and StorageFactory::get resolves engines by exact,
case-sensitive string lookup. So a table is a StorageAlias if and only if its
definition says ENGINE = Alias, and for any other object the skipped check
would have returned nullptr from the cast anyway.

Rejected alternatives: wrapping the lookup in catch(...) would make SHOW CREATE
swallow real errors and would silently disable the new access check for any
table whose open throws; changing DatabaseDataLake::tryGetTable to return
nullptr would break three other contracts that depend on the error surfacing.

The coverage gap is closed in the existing datalake_try_get_table_throw test,
which already asserted create_table_query from system.tables but never
SHOW CREATE TABLE, a different interpreter.
@fm4v fm4v removed the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Aug 30, 2026
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Aug 30, 2026
@PedroTadim

Copy link
Copy Markdown
Member

The closed cherry picks seem to be the pre-requisite to backport #118063 to the supported branches

@nauu

nauu commented Sep 10, 2026

Copy link
Copy Markdown
Member Author

The closed cherry picks seem to be the pre-requisite to backport #118063 to the supported branches

should we support these versions?

@PedroTadim

Copy link
Copy Markdown
Member

26.3, 26.6, 26.7 in public and 26.4 and 26.6 in private

acking-you pushed a commit to acking-you/ClickHouse that referenced this pull request Nov 8, 2026
StorageBuffer::totalRows added destination->totalRows(context) with no
access check. system.tables lists a Buffer on SHOW TABLES of the Buffer
alone and reads totalRows with the user's context, so a user granted
SELECT on the Buffer and nothing on its destination got the destination's
exact row count, while every read of the Buffer requires SELECT on the
destination. DROP TABLE IF EMPTY used the same number.

Count the destination only when SHOW TABLES is granted on the declared
destination, checked before the table is resolved so that a hidden and a
missing destination give the same answer. Otherwise only the buffer's
own rows are returned, which is what the function already returns when
the destination is missing (value_or(0), ClickHouse#40643). SHOW TABLES is the
privilege under which system.tables shows the destination's own
total_rows, and every grant on the destination implies it, so users with
any privilege on it see no change. StorageAlias::totalRows uses the same
gate (ClickHouse#114596).

NULL (as Alias returns) was rejected: a Buffer has rows of its own, and
Buffer -> Alias -> hidden table already yields the buffer's rows.

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 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.

Alias table engine leaks a target's schema and row count to a user with no grant on it (metadata access-control bypass)

9 participants