Skip to content

Cherry pick #122688 to 26.9: Substitute query parameters in row policy filters and reject unsubstituted Identifier parameters - #127324

Merged
PedroTadim merged 10 commits into
backport/26.9/122688from
cherrypick/26.9/122688
Oct 22, 2026
Merged

PedroTadim merged 10 commits into
backport/26.9/122688from
cherrypick/26.9/122688

Conversation

@robot-clickhouse-ci-1

Copy link
Copy Markdown
Contributor

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-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 10 commits September 28, 2026 12:59
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]>
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
@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-bugfix Pull request with bugfix, not backported by default labels Oct 22, 2026
@groeneai

Copy link
Copy Markdown
Collaborator

Three files conflict, each because 26.9 lacks master code next to the lines this PR changes:

git fetch https://github.com/groeneai/ClickHouse resolve-26.9-cherrypick-122688 && git push origin FETCH_HEAD:cherrypick/26.9/122688
  • d404094f3128 is a fast-forward from the cherry-pick head fed910c53fbb. Compared with backport/26.9/122688 it changes the files of this PR except AccessEntityIO.cpp, with the same added and removed lines as this PR in those files (+169/-6).
  • On a 26.9 build (Debug, clang-22), 05291_query_parameters_in_row_policy_and_filter_settings and 05292_row_policy_query_parameters_in_http_handler pass 25/25 each with randomized settings. Without the source changes both fail, and an additional_table_filters query with an unset {x:Identifier} aborts the server with Logical error: '!part.empty()'.

@PedroTadim
PedroTadim merged commit 7f1fa65 into backport/26.9/122688 Oct 22, 2026
14 checks passed
@PedroTadim
PedroTadim deleted the cherrypick/26.9/122688 branch October 22, 2026 07:31
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.

4 participants