Skip to content

Cherry pick #133420 to 26.9: Require READ and WRITE ON FILE to create a table as filesystem(...) - #133691

Merged
robot-clickhouse merged 4 commits into
backport/26.9/133420from
cherrypick/26.9/133420
Nov 24, 2026
Merged

robot-clickhouse merged 4 commits into
backport/26.9/133420from
cherrypick/26.9/133420

Conversation

@robot-clickhouse

Copy link
Copy Markdown
Member

Original pull-request #133420

Do not merge this PR manually

This pull-request is a first step of an automated backporting.
It contains changes similar to calling git cherry-pick locally.
If you intend to continue backporting the changes, then resolve all conflicts if any.
Otherwise, if you do not want to backport them, then just close this pull-request.

The check results does not matter at this step - you can safely ignore them.

Before you resolve anything

Conflicts are often caused by a prerequisite change that has not been backported yet, rather than by a real divergence. The bot re-tries this cherry-pick against the release branch on every run, so if that is the case here it will merge itself as soon as the prerequisite lands, and you will see a comment saying so. Manual resolution is only needed while the conflict persists.

Troubleshooting

If the conflicts were resolved in a wrong way

If this cherry-pick PR is completely screwed by a wrong conflicts resolution, and you want to recreate it:

  • delete the pr-cherrypick label from the PR
  • delete this branch from the repository

You also need to check the Original pull-request for pr-backports-created label, and delete if it's presented there

The PR source

The PR is created in the CI job

groeneai and others added 3 commits November 21, 2026 16:35
Since #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]>
…em-file-grants

Require `READ` and `WRITE ON FILE` to create a table as `filesystem(...)`
@robot-clickhouse robot-clickhouse added pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only! do not test disable testing on pull request pr-bugfix Pull request with bugfix, not backported by default labels Nov 23, 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]>
@groeneai

Copy link
Copy Markdown
Collaborator

The only conflict is context: in src/TableFunctions/ITableFunction.h, 26.9 has isClusterFunction right after the protected getSourceAccessObject declaration that this PR moves to the public section. The resolution drops only that declaration.

26.9 also has a third caller of getSourceEngineOfTableFunction that master does not have, in the ON CLUSTER check of a definition inherited by CREATE TABLE copy ON CLUSTER ... AS src. That call came with the 26.9 backport of #129605 (#133148). The merge leaves it calling the old name, which this PR renames, so the merged tree does not compile (use of undeclared identifier 'getSourceEngineOfTableFunction'). The resolution switches it to getRequiredAccessOfTableFunction the same way as the other two callers. Apart from those two lines, it changes exactly the lines this PR changes.

On a 26.9 debug build of the resolved tree, 05842_create_table_as_filesystem_file_grants passes in 50 of 50 runs, and it fails on the official 26.9.37.6 build. CREATE TABLE copy ON CLUSTER test_shard_localhost AS <a table created AS filesystem(...)> is refused without READ and WRITE ON FILE on the resolved build, and allowed on 26.9.37.6.

I cannot push to cherrypick/26.9/133420. The branch on my fork has this PR's head 45ccd89175e1 as an ancestor, so applying it is a fast-forward:

git fetch https://github.com/groeneai/ClickHouse.git resolve-26.9-cherrypick-133420
git push origin FETCH_HEAD:cherrypick/26.9/133420

@robot-clickhouse
robot-clickhouse merged commit 1531564 into backport/26.9/133420 Nov 24, 2026
2 checks passed
@robot-clickhouse
robot-clickhouse deleted the cherrypick/26.9/133420 branch November 24, 2026 14:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do not test disable testing on pull request pr-bugfix Pull request with bugfix, not backported by default pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants