Skip to content

Cherry pick #120313 to 26.7: Hide secret arguments in EXPLAIN AST output - #122801

Merged
PedroTadim merged 11 commits into
backport/26.7/120313from
cherrypick/26.7/120313
Oct 2, 2026
Merged

PedroTadim merged 11 commits into
backport/26.7/120313from
cherrypick/26.7/120313

Conversation

@robot-clickhouse-ci-1

Copy link
Copy Markdown
Contributor

Original pull-request #120313

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

harikrishnan94 and others added 10 commits September 15, 2026 22:30
`EXPLAIN AST optimize = 1` inlines the definition of a view the user may `SELECT` from and dumps
the result through `DumpASTNode`, which prints every literal verbatim. A user holding only
`SELECT` on a `SQL SECURITY DEFINER` view could therefore read the definer's `encrypt` key that
`SHOW CREATE VIEW` masks for the same user. The secret arguments found by
`FunctionSecretArgumentsFinderAST` are now replaced with `'[HIDDEN]'` literals before the dump,
under the same gate as `SHOW CREATE`, for the tree and the `graph = 1` output alike and for
`optimize = 0` as well.

Closes: ClickHouse/clickhouse-private#72669
Related: #118129
The visitor and call-site comments now say in short sentences what the dump cannot do and why the
tree is edited instead. The test header reads the same way. No behaviour change.
The dump looked for a `key = value` pair inside every secret argument and kept the key visible.
`SHOW CREATE` does that only for a named argument and hides a positional one whole. A positional
secret written as a comparison, such as `encrypt('aes-128-ecb', 'plain', 'k1' = 'k2')`, therefore
showed its left operand. The dump now peels the value only when the finder reports the argument
as named, or when it is an entry of a nested map such as `headers(...)`.
`HideSecretArgumentsMatcher` ran `hideLiteralsInSubtree` on every secret slot, so a slot that
`markSecretArgument` marks because the finder cannot read it (a url built by `concat(...)`, an
identifier in a password slot, a positional secret written as a comparison) still dumped its
expression node by node: `Function concat`, `Function equals`, `Identifier ...`. That is part of a
`SQL SECURITY DEFINER` view body.

Such a slot is now one `'[HIDDEN]'` literal, as `ASTFunction::formatImpl` prints it. A partially
masked argument (a URL with its credentials removed, the reconstructed `S3(...)` of a `Backup`
database) is re-parsed from the formatter text instead of walked. `hideLiteralsInSubtree` is kept
only for the `encrypt` / `HMAC` key, where the expression shape is not a secret.

The test prints the full AST for the fail-closed shapes so the collapse to a single node is visible.

Review: #120313 (comment)
Keep `EXPLAIN AST` secret masking and the upstream removal of obsolete plan-secret checks.

Co-authored-by: Copilot App <[email protected]>
The upgrade check failed on the old base because master has since disabled the AI function quotas by default, so the previous release and this branch disagreed on the defaults of `ai_function_max_*_per_query`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…t` / `HMAC`

The visitor treated every unnamed secret span without a replacement as the
`encrypt` / `HMAC` span and hid only the literals inside it. `mongodb` with
two arguments produces the same shape when the finder cannot read the url,
so `EXPLAIN AST` of `mongodb(concat('mongodb://user:', password_column, '@host/db'), 'c')`
still dumped `Function concat` and `Identifier password_column`.
`SHOW CREATE` prints `'[HIDDEN]'` for the whole argument there.

Keep the structure only for the functions the finder masks as
`encrypt` / `HMAC`, and hide any other such slot whole.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Hide secret arguments in `EXPLAIN AST` output
@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 Sep 29, 2026
@robot-ch-test-poll2

Copy link
Copy Markdown
Contributor

Dear @harikrishnan94, @Fgrtue, this cherry-pick PR has not been updated for 3d0h7m12s. Please resolve the conflicts to backport #120313, or close this PR if the backport is no longer needed. This PR will be automatically closed after 7 days of inactivity.

The only conflict is in `InterpreterExplainQuery.cpp`: the new `EXPLAIN AST` secret-hiding helpers
are inserted where `release/26.7` has the plan-dump secret checks. Keep both.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@PedroTadim
PedroTadim merged commit c5c97f8 into backport/26.7/120313 Oct 2, 2026
1 check passed
@PedroTadim
PedroTadim deleted the cherrypick/26.7/120313 branch October 2, 2026 08:22
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.

6 participants