Repository navigation
Fix for #101423 GRANT SELECT(column) does not give access to its subcolumns - #103402
Conversation
|
Workflow [PR], commit [1b49f63] Summary: ✅
AI ReviewSummaryReviewed #103402 at The newly selectable subcolumn read is consumed by Validation on the exact PR Fast test binary: Final VerdictStatus: ✅ Approve |
1d10dc0 to
5caacf1
Compare
…ng-access-to-subcolumns
…ng-access-to-subcolumns
|
I don't think this solution is correct. It isn't general and misses some other critical paths with the same problem (like StorageMerge) |
…ClickHouse into granting-access-to-subcolumns
5d4afe3 to
2f9639e
Compare
…bcolumn grant on the target With `GRANT SELECT ON a` (or `GRANT SELECT(p) ON a`) on an `Alias` and ``GRANT SELECT(`p.s`)`` on its target, `SELECT p.s FROM a` was allowed, but `SELECT count() FROM a` and `SELECT 1 FROM a` threw `ACCESS_DENIED`: the trivial-query fallback looked for candidate subcolumns only in the grants on the alias itself. Candidates are now collected from the grants on every table of the alias chain (the new `StorageAlias::getTargetChain`), and a candidate counts only if the alias allows reading it, checked the same way as a query that reads it (`ColumnsDescription::getColumnNamesForSelectAccessCheck`), and the chain grants it. Applied to both the analyzer (`checkAccessRights`) and the old interpreter (`checkAccessRightsForSelect`). The regression test covers the reverse arrangement and the cases where the alias does not grant the subcolumn. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…nversion A subcolumn that exists only in the `Merge` type of a column (e.g. `s.x` of a `String` child column `s` exposed as `JSON`) is read through the whole child column, but the access check of the child authorized `s.x` itself. So a revoke on `s` did not deny `s.x`, and a grant on `s` alone did not allow it. The read and the access check now share `getChildColumnToRead`, so the check authorizes the column that is actually read. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… hop The trivial-query fallback (`SELECT count()`, `SELECT 1`) checked each candidate name raw across the whole `Alias` chain, so a chain that grants the column on one hop and the exact subcolumn on another denied it, while `SELECT p.s` through the same chain is allowed. The new `StorageAlias::filterColumnsSelectableThroughChain` normalizes each name separately on each hop, as `StorageAlias::read` does, and both the analyzer and the old interpreter use one shared helper, `getColumnsSelectableByTrivialQuery`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The conditional operator mixing `std::move(*column_to_read)` with a const `String` produced a copy; use explicit branches instead. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=103402&sha=f18275827ef15ca9acbe64faac97370128e2423b&name_0=PR&name_1=Build%20(arm_tidy%2C%201%2F4 ClickHouse#103402 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…torage without subcolumn support `chooseSmallestColumnToReadFromStorage` could return an exactly granted subcolumn (e.g. `p.s`) for a storage that only reads whole columns, such as `StripeLog` or `Join`, which made `SELECT 1` and `SELECT count()` fail with `INCORRECT_INDEX` or `NOT_FOUND_COLUMN_IN_BLOCK` once that grant was added. Honor `IStorage::supportsSubcolumns` when choosing the read column, so such storages always read a physical column. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Since ClickHouse#103402 a subcolumn inherits the grants of its column, and a grant on the subcolumn's own name is enough to select it and to run `count()`. Two reads of the fill still used the rules from before: - The destination columns the fill reads were checked by their raw names, so a user with SELECT(t) on the destination could select `t.a` from the Buffer but got ACCESS_DENIED for a Buffer-only column with `DEFAULT t.a`. They are now mapped with getColumnNamesForSelectAccessCheck, like the selected columns. - The column read for the row count was chosen among whole columns only, so with a grant on `j.a` alone it fell back to a column the user may not read, which an `Alias` destination then denied. It is now chosen by the planner's own chooseSmallestColumnToReadFromStorage (moved out of the anonymous namespace of PlannerJoinTree.cpp), so it is the column `count()` reads, including granted subcolumns and dynamic paths. 03631 gains both cases; each fails without its change. Also read a default input from the destination only when the name resolves to the same column there. With `j JSON, y DEFAULT j.c::UInt64` over a destination that has a column named `j.c`, the fill read that column after the flush instead of the path of `j` (9 before the flush, 0 after). The input is now read through `j`; fixture W of 05337 covers it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Resolve the conflict in src/Planner/PlannerJoinTree.cpp: keep the 26.10 side and take only the lines of #131371. The `skip_subcolumns` argument of the master call refers to `filtered_by_allowed_columns`, which comes from #103402 (not in 26.10), so the call uses the default, as the replaced `getSmallestColumn` call on 26.10 did.
…arget-access Conflicts in `src/Analyzer/Resolve/IdentifierResolver.cpp` and `src/Storages/StorageAlias.h`. master made `IdentifierResolver::checkAccessToTableMetadata` a public static taking the storage, id and snapshot, counted exact subcolumn grants and virtual columns as making the table visible, and gated the view-source swap on `replaced_storage`. The Alias chain check now runs once the table is visible by any of those paths, in a file-local `checkAccessThroughAliasChain`, and skips exactly the view source the analysis swaps in (`checkAccessToTableMetadata` takes `replaced_storage`). It covers virtual columns, so the per-virtual `isTargetTableGranted` clause master added for an `Alias` is folded into it. Since ClickHouse#103402 a subcolumn inherits the grants of its column on each table unless that table has a grant or revoke on the subcolumn itself (`getColumnNamesForSelectAccessCheck`), and `StorageAlias::read` decides each hop that way. The chain check maps each name per hop the same way, so the enumerated subcolumns and the stand-in name for unnamed dynamic paths are no longer needed: such a subcolumn is visible exactly when its column is. Without the mapping, the chain case of `05508_grant_select_subcolumn_trivial_query` (a column grant on the middle hop, an exact subcolumn grant on the target) was refused. master no longer creates a temporary table with the `Alias` engine (74af670), so the check for a temporary `Alias` and its test case are dropped. Test cases that master itself now refuses at execution (a subcolumn of a revoked column, a read through an `Alias` of `system.one` without `SHOW TABLES` on it) are removed or reduced to what master reads. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Closes: #101423
Column-level grants are stored against top-level storage columns, but a query that reads a subcolumn (
t.a,m.keys,arr.size0,n.null,json.a.b, ...) reached the access check under the subcolumn name, soGRANT SELECT(t)did not allowSELECT t.a. The new helperColumnsDescription::getColumnNamesForSelectAccessCheckmaps each requested name to the storage column that identifier resolution actually reads (type-aware, including dynamic subcolumns; real columns with a dot in the name resolve to themselves; unknown names are left unchanged and fail closed). It is applied to every column-levelSELECTcheck: the analyzer and the old interpreter,joinGet,Alias,Buffer,Merge(per child schema),MaterializedView,mergeTreeIndex,mergeTreeTextIndex, and hypothetical indexes and projections.This also closes the opposite direction: with
GRANT SELECT ON tandREVOKE SELECT(m),SELECT m.keysused to be allowed. It is now denied.A subcolumn is treated as one more level below its column, like a column below its table: it inherits the grants of its column, and a
GRANTorREVOKEon the exact subcolumn name takes precedence. An explicit entry is detected with the newAccessRights::isGrantedInherited, which returns what a column name inherits from its enclosing level while ignoring a grant or revoke on that exact name: when the exact name differs from that, the subcolumn name is checked as is, otherwise its parent column is checked. The analyzer's table visibility check (checkAccessToTableMetadata, from #117979) also accepts a table when the user has an explicit grant on a subcolumn name, found by the newAccessRights::hasExplicitGrantOnColumnsWithPrefix, so a user whose only grant isGRANT SELECT(`json.a`)can query it.Compatibility
The table has
p Tuple(s String, o String)andj JSON. "Before" is measured on 26.8; since #117979, master additionally denied every row whose only grants are on subcolumn names, because no top-level column was visible. "After" is pinned by05257_grant_select_subcolumn_explicit_entries.GRANT SELECT(p)ponly;p.s,p.odeniedp,p.s,p.oallowedGRANT SELECT(`p.s`)p.sonlyp.sonlyGRANT SELECT(`j.a`)j.aonlyj.aonlyGRANT SELECT ON t,REVOKE SELECT(p)pdenied;p.s,p.oallowedp,p.s,p.odeniedGRANT SELECT ON t,REVOKE SELECT(m)for aMapcolumnmmdenied;m.keys,m.valuesallowedm,m.keys,m.valuesdeniedGRANT SELECT ON t,REVOKE SELECT(`p.s`)p.sdenied;p,p.oallowedp.sdenied;p,p.oallowedGRANT SELECT ON t,REVOKE SELECT(`j.a`)j.adenied; rest allowedj.adenied; rest allowedGRANT SELECT(`p.s`),REVOKE SELECT(p)p.sonlyp.sonlyGRANT SELECT(p),REVOKE SELECT(`p.s`)ponlyp,p.s,p.oallowedp.sinherits from the table, so it is a no-op andp.sfollowspGRANT SELECT(p)ponlyp,p.s,p.oallowedGRANT SELECT(`p.s`)p.sonlyp.sonlyKnown limits, both failing closed:
GRANT SELECT ON t,REVOKE SELECT(p),GRANT SELECT(`p.s`)deniesp.s.A revoke on a subcolumn name never hides the data on its own, because reading the parent column still returns it.
The branch also makes
EXPLAIN WHATIFdeny index estimates when the table has an effective row policy, consistent with what master already does formergeTreeIndexandmergeTreeTextIndex.mergeTreeAnalyzeIndexesis left as on master, which intentionally does not enforce row policies there.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
A column-level grant now covers the subcolumns of that column:
GRANT SELECT(t)allowsSELECT t.a,m.keys,arr.size0,n.nulland dynamicJSONpaths, and a revoked column also denies its subcolumns (previouslyGRANT SELECT ON twithREVOKE SELECT(m)still allowedSELECT m.keys). A grant or revoke on the exact subcolumn name, such asGRANT SELECT(`json.a`), keeps taking precedence over its column.EXPLAIN WHATIFis now denied on tables with a row policy.Documentation entry for user-facing changes
Workflow [PR]
Sync PR [sync-upstream/pr/103402]
Version info
26.11.1.1809-master(included in26.11and later)