Repository navigation
Cherry pick #122688 to 26.9: Substitute query parameters in row policy filters and reject unsubstituted Identifier parameters - #127324
Merged
Conversation
ASTCreateRowPolicyQuery keeps its filters outside `children`, and
ReplaceQueryParameterVisitor had no case for them, so CREATE / ALTER ROW
POLICY neither substituted nor rejected a query parameter in a USING
clause and stored the placeholder. A stored `{db:Identifier}.keys` then
read `keys` from the reader's current database, a value parameter made
every read of the table fail with UNKNOWN_QUERY_PARAMETER, and an unset
parameter was accepted.
Visit the filters explicitly in ReplaceQueryParameterVisitor, writing a
replaced top-level parameter back into `filters`, and in
QueryParameterVisitor, so an HTTP handler whose query is CREATE / ALTER
ROW POLICY also discovers and binds the filter parameters.
The filters stay out of `children` on purpose: a filter is evaluated when
a table is read, in the reading query's context. Registering them as
children exposes a stored filter to the generic DDL rewriters, e.g.
AddDefaultDatabaseVisitor::visitDDL of ON CLUSTER, which replaces
`currentDatabase()` with the initiator's database, and the create-time
normalizers of executeQuery (construction settings, UNION / EXCEPT modes,
WITH propagation).
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…builder
Text parsed outside executeQuery never meets ReplaceQueryParameterVisitor:
row policy filters stored by an older version or defined in users.xml,
additional_table_filters, additional_result_filter,
parallel_replicas_custom_key. An `{x:Identifier}` there reached
QueryTreeBuilder, which dropped the parameter and built a name with an
empty part. Resolution then read a table from the current database or
failed with a misleading error, and any error message that converted the
node back to AST hit the `!part.empty()` assertion of ASTIdentifier, so
debug and sanitizer builds aborted (Stress test (amd_msan), STID 2508-3010).
Throw UNKNOWN_QUERY_PARAMETER, like the builder already does for an
unsubstituted value parameter, wherever it turns an identifier that a
parameter-capable parser produces into an analyzer name.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
ASTCreateMaskingPolicyQuery keeps its UPDATE assignments and WHERE
condition outside `children`, like the row policy filters, so
ReplaceQueryParameterVisitor and QueryParameterVisitor skipped them: a
query parameter there reached the interpreter unsubstituted
(`UPDATE k = {v:UInt64}` with `param_v` set), and an HTTP handler whose
query is CREATE MASKING POLICY did not bind it from the request.
Visit both members explicitly in both visitors, as for the row policy
filters. Masking policies are executable only in ClickHouse Cloud, so the
tests check what this build can observe: an unset parameter in UPDATE or
WHERE now fails with UNKNOWN_QUERY_PARAMETER instead of
SUPPORT_IS_DISABLED, and a handler binds the parameter (a value that does
not parse fails with BAD_QUERY_PARAMETER).
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
The load-time check `checkAccessEntityHasNoQueryParameters` uses
`analyzeReceiveQueryParams`, which now also visits row policy filters and
masking policy expressions. A row policy stored by an older version with an
unsubstituted parameter in its filter (`USING k = {x:UInt64}`) was then
rejected while loading the access storage:
- on a normal restart every query of every user failed with
INCORRECT_ACCESS_ENTITY_DEFINITION, because the row policy cache reads all
policies;
- on a rebuild of the lists (`need_rebuild_lists.mark`, SYSTEM RELOAD USERS)
the policy was skipped and dropped from the lists, so the rows it hid
became readable.
Skip policy definitions in that check, as before: such a policy loads again
and reading its table fails with UNKNOWN_QUERY_PARAMETER.
Found by the AI review of #122688 after the merge with #109696.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
`analyzeReceiveQueryParams` serves two callers: handler binding needs every parameter, including those in row policy filters and masking policy expressions, while the load-time check of access entities must not look into those expressions, because they are evaluated later, in the context of the reading query. Replace the per-entity-type early return in `checkAccessEntityHasNoQueryParameters` with an `include_deferred_expressions` flag on the visitor, so the check still covers the rest of a policy. Drop the gtest: the SQL tests cover the behaviour. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…-query-parameters Substitute query parameters in row policy filters and reject unsubstituted `Identifier` parameters
Collaborator
|
Three files conflict, each because 26.9 lacks master code next to the lines this PR changes:
|
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 #122688
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.
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:
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