Skip to content

Mask credentials in setting values in logs and system tables - #117523

Merged
Algunenano merged 17 commits into
ClickHouse:masterfrom
Algunenano:mask-secrets-in-setting-values
Sep 8, 2026
Merged

Algunenano merged 17 commits into
ClickHouse:masterfrom
Algunenano:mask-secrets-in-setting-values

Conversation

@Algunenano

@Algunenano Algunenano commented Sep 1, 2026 •

Copy link
Copy Markdown
Member

References: https://github.com/ClickHouse/clickhouse-private/issues/69090
References: https://github.com/ClickHouse/clickhouse-private/issues/69148

system.query_log.query has always shown format_avro_schema_registry_url = 'http://user:[HIDDEN]@registry:8080', but every other place that prints a setting value printed the password verbatim. A user granted only SELECT(Settings) ON system.query_log, or SELECT ON system.processes, could read another user's schema registry credentials in cleartext.

The settings whose value can carry a credential now live in one shared map in SettingsSecrets.h, read both by ASTSetQuery for the query text and by every value sink, so the two cannot drift. Besides format_avro_schema_registry_url it covers url_base and s3_base, which resolve relative URLs and were masked nowhere at all, not even in the query text.

Where the reader is known the masking is optional, gated exactly like SHOW CREATE TABLE: the display_secrets_in_show_and_select server setting, the format_display_secrets_in_show_and_select format setting and the displaySecretsInShowAndSelect grant all have to allow it. That covers system.settings, system.processes, system.settings_profile_elements, system.distributed_ddl_queue, SHOW CREATE USER and SHOW CREATE SETTINGS PROFILE. The three-way check was already written out in three places, so it is extracted into canDisplaySecrets.

Where the value is written to a log there is no reader to ask, so the masking is unconditional, matching how the query column is already masked: the Settings map of system.query_log, system.session_log.settings, the clickhouse.setting.* OpenTelemetry span attributes and the Changed settings: line the fatal signal handler writes.

Three more leaks of the same shape turned up while auditing the sinks, and are fixed here too:

  • system.query_log.formatted_query used formatWithSecretsOneLine, so with log_formatted_queries = 1 it leaked the very password that the query column beside it hid. It now uses formatForLogging, which also applies the query_masking_rules regexes.
  • ALTER TABLE t MODIFY SETTING kafka_sasl_password = '...' wrote the password to system.query_log.query in cleartext, while SHOW CREATE TABLE t masked the same setting. Detection was never the problem: hasSecretParts checks the per-engine SETTINGS_TO_HIDE maps without an engine gate and correctly routed the query to the masking formatter. formatImpl then failed to mask, because it only consulted five of the six maps when FormatStateStacked::create_engine_name matched, and the MODIFY SETTING branch never sets it. Both now read the same list of maps. This also affected nats_password, nats_url, rabbitmq_password, rabbitmq_address, after_processing_move_secret_access_key and after_processing_move_connection_string.
  • system.distributed_ddl_queue returned the queued statement and its settings verbatim, so a CREATE TABLE ... ON CLUSTER carrying a credential handed it to anyone with SELECT on that table. The entry in Keeper has to keep the real values because every host of the cluster executes it, so the masking is done on read. The entry was already parsed to get the cluster name and the AST thrown away; it is kept now instead, so this costs no extra parse, and the rendering is idempotent, leaving the query column byte for byte what it was.

MergeTreeSettings and ServerSettings were audited as well and need nothing. The only MergeTree setting whose value can carry a credential is disk, and its inline disk(...) form is already masked through the ungated CustomType branch, with resolveDiskSetting replacing the value by the generated disk name before it is ever stored. No ServerSettings value is a live credential; they are file paths, handler class names, a public key, host lists and numbers.

Changelog category (leave one):

  • Critical Bug Fix (crash, data loss, RBAC)

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

Hide the credentials that a setting value can carry, such as the password in format_avro_schema_registry_url or url_base, everywhere a setting value is displayed or logged. system.query_log, system.processes, system.settings, system.settings_profile_elements, system.session_log, system.distributed_ddl_queue, SHOW CREATE USER and SHOW CREATE SETTINGS PROFILE previously showed them in plaintext to any user who could read them.


Workflow [PR]
Sync PR [sync-upstream/pr/117523]

Version info

  • Merged into: 26.9.1.954 (included in 26.9 and later)
  • Backported to: 26.8.3.71, 26.6.5.85, 26.3.33.24

Algunenano and others added 4 commits September 1, 2026 15:01
`system.query_log.query` has always shown
`format_avro_schema_registry_url = 'http://user:[HIDDEN]@registry:8080'`, but every
other place that prints a setting *value* printed the password verbatim. A user with
only `SELECT(Settings) ON system.query_log`, or with `SELECT ON system.processes`,
could read another user's schema-registry credentials in cleartext.

The settings whose value can carry a credential now live in one shared map in
`SettingsSecrets.h`, consulted both by `ASTSetQuery` for the query text and by every
value sink, so the two cannot drift. Besides `format_avro_schema_registry_url` the map
covers `url_base` and `s3_base`, which resolve relative URLs and were masked nowhere at
all, not even in the query text.

Where the reader is known the masking is optional, gated exactly like
`SHOW CREATE TABLE`: the `display_secrets_in_show_and_select` server setting, the
`format_display_secrets_in_show_and_select` format setting and the
`displaySecretsInShowAndSelect` grant all have to allow it. That covers
`system.settings`, `system.processes`, `system.settings_profile_elements` and
`SHOW CREATE USER` / `SHOW CREATE SETTINGS PROFILE`. The three-way check was written out
in three places already, so it is extracted into `canDisplaySecrets`.

Where the value is written to a log there is no reader to ask, so the masking is
unconditional, matching how the `query` column is already masked: the `Settings` map of
`system.query_log`, `system.session_log.settings`, the `clickhouse.setting.*`
OpenTelemetry span attributes and the `Changed settings:` line the fatal signal handler
writes.

`query_log.formatted_query` used `formatWithSecretsOneLine`, so with
`log_formatted_queries = 1` it leaked the same password that the `query` column beside it
hid. It now uses `formatForLogging`, which also applies the `query_masking_rules`
regexes.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
`ALTER TABLE t MODIFY SETTING kafka_sasl_password = 'p'` wrote the password to
`system.query_log.query` in cleartext, while `SHOW CREATE TABLE t` correctly showed
`[HIDDEN]` for the same setting. The same held for `nats_password`, `nats_url`,
`nats_credentials`, `nats_server_list`, `nats_credential_file`, `rabbitmq_password`,
`rabbitmq_address`, `after_processing_move_secret_access_key` and
`after_processing_move_connection_string`.

Detection was never the problem: `hasSecretParts` checks the per-engine
`SETTINGS_TO_HIDE` maps without an engine gate, so the query was correctly routed to the
masking formatter. `formatImpl` then failed to mask, because it only consulted five of
the six maps when `FormatStateStacked::create_engine_name` matched, and that field is
only set while formatting a `SETTINGS` clause inside `ENGINE = ...`. The `MODIFY SETTING`
branch of `ASTAlterCommand::formatImpl` never sets it, so no engine map applied and the
value was printed verbatim. It leaked even when the alter itself was rejected, since the
query text is logged either way.

`formatImpl` and `hasSecretParts` now read the same list of maps, so the two cannot
disagree about what is secret again. The setting names are engine-prefixed, so consulting
every map regardless of the engine cannot collide.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
A `SELECT` grant on `system.distributed_ddl_queue` was enough to read another user's
credentials in cleartext, from either of two columns. `query` showed the whole statement,
so a `CREATE TABLE ... ON CLUSTER` carrying `kafka_sasl_password` handed the password to
anyone who could read the table, and `settings` showed the initiator's changed query
settings verbatim, `url_base` among them.

The entry in Keeper has to keep the real values, because every host of the cluster
executes it, so the masking belongs on the way out. `query` is rendered through the same
gate as `system.tables.create_table_query`, and the values in `settings` go through the
same masking as everywhere else. The entry was already parsed to get the cluster name and
the AST thrown away; it is kept now instead, so this costs no extra parse. An entry that
does not parse has no AST to hide a secret in, so it falls back to the masking rules, as
`executeQuery` does for a query it cannot parse.

