Repository navigation
Fix secret bug in explain - #118129
Fix secret bug in explain#118129
Conversation
…t setting and EXPLAIN actions=1
…curity-bug-in-explain-actions
|
Workflow [PR], commit [4b0e7d2] Summary: ✅
AI ReviewSummaryThis PR tightens PR Metadata
Missing context / blind spots
Findings❌ Blockers
Tests
Final Verdict❌ Changes requested. LLVM Coverage ReportMeasured on commit 4b0e7d2.
Changed lines: Changed C/C++ lines covered: 98/141 (69.50%) · Uncovered code |
…now hides disk secrets `EXPLAIN SYNTAX` now honours `canDisplaySecretsInShowAndSelect`, so the `disk` function arguments are printed as `[HIDDEN]`, the same as in `SHOW CREATE TABLE`. Co-Authored-By: Claude Fable 5.1 <[email protected]>
…r reveals secrets `Context::canDisplaySecretsInShowAndSelect` requires the `display_secrets_in_show_and_select` server setting and the `displaySecretsInShowAndSelect` privilege in addition to the `format_display_secrets_in_show_and_select` session setting. The stateless test server has neither, so `EXPLAIN QUERY TREE` and `EXPLAIN actions = 1` keep secrets hidden after the `SET`. The references still encoded the old analyzer behaviour that honoured the session setting alone. CI: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=118129&sha=latest&name_0=PR PR: #118129 Co-Authored-By: Claude Fable 5.1 <[email protected]>
| /// redaction (which may replace a non-constant secret value with a hidden constant) can never | ||
| /// change how the query is analyzed. With run_passes = 0 the tree is dumped without analysis. | ||
| if (!query_context->getSettingsRef()[Setting::format_display_secrets_in_show_and_select]) | ||
| if (!query_context->canDisplaySecretsInShowAndSelect()) |
There was a problem hiding this comment.
This still leaks through EXPLAIN SYNTAX when a secret argument has already been folded into a ConstantNode with a source_expression. Scalar subqueries definitely take that path in evaluateScalarSubqueryIfNeeded.cpp:406-419: the secret becomes ConstantNode(constant_value, node).
The dump visitor run here only masks the folded constant itself. Later, EXPLAIN SYNTAX rebuilds AST with use_source_expression_for_constants = true, and ConstantNode::toASTImpl returns source_expression->toAST(options) before looking at isMasked() (ConstantNode.cpp:215-216). So a query like EXPLAIN SYNTAX SELECT encrypt('aes-256-ofb', (SELECT 'qwerty'), '12345678901234567890123456789012') will still print the subquery literal even though the user lacks displaySecretsInShowAndSelect.
The masking pass needs to recurse into ConstantNode::getSourceExpression() as well, or masked constants must suppress source-expression rendering. Please add a focused EXPLAIN SYNTAX regression for a scalar-subquery or other folded secret argument.
There was a problem hiding this comment.
- Essentially, this concern is senseless -- if the user themselves run query
EXPLAIN SYNTAX SELECT encrypt('aes-256-ofb', (SELECT 'qwerty'), '12345678901234567890123456789012'), then it is not so important if we show the argument as hidden or not. - If you run this query by user, then as an output you will get
SELECT encrypt('aes-256-ofb', '[HIDDEN]'). It happens with turned on/off analyzer and with turned onformat_display_secrets_in_show_and_select.
TL;DR this is a non-existing concern.
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes6 object files changed (+56.77 KiB total), 0 added.
716 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units63 translation units recompiled, 135 s compile time in total, 60 of them have a recent master baseline. Median compile-time ratio to the baselines is ×1.11 (machine-speed difference or a change affecting every TU); per-TU deltas below are relative to that ratio. |
diegomestre2
left a comment
There was a problem hiding this comment.
Great work on fixing the issues, I left a few comments. The main issue for me is the exception message, besides that, the rest of the code looks clear and easy to follow.
|
@diegomestre2 thank you for the review! I applied the changes that you requested. Could you take a look if they are fine please? |
diegomestre2
left a comment
There was a problem hiding this comment.
No new remarks from my side, great work on adding the pass over the DAG and checking the user's access rights. I spent some time thinking about the function bool hasSecretsInStep(const IQueryPlanStep & step), trying to simplify it but I think the only way would require to have virtual calls to different points of the code, like a visitor pattern, having it centralized looks better for maintenance.
| bool node_has_secret = FunctionSecretArgumentsFinderActionsDAG(node).getResult().hasSecrets(); | ||
| bool child_has_secret = std::any_of( | ||
| node.children.begin(), node.children.end(), [](const ActionsDAG::Node * child) { return child->is_masked_secret; }); | ||
| mutable_node.is_masked_secret = node_has_secret || (node.column && child_has_secret); |
There was a problem hiding this comment.
QueryPlanFormat::formatNodePretty hides every node with is_masked_secret, regardless of permissions. Because this new old-analyzer path sets that bit unconditionally for every secret-bearing FUNCTION node, a user who actually passes the full canDisplaySecrets() gate still gets [HIDDEN] in pretty EXPLAIN PLAN / EXPLAIN ANALYZE output instead of the real encrypt(...) / HMAC(...) expression. The analyzer path gates the same propagation on !canDisplaySecrets(), so the two modes now diverge.
Please make this marker propagation permission-aware here, or make the pretty formatter ignore is_masked_secret when secrets may be shown, and add a focused old-analyzer positive regression for the authorized case.
There was a problem hiding this comment.
This is out of scope for this PR
Resolve conflict in `src/Processors/QueryPlan/ArrayJoinStep.h`: keep the `master` accessors `getElementFilter` (returning `const std::optional<ActionsDAG> &`) and `getElementFilterColumnName`; the secrets check in `InterpreterExplainQuery` works unchanged with the optional-returning form. Co-Authored-By: Claude Fable 5.1 <[email protected]>
|
@Fgrtue @diegomestre2 — ClickGap found the following in this PR:
Close anything that's wrong or already addressed. |
|
@clickgapai I am aware of those ones, fixing them is planned as well. |
Resolve the conflicts of the cherry-pick of #118129 to 26.7: - `src/Interpreters/InterpreterExplainQuery.cpp`: drop both conflicting lines of the `Setting` block. `explain_syntax_single_record` does not exist on 26.7, and the original PR removes `format_display_secrets_in_show_and_select` in favour of `canDisplaySecrets`. Drop the `ArrayJoinStep` branch of `hasSecretsInStep` too: `ArrayJoinStep::getElementFilter` does not exist on 26.7, where `ARRAY JOIN` carries no expression DAG that could hold a secret. - `tests/queries/0_stateless/02454_create_table_with_custom_disk.reference`: keep the multi-line `EXPLAIN SYNTAX` shape of 26.7 (master prints one record since `explain_syntax_single_record` defaults to 1) with the disk path shown as `[HIDDEN]`. PR: #119178 Co-Authored-By: Claude Fable 5.1 <[email protected]>
Cherry pick #118129 to 26.7: Fix secret bug in explain
Backport #118129 to 26.7: Fix secret bug in explain
Backport #118129 to 26.8: Fix secret bug in explain
Cherry pick #118129 to 26.6: Fix secret bug in explain
The setting `explain_query_plan_default` and `EXPLAIN ANALYZE` were introduced in 26.7 and do not exist in 26.6, so the test `05057_explain_hide_secrets_without_privilege` failed with `UNKNOWN_SETTING`. Remove the setting from the queries, drop the two `EXPLAIN ANALYZE` checks, and regenerate the reference: on 26.6 `EXPLAIN PLAN` and `EXPLAIN SYNTAX` print the legacy format. Secrets are still shown as `[HIDDEN]` everywhere and the key text never appears. Also remove six includes in `InterpreterExplainQuery.cpp` that came from the master side of the merge and are not used in 26.6. Backport of #118129 Backport PR: #120003 Co-Authored-By: Claude Fable 5.1 <[email protected]>
Cherry pick #118129 to 26.3: Fix secret bug in explain
Backport #118129 to 26.6: Fix secret bug in explain
Backport #118129 to 26.3: Fix secret bug in explain
Closes: https://github.com/ClickHouse/clickhouse-private/issues/69267
Closes: https://github.com/ClickHouse/clickhouse-private/issues/69309
Closes: https://github.com/ClickHouse/clickhouse-private/issues/69186
Changelog category (leave one):
format_display_secrets_in_show_and_selectas a setting requires a server setting and a permission to be used https://clickhouse.com/docs/reference/settings/formats/format#format_display_secrets_in_show_and_select in order to see the secrets.In EXPLAIN the check was only for the setting
format_display_secrets_in_show_and_select. Now this is fixed.EXPLAIN actions=1we reveal some of the secrets. Now we traverse the actionsDAG in the appropriate place in order to eliminate the chance of leaking a secret. Users that don't have right permissions are restricted in their ability to runEXPLAIN [PLAN | ANALYZE]when they don't have a right permission AND actionsDAG has a secret AND they use old analyzer.Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
format_display_secrets_in_show_and_selectworks as expected in EXPLAIN.Workflow [PR]
Sync PR [sync-upstream/pr/118129]
Version info
26.9.1.1111(included in26.9and later)26.8.4.3,26.7.7.85,26.6.7.12,26.3.33.83