Repository navigation
Fix target access checks for the Alias engine - #114596
Conversation
|
Workflow [PR], commit [a8691e5] Summary: ✅
AI ReviewSummaryThis PR closes several obvious Findings❌ Blockers
Tests
Final VerdictStatus: Minimum required actions:
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 223/237 (94.09%) · Uncovered code |
|
@nauu did you also test the alias engine with row policies? The target table row policies should be applied when querying the alias table. |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
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 units20 translation units recompiled, 134 s compile time in total, 20 of them have a recent master baseline. |
@PedroTadim It currently uses the row policy defined on the Alias. |
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. |
| 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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
row policy will use a separate PR.
There was a problem hiding this comment.
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?
| return metadata.get(); | ||
| } | ||
|
|
||
| /// Some metadata accessors, such as `totalBytesUncompressed`, do not accept a `ContextPtr` and cannot check |
There was a problem hiding this comment.
I think we can remove these trivial comments but explain what isGrantedToExposeMetadata is
| return DatabaseCatalog::instance().getTable(StorageID(target_database, target_table), getContext()); | ||
| } | ||
|
|
||
| bool StorageAlias::isTargetAccessGranted(const TargetAccess & access_check) const |
There was a problem hiding this comment.
This function is only used by isGrantedToExposeMetadata. Does it make sense to make it an independent function?
the interfaces such as |
|
@nauu before this change, the guard before |
@PedroTadim Here it is: #116125 |
Backport #114596 to 26.8: Fix target access checks for the Alias engine
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.
…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.
|
The closed cherry picks seem to be the pre-requisite to backport #118063 to the supported branches |
should we support these versions? |
|
26.3, 26.6, 26.7 in public and 26.4 and 26.6 in private |
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]>
Aliastable now requiresSHOW COLUMNSon its target when a new definition is submitted. This prevents users from usingAliasto reveal a target table's schema.The trivial
countoptimization is disabled when the user has noSELECTprivilege on the target, allowing the normal read path to enforce access checks.rowsandbytesstatistics are also hidden unless the user hasSHOW TABLESon the target.Closes: #114511
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed an RBAC bypass in the
Aliastable 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
26.9.1.43(included in26.9and later)26.8.1.1994