Repository navigation
Require SHOW COLUMNS to read DDL columns in system.tables - #117448
alexey-milovidov merged 16 commits into
Conversation
A user holding only a column-scoped grant, such as GRANT SELECT(public_col) ON db.t, could read the full DDL of db.t out of system.tables, although DESCRIBE and SHOW CREATE TABLE correctly refuse them the same information. A column-level grant is promoted to table-level SHOW_TABLES (ContextAccess.cpp, the leaf_or_wildcard clause), so the row passes the row filter. Table-level SHOW_COLUMNS is "on every column" (AccessRights.cpp min_flags_with_children) and stays false, but TablesBlockSource::generate never consulted it, so every schema-revealing column was filled unconditionally. The interpreters do gate: InterpreterShowCreateQuery and InterpreterDescribeQuery both checkAccess on SHOW_COLUMNS. system.tables was the only holdout. Two invariants, so two mechanisms: - can_show_columns gates the columns that describe the table's own schema: create_table_query, engine_full, as_select, the five key expressions, skipping_indices_types and parameterized_view_parameters, in both the main loop and the temporary/external-table path. It requires table-level SHOW_COLUMNS on the row's table and, for a StorageAlias row, on its target, mirroring InterpreterShowCreateQuery exactly. It composes with the existing can_expose_metadata rather than replacing it. Denial renders the column's default instead of throwing, matching can_expose_metadata and the system.* convention that these tables hide information rather than fail the query. The global short-circuit follows StorageSystemColumns.cpp verbatim, so a user with instance-wide SHOW COLUMNS pays no per-row check. - is_dependency_visible filters, per element, the columns that name *other* tables: dependencies_*, the four loading_* arrays and target_*. Both halves of every pair are skipped together, because programs/server/schema.html zips them by index and a one-sided filter would pair the wrong database with the wrong table. Deliberately out of scope, since they carry no column-level information: comment, definer, metadata_path and storage_policy. The fast path fillTableNamesOnly emits only database and name, so it is unaffected. 03636_storage_alias_metadata_access_rights pinned the leak: a user granted only SELECT(value) on an Alias target was asserted to see the whole DDL through system.tables while SHOW CREATE TABLE on the same object threw ACCESS_DENIED. Those two assertions now read 0, the paired ACCESS_DENIED assertion is added so the reference proves the two surfaces agree, and the block titles are corrected to say "column-scoped target permission" to match the grant they exercise. INFORMATION_SCHEMA.VIEWS.view_definition reads as_select with SQL SECURITY INVOKER, so the gate propagates there; that is intended, since SHOW CREATE TABLE on the same view already refuses the same user.
… the Alias target
Review round 1 on the SHOW COLUMNS gate for the DDL columns of system.tables.
InterpreterShowCreateQuery authorizes a CREATE query with two different
privileges, not one: SHOW DICTIONARIES when the statement is SHOW CREATE
DICTIONARY, SHOW COLUMNS otherwise. The gate implemented only the second, so a
user holding row visibility plus SHOW DICTIONARIES read empty DDL columns out of
system.tables while SHOW CREATE DICTIONARY handed them the full text for the
same object. That is a loss of information the user is authorized to have, and
it made the changelog's parity claim inaccurate for dictionary rows.
can_show_create_query adds the dictionary disjunct at exactly one site, the
rendered-CREATE trio. The other gated columns stay on can_show_columns because
DESCRIBE of a dictionary still requires SHOW COLUMNS; for a dictionary row they
are empty anyway, so this keeps the change interpreter-shaped and minimal.
The object-kind test is a non-null configuration, verified in-tree as equivalent
to Location::SameDatabaseAndNameAsDictionary by the chassert in
StorageDictionary::renameInMemory. IStorage::isDictionary() and
DatabaseCatalog::isDictionaryExist() are deliberately not used: both are also
true for CREATE TABLE ... ENGINE = Dictionary (Location::Custom), whose CREATE
query carries a plain table's column list, so either would open a new leak
rather than close one. Substituting isDictionary() in a throwaway build makes
the new negative control in 05055 hand a SHOW DICTIONARIES holder the full
column list of a table that SHOW CREATE TABLE refuses them, which is why the
control is in the test rather than the reasoning being in a comment.
Two guards named in the changelog had no test that would notice their removal:
- The Alias target conjunct of can_show_columns was only ever observed in its
denied state. Every Alias assertion on a gated column expected a blank, and
the one test asserting a non-empty create_table_query for an Alias row runs
as the default user, where the global short-circuit fires first. Forcing the
conjunct to false left the whole suite green. 03636 now also probes the row
in the granted state, inside the block that grants SHOW COLUMNS on the
target, and all seven flags come back set.
- unique_key had a guard and a changelog mention but no oracle. Covered by a
new test rather than by extending 05055: every UNIQUE KEY test needs several
environment exclusion tags, and importing those onto 05055 would delete the
rest of that file from those CI lanes, i.e. weaken the tests that pin this
fix. The new test omits no-fasttest because it never inserts, matching
04657, which creates a UNIQUE KEY table without inserting and runs there.
Each of the three new oracles was proved live by reverting its guard in a
separate build and confirming the corresponding test fails.
…h emits it Review round 2 on the `SHOW COLUMNS` gate for the DDL columns of `system.tables`. Round 1 made the authorization of the rendered-CREATE trio depend on the kind of the object: a non-null `StorageDictionary` configuration plus `SHOW DICTIONARIES` authorizes the `CREATE` query the way `SHOW CREATE DICTIONARY` does. That kind is read off the storage object the tables iterator captured, while the value emitted is resolved again by name, because `IDatabase::getRenderedCreateTableQuery` goes through `getRenderedCreateTableQueryImpl`, which renders whatever `tryGetCreateTableQuery` returns for that name. So the privilege was checked against one object and the text was fetched for whatever holds the name at the moment the row renders. The window is not a single instruction: the tables iterator is a snapshot of the database's table map, taken once per database per `generate` call, and rows are then rendered one at a time with metadata I/O in between, so a late row can render long after its snapshot was taken. A name dropped as a `CREATE DICTIONARY` object and recreated as a regular table inside that window rendered the new table's full DDL to a holder of `SHOW DICTIONARIES`, which is exactly what `SHOW CREATE TABLE` refuses them. `RenderedCreateQuery` now carries `is_dictionary`, set in `renderCreateQuery` where the `ASTCreateQuery` is already in hand, and a rendering that only the dictionary disjunct authorized is discarded unless it is itself a `CREATE DICTIONARY`. That validates the artifact actually emitted, which is what `InterpreterShowCreateQuery` gets for free by fetching and validating in one lookup. Two alternatives rejected. Calling `tryGetCreateTableQuery` a second time to inspect the kind is another lookup by name, so it is a fresh instance of the same problem rather than a fix, and it doubles the cost of the most expensive column in `system.tables`. Holding a lock across the authorize-and-render pair, or changing the iterator's snapshot semantics, widens synchronization on a hot path to settle a question the rendered value already answers. The race direction has no deterministic oracle without a new failpoint inside `TablesBlockSource::generate`, and a failpoint in that path is a worse trade than the guard. The non-race direction is covered: forcing `is_dictionary` false in a throwaway build turns the granted dictionary arm of `05055_system_tables_show_columns_leak` from `1 0 0` to `0 0 0` on exactly one line, and leaves the other two tests green. So the guard sits on the executed path and it does not blank the dictionary rows round 1 restored. `docs/reference/system-tables/tables.mdx` said the schema columns require `SHOW COLUMNS` and that without it they read as empty, which round 1 made false for dictionary rows and left the diff contradicting its own changelog entry. The page now states the carve-out, and names `CREATE DICTIONARY` rather than "a dictionary" so that a table declared `CREATE TABLE ... ENGINE = Dictionary` is not described as if it were covered. It also mentions the `Alias` target conjunct, which it never did. The comment above `dictionary_probe` in `05055` attributed the empty `partition_key` and `skipping_indices_types` to the gate. They are empty because `StorageDictionary` sets only columns, comment and virtuals, so it has no key expressions and no secondary indices: those two flags are a non-regression check in both arms, and the width of the `SHOW DICTIONARIES` disjunct is established by the `create_table_query` transition and the `ENGINE = Dictionary` control. Co-Authored-By: Claude Opus 5 <[email protected]>
…endency loop Two test-only gaps, both of which let a guard be hard-coded with the whole suite still green. The temporary and external table branch of StorageSystemTables carries its own copy of the schema gate, applied to create_table_query, parameterized_view_parameters and skipping_indices_types. No test reached it: the persisted tests build no temporary Alias, and the temporary MergeTree test runs as an unrestricted user, where the global short-circuit fires before any conjunct is evaluated. The conjunct is not cosmetic. StorageAlias forwards getInMemoryMetadataPtr to the target, so the index types and view parameters on such a row belong to the target and are exactly the information this gate withholds elsewhere. The new test drives it over one HTTP session. A same-connection test cannot reach the interesting state at all: creating an Alias requires table-level SHOW COLUMNS on the target, so the withheld state exists only after that privilege is revoked, and the revoke has to come from an administrator on another connection while the temporary table stays alive. An HTTP session gives that deterministically and with no timing window: grant, create, read, revoke elsewhere, read again. A second user cannot substitute for it, because the create-time check would refuse the alias to a user who lacks the grant. The probe also selects an ungated column and asserts it in both arms. A temporary row inserts a default database, so without that a row which had simply disappeared would read as a row whose columns were withheld. For the dependency arrays, the per-element filter runs in two separate loops, over getLoadingDependencies and over getLoadingDependents. Three of the four name families asserted both a hidden and a visible element, but loading_dependencies_* asserted only the hidden one, and the alignment block compares lengths only. Dropping every loading dependency for any restricted user therefore kept the suite green. One query closes it, on a dependency the existing administrator assertion already proves exists, so no fixture changed. Each guard was checked by mutation, against the final text of the tests rather than an earlier draft. Hard-coding the temporary conjunct true moves the withheld arm and nothing else; hard-coding it false moves the granted arm and nothing else; skipping the first dependency loop for restricted users moves the new visible-dependency line and leaves the administrator line alone. The same dependency mutation leaves the suite green when the new assertion is removed, which is the reason for adding it. One alternative was refuted rather than chosen. Asserting withholding by granting only column-scoped access to the target is not constructible: the create-time check demands the table-level privilege, so the alias cannot be created in that state in the first place. Co-Authored-By: Claude Opus 5 <[email protected]>
can_show_columns_temp gates three columns on a temporary or external table row, and 05057 reached only two of them: create_table_query and skipping_indices_types. Deleting the conjunct from the parameterized_view_parameters site alone left the whole suite green. StorageAlias forwards getInMemoryMetadataPtr to its target and the column is built from the target's inner SELECT, so a temporary Alias over a parameterized view reports the target view's parameter names and types. That is the information this gate withholds elsewhere, and DESCRIBE already refuses the same object for the same user. The test now creates a second temporary alias over a parameterized view in the same session and probes its parameter list next to the ungated engine column, so a withheld column stays distinguishable from a row that vanished. The parameter is deliberately not named after a column of the base table. No source change. Removing the conjunct from that one site reddens the withheld arm and nothing else; forcing the whole gate closed reddens the granted arm, now including the new flag.
Two test-only fixes. No source change. 05057 created two temporary Alias tables as a restricted user without granting TABLE ENGINE on Alias. InterpreterCreateQuery::getRequiredAccess has no early return for temporary tables: after the isTemporary branch appends CREATE ARBITRARY TEMPORARY TABLE, control falls through to the TABLE ENGINE entry, and getTablePropertiesAndNormalizeCreateQuery re-checks the same privilege after setEngine. It is enforced when table_engines_require_grant is set, which tests/config/config.d/enable_access_control_improvements.xml does and tests/config/install.sh links into every functional-test server. Both CREATE TEMPORARY TABLE statements were therefore a certain ACCESS_DENIED under CI while passing against a plain server. 03636 already grants the same privilege for the same engine and user shape, and 02561 shows it applies to the temporary path. 05055 asserted only target_database on the materialized-view target pair. StorageSystemTables fills target_database and target_table from two separate inserts, so filtering one and not the other leaves the reference green, and the unfiltered one would be the table name. The probe now asserts both halves, in the admin arm as well, so the fixture is shown to populate them before the restricted arm reads them. Both are validated against a server carrying the stateless-test config overlay instead of a plain one, which is what let the missing grant through earlier.
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 18 findings over 5 rounds,
| 13 | | 17 | Session id: cron:clickhouse-review-slot-11:20260901-032500 |
|
Workflow [PR], commit [c920b53] Summary: ✅
AI ReviewSummaryThis PR tightens Findings
Final Verdict
|
Pre-PR validation gate
Also verified, on a server carrying the stateless-test configuration overlay that CI installs rather than a plain one: |
|
cc @alexey-milovidov @vitlibar, could you review this? It re-introduces the gate from #105367: the columns of |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units9 translation units recompiled, 22 s compile time in total, 9 of them have a recent master baseline. |
CI finish ledger - fa4f036Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
Note for anyone re-checking this against Session id: cron:our-pr-ci-monitor:20260901-093000 |
…les-show-columns-gate Conflicts in the 03636 pair only, both from the split that landed with ClickHouse#117490: the "database-level access shortcuts" section moved out to 03636_storage_alias_metadata_database_grants and a "CREATE TABLE ... AS an Alias" section took its place. Kept master's new section and this branch's "table and persisted metadata with target permission" block, which asserts the seven flags come back once the target grants SHOW COLUMNS.
The dictionary probe asserted only create_table_query, so nothing pinned whether the exception carried by can_show_create_query also emits the other two rendered columns. It does not: engine_full is rendered from ASTCreateQuery::storage and as_select from its select node, and ParserCreateDictionaryQuery sets neither, so a CREATE DICTIONARY row reads both as empty for every reader, including one holding every privilege. Add engine_full to both selects and run the probe as admin first. That arm is the ceiling: local_dict reads engine_full 0 there, so no grant can widen it, while dict_engine_tbl reads 1, which is what makes the zeros in the two restricted arms withholding rather than a structurally empty column. The dict_engine_tbl control previously asserted only create_table_query and could have agreed for the wrong reason.
CI finish ledger - ddff9e9Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task whose
This PR touches Session id: cron:our-pr-ci-monitor:20260916-200109 |
| /// The dictionary disjunct is decided on the object the iterator captured, while | ||
| /// the rendering resolves the name again. Emit it only when that one rendering is | ||
| /// itself a dictionary, as `SHOW CREATE DICTIONARY` requires. | ||
| if (!can_show_columns && !rendered->is_dictionary) |
There was a problem hiding this comment.
The dictionary TOCTOU is closed here, but the same authorize-on-snapshot / render-by-name split still exists for Alias. can_show_columns was computed from tables_it.table() earlier, so if this row is snapshotted as a regular table and then recreated as ENGINE = Alias(hidden) before getRenderedCreateTableQuery runs, the rendered DDL now comes from the alias while the alias-target SHOW COLUMNS check never runs. SHOW CREATE TABLE on the current object would deny the same user, but system.tables.engine_full still leaks the hidden target name, and create_table_query can leak the persisted alias schema.
Please revalidate rendered Alias definitions against the current storage before emitting them, mirroring the dictionary revalidation in this block, and add a focused race/failpoint regression test for the swap.
CI finish ledger - 88cc3d3Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task whose
176 check runs finished as 152 success, 19 skipped, 5 failures, and the head-scoped CIDB read over Session id: cron:our-pr-ci-monitor:20260919-053557 |
…les-show-columns-gate Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Since cb5903b the whole body of docs/reference/system-tables/tables.mdx is generated from the system.tables comment in src/Storages/System/attachSystemTables.cpp, so the hand-written "Required privileges" section landed inside the generated region and failed the Docs check. Moving it into that comment would also require regenerating the page in this PR, which the docs guard accepts only with the pr-autogenerated-docs label. The changelog entry documents the new requirement. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The system.tables row filter runs before the dictionary exception is consulted, and SHOW DICTIONARIES does not imply SHOW TABLES, so a user holding only SHOW DICTIONARIES gets no row for the dictionary at all. The comment claimed that privilege alone makes the CREATE query readable. This PR does not change row visibility, so narrow the comment, not the filter. Co-Authored-By: Claude Opus 5.5 <[email protected]>
dep_user held SHOW TABLES on the whole database and every withheld dependency lived in another database, so replacing the per-table check in is_dependency_visible with a database-level one kept 05055 green. Grant SHOW TABLES on secret and dep_view only, and assert that dep_view stays in secret's dependencies_table while mv_local, which depends on secret from the same database, is dropped. The database-level variant now fails on exactly that line. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Dear @pufit, you haven't been active on this PR for 30 days. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself. |
…les-show-columns-gate Co-Authored-By: Claude Opus 5.5 <[email protected]>
…solete Since ClickHouse#115141, `SHOW CREATE TABLE` (and `SHOW CREATE TEMPORARY TABLE`) of an `Alias` no longer throws `ACCESS_DENIED` without `SHOW COLUMNS` on the target; it strips the inlined columns instead. `03636_storage_alias_metadata_access_rights` and `05057_system_tables_temporary_alias_show_columns` asserted that refusal next to the withheld `system.tables` columns, so after the master merge both failed on exactly that line. Remove the two assertions and their comments, as ClickHouse#115141 did for the same cases in master's copies of the 03636 tests. The `system.tables` gate itself is unchanged. `create_table_query` is read from the stored definition and is not stripped: an `Alias` stored by an older server still returns the target's columns there (measured: `ATTACH TABLE ... (id UInt64, secret String) ENGINE = Alias(...)` shows both columns in `create_table_query`, while `SHOW CREATE TABLE` prints none). So the declared-target `SHOW COLUMNS` check still protects those definitions; the two comments that justified it by parity with `SHOW CREATE TABLE` now state that reason instead. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Out of scope. The fix is already good enough. |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Reading the columns of
system.tablesthat describe a table's schema requires theSHOW COLUMNSprivilege on that table, the same privilegeDESCRIBEandSHOW CREATE TABLErequire:create_table_query,engine_full,as_select,partition_key,sorting_key,primary_key,sampling_key,unique_key,skipping_indices_typesandparameterized_view_parameters. Previously any column-level grant, such asGRANT SELECT(col) ON db.t, sufficed to read the full DDL ofdb.t. For a table created byCREATE DICTIONARYtheCREATEquery followsSHOW CREATE DICTIONARYand stays readable withSHOW DICTIONARIES; the row itself is still listed only withSHOW TABLES. The columns naming other tables (dependencies_*,loading_dependencies_*,loading_dependent_*,target_database,target_table) now list only tables the user may see withSHOW TABLES.INFORMATION_SCHEMA.VIEWS.view_definitionfollows the same rule. To restore the previous behaviour, grantSHOW COLUMNS ON db.t, the same on anAliastarget, andSHOW TABLESon the tables the dependency columns name.Description
Root cause: a column-level grant is promoted to table-level
SHOW_TABLES, so the row passes the row filter; table-levelSHOW_COLUMNSmeans "on every column" and stays false, butTablesBlockSource::generatenever consulted it.Two invariants, so two mechanisms.
can_show_columnsgates the columns describing the row's own schema, requiring table-levelSHOW_COLUMNSasInterpreterShowCreateQuerydoes, including itsSHOW DICTIONARIESbranch, and, for aStorageAliasrow, the same on its target; it composes with the existingcan_expose_metadata.is_dependency_visiblefilters per element the columns naming other tables, dropping both halves of each pair together so they stay index-aligned. Denial renders the column default, not an error.Out of scope, no column-level information:
comment,definer,metadata_path,storage_policy.03636_storage_alias_metadata_access_rightspinned this leak: a user granted onlySELECT(value)on anAliastarget saw the whole DDL. Those assertions now read0. Since #115141SHOW CREATE TABLEstrips anAlias's inlined columns, butcreate_table_queryreturns the stored definition as is, so the target check stays.Disclosed, not fixed:
system.data_skipping_indices,system.projectionsandsystem.constraintsareSHOW_TABLES-gated and each exposes a definition naming columns.Related: #105367
Re-introduces @ pufit's PR, following its approach, widened to the surfaces raised in review.
Measured effect on consumers that read the gated columns
Each measured on this branch against an unpatched build of the same base, as a user holding only
SHOW TABLES.INFORMATION_SCHEMA.VIEWS.view_definition(readsas_select,SQL SECURITY INVOKER)SELECTtextSHOW INDEX/SHOW KEYS(rewritten ontoprimary_key)PRIMARYrow with an emptycolumn_nameArrowFlightCommandGetPrimaryKeys(readsprimary_key)/schemaUI,play.htmltable propertiesThe
SHOW INDEXresult is not a new output shape: an engine without a primary key, such asMemory, already yields exactly that row today for any user, which is whyInterpreterShowIndexesQueryis left alone here rather than given its own check.INFORMATION_SCHEMA.TABLESis unaffected: itsprimary_keyreference isprimary_key_sizefromsystem.parts, and every column it takes fromsystem.tablesis ungated.Workflow [PR]
Sync PR [sync-upstream/pr/117448]
Version info
26.11.1.112-master(included in26.11and later)