Repository navigation
Cherry pick #117523 to 26.7: Mask credentials in setting values in logs and system tables - #118769
Merged
robot-clickhouse-ci-1 merged 23 commits intoSep 8, 2026
Merged
Conversation
`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]>
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]>
`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 #117419, along with the measurement approach. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
`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
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]>
`ASTSetQuery` and `ASTSettingsProfileElement` now call `CoreSettings::renderSecretSettingValue`, which lives in a translation unit the wasm parser did not list, so `parser.wasm` failed to link with an undefined symbol. Both extreme configurations stay under their size ceilings: 2058997 bytes by default and 811322 bytes with formatting and DCL off. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
A custom setting has no default of its own, so `system.settings.default` repeats its value, and that value can be an AST that embeds a credential: `SET custom_x = disk(type = 's3', secret_access_key = 'secret')` showed `[HIDDEN]` in `value` but the full dump in `default`. `getDefaultValueString` now takes `show_secrets` like `getValueString` does. `min`, `max` and `disallowed_values` have the raw `Field` at hand, so they use the field-aware masking rather than matching on the setting name after the value has been rendered. `system.session_log.settings` uses the same field-aware path. Nothing can reach that sink with an AST today, because a user's or a profile's setting value only parses as a literal, but the sink no longer depends on that. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…lues Mask credentials in setting values in logs and system tables
…x-26.7-117523 # Conflicts: # src/Common/maskURIPassword.h # src/Core/Settings.cpp # src/Core/Settings.h # src/Databases/RenderedCreateQuery.cpp # src/Interpreters/SessionLog.cpp # src/Interpreters/executeQuery.cpp # src/Parsers/ASTSetQuery.cpp # src/Parsers/Access/ASTCreateUserQuery.cpp # src/Storages/StorageQueryRunner.cpp # utils/wasm-parser/CMakeLists.txt
…s a Settings pointer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Original pull-request #117523
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-picklocally.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:
pr-cherrypicklabel from the PRYou also need to check the Original pull-request for
pr-backports-createdlabel, and delete if it's presented thereThe PR source
The PR is created in the CI job