Repository navigation
Mask credentials in setting values in logs and system tables - #117523
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]>
|
Workflow [PR], commit [a416969] Summary: ❌
AI ReviewSummaryThis 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 ReportMeasured on commit a416969.
Changed lines: Changed C/C++ lines covered: 390/409 (95.35%) · Uncovered code |
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 ClickHouse#117419, along with the measurement approach. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes87 object files changed (+246.25 KiB total), 1 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 units1903 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. |
`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
| { | ||
| if (!CoreSettings::SETTINGS_TO_HIDE.contains(setting_name)) | ||
| return false; | ||
| return value || min_value || max_value || !disallowed_values.empty(); |
There was a problem hiding this comment.
value || min_value || max_value how is that part relevant to the hasSecretmethod?
There was a problem hiding this comment.
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
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]>
87a70da
Cherry pick #117523 to 26.3: Mask credentials in setting values in logs and system tables
Cherry pick #117523 to 26.6: Mask credentials in setting values in logs and system tables
Cherry pick #117523 to 26.7: Mask credentials in setting values in logs and system tables
Cherry pick #117523 to 26.8: Mask credentials in setting values in logs and system tables
Backport #117523 to 26.7: Mask credentials in setting values in logs and system tables
|
@Algunenano @CheSema — ClickGap found the following in this PR:
Close anything that's wrong or already addressed. |
Backport #117523 to 26.6: Mask credentials in setting values in logs and system tables
Backport #117523 to 26.3: Mask credentials in setting values in logs and system tables
Backport #117523 to 26.8: Mask credentials in setting values in logs and system tables
References: https://github.com/ClickHouse/clickhouse-private/issues/69090
References: https://github.com/ClickHouse/clickhouse-private/issues/69148
system.query_log.queryhas always shownformat_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 onlySELECT(Settings) ON system.query_log, orSELECT 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 byASTSetQueryfor the query text and by every value sink, so the two cannot drift. Besidesformat_avro_schema_registry_urlit coversurl_baseands3_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: thedisplay_secrets_in_show_and_selectserver setting, theformat_display_secrets_in_show_and_selectformat setting and thedisplaySecretsInShowAndSelectgrant all have to allow it. That coverssystem.settings,system.processes,system.settings_profile_elements,system.distributed_ddl_queue,SHOW CREATE USERandSHOW CREATE SETTINGS PROFILE. The three-way check was already written out in three places, so it is extracted intocanDisplaySecrets.Where the value is written to a log there is no reader to ask, so the masking is unconditional, matching how the
querycolumn is already masked: theSettingsmap ofsystem.query_log,system.session_log.settings, theclickhouse.setting.*OpenTelemetry span attributes and theChanged 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_queryusedformatWithSecretsOneLine, so withlog_formatted_queries = 1it leaked the very password that thequerycolumn beside it hid. It now usesformatForLogging, which also applies thequery_masking_rulesregexes.ALTER TABLE t MODIFY SETTING kafka_sasl_password = '...'wrote the password tosystem.query_log.queryin cleartext, whileSHOW CREATE TABLE tmasked the same setting. Detection was never the problem:hasSecretPartschecks the per-engineSETTINGS_TO_HIDEmaps without an engine gate and correctly routed the query to the masking formatter.formatImplthen failed to mask, because it only consulted five of the six maps whenFormatStateStacked::create_engine_namematched, and theMODIFY SETTINGbranch never sets it. Both now read the same list of maps. This also affectednats_password,nats_url,rabbitmq_password,rabbitmq_address,after_processing_move_secret_access_keyandafter_processing_move_connection_string.system.distributed_ddl_queuereturned the queued statement and its settings verbatim, so aCREATE TABLE ... ON CLUSTERcarrying a credential handed it to anyone withSELECTon 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 thequerycolumn byte for byte what it was.MergeTreeSettingsandServerSettingswere audited as well and need nothing. The only MergeTree setting whose value can carry a credential isdisk, and its inlinedisk(...)form is already masked through the ungatedCustomTypebranch, withresolveDiskSettingreplacing the value by the generated disk name before it is ever stored. NoServerSettingsvalue is a live credential; they are file paths, handler class names, a public key, host lists and numbers.Changelog category (leave one):
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_urlorurl_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 USERandSHOW CREATE SETTINGS PROFILEpreviously showed them in plaintext to any user who could read them.Workflow [PR]
Sync PR [sync-upstream/pr/117523]
Version info
26.9.1.954(included in26.9and later)26.8.3.71,26.6.5.85,26.3.33.24