Skip to content

Do not let filtered source grants be bypassed by INSERT INTO FUNCTION destinations or CREATE TABLE ... AS - #129605

Merged
foadl merged 20 commits into
masterfrom
fix-partitioned-url-bypass-filter
Nov 17, 2026
Merged

foadl merged 20 commits into
masterfrom
fix-partitioned-url-bypass-filter

Conversation

@foadl

@foadl foadl commented Nov 5, 2026 •

Copy link
Copy Markdown
Member

This change checks access rights for each partition written by INSERT INTO FUNCTION ... PARTITION BY into url, s3, azureBlobStorage, hdfs and their *Cluster variants. It also makes CREATE TABLE ... AS a source table function, such as s3(...), need the TABLE ENGINE grant, like ENGINE = S3(...), in addition to the existing source check of the typed URI.

Problem

A table function checked its source grant once, against the URI template, before {_partition_id} was replaced. The partition id comes from the inserted data, so it could take the write outside the path allowed by a filtered grant. For example, a user with GRANT WRITE ON URL('^http://host/allowed/.*$') could run:

INSERT INTO FUNCTION url('http://host/allowed/{_partition_id}.tsv', 'TSV', 'p String, v UInt32')
PARTITION BY p
VALUES ('a', 1), ('../protected/x', 2);

The template matches the grant, but the second partition is written to http://host/protected/x.tsv.
The same problem occurs for unpartitioned inserts when the setting s3_create_new_file_on_insert=1 and the key is renamed.

CREATE TABLE t AS s3(...) creates the same table as CREATE TABLE t ENGINE = S3(...), but only its URI was checked against the source grant, not TABLE ENGINE ON S3. Only unfiltered READ ON S3 and WRITE ON S3 give TABLE ENGINE ON S3, so a user with a filtered grant could create a table that ENGINE = S3 would refuse. Writes to a table are not checked against source grants, so it could write outside the filter. The check had to run as the user before the table leaves the user's hands: ON CLUSTER creates the table on hosts with full access, and CREATE TABLE copy AS src inherits the table function of src after the access check of the query.

Solution

The table function gives its storage a write access check, and each partitioned sink runs it on the destination of every new partition before writing anything to it. The destination is normalized like the template, so dot segments are resolved before matching. The check runs when a partition is first seen, because partition ids are known only when the data is read: they come from VALUES, from streamed input or from INSERT SELECT, so they cannot be checked when the query is parsed.

The renamed key of unpartitioned writes is checked too, and the check is checkSourceAccessForURI, the same one as for the typed URI since #129899.

For object storages, the check uses the key that is actually written rather than the URI as typed. hdfs grants filter only the authority, so its partitions are checked against the authority, which a partition cannot change.

CREATE TABLE ... AS a table function now checks TABLE ENGINE ON <engine> when the engine has a source (S3, URL, AzureBlobStorage, HDFS, ...), the same check as ENGINE = <engine>. The write check is set only for INSERT INTO FUNCTION, not for a table created with AS: like a table with ENGINE = S3, it is written by users with INSERT on it, and it behaves the same before and after a restart.

The grant is part of getRequiredAccess, which is checked as the user locally and on the initiator before an ON CLUSTER query is sent. A table function inherited by CREATE TABLE copy AS src is checked after setEngine, next to the existing check of an inherited engine, and in the preflight of the legacy ON CLUSTER format. A definition that cannot be a table is refused before the grant is checked, so its error does not depend on the user's grants.

Out of scope

  • RESTORE ... ON CLUSTER of a table created AS <function> does not check TABLE ENGINE on the initiator, as on master. Checking it there means resolving the function, which fails when its named collection is restored from the same backup. A local RESTORE is checked.
  • The arguments of a table function are evaluated each time the function is built, so a non-deterministic argument, such as randConstant, can give the check and the created table different engines. This is not a regression: master does not check TABLE ENGINE for CREATE TABLE ... AS at all.