The rendering is idempotent for a real entry: the text in Keeper was itself produced by
formatting the AST, so the `query` column is byte for byte what it was before.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [a416969]

Summary: ❌

job_name test_name status info comment
Build profile diff ERROR

AI Review

Summary

This PR centralizes secret-aware rendering for setting values so credentials are masked consistently in logs, system tables, access-entity formatting, and presigned URL handling. I re-checked the current head against the prior discussion and do not see any remaining correctness or coverage gaps that rise to a review finding.

Final Verdict

✅ No remaining review findings on the current head.

LLVM Coverage Report

Measured on commit a416969.

Metric Baseline Current Δ
Lines 88.80% 88.80% +0.00%
Functions 91.80% 91.80% +0.00%
Branches 81.20% 81.20% +0.00%

Changed lines: Changed C/C++ lines covered: 390/409 (95.35%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added pr-critical-bugfix pr-must-backport Pull request should be backported intentionally. Use this label with great care! labels Sep 1, 2026
Algunenano and others added 2 commits September 1, 2026 16:45
The `system.distributed_ddl_queue` case queued its entry with
`CREATE TABLE ... ENGINE = Kafka`, and the reduced Fast test build has no Kafka engine, so
the statement was rejected on the initiator before it ever reached the queue. The
assertion then read zero rows and reported no masking. The `curl` call sent its output to
`/dev/null`, which hid the rejection.

The case now lives in its own test and carries its secret in a settings profile element
instead of a table engine, so it depends on nothing optional, and `curl` keeps `-sS` so a
rejection is visible instead of silently turning into an empty result.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
A URL carries its credential either as `user:password@` userinfo or, when it is presigned,
in the query parameters, and `s3_base` is documented to hold the presigned form. Only the
userinfo was masked, so `SET s3_base = 'https://...?X-Amz-Signature=...'` reached
`system.query_log` with the signature intact.

The three settings that hold a URL now mask both forms. Which settings are masked does not
change: `maskSettingValue` still only looks at the values of the settings named in
`SETTINGS_TO_HIDE`, so nothing else is scanned.

Scanning for a presigned parameter is only sound on a value that is one whole URL, because
such a parameter ends at `&`, at `#` or at the end of the text. Keying the masking off the
setting name gives that precondition for free: every setting in the list holds one whole
URL, so no check on the value is needed.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Comment thread src/Core/Settings.cpp Resolved
Comment thread src/Interpreters/executeQuery.cpp Resolved
Algunenano and others added 2 commits September 1, 2026 18:45
`system.settings` hides the credential a setting value can carry, but `getSetting` and
`getSettingOrDefault` read the same value and returned it verbatim, so the column could be
read around. It matters for a setting an administrator puts in a settings profile: the user
the profile applies to could read the credential back in plaintext while the same value
showed as `[HIDDEN]` in `system.settings` for that same user.

Both functions share one `getValue`, and it is gated like the column it mirrors, so a user
holding `displaySecretsInShowAndSelect` still gets the real value. A value that carries no
credential is returned untouched, so the functions stay usable for the ordinary case.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
`maskPresignedURLParameters` was quadratic in the length of the string in two independent
ways, and masking the value of a setting put it on the logging path, where the length is
chosen by whoever set the setting and is bounded only by `max_query_size`.

It looked for each parameter's `=` across the whole remainder of the string, so a string of
separators made every parameter scan the rest of it, and it replaced each value in place,
so every match of a different length shifted the tail. The name scan now stops at the first
separator - none of the parameter names contains one - and the result is built in one pass.

With `s3_base` set to 120 KB of separators, a bare `SELECT 1` took 83.7 ms against a 0.9 ms
baseline, and doubling the length quadrupled the time. It now costs 2.9 ms and grows
linearly. `gtest_mask_uri_password` already checks this function against the regular
expression it replaced, over a corpus and 50000 random token strings, and passes unedited.

Reported by @groeneai in ClickHouse#117419, along with the measurement approach.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing d5ef2f432 with master 323d42647 (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Object file sizes

87 object files changed (+246.25 KiB total), 1 added.

Object file Master PR Δ
src/Functions/CMakeFiles/clickhouse_functions_obj.dir/getSetting.cpp.o 248.29 KiB 301.09 KiB +52.80 KiB (+21.27%)
src/CMakeFiles/dbms.dir/Core/SettingsSecrets.cpp.o new 40.15 KiB +40.15 KiB
src/CMakeFiles/dbms.dir/Core/Settings.cpp.o 3.42 MiB 3.45 MiB +26.36 KiB (+0.75%)
src/Parsers/CMakeFiles/clickhouse_parsers.dir/Access/ASTSettingsProfileElement.cpp.o 103.62 KiB 128.30 KiB +24.68 KiB (+23.82%)
src/CMakeFiles/dbms.dir/Interpreters/SessionLog.cpp.o 194.84 KiB 218.77 KiB +23.93 KiB (+12.28%)
src/Storages/System/CMakeFiles/clickhouse_storages_system.dir/StorageSystemSettingsProfileElements.… 204.08 KiB 225.79 KiB +21.71 KiB (+10.64%)
src/Storages/System/CMakeFiles/clickhouse_storages_system.dir/StorageSystemDDLWorkerQueue.cpp.o 397.86 KiB 418.21 KiB +20.36 KiB (+5.12%)
src/CMakeFiles/dbms.dir/Interpreters/executeQuery.cpp.o 1004.79 KiB 1022.48 KiB +17.70 KiB (+1.76%)

716 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.

Compile time of recompiled translation units

1903 translation units recompiled, 11734 s compile time in total, 1902 of them have a recent master baseline.

Median compile-time ratio to the baselines is ×1.06 (machine-speed difference or a change affecting every TU); per-TU deltas below are relative to that ratio.
The matched translation units cost +714.4 s (+6%) in total before that adjustment.

Job report

@Algunenano
Algunenano added this pull request to the merge queue Sep 2, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to no response for status checks Sep 2, 2026
Comment thread src/Core/Settings.cpp Resolved
@clickhouse-gh clickhouse-gh Bot added the comp-settings Settings & configuration infrastructure (server/user/query settings, profiles). label Sep 4, 2026
Algunenano and others added 5 commits September 4, 2026 16:18
`CREATE SETTINGS PROFILE p SETTINGS format_avro_schema_registry_url = 'http://user:secret@reg:8080/'`
wrote the credential to `system.query_log.query` verbatim, and so did the same clause on
`CREATE USER`, `ALTER USER`, `CREATE ROLE` and `ALTER SETTINGS PROFILE ... MODIFY SETTINGS`.

`executeQuery` only routes a query through the secret-masking formatter when `hasSecretParts`
returns true. `ASTSettingsProfileElement` had no override, and in the three create queries the
`settings` and `alter_settings` members are held outside `children`, so the default
`childrenHaveSecretParts` never reached them. The masking formatter was correct but unreachable.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
A custom setting can hold an AST instead of a literal, e.g. `SET custom_x = disk(type = 's3',
secret_access_key = '...')` when the server config registers `custom_settings_prefixes`. Such a
value is a `CustomType` `Field`, and every plain `Field` formatter renders it through
`CustomType::toString`, whose `show_secrets` parameter defaults to true. Four sinks printed the
credential in cleartext: `system.settings.value`, the `clickhouse.setting.*` OpenTelemetry span
attributes, `system.distributed_ddl_queue.settings` and the `Changed settings:` line the fatal
signal handler writes.

The three sinks that stringify the `Field` each use a different formatter, so rather than unify
them they now go through a `Field`-aware overload of `maskSettingValue`, which keeps each
formatter for values that are not a secret AST. `system.settings` reads the value through
`SettingFieldRef::getValueString` instead, so that now takes a required `show_secrets`.

`system.query_log.Settings` and `system.processes.Settings` were already correct: they render
custom settings through `SettingFieldCustom::toString(show_secrets)`.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…ecrets-in-setting-values

# Conflicts:
#	src/Core/Settings.cpp
#	src/Core/Settings.h
#	src/Interpreters/executeQuery.cpp
#	src/Storages/StorageQueryRunner.cpp
Comment thread src/Common/maskURIPassword.h Resolved
{
if (!CoreSettings::SETTINGS_TO_HIDE.contains(setting_name))
return false;
return value || min_value || max_value || !disallowed_values.empty();

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.

value || min_value || max_value how is that part relevant to the hasSecretmethod?

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.

For any setting that might have values to hide (CoreSettings::SETTINGS_TO_HIDE), the value in a profile might be in any of the 4 Fields. For example:

CREATE SETTINGS PROFILE profile
SETTINGS format_avro_schema_registry_url = 'http://user:secret@reg:8080/'

Or even though it doesn't make much sense here:

CREATE SETTINGS PROFILE profile
SETTINGS format_avro_schema_registry_url MIN = 'http://user:secret@reg:8080/'

Same with MAX. Or in xml (I don't see it being possible in SQL) the disallowed_values too

@CheSema CheSema self-assigned this Sep 7, 2026
The value of a presigned URL parameter ends at the next `&`, at `#`, or at
the end of the text. A renderer that masks the already-quoted literal
therefore replaces the closing quote along with the credential, so
`SHOW CREATE SETTINGS PROFILE p` returned
`SETTINGS s3_base = 'https://bucket/f.csv?X-Amz-Signature=[HIDDEN]`, which
no longer parses.

`CoreSettings::renderSecretSettingValue` now renders a value that holds a
secret as the SQL text that hides it, masking the raw string and quoting
the result afterwards, and returns nothing for a value that holds none.
Whether a value holds a secret and how it is hidden are the same question,
so `ASTSetQuery`, `ASTSettingsProfileElement` and `Settings::toString` ask
it in one place: each `formatImpl` and the matching `hasSecretParts` can no
longer disagree, and `ASTSettingsProfileElement::hasSecretParts` is as
precise as its formatter instead of matching on the setting name alone.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Comment thread src/Interpreters/SessionLog.cpp Resolved
Comment thread src/Core/Settings.cpp Resolved
Merged via the queue into ClickHouse:master with commit 87a70da Sep 8, 2026
175 of 176 checks passed
@Algunenano
Algunenano deleted the mask-secrets-in-setting-values branch September 8, 2026 10:18
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 8, 2026
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Sep 8, 2026
robot-clickhouse-ci-1 added a commit that referenced this pull request Sep 8, 2026
Cherry pick #117523 to 26.3: Mask credentials in setting values in logs and system tables
robot-clickhouse added a commit that referenced this pull request Sep 8, 2026
robot-clickhouse-ci-1 added a commit that referenced this pull request Sep 8, 2026
Cherry pick #117523 to 26.6: Mask credentials in setting values in logs and system tables
robot-clickhouse added a commit that referenced this pull request Sep 8, 2026
robot-clickhouse-ci-1 added a commit that referenced this pull request Sep 8, 2026
Cherry pick #117523 to 26.7: Mask credentials in setting values in logs and system tables
robot-clickhouse added a commit that referenced this pull request Sep 8, 2026
robot-clickhouse-ci-1 added a commit that referenced this pull request Sep 8, 2026
Cherry pick #117523 to 26.8: Mask credentials in setting values in logs and system tables
robot-clickhouse added a commit that referenced this pull request Sep 8, 2026
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Sep 8, 2026
clickhouse-gh Bot added a commit that referenced this pull request Sep 8, 2026
Backport #117523 to 26.7: Mask credentials in setting values in logs and system tables
@clickgapai

Copy link
Copy Markdown
Contributor

@Algunenano @CheSema — ClickGap found the following in this PR:

Close anything that's wrong or already addressed.

Algunenano added a commit that referenced this pull request Sep 9, 2026
Backport #117523 to 26.6: Mask credentials in setting values in logs and system tables
Algunenano added a commit that referenced this pull request Sep 9, 2026
Backport #117523 to 26.3: Mask credentials in setting values in logs and system tables
clickhouse-gh Bot added a commit that referenced this pull request Sep 9, 2026
Backport #117523 to 26.8: Mask credentials in setting values in logs and system tables
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-settings Settings & configuration infrastructure (server/user/query settings, profiles). pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-critical-bugfix pr-must-backport Pull request should be backported intentionally. Use this label with great care! 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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants