Repository navigation
Require READ and WRITE ON FILE to create a table as filesystem(...) - #133420
alexey-milovidov merged 2 commits into
Conversation
Since ClickHouse#129605 a table created as a table function needs `TABLE ENGINE` on the function's engine when that engine has a source, the same grant as `ENGINE = <engine>`. `filesystem` has no registered engine: it declares its source only through `ITableFunction::getSourceAccessObject()` (FILE), so the `StorageFactory` lookup missed and nothing was required. With an explicit column list the structure is not inferred, so the READ check of the inference never ran, and the table function was executed only for writing (`WRITE ON FILE`). `ON CLUSTER` and `Replicated` databases build the table with full access, so there no FILE grant was needed at all. `StorageFilesystem` reads with the global context, so a later `SELECT` checks only the table's grant: a user with `CREATE TABLE` and `WRITE ON FILE` (or nothing, via `ON CLUSTER`) could read every file under `user_files`. `getSourceEngineOfTableFunction` becomes `getRequiredAccessOfTableFunction` and returns the required element: `TABLE ENGINE` on a registered source engine (unchanged), nothing for a registered engine without a source (unchanged), and unfiltered `READ` and `WRITE` on the source a function declares when it has no engine. Those are the grants that imply `TABLE ENGINE` on a source engine, and the element `ATTACH ... FROM '<path>'` already requires. Both call sites, the local/ON CLUSTER/Replicated initiator in `getRequiredAccess` and the inherited function of `CREATE TABLE copy AS src` (also short `ATTACH` and local `RESTORE`), use it. `filesystem` is the only table function that overrides `getSourceAccessObject`. Behaviour change: a short `ATTACH` or local `RESTORE` of a table created as `filesystem(...)` now needs `READ` and `WRITE ON FILE`, as such a `File` table needs `TABLE ENGINE ON File`. Server startup and replicas are not affected. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Remove an inline comment that repeated the function's doc comment. Co-Authored-By: Claude Opus 5.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 review (2 nits).
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-8:20261121-164200 |
|
cc @foadl @nikitamikhaylov, could you review this? It extends the #129605 check of CREATE TABLE ... AS to a function that declares a source but has no registered engine (onlyfilesystem): such a table now needs unfiltered READ and WRITE ON FILE, so an explicit column list no longer lets a user with only WRITE ON FILE (or no FILE grant via ON CLUSTER) read files under user_files. |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-5:20261121-160200 |
|
Workflow [PR], commit [63ce82e] Summary: ✅
AI ReviewSummaryReviewed head Findings❌ Blockers
Missing context / blind spots
Final VerdictStatus: ❌ Block Link the existing follow-up security issue for the deferred cluster-restore bypass, or close that path with focused regression coverage. |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units118 translation units recompiled, 698 s compile time in total, 118 of them have a recent master baseline. |
|
The |
45ccd89
…-named-collection-unknown-override-keys Conflicts in the code of ClickHouse#132354: master (ClickHouse#133420) renamed `InterpreterCreateQuery::getSourceEngineOfTableFunction` to `getRequiredAccessOfTableFunction`, which returns the whole required grant, and made `ITableFunction::getSourceAccessObject` public. The replay flag of ClickHouse#132354 is passed to the renamed function at both call sites.
Backport #133420 to 26.11: Require `READ` and `WRITE ON FILE` to create a table as `filesystem(...)`
Resolve the conflict in src/TableFunctions/ITableFunction.h: 26.9 keeps the protected isClusterFunction() next to the getSourceAccessObject() declaration that #133420 moves to the public section. 26.9 has a third caller of getSourceEngineOfTableFunction, the ON CLUSTER check of a definition inherited by CREATE TABLE copy AS src, added by the 26.9 backport of #129605 (#133148). Switch it to getRequiredAccessOfTableFunction like the other two callers. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Resolve the conflict in src/TableFunctions/ITableFunction.h: 26.10 keeps the protected isClusterFunction() next to the getSourceAccessObject() declaration that #133420 moves to the public section. 26.10 has a third caller of getSourceEngineOfTableFunction, the ON CLUSTER check of a definition inherited by CREATE TABLE copy AS src, added by the 26.10 backport of #129605 (#133147). Switch it to getRequiredAccessOfTableFunction like the other two callers. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Cherry pick #133420 to 26.9: Require `READ` and `WRITE ON FILE` to create a table as `filesystem(...)`
…e a table as `filesystem(...)`
Cherry pick #133420 to 26.10: Require `READ` and `WRITE ON FILE` to create a table as `filesystem(...)`
…te a table as `filesystem(...)`
Backport #133420 to 26.10: Require `READ` and `WRITE ON FILE` to create a table as `filesystem(...)`
Backport #133420 to 26.9: Require `READ` and `WRITE ON FILE` to create a table as `filesystem(...)`
Related: #129605
Related: #53610
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed
CREATE TABLE ... AS filesystem(...)with an explicit column list not checkingREAD ON FILE, which let a user withWRITE ON FILE(or with noFILEgrant at all, viaON CLUSTER) read any file underuser_filesthrough the new table. Such a table now needsREADandWRITEonFILE, the grants that implyTABLE ENGINE ON File. This also applies toCREATE TABLE copy AS src, shortATTACHand localRESTOREof such a table.Description
On 26.10.5.57 (also 26.8.37.168 and 26.9.25.15), a user with
CREATE TABLEandWRITE ON FILEbut noREAD ON FILErunsCREATE TABLE t (path String, name String, content Nullable(String)) AS filesystem('')and reads every file underuser_fileswithSELECT content FROM t. Reported privately by @ kolsha.#129605 requires
TABLE ENGINEon the engine of a table function used inCREATE TABLE ... AS, but only for an engine registered inStorageFactorywith a source.filesystemhas no engine: it declaresFILEthroughgetSourceAccessObject(), so nothing was required. With explicit columns the structure is not inferred (the onlyREADcheck), the function is executed for writing, andON CLUSTER/Replicatedhosts build the table with full access.getSourceEngineOfTableFunctionbecomesgetRequiredAccessOfTableFunctionand returns the required grant:TABLE ENGINEon a registered source engine (unchanged), or unfilteredREADandWRITEon the source of a function without an engine, the elementATTACH ... FROM '<path>'already requires.filesystemis the only such function. Both call sites use it.Behaviour change: a short
ATTACHor localRESTOREof a table created asfilesystem(...)needsREADandWRITE ON FILE, as aFiletable needsTABLE ENGINE ON File. Server startup and replicas are unaffected;RESTORE ... ON CLUSTERis still not checked on the initiator, as forTABLE ENGINEsince #129605.05842_create_table_as_filesystem_file_grantsfails on master and passes with the fix (local,ON CLUSTER, copy;file()keepsTABLE ENGINE ON File), 100/100 randomized runs.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/133420]
Version info
26.12.1.137-master(included in26.12and later)26.11.1.2928,26.10.13.4,26.9.38.10