Skip to content

Cherry pick #117737 to 26.3: Do not run the format_schema_source='query' schema query without a user - #117846

Merged
robot-clickhouse merged 5 commits into
backport/26.3/117737from
cherrypick/26.3/117737
Sep 3, 2026
Merged

robot-clickhouse merged 5 commits into
backport/26.3/117737from
cherrypick/26.3/117737

Conversation

@robot-clickhouse-ci-1

Copy link
Copy Markdown
Contributor

Original pull-request #117737

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.

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

Avogar and others added 4 commits September 2, 2026 17:14
`FormatSchemaInfo::querySchema` fell back to the global context when the thread
had no query context. A context without a user has full access, so the schema
query, which comes from the user-controlled `format_schema` setting, was executed
with all privileges. Background tasks are affected: streaming engine consumers
(`Kafka`, `NATS`, `RabbitMQ`, `ObjectStorageQueue`) and `Buffer` background
flushes have no user in their context.

Refuse to run the schema query when the context has no user. The check is on the
user and not on the presence of a query context, because those storages build a
query context of their own from the global one and never call `setUser`.

A schema that is already in the on-disk cache keeps working in background tasks,
since the cache can only have been populated by an access-checked execution.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
The access check added in the previous commit lives in `querySchema`, which
`handleSchemaSourceQuery` calls only on a cache miss, and the cache file name is
derived from the schema query text alone. A warm cache therefore served the schema
to any principal supplying the same text, skipping the check entirely: it let a
background task through again, and it let a user without the grants reuse an entry
cached by someone who had them.

Refuse a context without a user before the cache lookup, and add the user id to the
hash of the cache file name. Entries written before this change no longer match, so
they are not reused after an upgrade.

The exception no longer claims the cause is a background task: the context also has
no user when `INSERT` data is parsed on the client side.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
The stateless test covers the output path, a `Buffer` background flush, while a
streaming consumer reaches `FormatSchemaInfo::querySchema` through the input format.
Cover that path on the engine where the setting is actually reachable: `FileLog`
never applies the format settings from its `CREATE TABLE` query, so
`format_schema_source` never gets there.

The second test covers the schema cache: a user without the grants on the table the
schema query reads stays denied after another user has warmed the cache with the
same query text.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…uery-access

Do not run the format_schema_source='query' schema query without a user
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 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-critical-bugfix labels Sep 3, 2026
Resolve the conflict in `tests/integration/test_format_schema_source/test.py`:
26.3 imports `QueryRuntimeException` and the original PR adds the Kafka
helpers import next to it; both imports are kept.
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-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only! pr-critical-bugfix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants