Skip to content

Cherry pick #120371 to 26.7: Hide secret function arguments in EXPLAIN when the value comes from another plan step - #124223

Merged
robot-clickhouse merged 19 commits into
backport/26.7/120371from
cherrypick/26.7/120371
Oct 6, 2026
Merged

robot-clickhouse merged 19 commits into
backport/26.7/120371from
cherrypick/26.7/120371

Conversation

@robot-ch-test-poll

Copy link
Copy Markdown
Contributor

Original pull-request #120371

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

vdimir and others added 18 commits September 15, 2026 14:55
…utput

`is_masked_secret` is set by the planner only on the constant nodes it sees
while building a function's arguments. When the secret argument of `HMAC`,
`encrypt` etc. is a column of a derived table or of the opposite side of a
JOIN, the argument is an INPUT node at planning time; `mergeExpressions`
(via `deduplicateSubtrees`) or the join filter push-down (via
`inlineConstantInputs`) later bind it to an unflagged constant, and
`QueryPlanFormat::formatConstant` printed its value in cleartext. A user
with only `SELECT` on a `SQL SECURITY DEFINER` view could read a decrypted
key out of `EXPLAIN PLAN actions = 1`.

Re-derive the secret argument positions in `formatNodePretty` from the
function node itself with `FunctionSecretArgumentsFinderActionsDAG`, and
render everything inside such a slot fail-closed: any node carrying a value
is `[HIDDEN]`, a column reference shows its name only (never the expression
a child step computes it from), nested functions keep their structure.

Related: ClickHouse/clickhouse-private#72525

Co-Authored-By: Claude Fable 5.1 <[email protected]>
The analyzer folds `decrypt('mode', ciphertext, key)` with constant
arguments into a `ConstantNode` holding the plaintext. The arguments are
masked, but the folded result was not, so the planner named the action
node after its value (`_CAST('plaintext'_String, 'String'_String)`) and
EXPLAIN showed it: in the legacy `actions = 1` dump as the node name, in
the pretty dump as the constant value, and in `EXPLAIN QUERY TREE` as the
constant. A `SQL SECURITY DEFINER` view that only uses the decrypted value
internally leaked it to any user with `SELECT` on the view.

Mask the folded result whenever the function has secret arguments and
secrets are hidden, so it is named and displayed as `[HIDDEN id: N]` like
the arguments it was derived from. Execution is unaffected.

Related: ClickHouse/clickhouse-private#72525

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Review feedback: the flag only matters inside the recursion, so it lives on
a static `formatNodePrettyImpl`, and the declared `formatNodePretty` keeps
its original signature and forwards with `false`. Also document why the
flag is inherited by the whole subtree of a secret argument.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
…nition

The declaration moved into the .cpp kept the old five-argument signature,
so it was a second, undefined overload. Declare the single function with
`in_secret_slot = false` as default.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
…aliases

A masked constant leaves its plan step as a header column, which carries
only name, type and value, so the node the next step rebuilds from it had
no mask. `Project names` then aliased it to the user's name and
`removeUnusedActions` folded the alias into a plain COLUMN, and EXPLAIN
printed the plaintext in `Output:` for `SELECT decrypt(...) AS k`.

- `addInput(ColumnWithTypeAndName)` and the `duplicate_const_columns`
  constructor restore the mask from the placeholder name the planner gives
  every masked constant (`isMaskedSecretName`).
- `createAlias` inherits the mask; `project` and `addAliases` build their
  aliases through it instead of by hand.
- A function folded to a constant inherits the mask from its children.

Only one hop is covered: once an alias renamed the constant, the header
name no longer carries the placeholder, so a projected secret behind a
subquery or JOIN still shows in `Output:`. Carrying the mask in
`ColumnWithTypeAndName` itself would close that.

Related: ClickHouse/clickhouse-private#72525

Co-Authored-By: Claude Fable 5.1 <[email protected]>
`05213` gains the report's exact JOIN shape (the `HMAC` key is
`decrypt('aes-128-cbc', unhex(...), key, iv)` on the opposite side) and
its `WITH` alias control.

`05218` reproduces the privilege scenario: the four views from the report
are created by a definer user, a second user holding only `SELECT` on them
runs every EXPLAIN flavour and must not see the plaintext, `SHOW CREATE`
keeps hiding the arguments, `SELECT` stays usable, and a user without the
grant gets `ACCESS_DENIED`. Only leak counts and the presence of the
`[HIDDEN]` placeholder go into the reference, so it does not depend on the
plan layout.

Related: ClickHouse/clickhouse-private#72525

Co-Authored-By: Claude Fable 5.1 <[email protected]>
The pretty formatter hid the values in secret argument positions unconditionally, while the legacy
format, `SHOW CREATE` and `EXPLAIN SYNTAX` follow `canDisplaySecrets`. Thread a `show_secrets` option
from `InterpreterExplainQuery` into `buildPrettyNamesPerPlan`; every other caller keeps the default
and hides. The test uses clickhouse-local, since the stateless server does not enable
`display_secrets_in_show_and_select`.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
`EVP_MD_fetch` returns a reference-counted handle that `FunctionHMAC::executeImpl`
never released. Under ASan the leaked handle keeps the OpenSSL provider state alive
past `OPENSSL_cleanup`, and LeakSanitizer prints a "Suppressions used" summary at
exit of every `clickhouse-local` process that executed `HMAC`, including the
empty-block execution done by `EXPLAIN`. The stateless harness treats that summary
as stderr output, which failed `05219_explain_show_secrets_with_privilege` in the
ASan flaky check.

CI: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=120371&sha=39f9c0d2399f78e7f651b864d7d0fafcb025c645&name_0=PR&name_1=Stateless%20tests%20%28amd_asan_ubsan%2C%20flaky%20check%29
PR: #120371

Co-Authored-By: Claude Fable 5.1 <[email protected]>
# Conflicts:
#	src/Interpreters/InterpreterExplainQuery.cpp
A secret argument position (the key of `HMAC`, everything after the mode of `encrypt`) is
rendered as a single `[HIDDEN]` instead of its structure with the constants hidden, as the
AST formatter does for `SHOW CREATE`. Rendering the structure had to catch every place a
value can surface, and the `IN` operator formatted its literal set directly, so
`HMAC('sha256', msg, if(x IN ('a', 'b'), k1, k2))` printed the set elements in cleartext.

The `InSecretSlot` rendering state is gone. `05213` pins the whole-slot rendering for a
column reference and for the `encrypt` span and adds the `IN` set shape; `05057` changes
accordingly, the plaintext column of `encrypt` is hidden together with the key.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
The check "is argument `n` hidden" over the span, `masked_arguments` and
`replaced_arguments` was written three times: in the pretty plan formatter, in
`markFoldedSecretConstants` of the planner and in `forEachSecretArgumentNode` of the
query tree. `Result` owns that knowledge, so the three callers become one call each,
and a new kind of masking added to `Result` is handled in one place.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
…mask-across-steps

Hide secret function arguments in EXPLAIN when the value comes from another plan step
@robot-ch-test-poll robot-ch-test-poll 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 6, 2026
@robot-ch-test-poll robot-ch-test-poll added 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! labels Oct 6, 2026
Resolve the conflicts of the cherry-pick of #120371 (`InterpreterExplainQuery.cpp`, `QueryPlan.cpp`, `QueryPlan.h`, `QueryPlanFormat.h`): the EXPLAIN
options `inside_explain_analyze`, `estimates`, `time` and `matches` do not exist in 26.7, so only `show_secrets` is added
next to the release's fields. `BlockNestedLoopJoinStep.cpp` does not exist in 26.7 and is dropped.

The sealed-view check of `05218_explain_hide_secrets_definer_view_join` is removed: `ReadFromSealedView`
does not exist in 26.7, so the plan of a `SQL SECURITY DEFINER` view is shown and the test only asserts
that no secret reaches the output.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@robot-clickhouse
robot-clickhouse merged commit 7593db5 into backport/26.7/120371 Oct 6, 2026
1 check passed
@robot-clickhouse
robot-clickhouse deleted the cherrypick/26.7/120371 branch October 6, 2026 15:28
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