Repository navigation
Cherry pick #117737 to 26.3: Do not run the format_schema_source='query' schema query without a user - #117846
Merged
Conversation
`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
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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-picklocally.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:
pr-cherrypicklabel from the PRYou also need to check the Original pull-request for
pr-backports-createdlabel, and delete if it's presented thereThe PR source
The PR is created in the CI job