Corner cases

  • A percent-encoded placeholder, such as allowed/%7B_partition_id%7D.tsv, is decoded into the written key, so the key, not the typed URI, is checked. A % that the partition id puts into the key is a literal character, so %61 is not checked as a.
  • With s3_create_new_file_on_insert, an existing key is renamed by inserting a number before the first dot of the key, or of the file name after Put the create_new_file_on_insert sequence number into the file name, not a directory #129630, and the new key can be outside the grant. The renamed key is checked again. The original key is checked before it is looked up, so that the error for an existing key does not disclose objects outside the grant.
  • The rename applies to unpartitioned writes too.
  • {_schema_hash} is expanded in the written key, so the check expands it in the template URI too, and the combination with PARTITION BY keeps working with filtered grants.
  • A partition id in the first segment of an s3 key can make the key refer to another bucket, e.g. s3://other-bucket/x.tsv. Such partition keys are refused, because the checked URI would be in the granted bucket.
  • ON CLUSTER with explicit columns, and with distributed_ddl_entry_format_version below 3, is checked on the initiator, which does not otherwise resolve the function.
  • url('s3://...') takes the engine of its scheme, so it needs TABLE ENGINE ON S3, not ON URL.

Not affected

  • Tables with the S3, URL and similar engines: creating one needs an unfiltered source grant, and inserting into such a table is not checked against the source grants of the user. This now also holds for tables created with CREATE TABLE ... AS s3(...).
  • The file table function: without a URI, only an unfiltered grant allows it, and that grant covers every path. Its writes stay limited to user_files_path.

Tests

Dot segments are resolved by a real HTTP server (like Nginx) and by S3, so an integration test covers url and s3. It checks that:

  • a partition inside the granted prefix is written;
  • a direct write outside the prefix is refused;
  • a partition id that leaves the prefix is refused without writing anything there, also with an encoded placeholder;
  • a key renamed out of the grant by s3_create_new_file_on_insert is refused, with the number in either place;
  • a partition id that makes the key refer to another bucket is refused, and nothing is written to that bucket.
  • added the unpartitioned rename case, the test_s3_style_link mapper test and the Azure stateless test.
  • a table created by an admin with CREATE TABLE ... AS s3(...) accepts inserts from a user with only INSERT on it;
  • CREATE TABLE ... AS s3(...) by a user with only a filtered grant is refused.
  • a stateless test checks that a user with only a filtered grant cannot create a table AS url(...) or copy one with CREATE TABLE copy AS src, locally, ON CLUSTER and with entry format 2, or restore one locally, and that each is allowed with TABLE ENGINE ON URL.

Unit tests check how the checked URI is built from the written key for s3 (path-style, virtual-hosted, encoded placeholder, renamed key, literal and lone %, encoded dot segments, {_schema_hash}) and for azureBlobStorage (blob paths with escapes). The hdfs override is verified only by reading the code.

Backport: this fix needs a backport. The refusal of partition keys that refer to another bucket applies to 26.9 and later only and older releases do not resolve such keys to another bucket, so the backports leave it out. The TABLE ENGINE check for CREATE TABLE ... AS goes into getRequiredAccess and after setEngine, which all release branches have. 26.3 and 26.6 do not check an inherited engine in the legacy ON CLUSTER preflight, so that part is left out there, as for ENGINE = .....

Changelog category (leave one):

  • Critical Bug Fix (crash, data loss, RBAC)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Fixed filtered WRITE grants (such as GRANT WRITE ON S3('<regex>')) being bypassed by INSERT INTO FUNCTION into url, s3, azureBlobStorage and hdfs. Previously only the URI as typed was checked, so a PARTITION BY value like ../other/x, or a file renamed by s3_create_new_file_on_insert, could be written outside the granted path. Now every destination is checked. If a renamed file falls outside a filtered grant, widen the grant or use s3_truncate_on_insert. CREATE TABLE ... AS s3(...) and other source table functions now need TABLE ENGINE ON <engine> grant, like ENGINE = <engine>; with only a filtered source grant, grant the engine explicitly. This also applies to CREATE TABLE copy AS src when src is such a table, and to local RESTORE of such a table.


Workflow [PR]
Sync PR [sync-upstream/pr/129605]

Version info

  • Merged into: 26.11.1.2555-master (included in 26.11 and later)
  • Backported to: 26.10.8.35, 26.9.34.20

The SQL query `INSERT INTO FUNCTION ... PARTITION BY` checked the source grant once against
the URI with `{_partition_id}` placeholder still in it without any replacement. The partition
ids come from the inserted data, so a partition id like `../protected/foo` could write outside
the path that a filtered grant such as `WRITE ON URL('^http://host/allowed/.*$')` allows.

