Repository navigation
Require SHOW COLUMNS on an Alias target in hasColumnInTable - #117621
PedroTadim merged 1 commit into
Conversation
`hasColumnInTable` checks `SHOW COLUMNS` on the database and table name it is given, then reads that storage's metadata. For an `ENGINE = Alias` row `StorageAlias::getInMemoryMetadataPtr` forwards to the target, so the columns the caller learns belong to a table the check never covered: a user holding `SHOW COLUMNS` on the alias and nothing on the target got `1` for a column that exists on the target and `0` for one that does not, and could enumerate the target's columns by guessing. `DESCRIBE` of the same alias is denied, so the function was weaker than the surface it documents itself against. Add the second-stage check the rest of the tree already uses, in the shape of `InterpreterDescribeQuery`, reusing the existing immediate-hop predicate `StorageAlias::isTargetTableGranted`. This becomes the fourth call site that throws on it, after `InterpreterDescribeQuery`, `InterpreterShowCreateQuery` and `TableFunctionLoop`. The invariant is an equality: this function discloses no more about an object's columns than `DESCRIBE` of the same object, which is what its `FunctionDocumentation` already promised and what ClickHouse#108464 set out to achieve. The first-stage check stays on the raw names before resolution, so a denial still does not depend on the table or database existing. Guarding `StorageAlias::getInMemoryMetadataPtr` itself was rejected: the read path legitimately consumes the target's metadata without `SHOW COLUMNS` on the target, so a user holding only `SELECT(col)` on both the alias and the target would have had `SELECT col FROM alias` refused. Resolving the target through `getTargetTable({context, SHOW_COLUMNS})` was also rejected, because `Context::checkAccess` builds its message from the target's database and table, which would trade a column oracle for a target-identity disclosure; `isTargetTableGranted` plus a local throw names only the alias. `alias` is `nullptr` for every other storage, so no other engine is affected, and `hasPhysical` and `hasAlias` both read the one metadata handle, so the single guard covers both. Co-Authored-By: Claude Opus 5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 3 findings), plus my own cold review
Severity: ❌ blocker / Session id: cron:clickhouse-review-self-slot-58:20260902-051900 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-self-slot-57:20260902-044800 |
|
Workflow [PR], commit [c6f2696] Summary: ✅
AI ReviewSummaryThis PR adds a second-stage PR Metadata
Findings❌ Blockers
Tests
Final Verdict
LLVM Coverage Report |
|
cc @pufit @Ergus, could you review this? |
|
|
||
| /// An `Alias` reports the columns of its target, so seeing them takes the privilege on the target. | ||
| if (const auto * alias = table->as<StorageAlias>(); | ||
| alias && !alias->isTargetTableGranted(getContext(), AccessType::SHOW_COLUMNS, {})) |
There was a problem hiding this comment.
StorageAlias::isTargetTableGranted only checks the immediate target, but getInMemoryMetadataPtr keeps forwarding until it reaches the final non-Alias table. That leaves a supported two-hop carrier unfixed here: tests/queries/0_stateless/04946_storage_alias_attach_stored_definition.sh explicitly creates outer_alias -> inner_alias -> base_table, detaches/attaches it, and verifies that the chain still reads through.
With this patch, a user who has SHOW COLUMNS on outer_alias and inner_alias but not on base_table still gets 1/0 for base_table columns via hasColumnInTable, because this check stops at inner_alias and the metadata read continues to base_table. That means the RBAC oracle is still open on the stored alias-to-alias path.
This needs to follow the same alias chain that the metadata read follows, or use a shared helper that proves every metadata source in that chain is granted before getInMemoryMetadataPtr is called.
There was a problem hiding this comment.
Premise confirmed. Answering it with a measurement rather than the earlier rationale.
I built the 04946 carrier (outer_a -> inner_a -> protected, absent-target order; engines Alias/Alias/MergeTree, chain reads through) and probed it on this PR's own binary, buildId 63005741d5f08f7434be1e0775674649cfd4cf3f:
user holds SHOW COLUMNS on |
DESCRIBE outer_a |
hasColumnInTable(outer_a, 'pay') |
hasColumnInTable(outer_a, 'nope') |
|---|---|---|---|
outer_a only |
ACCESS_DENIED |
ACCESS_DENIED |
ACCESS_DENIED |
outer_a + inner_a |
pid UInt64, pay String |
1 |
0 |
Both users are denied DESCRIBE protected and hasColumnInTable('m13', 'protected', 'pay'), so neither holds anything on the final target.
Row 2 is real, but it is not a gap between this function and the rest of the tree: DESCRIBE of the same object, same user, same session, returns the entire target schema in one query. What this PR claims is that parity, and it holds on this carrier both before and after.
isTargetTableGranted is the immediate-hop predicate at all 15 of its call sites in src/, across 13 files, including InterpreterDescribeQuery.cpp:256, InterpreterShowCreateQuery.cpp:172, InterpreterSelectQuery.cpp:454, the eight system.* filters and TableFunctionLoop.cpp:150. Line 116 is the 15th and is InterpreterDescribeQuery.cpp:256 verbatim. Making only this site traverse would leave hasColumnInTable the sole traversing site, and stricter than DESCRIBE of the same object, against its own documented contract at hasColumnInTable.cpp:137 ("the same grant needed by DESCRIBE and SHOW CREATE TABLE"); it would also not close the surface, because DESCRIBE discloses more of it per query. Following the chain belongs at the shared predicate, with cycle handling (a self-referential Alias is loadable and bounded only by TOO_DEEP_RECURSION) and a per-site decision on what each caller dereferences. #117572 already records it as a residual of this family, in those words.
The suggested test follows from that: an ACCESS_DENIED assertion on the two-hop carrier would pin behaviour this PR does not claim, and would fail.
On the category, I do not self-apply Critical Bug Fix. It maps to pr-critical-bugfix, which ci/jobs/scripts/workflow_hooks/pr_labels_and_category.py:103 puts in AUTO_BACKPORT, and :269 then adds pr-must-backport, so selecting it opens backports to every active release branch on my own authority. That is a maintainer's decision, not mine. The same suggestion came up on #108464, the predecessor of this change on this file; I kept Bug Fix and a maintainer set the category afterwards. One word from a reviewer and I will switch it.
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units7 translation units recompiled, 8 s compile time in total, 7 of them have a recent master baseline. |
|
This seems to be a duct tape solution; the real one is to always check for the target table whenever a privilege is checked for an Alias table |
|
Agreed on the rule, and I am not defending the per-site guard as the destination. That rule already has a single home: Three things it has to settle, which is why I sent the single site first:
Your call, and I will do either: expand this PR into the chain-following predicate now, or keep it as the one-hop increment and send the structural change once #117253 and #117490 land. |
15ab60d
Related: #108464
Related: #117572
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed
hasColumnInTabletelling a user whether a column exists on the target of anENGINE = Aliastable when that user holdsSHOW COLUMNSon the alias but not on its target. The function now requires that privilege on the target too, so it discloses no more thanDESCRIBEof the same alias.Description
hasColumnInTablechecksSHOW COLUMNSon the database and table name it is given, then reads thatstorage's metadata. For an
ENGINE = Aliasrow the metadata read returns the target's columns, soa caller holding
SHOW COLUMNSon the alias and nothing on the target got1for a column that existson the protected table and
0for one that does not. Repeating the call enumerates the protectedtable's columns by guessing, and the function was weaker than
DESCRIBEof the very same alias, whichis denied.
The function's own documentation already states that it "requires the
SHOW COLUMNSprivilege on thetarget table (the same grant needed by
DESCRIBEandSHOW CREATE TABLE)". That was not true for anAlias.This adds the second-stage check the rest of the tree already uses, in the same shape as
InterpreterDescribeQuery, reusing the existingStorageAlias::isTargetTableGranted. It is +9/-0 inone function.
aliasisnullptrfor every other storage, so nothing butAliasis affected, and thefirst-stage check stays on the raw names so denial still does not depend on the table existing. A
table-level
SELECTgrant on the target impliesSHOW COLUMNSand keeps working; reads through analias are untouched.
Validated with a new stateless test that fails on the unmodified binary and passes with the fix (50/50
under 8-way self-concurrency), plus a sweep of the
AliasandhasColumnInTabletests.Measured, one-hop
Alias: user holdsSHOW COLUMNSon the alias onlyDESCRIBE nl.alACCESS_DENIEDACCESS_DENIEDhasColumnInTable('nl', 'al', '<existing column of the target>')1ACCESS_DENIEDhasColumnInTable('nl', 'al', '<absent column>')0ACCESS_DENIEDAfter also granting
SHOW COLUMNSon the target, all three succeed as before.Workflow [PR]
Sync PR [sync-upstream/pr/117621]