Repository navigation
Enforce TABLE ENGINE grant in table functions - #109331
Conversation
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-6:20260703-155200 |
|
cc @vitlibar @pufit — could you review this? It closes a |
|
Workflow [PR], commit [b7b9c3c] Summary: ❌
AI ReviewSummaryThis PR closes the direct Findings❌ Blockers
Final Verdict
LLVM Coverage Report |
fe85821 to
c5203bf
Compare
|
Update (revised fix). The previous revision gated Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-4:20260703-234500 |
CI finish ledger — c5203bfEvery failure below has an owner: a fixing PR (ours or external), or a full-effort fix task whose fixing-PR link will be posted here when it opens. Only
The PR-caused Session id: cron:our-pr-ci-monitor:20260704-043000 |
|
Fixing PR for the flaky |
executable()/executablePool() run a server-side script under the server's OS user, but table functions checked only source access (READ/WRITE ON S3/URL/...) plus CREATE TEMPORARY TABLE, never the TABLE ENGINE grant that CREATE TABLE enforces. So with table_engines_require_grant=true, SELECT/DESCRIBE over executable(...) bypassed the engine denial: it ran a server-side script even though ENGINE=Executable was denied without GRANT TABLE ENGINE ON Executable. Add ITableFunction::checkEngineAccess(), called from execute() and getActualTableStructureWithAccess() (covers SELECT, DESCRIBE, CREATE TABLE AS). It is scoped to capability engines via a new opt-in virtual requiresTableEngineGrant(), set only on TableFunctionExecutable. Wrapper/ proxy engine table functions (merge/loop/dictionary/view/distributed) stay gated by their delegated data access, source engines by checkSourceAccess, and pseudo-engines (numbers/values/...) need no grant, so none of them opt in. No-op when table_engines_require_grant=false.
c5203bf to
ab2ca32
Compare
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 18/18 (100.00%) · Uncovered code |
CI finish ledger — ab2ca32CI fully finished after the 2026-07-08 rebase onto master (Finish Workflow + Mergeable Check green). Every failure below has an owner.
The two Session id: cron:our-pr-ci-monitor:20260708-153000 |
|
📊 Cloud Performance Report ✅ AI verdict: no significant changes detected. K_source=6 K_base=30 flagged=0/65 clickbench🟢 No significant changes tpch_adapted_1_official🟢 No significant changes Debug info
|
Resolves a conflict in `ITableFunction::execute`, where master gained the `check_create_temporary_table` and `check_source_access` parameters for the `URL` database engine (which resolves its tables through the `url` table function). `checkEngineAccess` is called unconditionally rather than under `check_source_access`. That flag means the caller has taken over the *source* check because it cannot yet know the direction of the access; neither caller that passes it as false (`DatabaseURL::getTableImpl` and `TableFunctionURL::executeImpl` delegation) performs an engine-grant check, so gating on it would silently drop the grant enforcement this change adds. It is a no-op for those paths anyway: only `TableFunctionExecutable` opts in via `requiresTableEngineGrant`, and `url` and its delegates are source engines.
The rationale for gating only capability engines, and for calling `checkEngineAccess` outside `check_source_access`, belongs in the commit history rather than at each call site. Keep at each site only what the next reader needs there.
Only the `executable` table function is registered here; `ExecutablePool` is a table engine registered by `StorageExecutable`. The gate is on the `Executable` engine name either way, so this is a wording fix with no behavior change.
| { | ||
| /// Resolving table structure is always a read operation. | ||
| checkSourceAccess(context, /*is_insert_query*/ false); | ||
| checkEngineAccess(context); |
There was a problem hiding this comment.
getActualTableStructureWithAccess only protects callers that actually delegate to it. TableFunctionViewIfPermitted::getActualTableStructure still calls its fallback's raw getActualTableStructure (src/TableFunctions/TableFunctionViewIfPermitted.cpp:92-95), so the structure-only paths are still bypassable when the dangerous table function is nested: DESCRIBE / CREATE TABLE AS viewIfPermitted(... ELSE executable(...)) skip the new TABLE ENGINE check, and source-backed fallbacks such as url(..., 'auto') still do schema inference without checkSourceAccess. If the contract here is "all table-function structure resolution goes through the guarded helper", this wrapper needs its own guard/reject path and a regression for the nested case.
There was a problem hiding this comment.
You are right about the code path, and I have corrected the PR description because of it. On severity I disagree for the engine axis, and I agree the source-axis gap is real but think it belongs in its own PR. Measurements below, on this head (server buildId 7A89F7F0...) with table_engines_require_grant = true and a user holding only CREATE TEMPORARY TABLE.
Engine axis. TableFunctionViewIfPermitted::getActualTableStructure does call the fallback's raw getActualTableStructure, so checkEngineAccess is skipped there. But the capability stays gated, including the CREATE TABLE AS shapes:
| probe | result | script ran? |
|---|---|---|
DESCRIBE executable(...) (baseline) |
Code: 497 TABLE ENGINE ON Executable |
- |
SELECT via viewIfPermitted, incl. forced-ELSE with matching columns |
Code: 497 |
no |
CREATE TABLE t ENGINE = Memory AS SELECT ... viewIfPermitted(...) |
Code: 497 |
no |
CREATE TABLE t AS viewIfPermitted(...) |
creates a Proxy table |
no |
reading that Proxy (as the user, and as full access) |
Code: 497 / 0 rows |
no |
DESCRIBE viewIfPermitted(SELECT 1 ELSE executable(...)) |
returns x String |
no |
Execution routes through else_table_function->execute, which does check the grant. The probe script touched a sentinel file, and a full-access control run of executable created it, so those "no" results are a live oracle rather than a blind assertion. The CREATE TABLE t AS row does persist a structure-only Proxy from InterpreterCreateQuery, but no read of it reaches the script.
So the residue is DESCRIBE echoing a structure the caller supplied itself in the same statement, since executable takes its structure as an explicit literal argument. That is worth documenting, not gating, and I have added it to the description - my previous wording claimed the two guarded surfaces cover DESCRIBE unconditionally, which was wrong for the nested case.
Source axis. Confirmed real, and pre-existing. Timing against a closed port separates a denial from a connection attempt:
| arm | probe | rc | wall |
|---|---|---|---|
| this PR | DESCRIBE url(...), no READ ON URL |
241 | 81 ms (Code: 497) |
| this PR | nested in viewIfPermitted, no grant |
124 | 25545 ms |
| this PR | direct, full access | 124 | 25018 ms |
| pristine master | direct, no grant | 241 | 218 ms (Code: 497) |
| pristine master | nested, no grant | 124 | 25017 ms |
Nested-without-grant is indistinguishable from full access, and pristine master reproduces it exactly, so this PR neither introduces nor worsens it. TableFunctionViewIfPermitted.cpp is not in this diff (last touched by master 3dfacb15780a11b, an ancestor of this PR's merge base).
Routing that call through getActualTableStructureWithAccess would newly add source-access enforcement to an untouched master path, which is a user-visible access-control change to viewIfPermitted and needs its own tests and reviewer rather than riding along here. TableFunctionLoop.cpp:105 already delegates to the guarded helper, so that is the shape to follow. I am not dropping it.
CI finish ledger — ac6ceceCI is fully finished on this head (175 check-runs, 0 incomplete,
The The other 153 checks are green; 21 are skipped by configuration. Session id: cron:our-pr-ci-monitor:20260803-230000 |
|
Dear @thevar1able, 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. |
|
@groeneai merge latest master |
|
Merged master @ One text fix while I was there: the changelog entry named an |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units93 translation units recompiled, 569 s compile time in total, 92 of them have a recent master baseline. |
CI finish ledger -
|
| Check / test | Reason | Owner / fixing PR |
|---|---|---|
Parser memory check / Resolve master binary |
No master ``clickhouse-examples`` artifact was found. #110081 dropped the suppression of the workflow segment in the S3 prefix, so ci/jobs/parser_memory_check.py probes a hand-spelled REFs/master/<sha>/build_arm_release/ key that now 403s on every master sha it walks. CI-infra, and this diff touches no ci/ file: over 24 h the check reports error on 170 distinct pull requests (17,271 success rows in the same window), so it is a property of master |
#117701 (mine, merged 2026-09-02T16:49:23Z), rule 3c: measured ABSENT from this tree (0 occurrences of the symbol it adds at b7b9c3c71d40, 1 at its merge commit d4f4f2a50e0f, pre-fix control 0) |
LLVM Coverage / Generate LLVM Coverage Diff Report, Print Uncovered Code |
the same S3 prefix change at the coverage call site: the baseline lookup and the report links are hand-spelled the same way. 606 failure rows across 96 distinct pull requests in 24 h, 0 on master |
#117718 (external, open) |
Upgrade check (amd_release) / Error message in clickhouse-server.log (see upgrade_error_messages.txt) |
04510_mutation_query_plan_only_virtual_columns asserts a mutation failure on purpose and _table cannot be materialized in a mutation, so a background MutatePlainMergeTreeTask logs Code: 16 ... Unexpected const virtual column: _table ... While executing MergeTreeSequentialSource (NO_SUCH_COLUMN_IN_TABLE), which the log scanner then flags. 52 rows on 52 distinct pull requests in 14 d, 0 on master |
#117218 (mine, merged 2026-09-02T14:31:57Z), rule 3c: measured ABSENT from this tree (0 occurrences of the allowlist line it adds at b7b9c3c71d40, 1 at its merge commit 84ac4b28254a, pre-fix control 0) |
| Sync | - | CH Inc sync (private, not actionable by me) |
I am not merging master to pick the two merged fixes up in this tick. Mergeable Check gates on
all three rows, and the middle one is owned by a PR that is still open, so a rerun now cannot make
this head green. One later update collects all three instead of spending two CI cycles.
The praktika report has 0 DROPPED nodes of 175, so this is real signal and not a build-gate
cascade: 144 OK, 23 SKIPPED. My diff is 3 files under src/TableFunctions/ plus one
integration test.
Session id: cron:our-pr-ci-monitor:20260902-220000
dbed019
Cherry pick #109331 to 26.3: Enforce TABLE ENGINE grant in table functions
Cherry pick #109331 to 26.6: Enforce TABLE ENGINE grant in table functions
Backport #109331 to 26.8: Enforce TABLE ENGINE grant in table functions
Backport #109331 to 26.6: Enforce TABLE ENGINE grant in table functions
Backport #109331 to 26.3: Enforce TABLE ENGINE grant in table functions
Backport #109331 to 26.7: Enforce TABLE ENGINE grant in table functions
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed a privilege-escalation gap where the
executabletable function did not enforce theTABLE ENGINE ON Executablegrant. Withtable_engines_require_grantenabled, a user deniedCREATE TABLE ... ENGINE = Executablecould still run the same server-side script viaSELECT ... FROM executable(...). It now requiresGRANT TABLE ENGINE ON Executable, matchingCREATE TABLE.Description
executableruns a server-side script under the ClickHouse OS user. Table functions checked only source access (READ/WRITE ON S3/URL/...) andCREATE TEMPORARY TABLE, never theTABLE ENGINEgrantCREATE TABLEenforces viaInterpreterCreateQuery. So withtable_engines_require_grant = true, a user withoutGRANT TABLE ENGINE ON Executablewas correctly deniedCREATE TABLE ... ENGINE = Executable(...)but could still reach the sameStorageExecutablecapability viaSELECT * FROM executable('sh -c ...', ...).Bounded, not RCE: needs
table_engines_require_grant = trueplus a pre-existing executable underuser_scripts_path, and runs as the ClickHouse OS user; not exploitable on Cloud (setting force-disabled, no write primitive there). It is a prerequisite for enabling the setting, which otherwise deniesENGINE = Executablewhile leavingexecutableopen.Fix. New
ITableFunction::checkEngineAccess, called from bothexecuteandgetActualTableStructureWithAccess, soSELECT,DESCRIBEandCREATE TABLE ASare gated when the table function is named directly. It is scoped by a new opt-in virtualrequiresTableEngineGrant,trueonly onTableFunctionExecutable(engineExecutable), and is a no-op when the setting is off.Deliberately not gated: wrapper/proxy engines (
merge,loop,dictionary,view,remote), already gated by delegated data access (SELECT/SHOW COLUMNSon the wrapped table, dictionary access, row policies) - gating them would be a new requirement and breaks03680_loop_table_function_access_check,04411_loop_table_function_describe_access_check,03928_loop_row_policyand03273_dictionary_rbac; pseudo-engines (numbers,values), which have no storage engine; and source functions (s3,url,file), gated on the source axis by the filter-awarecheckSourceAccess.One structure-only path deliberately left out of scope (
viewIfPermitted)One structure-only path is out of scope:
viewIfPermittedresolves itsELSEbranch through the fallback's rawgetActualTableStructure(TableFunctionViewIfPermitted.cpp:92-95), soDESCRIBE viewIfPermitted(... ELSE executable(...))answers without the grant check. It discloses nothing (executabletakes its structure as an explicit literal argument, so the answer is what the caller typed) and never reaches the script - execution goes viaelse_table_function->execute, which does check, so nestedSELECTandCREATE TABLE ... AS SELECTare denied. That path bypasses master's owncheckSourceAccessidentically, verified against a pristine-master build, so it is pre-existing and belongs in its own PR.Tests in
tests/integration/test_grant_and_revoke/test_with_table_engine_grant.py:executableSELECT/DESCRIBEdenied without the grant, allowed with it, plus a regression asserting wrapper (null,merge), pseudo (numbers,values) and source (urlwith a source grant) table functions stay ungated onTABLE ENGINE.Workflow [PR]
Sync PR [sync-upstream/pr/109331]
Version info
26.9.1.585(included in26.9and later)26.8.3.22,26.7.7.20,26.6.5.40,26.3.30.11