Now the table function passes a write access check to its storage, and each partitioned sink
runs it on the destination of every new partition before writing to it. For object storages,
the check uses the key that is actually written: the decoded key, so that a percent-encoded
`{_partition_id}` cannot hide it, and the key after a rename by `s3_create_new_file_on_insert`.
The key is checked before it is looked up, so that an existing object outside the grant is not
disclosed. `hdfs` grants filter only the authority, so its partitions are checked against the
authority, which a partition cannot change.

This covers `url`, `s3`, `azureBlobStorage`, `hdfs` and their `*Cluster` variants. Tables with
these engines are not affected, because creating one requires an unfiltered grant on the source.
The `file` function is not affected either, because its grant has no URI to filter.
@clickhouse-gh

clickhouse-gh Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [500fd6f]

Summary: ✅


AI Review

Summary

The PR checks computed destinations of INSERT INTO FUNCTION writes and requires source-engine grants for persistent tables created from table functions. Reviewed head 500fd6f0b1f95f9770ef01b670d2d2d5d3b23672, including the latest AST-cloning fix and all prior discussion. No genuinely new inline findings remain; the previously dismissed concerns below still hold in the current code. Their threads were left untouched.

Findings

❌ Blockers

  • The authorized engine can differ from the engine created. src/Interpreters/InterpreterCreateQuery.cpp:1062 [dismissed by author -- https://github.com/Do not let filtered source grants be bypassed by INSERT INTO FUNCTION destinations or CREATE TABLE ... AS #129605#discussion_r4565867910]. Grant discovery discards its parsed instance; normalization and construction parse again. With explicit columns and url(if(randConstant() % 2, '<http URI>', '<s3 URI>'), 'TSV', 'x UInt32'), the checks can authorize URL while construction chooses S3. A user with TABLE ENGINE ON URL and only filtered source grants can consequently acquire a persistent S3 table whose writes have no destination callback. randConstant generates its value when each function instance is built, so cloning the AST does not bind these decisions. Pin the evaluated definition through checking, creation, dispatch, and reload, or link the separate issue tracking this remaining bypass. Why retained: being pre-existing does not make the new engine-grant invariant complete.

  • Forwarded inserts enforce the worker's destination grants. src/TableFunctions/ITableFunction.cpp:160 [dismissed by author -- https://github.com/Do not let filtered source grants be bypassed by INSERT INTO FUNCTION destinations or CREATE TABLE ... AS #129605#discussion_r4485525610]. An eligible INSERT SELECT with parallel_distributed_insert_select = 2 and parallel_replicas_local_plan = 0 can run entirely on replicas. Without an interserver secret, a more privileged configured cluster user supplies the callback's access context; the initiator checks only the template and never authorizes the resulting partitions. Preserve the initiating identity/restrictions, refuse this optimization when they cannot be preserved, or link a follow-up issue. Why retained: query forwarding remains a reachable way around the initiating user's filtered destination grant; the author deliberately deferred it.

  • Cluster restore still omits source-table-function engine grants on the initiator. src/Backups/RestorerFromBackup.cpp:507 [dismissed by author -- https://github.com/Do not let filtered source grants be bypassed by INSERT INTO FUNCTION destinations or CREATE TABLE ... AS #129605#discussion_r4565867931]. The preflight checks create.storage and inner engines, but not create.as_table_function. Restoring a backup of a table created AS s3(...) can therefore create the permanent table on workers with full access without the initiator holding TABLE ENGINE ON S3. The removed precheck's named-collection regression is resolved; this authorization gap remains. Resolve engine identity using backup dependencies, or provide the reference to the follow-up security issue mentioned by the author. Why retained: the same persistent-table privilege boundary remains bypassable through restore, although this path is explicitly outside this PR's scope.

⚠️ Majors

  • Grant discovery precedes external-function replacement with Null. src/Interpreters/InterpreterCreateQuery.cpp:4388 [dismissed by author -- https://github.com/Do not let filtered source grants be bypassed by INSERT INTO FUNCTION destinations or CREATE TABLE ... AS #129605#discussion_r4582670559]. With session setting restore_replace_external_table_functions_to_null = 1, CREATE TABLE t (x UInt32) AS s3(missing_collection) now resolves the unavailable collection before setEngine can replace the definition. Previously this produced a Null table. Apply the replacement decision before dependency resolution and require the effective engine's grant. Why retained: the author considers direct creation with this testing setting unsupported, but the existing replacement behavior and its broad setting description remain; this is a reproducible regression confined to that workflow.
Tests
  • ⚠️ The latest AST-cloning fix has no focused regression proving that function-local settings survive grant discovery. Add a CREATE TABLE ... AS mysql(...) case with a conflicting session value and function-local mysql_datatypes_support_level, asserting the inferred fractional timestamp type. Existing coverage tests ordinary creation and function-local settings separately, so it does not cover their combination.
  • ⚠️ No local build or server was available, so the traces above were verified from code. The fetched Praktika report lists 14,879 passed, 4,384 skipped, and zero failed tests; those results do not cover the deferred bypasses.
Final Verdict

Status: ❌ Block. Minimum actions: fix the remaining authorization gaps or link the issues that explicitly track their accepted deferral, and add focused regression coverage for the AST-cloning fix. The dismissed testing-setting concern remains recorded without reopening its thread.

@clickhouse-gh clickhouse-gh Bot added pr-critical-bugfix pr-must-backport Pull request should be backported intentionally. Use this label with great care! labels Nov 5, 2026
@foadl
foadl marked this pull request as ready for review November 5, 2026 20:03
@foadl
foadl requested a balanced review from Copilot November 5, 2026 20:04
@foadl foadl added the can be tested Allows running workflows for external contributors label Nov 5, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-rbac Authorization: roles, grants, quotas, row-level security, access checks. label Nov 5, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Critical authorization gaps permit writes outside filtered grants through bucket overrides, replica forwarding, and renamed destinations, while candidate probing can disclose forbidden object existence.

5 open issues
What changed in this PR

This PR adds per-partition destination checks to ClickHouse table-function writes, addressing cases where data-derived partition IDs can escape paths permitted by filtered WRITE grants.

Changes:

  • Passes write-access callbacks from table functions to URL and object-storage partitioned sinks.
  • Reconstructs access-check URIs from resolved object keys and rechecks renamed destinations.
  • Adds integration and unit coverage for allowed writes, path traversal, encoded placeholders, and key renaming.
File Description
tests/​integration/​test_storage_url/​test.py Adds filtered-grant write regression coverage.
src/​TableFunctions/​TableFunctionURL.h Removes the specialized partition setter.
src/​TableFunctions/​TableFunctionURL.cpp Forwards partition expressions to delegates during execution.
src/​TableFunctions/​TableFunctionObjectStorage.h Uses shared partition-expression storage.
src/​TableFunctions/​ITableFunction.h Centralizes partition-expression handling.
src/​TableFunctions/​ITableFunction.cpp Attaches partition write-access callbacks.
src/​Storages/​StorageURL.cpp Checks each partition URL before writing.
src/​Storages/​ObjectStorage/​tests/​gtest_uri_for_access_check.cpp Tests access-URI reconstruction.
src/​Storages/​ObjectStorage/​StorageObjectStorageSink.h Adds the partition sink callback parameter.
src/​Storages/​ObjectStorage/​StorageObjectStorageSink.cpp Checks partition keys and renamed destinations.
src/​Storages/​ObjectStorage/​StorageObjectStorageConfiguration.h Declares destination access-URI reconstruction.
src/​Storages/​ObjectStorage/​StorageObjectStorageConfiguration.cpp Reconstructs URIs using resolved write paths.
src/​Storages/​ObjectStorage/​StorageObjectStorageCluster.cpp Forwards callbacks for cluster storage writes.
src/​Storages/​ObjectStorage/​StorageObjectStorage.h Extends the sink factory interface.
src/​Storages/​ObjectStorage/​StorageObjectStorage.cpp Passes callbacks into partitioned sinks.
src/​Storages/​ObjectStorage/​HDFS/​Configuration.h Uses authority-only access checks for HDFS.
src/​Storages/​IStorage.h Stores callbacks with a table-function-only setter.

Review effort: Balanced

Comment thread src/TableFunctions/ITableFunction.cpp Resolved
Comment thread src/TableFunctions/ITableFunction.cpp Resolved
@clickhouse-gh

clickhouse-gh Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 500fd6f0b with master fdc4389b6 (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Object file sizes

463 object files changed (+92.02 KiB total), 0 added.

Object file Master PR Δ
src/TableFunctions/CMakeFiles/clickhouse_table_functions.dir/TableFunctionObjectStorage.cpp.o 3.05 MiB 3.02 MiB -24.32 KiB (-0.78%)
src/TableFunctions/CMakeFiles/clickhouse_table_functions.dir/TableFunctionObjectStorageCluster.cpp.o 1.05 MiB 1.04 MiB -18.55 KiB (-1.72%)

711 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.

Compile time of recompiled translation units

733 translation units recompiled, 7343 s compile time in total, 733 of them have a recent master baseline.

Job report

@pufit

pufit commented Nov 7, 2026

Copy link
Copy Markdown
Member

@groeneai please review

@groeneai groeneai left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 66ff3d4. The per-partition check refuses the cases in the description. I measured on master caf2f3b with this diff applied (MinIO, Azurite), and on the official 26.10.2.103 for release behaviour. Two gaps: the check will diverge from the template check once #129899 lands (inline below), and the unpartitioned s3_create_new_file_on_insert rename still leaves a filtered grant with #129630 in the tree (my reply in the thread on ITableFunction.cpp:128).

Comment thread src/TableFunctions/ITableFunction.cpp Resolved
@pufit

pufit commented Nov 10, 2026

Copy link
Copy Markdown
Member

The per-destination check works for me on INSERT INTO FUNCTION (A/B of the CI builds against MinIO). One thing to settle before merge: CREATE TABLE ... AS s3(...).

InterpreterCreateQuery calls ITableFunction::execute with is_insert_query = true, so the new block attaches the check to the persistent storage. That happens only when the function has an explicit structure (otherwise the storage is a Proxy), and only until the server restarts (DatabaseOnDisk reloads with is_insert_query = false). Two effects, both measured:

  1. A table created by an admin, user u with only INSERT ON t: INSERT INTO t is refused with WRITE ON S3 (497) until restart. Master and ENGINE = S3 allow it.
  2. A user with only READ, WRITE ON S3('^.../[a-z]+\.tsv$') and CREATE TABLE can create t AS s3('.../data.tsv', ...), and then INSERT INTO t SETTINGS s3_create_new_file_on_insert = 1 writes data.1.tsv, which he cannot write directly. On master always; with this PR after a restart, or at once when the structure is inferred.

So "creating a table needs an unfiltered source grant" holds for ENGINE = S3 (through TABLE ENGINE ON S3) but not for CREATE TABLE ... AS s3(...).

Suggestion: require for CREATE TABLE ... AS <source table function> what the engine requires, and do not attach the write check to tables. Then (1) and (2) are both gone and nothing depends on uptime. Tests for both cases would pin it.

Generated by Nerve

@foadl

foadl commented Nov 11, 2026

Copy link
Copy Markdown
Member Author

The per-destination check works for me on INSERT INTO FUNCTION (A/B of the CI builds against MinIO). One thing to settle before merge: CREATE TABLE ... AS s3(...).

InterpreterCreateQuery calls ITableFunction::execute with is_insert_query = true, so the new block attaches the check to the persistent storage. That happens only when the function has an explicit structure (otherwise the storage is a Proxy), and only until the server restarts (DatabaseOnDisk reloads with is_insert_query = false). Two effects, both measured:

  1. A table created by an admin, user u with only INSERT ON t: INSERT INTO t is refused with WRITE ON S3 (497) until restart. Master and ENGINE = S3 allow it.
  2. A user with only READ, WRITE ON S3('^.../[a-z]+\.tsv$') and CREATE TABLE can create t AS s3('.../data.tsv', ...), and then INSERT INTO t SETTINGS s3_create_new_file_on_insert = 1 writes data.1.tsv, which he cannot write directly. On master always; with this PR after a restart, or at once when the structure is inferred.

So "creating a table needs an unfiltered source grant" holds for ENGINE = S3 (through TABLE ENGINE ON S3) but not for CREATE TABLE ... AS s3(...).

Suggestion: require for CREATE TABLE ... AS <source table function> what the engine requires, and do not attach the write check to tables. Then (1) and (2) are both gone and nothing depends on uptime. Tests for both cases would pin it.

Generated by Nerve

Thank you @pufit . Both are fixed CREATE TABLE ... AS <source function> now needs the TABLE ENGINE grant of its engine, like ENGINE = ..., and the write check is attached only to storages that don't outlive the query, so tables behave the same before and after a restart.

@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Nov 17, 2026
alexey-milovidov added a commit that referenced this pull request Nov 17, 2026
The conflicts are with #129605, which checks
the written keys of an insert against a filtered `WRITE ON` grant. The check is applied to
the starting key of an insert, to the keys `checkAndGetNewFileOnInsertIfNeeded` steps aside
into, and also to the numbered keys of this PR: `getNextKeyForSplittingBySize` and
`removeStaleSplitObjectsByNumber` check every key before it is looked up, written or removed.
The check is captured by value, because the sink calls it for every next object.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
kssenii added a commit that referenced this pull request Nov 19, 2026
…ct fix

The checks for a `url(...)` nested in a persisted `remote`, `loop`, `view` or `Remote`
definition gated only the `CREATE`: the same read runs in a query with the same grants,
as the connection user of `remote`. They also refused valid definitions, such as
`AS remote(..., sharding_key = rand())` or `AS s3(..., filename = currentDatabase() || ...)`.

A table created `AS url(...)` already needs `TABLE ENGINE ON URL` since #129605, so the
creation hook of `url` is not needed either: only a user who may create a table with the
`URL` engine for any URL can create a table that is read with the grant on the table.

Co-Authored-By: Claude <[email protected]>
foadl added a commit that referenced this pull request Nov 20, 2026
Adapted to the release: `StorageTableFunctionProxy` has no `hasUnreplicatedTableDataOnDisk` argument, `StorageURL` names the method `http_method`, and `StorageObjectStorage::createSink` writes `paths.back()`, so that path is checked. `05565_azure_structure_inference_does_not_create_container` is not on the release, so it stays deleted.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
robot-ch-test-poll added a commit that referenced this pull request Nov 20, 2026
Cherry pick #129605 to 26.10: Do not let filtered source grants be bypassed by `INSERT INTO FUNCTION` destinations or `CREATE TABLE ... AS`
robot-clickhouse added a commit that referenced this pull request Nov 20, 2026
…sed by `INSERT INTO FUNCTION` destinations or `CREATE TABLE ... AS`
foadl added a commit that referenced this pull request Nov 20, 2026
Adapted to the release: `StorageTableFunctionProxy` has no `hasUnreplicatedTableDataOnDisk` argument, `StorageURL` names the method `http_method`, and `StorageObjectStorage::createSink` writes `paths.back()`, so that path is checked. `05565_azure_structure_inference_does_not_create_container` is not on the release, so it stays deleted. The new integration test imports `uuid`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
robot-ch-test-poll added a commit that referenced this pull request Nov 20, 2026
Cherry pick #129605 to 26.9: Do not let filtered source grants be bypassed by `INSERT INTO FUNCTION` destinations or `CREATE TABLE ... AS`
robot-clickhouse added a commit that referenced this pull request Nov 20, 2026
…ed by `INSERT INTO FUNCTION` destinations or `CREATE TABLE ... AS`
@robot-clickhouse robot-clickhouse added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Nov 20, 2026
clickhouse-gh Bot added a commit that referenced this pull request Nov 20, 2026
Backport #129605 to 26.10: Do not let filtered source grants be bypassed by `INSERT INTO FUNCTION` destinations or `CREATE TABLE ... AS`
clickhouse-gh Bot added a commit that referenced this pull request Nov 20, 2026
Backport #129605 to 26.9: Do not let filtered source grants be bypassed by `INSERT INTO FUNCTION` destinations or `CREATE TABLE ... AS`
m7kss1 pushed a commit to m7kss1/ClickHouse that referenced this pull request Nov 22, 2026
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]>
kolsha pushed a commit that referenced this pull request Nov 24, 2026
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]>
kolsha pushed a commit that referenced this pull request Nov 24, 2026
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-rbac Authorization: roles, grants, quotas, row-level security, access checks. pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-critical-bugfix pr-must-backport Pull request should be backported intentionally. Use this label with great care! pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants