Repository navigation
Require SHOW COLUMNS on an Alias target in CREATE TABLE ... AS - #117702
Conversation
`InterpreterCreateQuery::getTablePropertiesAndNormalizeCreateQuery` checks
`SHOW COLUMNS` on the database and table name the user typed, then reads that
storage's metadata and copies its columns into the new table. For an
`ENGINE = Alias` row those are two different tables:
`StorageAlias::getInMemoryMetadataPtr` resolves the target with
`tryGetTargetTable` and forwards the target's metadata with no privilege check
of any kind, so only the alias row was ever authorized.
A user holding `SHOW COLUMNS` on the alias and no privilege at all on its
target could therefore run
CREATE TABLE own.copy AS nl.al ENGINE = Memory;
and read the protected table's schema back with `DESCRIBE own.copy`. With an
explicit destination engine the copy does not inherit `ENGINE = Alias`, so the
disclosure is persistent. Naming the target directly is denied, and so is
`DESCRIBE` of the alias, which is what made this spelling the weakest of the
three. Rows were never disclosed; only the structure crossed.
The metadata forward itself is deliberately left unchecked, because callers
legitimately reach it with a column-scoped entitlement and the `system` tables
need it to degrade gracefully rather than throw. That is why the invariant
lives at each consuming seam with its own `AccessType` and column scope. This
adds the missing seam check, in the same shape and with the same wording as
`InterpreterDescribeQuery`, reusing `StorageAlias::isTargetTableGranted`.
The scope is table level rather than a column name because the statement
publishes every column: a grant covering only some columns, or even an
exhaustive set of column grants, must not admit it. `DESCRIBE` of the target
is denied in exactly those states too, so the new check is neither stricter
nor looser than the gate it mirrors. It also runs before `lockForShare`, so a
denied statement no longer takes a share lock on the target.
One error code changes: for a user without the target privilege,
`CREATE TABLE d AS <alias>` with no explicit engine now reports
`ACCESS_DENIED` instead of `BAD_ARGUMENTS`, because it is refused earlier. An
authorized user still gets `BAD_ARGUMENTS` from the `Alias` creator. No
in-tree test asserts the old code for that spelling under a restricted user.
The new test covers three states of the same statement, differing only in the
grant on the target: none, column scoped, and table level. Arms one and two
fail on the unmodified binary. Changing the table-level scope to a column name
reddens the column-scoped arm alone, so that argument is covered rather than
assumed.
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), adjudicated against my
My own cold review found one further seam of the same class, Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-9:20260902-131300 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-7:20260902-114100 |
|
Workflow [PR], commit [ccc09f0] Summary: ✅
AI ReviewSummaryThis PR closes the eager, one-hop Findings❌ Blockers
Tests
Final VerdictStatus: Minimum required actions:
LLVM Coverage ReportMeasured on commit ccc09f0.
Changed lines: Changed C/C++ lines covered: 8/8 (100.00%) · Uncovered code |
|
cc @pufit @davenger, could you review this? |
|
|
||
| /// An `Alias` reports its target's metadata, so copying that metadata requires the privilege on the | ||
| /// target that describing the target requires. | ||
| if (const auto * alias = as_storage->as<StorageAlias>(); |
There was a problem hiding this comment.
This only catches a live StorageAlias. In a database with lazy_load_tables = 1, DatabaseOrdinary::shouldLazyLoad still wraps ENGINE = Alias tables in StorageTableProxy, so as<StorageAlias>() is false here while the proxy still serves the columns cached from the stored CREATE query. Because Alias persists its target columns into that stored definition, a user with SHOW COLUMNS on the alias but nothing on its target can still run CREATE TABLE dst AS alias ENGINE = Memory and copy the protected schema under that setting.
Please either include the #117490 lazy-load exclusion in this PR or make this check identify Alias through the stored definition / proxy before trusting getInMemoryMetadataPtr.
There was a problem hiding this comment.
Confirmed by measurement, and it is not specific to this statement.
On this PR's head, with CREATE DATABASE ... ENGINE = Atomic SETTINGS lazy_load_tables = 1 and the alias loaded from metadata after a restart (system.tables.engine reads TableProxy for the untouched alias, so the proxy is armed), for a user holding SHOW COLUMNS on the alias only and nothing on its target:
- eager alias, same grants (control):
DESCRIBE <alias>andCREATE TABLE dst AS <alias> ENGINE = Memoryare bothACCESS_DENIED. - lazily loaded alias:
DESCRIBE <alias>returns the target's two columns;CREATE TABLE dst AS <alias> ENGINE = Memorysucceeds andDESCRIBE dstreturns them;SHOW CREATE TABLE <alias>returns the stored definition including both columns;SELECT name, type FROM system.columns WHERE database = ...returns both.SELECT count() FROM <alias>staysACCESS_DENIED, so rows are not disclosed.
So the proxy defeats the pre-existing DESCRIBE check this one mirrors (InterpreterDescribeQuery.cpp:255), plus InterpreterShowCreateQuery.cpp:171 and StorageSystemColumns.cpp:151. as<StorageAlias> is an exact typeid_cast and it is how all 14 alias-target privilege checks in src/ identify an alias, so unwrapping the proxy at this one site would close 1 of 14 and would not reduce the disclosure: the same user in the same database keeps reading the same schema out of three other statements.
#117490 fixes it where the proxy is created: DatabaseOrdinary::shouldLazyLoad returns false for ENGINE = Alias, so no proxy ever wraps one and all 14 sites see the real storage. Copying that hunk here would put the same change to shouldLazyLoad in two of my open PRs. Identifying the alias from the stored definition at this site instead is possible, but it reimplements per site what #117490 removes at the source and leaves the other statements disclosing. This gap is listed in this PR's description with the link, and if #117490 is not accepted I will carry a proxy-transparent fix for the whole family rather than for this site alone.
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, 22 s compile time in total, 7 of them have a recent master baseline. |
CI finish ledger - 7a8fe66Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
Fix presence for Session id: cron:our-pr-ci-monitor:20260902-200000 |
| /// An `Alias` reports its target's metadata, so copying that metadata requires the privilege on the | ||
| /// target that describing the target requires. | ||
| if (const auto * alias = as_storage->as<StorageAlias>(); | ||
| alias && !alias->isTargetTableGranted(getContext(), AccessType::SHOW_COLUMNS, {})) |
There was a problem hiding this comment.
isTargetTableGranted only authorizes one hop, but StorageAlias::getInMemoryMetadataPtr keeps resolving through nested aliases. A stored chain is a supported state today (04946_storage_alias_attach_stored_definition.sh): outer_alias -> inner_alias -> hidden loads successfully after ATTACH. For a user granted SHOW COLUMNS on outer_alias and inner_alias but nothing on hidden, this check passes and properties.columns = as_storage_metadata->getColumns() still copies hidden's schema into the new table.
The seam here is "authorize the table whose metadata we are about to publish", so the guard needs to resolve through alias chains (cycle-safe) or otherwise authorize the final non-Alias target before copying columns.
There was a problem hiding this comment.
Confirmed, and measured to the point where the measurement decides where the fix belongs.
Head 8882fecd, debug build 0fa1c881, server config carrying enable_access_control_improvements.xml. Chain ch.al_outer -> ch.al_inner -> tgt.hidden, built the way 04946_storage_alias_attach_stored_definition.sh builds it (the outer alias created while the inner name is still absent, the only order the constructor's Alias -> Alias rejection cannot see). The user holds SHOW TABLES, SHOW COLUMNS on the two alias databases and nothing at all on tgt:
| statement, as that user | result |
|---|---|
DESCRIBE nl.al (one hop) |
ACCESS_DENIED |
CREATE TABLE own.c1 AS nl.al ENGINE = Memory (one hop, this PR) |
ACCESS_DENIED |
DESCRIBE ch.al_inner (one hop) |
ACCESS_DENIED |
CREATE TABLE own.c2 AS ch.al_outer ENGINE = Memory (two hops) |
succeeds, and DESCRIBE own.c2 returns both columns |
DESCRIBE ch.al_outer (two hops) |
returns both columns |
SELECT name, type FROM system.columns WHERE database = 'ch' AND table = 'al_outer' |
returns both columns |
SHOW CREATE TABLE ch.al_outer |
the alias definition only, no columns |
SELECT count() FROM ch.al_outer |
ACCESS_DENIED |
The first three rows are the armed-binary controls, and a user who does hold SHOW COLUMNS on tgt.hidden is denied nothing in any arm, so no cell is blind. Rows stay undisclosed at both depths.
Rows 5 and 6 are why I am not walking the chain in this hunk. They are InterpreterDescribeQuery.cpp:255 and StorageSystemColumns.cpp:215, which this diff does not touch, and they hand that user the same two columns with a shorter statement. Resolving the chain here would take nothing away from that user; it would only make CREATE TABLE ... AS stricter than a DESCRIBE of the same object, which is the asymmetry this family of changes exists to remove. isTargetTableGranted authorizes the name written in the alias's own definition, and that is the contract all 19 of its call sites are written against.
So I would rather close it once for the whole family than here, and that needs a design call I would rather not guess:
- Resolve to the final non-
Aliastarget insideisTargetTableGranted, cycle-safe, so every site moves together. Constraints I measured: 8 of the 19 call sites aresystem.*row filters that skip a row rather than throw, so the walk has to stay non-throwing, and cycles are still constructible until Reject aRENAME DATABASEthat would make anAliastable cyclic #117253 lands. - Keep the check one hop and stop the chained state from existing, in the same spirit as Reject a
RENAME DATABASEthat would make anAliastable cyclic #117253. The constructor already rejectsAlias->Aliaswhen the target exists; the remaining hole is the outer-created-first order, and rejecting it during metadata load would make stored definitions that load today fail to load.
I will take 1 unless you prefer 2. The gap is listed as a residual in the description.
There was a problem hiding this comment.
Opened #118967 for this: shape 1, the chain walk with a visited set, since the chained state has to stay loadable. It keeps the one-hop check for the two surfaces that render only the alias's own definition.
The three arms covering `CREATE TABLE dst AS <alias>` were in a dedicated
05104_create_table_as_alias_target_access.{sh,reference}.
03636_storage_alias_metadata_access_rights already builds the target table, an
`Alias` over it and a privilege ladder, so the arms now sit at the end of that
test and reuse its fixture, and the dedicated file is removed.
What they assert is unchanged: no privilege on the target and a column-scoped
`SELECT` on the target are both denied, a table-level `SHOW COLUMNS` on the
target copies the schema.
Verified against a server carrying config.d/enable_access_control_improvements.xml:
the test passes on this build, and with the guard deleted from
getTablePropertiesAndNormalizeCreateQuery both denial arms lose their
ACCESS_DENIED line while every other line of the test is unchanged.
|
Progress: the change is complete and was green. Test move: done in 63e2502 (63e2502). The three arms now sit at the end of One measurement from re-checking the diff, which this PR does not fix: a -- as a user holding nothing at all on `tgt`, plus TABLE ENGINE grants and
-- allow_experimental_time_series_table = 1
CREATE TABLE own.copy AS tgt.hidden_ts ENGINE = TimeSeries; -- succeeds
DESCRIBE own.copy; -- returns the source's 7 columns
|
|
Correction to the This PR's own guard is unaffected by that: on the same master binary |
CI finish ledger - 63e2502Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
My own merged #119778 ("Fix flaky 04365_cancel_insert_when_client_dies_distributed under host
Session id: cron:our-pr-ci-monitor:20260914-073158 |
|
LGTM |
|
@groeneai make the PR green |
No content change. The only failure on 63e2502 was 04365_cancel_insert_when_client_dies_distributed in Stateless tests (arm_binary, parallel), where the runner's own re-run of the failing test passed 2/2 and reported the failure as not reproducible. That test does not touch access checks, so it cannot be reached by this diff.
|
CI is running again on The single red on
|
|
Fixing PR for the It reverts my #119778, which regressed that guard on this lane: 0 failures in 10251 runs of the previous test-file revision against 2 in 280 after it merged. |
Related: #117572
Related: #116793
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed
CREATE TABLE dst AS srccopying the schema of anENGINE = Aliastable's target for a user who holdsSHOW COLUMNSon the alias but no privilege at all on its target. The statement now requires table-levelSHOW COLUMNSon the target, the same grant thatDESCRIBEof that target already requires.Description
CREATE TABLE dst AS srcchecksSHOW COLUMNSon the name it is given, then copies that storage'smetadata columns into the new table. For an
ENGINE = Aliasrow the metadata read returns thetarget's columns, so a user holding
SHOW COLUMNSon the alias and nothing on the target couldcopy the protected table's schema into a table of their own and read it back with
DESCRIBE. With anexplicit destination engine that copy is persistent. Both naming the target directly and
DESCRIBEof the alias are denied, so this spelling was the weakest of the three. Rows were never disclosed.
This adds the second-stage check the rest of the tree already uses, in the same shape as
InterpreterDescribeQuery, reusingStorageAlias::isTargetTableGranted.aliasisnullptrforevery other storage, so nothing but
Aliasis affected, and the check is table-level because thestatement publishes every column. A table-level
SELECTgrant on the target impliesSHOW COLUMNSand keeps working.Validated with a new stateless test that fails on the unmodified binary and passes with the fix
(50/50 under 8-way self-concurrency), a mutant check proving the table-level scope load-bearing, and
25 existing
AliasandCREATE ... AStests unchanged.Answering the sibling-engine question from #117572: this seam is now closed at
merge,Distributed,Remote,remote,cluster,BufferandDatabaseRemoteby #117572, athasColumnInTableby #117621, atloopby #116873 and #116793, and atCREATE TABLE ... AShere.The
loopstructure half listed as a residual on #117572 is already covered by #116793, so it isnot carried here. Gaps I am not carrying here: an
Aliaswhose target is itself anAlias, alazy_load_tablesproxy hiding the engine fromas<StorageAlias>(#117490), andMySQLHandler::comFieldList, which resolves the metadata after checking only the name it was given.Measured: user holds
SHOW COLUMNSon the alias only, nothing on its targetDESCRIBE nl.alACCESS_DENIEDACCESS_DENIEDCREATE TABLE own.copy AS nl.al ENGINE = MemoryACCESS_DENIEDDESCRIBE own.copyafter itCREATE TABLE own.copy2 AS tgt.hidden ENGINE = Memory(target named directly)ACCESS_DENIEDACCESS_DENIEDSHOW COLUMNSon the targetSELECT(one column)on the targetACCESS_DENIEDWorkflow [PR]
Sync PR [sync-upstream/pr/117702]
Version info
26.9.1.1474(included in26.9and later)