Skip to content

Mask secrets for XDBC and NATS engines#99344

Merged
alexey-milovidov merged 9 commits intomasterfrom
more-secret-hiding
Mar 22, 2026
Merged

Mask secrets for XDBC and NATS engines#99344
alexey-milovidov merged 9 commits intomasterfrom
more-secret-hiding

Conversation

@antaljanosbenjamin
Copy link
Copy Markdown
Member

@antaljanosbenjamin antaljanosbenjamin commented Mar 12, 2026

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Credentials in JDBC, ODBC, and NATS connection strings are now masked in query logs and SHOW CREATE output, preventing accidental exposure of sensitive information. For URI-style connection strings (e.g. {scheme}://{user}:{password}@{host}), only the password portion is masked while the rest remains visible for easier debugging. The nats_token setting is now also masked.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Note

Medium Risk
Touches centralized secret-masking logic for function/table-engine argument rendering; mistakes could either leak credentials or over-mask user-visible queries, but scope is limited to JDBC/ODBC and NATS settings.

Overview
Prevents credential leakage by extending secret masking to JDBC/ODBC table engines and jdbc/odbc table functions, treating the DSN/connection string as sensitive.

For URI-style connection strings, it now rewrites only the password portion (via maskURIPassword), while non-URI DSNs are fully replaced with '[HIDDEN]'; named-collection calls also handle datasource/connection_settings (and defensively hide all named args if both are provided).

Additionally, NATS engine masking now hides nats_token, and integration tests are expanded to assert the new masking behavior in logs and SHOW CREATE output.

Written by Cursor Bugbot for commit b0dedc8. This will update automatically on new commits. Configure here.

@clickhouse-gh
Copy link
Copy Markdown
Contributor

clickhouse-gh Bot commented Mar 12, 2026

Workflow [PR], commit [6f7022d]

Summary:


AI Review

Summary

This PR extends secret masking to JDBC/ODBC table engines and jdbc/odbc table functions, and adds masking for nats_token. It also fixes NATSHandler libuv handle shutdown ordering and adds integration/stateless coverage for the new masking behavior. I did not find any high-confidence correctness, safety, concurrency, or performance issues in the submitted changes.

ClickHouse Rules

Item Status Notes
Deletion logging
Serialization versioning
Core-area scrutiny
No test removal
Experimental gate
No magic constants
Backward compatibility
SettingsChangesHistory.cpp
Safe rollout
Compilation time

Final Verdict

  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Mar 12, 2026
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Comment thread src/Parsers/FunctionSecretArgumentsFinder.h Outdated
@kssenii kssenii self-assigned this Mar 12, 2026
@antaljanosbenjamin antaljanosbenjamin changed the title Mask secrets for XDBC and NATS engiens Mask secrets for XDBC and NATS engines Mar 13, 2026

if (ds_idx >= 0 && cs_idx >= 0)
{
/// Both present — hide all named arguments starting from index 1.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why we decide to hide all arguments here and not just those two?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because FunctionSecretArgumentsFinder::Result can only hide arguments next to each other as it has start and count only. So in case the arguments are not next to each other, we should either extend this logic or hide arguments in between. As specifying both connection_settings and datasource is not a valid option, I opted to go with the easiest solution that shouldn't cause any harm. Basically the query shouldn't succeed, so hiding more values is okay in my opinion.

Because if the default destruction order `execute_tasks_scheduler` got destroyed before `loop`, but `loop` closes all still registered handles in its destructor.
Comment on lines +39 to +46
NATSHandler::~NATSHandler()
{
/// Close the async handle before UVLoop destructor runs,
/// otherwise uv_loop_close reads from already-destroyed memory.
uv_close(reinterpret_cast<uv_handle_t *>(&execute_tasks_scheduler), nullptr);
uv_run(loop.getLoop(), UV_RUN_NOWAIT);
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kssenii this is an addition to address the MSAN error encountered here. This is the MSAN error.

@antaljanosbenjamin
Copy link
Copy Markdown
Member Author

test_keeper_remove_rejoin_leader is fixed by #100051

@clickhouse-gh
Copy link
Copy Markdown
Contributor

clickhouse-gh Bot commented Mar 20, 2026

LLVM Coverage Report

Metric Baseline Current Δ
Lines 83.70% 83.80% +0.10%
Functions 24.00% 24.00% +0.00%
Branches 76.30% 76.40% +0.10%

PR changed lines: PR changed-lines coverage: 98.70% (76/77, 0 noise lines excluded)
Diff coverage report
Uncovered code

@alexey-milovidov alexey-milovidov merged commit 933424a into master Mar 22, 2026
151 of 152 checks passed
@alexey-milovidov alexey-milovidov deleted the more-secret-hiding branch March 22, 2026 13:23
@robot-ch-test-poll1 robot-ch-test-poll1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Mar 22, 2026
@antaljanosbenjamin antaljanosbenjamin added pr-backport Changes, backported to release branch. Do not use manually - automated use only! v25.8-must-backport v25.10-must-backport v25.12-must-backport v26.2-must-backport labels Mar 23, 2026
@robot-ch-test-poll robot-ch-test-poll added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Mar 23, 2026
clickhouse-gh Bot added a commit that referenced this pull request Mar 23, 2026
Backport #99344 to 26.2: Mask secrets for XDBC and NATS engines
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Mar 23, 2026
antaljanosbenjamin added a commit that referenced this pull request Mar 25, 2026
Backport #99344 to 25.8: Mask secrets for XDBC and NATS engines
antaljanosbenjamin added a commit that referenced this pull request Mar 25, 2026
Backport #99344 to 25.12: Mask secrets for XDBC and NATS engines
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-backport Changes, backported to release branch. Do not use manually - automated use only! pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-bugfix Pull request with bugfix, not backported by default pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-synced-to-cloud The PR is synced to the cloud repo v25.8-must-backport v25.10-must-backport v25.12-must-backport v26.2-must-backport

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants