Skip to content

Hide a non-String value of nats_url and the other secret-bearing settings in logs - #122997

Closed
groeneai wants to merge 8 commits into
ClickHouse:masterfrom
groeneai:mask-non-string-secret-setting-values
Closed

groeneai wants to merge 8 commits into
ClickHouse:masterfrom
groeneai:mask-non-string-secret-setting-values

Conversation

@groeneai

@groeneai groeneai commented Sep 30, 2026 •

Copy link
Copy Markdown
Collaborator

Related: https://github.com/ClickHouse/clickhouse-private/issues/74204
Related: #119028
Related: #116882

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):

Fixed a credential leak in system.query_log, system.text_log and the server log: a Map or other non-String value of nats_url, rabbitmq_address, after_processing_move_connection_string, format_avro_schema_registry_url, url_base or s3_base was logged in cleartext before the statement was rejected. Such a value is now hidden whole, and the error rejecting a Map, Array or Tuple value names only its type. A queue setting written with the legacy s3queue_ prefix is now masked as well.

Description

On 26.8.10.6, CREATE TABLE t (a String) ENGINE = NATS SETTINGS nats_url = {'u':'nats://user:secret@host:4222'}, ... is rejected, but secret is written to system.query_log and the server log in cleartext. On master the same holds for SET url_base = {...}, ALTER TABLE ... MODIFY SETTING and the other settings above.

The rules that mask inside the value took any non-String value to mean "no secret", so the formatter printed the raw Map. The rejection message added by #116882 (master only) also echoed the Map with only scheme://user:password@ masked, so an Azure AccountKey= stayed visible in query_log.exception.

Now the three engine rules and CoreSettings::renderSecretSettingValue hide such a value whole, as the whole-value rules already do, including a disk(...) value (its own masking keeps type, so the engine rules are now asked first). The rejection message names only the type of a value that is not a plain scalar. All six settings are String or URI, so such a literal is always rejected; hence nats_url = 4222 in 05153 is now logged as '[HIDDEN]'.

The queue engines also accept each setting with the legacy s3queue_ prefix, which the lookup did not strip: on master an accepted CREATE TABLE ... SETTINGS s3queue_after_processing_move_secret_access_key = '...' is logged and shown by SHOW CREATE TABLE in cleartext. The prefix is now dropped first.

Validation: 05153_settings_masking_non_string_value gains a SET arm per setting and legacy spelling, plus Map, Array and Tuple query-parameter, disk(...) and AST JSON Number arms, each checking the server's log line for the query and the error. It fails on master with the exact inverse diff and passes with the fix (50/50 randomized); the other masking tests and parser unit tests pass.

🤖 Generated with Claude Code


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

groeneai and others added 8 commits September 29, 2026 18:14
`nats_url`, `rabbitmq_address` and `after_processing_move_connection_string` are masked by
searching their String value for the credential, and so are `format_avro_schema_registry_url`,
`url_base` and `s3_base` in `CoreSettings::renderSecretSettingValue`. Since ClickHouse#119028 a value of
another type was taken to carry no secret, so a `Map` literal such as
`SETTINGS nats_url = {'u':'nats://user:secret@host:4222'}` was formatted verbatim into
`system.query_log`, `system.text_log` and the server log before the setting rejected it.
Such a value is now hidden whole, as `DEFAULT_MASKING_RULE` and the engine-argument form of these
settings already do. None of these settings accepts a non-String value, so only the text of
statements that are rejected anyway changes; `nats_url = 4222` in 05153 is now `'[HIDDEN]'`.

The rejection context added by ClickHouse#116882 ("while setting '<name>' to value <v>") rendered a
composite value with `FieldVisitorToString` and masked only `scheme://user:password@`, so an Azure
`AccountKey=` or a scheme-less NATS userinfo inside a `Map` still reached `query_log.exception`.
It now names only the type of an Array, Tuple, Map, Object, AggregateFunctionState or CustomType
value.

05153 gains a SET arm for each of the six settings that checks the server's own executeQuery log
line, which carries both the query text and the exception, for the credential.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
`formatValueForErrorMessage` names only the type of an Array, Tuple or Map value, but 05153 sent
only a Map literal, so dropping the Array or the Tuple case kept it green. Neither literal parses in
`SET`, while a typed query parameter reaches the setting as a real Array or Tuple value. Part 5 sends
all three that way to `url_base` and checks the logged query text, the type-only error text and that
the credential appears nowhere in the server's own log line.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A `NumberLiteral` holds the unparsed text of a number literal, and the AST JSON dialect builds one
from any `Number_<text>` dump. `formatValueForErrorMessage` rendered it with `FieldVisitorToString`,
which returns that text as is, so "while setting 'url_base' to value ..." echoed a credential that
the logged statement itself hides. It now names only the type, as for the other values that are not
plain scalars. The SQL parser does not produce a `NumberLiteral`, so no SQL statement's error text
changes.

05153 part 5 also sends a `disk(...)` value (a `CustomType`) in SQL and a number literal in the AST
JSON dialect to `url_base`, and checks that each is hidden in the logged query, is named only by its
type in the error, and leaves the credential nowhere in the server's own log line.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
`DiskConfigurationMasker` keeps the `type`, `disk` and `name` arguments of a `disk(...)` visible, and
`CoreSettings::renderSecretSettingValue` returned that partial rendering before its branch that hides a
value that is not a String whole, so `SET url_base = disk(type = '<credential>', ...)` was logged with
the credential in it. `renderSecretChangeValue` also asked the Core renderer before the engine rules,
so the same partial rendering answered for `nats_url`, `rabbitmq_address`,
`after_processing_move_connection_string` and every other engine setting, whose rules all hide a value
that is not a String whole.

`renderSecretSettingValue` now hides a non-String value of `format_avro_schema_registry_url`,
`url_base` and `s3_base` whole before it looks at a `disk(...)`, and `renderSecretChangeValue` asks the
engine rules first. Engine setting names and the three Core names do not overlap, so the new order only
changes a secret `disk(...)` value of an engine setting. A `disk(...)` value of any other setting, such
as `SETTINGS disk = disk(...)`, is masked as before.

05153 part 5 now puts the canary in the `type` argument of the `disk(...)` arm, and sends the same
value to `nats_url`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… rule as one early return

`formatValueForErrorMessage` listed the `Field` types it names only by type in a switch whose
`default:` echoed every other value, so a `Field` type added later would be echoed verbatim. That
list is exactly the set `Field::isScalar` classifies as not a plain scalar, and `isScalar` has no
default, so a new type must be classified there before it compiles. The echo now asks `isScalar`.

`CoreSettings::renderSecretSettingValue` gets its one new rule (a value that is not a String, of
`format_avro_schema_registry_url`, `url_base` or `s3_base`, is hidden whole) as an early return in
front of the unchanged function instead of a restructured body.

Both changes keep the behavior; 05153 and its reference are unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The queue engines take each of their settings with the legacy `s3queue_` prefix as well
(`adjustSettingName` strips it before the settings are applied), but the engine masking rules were
looked up by the name as written. So a value of `s3queue_after_processing_move_connection_string`
or `s3queue_after_processing_move_secret_access_key`, a String included, was logged in cleartext,
and `SHOW CREATE TABLE` of a table created with that spelling printed it.

`renderSecretChangeValue` now drops the prefix before the engine-rule lookup. The Core lookup keeps
the written name: no Core setting starting with `s3queue_` is in an engine map.

Part 4 of 05153 sends a Map to both legacy names.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ue_` prefix

The queue engine settings include every format setting, and `adjustSettingName` strips the legacy
`s3queue_` prefix from any of them. `format_avro_schema_registry_url` is one, and it is masked by the
Core rule, but only the engine-rule lookup dropped the prefix. So a value of
`s3queue_format_avro_schema_registry_url` matched no rule: it was logged in cleartext, and
`SHOW CREATE TABLE` of a queue table created with that spelling printed it.

`renderSecretChangeValue` now gives the unprefixed name to the Core lookup too. The Core settings
that start with `s3queue_` strip to names that are in no masking map, so they stay unmasked.

Part 4 of 05153 sends a Map to `s3queue_format_avro_schema_registry_url`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Condense the two comments on the lookup order in renderSecretSettingValue and renderSecretChangeValue to one line each.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-oranjeai PR origin: delegated from the OranjeAI sibling fleet labels Sep 30, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author
Internal second-model review: adjudication log (click to expand)

Pre-publication review by an independent model (engine: codex; 6 rounds, 5 findings), plus my own cold review of the diff.

# Sev Finding Verdict Evidence / action
1 ⚠️ The test sent only a Map, so the Array and Tuple cases of the type-only rejection message were untested AGREE, fixed in 1d390d5 a typed query parameter per type; each arm asserts the hidden query, to value of type <T> and zero canary hits, and fails on master
2 ❌ Through the AST JSON dialect a number literal carries raw text, which the rejection message echoed verbatim AGREE, fixed in a3daf5e a Number value is named only by its type; nothing builds a number literal from SQL, so no SQL error text changes
3 💡 (own review) The CustomType case of the rejection message was untested AGREE, fixed in a3daf5e one SET url_base = disk(...) arm
4 ❌ A disk(...) value is masked by its own rule, which keeps type visible, before the new hide-it-whole branch, so SET url_base = disk(type = '<secret>') (and nats_url, via the Core renderer) still logged the credential AGREE, fixed in 214fa4f the three Core names hide such a value whole, the engine rules are asked before the Core renderer, and the arms put the canary in type
5 💡 (own review) hasSecretParts now reports a secret for the valueless form of these six settings noted its consumers only pick the masked formatter for logging; the statement is rejected anyway
6 💡 (own review) The AST JSON Number arm relies on master accepting any Number_<text> dump; #102646 validates that text during deserialization noted when #102646 lands, that arm's expected output changes; the type-only message itself stays correct
7 ⚠️ (own review) The type list of the rejection message duplicated Field::isScalar with a default: that echoes any future Field type verbatim, which is how row 2 was missed AGREE, fixed in 805904d the message now asks Field::isScalar, whose exhaustive switch makes every new type be classified; the Core masking rule is one early return in the otherwise unchanged function
8 ❌ A queue setting written with its documented legacy s3queue_ prefix, e.g. s3queue_after_processing_move_connection_string, missed the name-keyed masking, so its value was logged raw, a String value included AGREE, fixed in 9989e3c the engine-rule lookup drops that prefix first; a Map arm for both queue secrets in that spelling
9 💡 (own review) The Core rule also hides an unsubstituted {p:Type} placeholder of url_base, s3_base or format_avro_schema_registry_url, e.g. in SHOW CREATE of a parameterized view noted display-only; a placeholder at a secret argument position of a table function is already shown as '[HIDDEN]'
10 ❌ (also my own review) Row 8's fix dropped the prefix only for the engine rules, while the queue engines take every format setting under the same prefix, so s3queue_format_avro_schema_registry_url still missed the Core rule and was logged raw AGREE, fixed in 0a2c21c the prefix is dropped before the Core lookup too; a Map arm for that spelling

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are
terminal per finding.

Bounce cap reached (5 + 1 fix rounds): published as is. The row 10 fix, made in the final round, was verified by my review of the final diff and by its test arm failing on the previous head, without a seventh gate run. Rows 5, 6 and 9 are noted, not blocking.

Session id: cron:clickhouse-review-slot-8:20260930-013227

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes: SET url_base = {'u':'u:X@h'} (and the five other settings) puts X in the server's own executeQuery log line on master, every run; the reported CREATE TABLE ... ENGINE = NATS/RabbitMQ/AzureQueue SETTINGS <s> = {map} statements put the credential in system.query_log 4 of 4 times.
b Root cause explained? The name-keyed renderers read the value as a String and return "no secret" for any other type, so the raw Map is formatted into the logged query; the #116882 rejection context echoes composite values with a URI-only masker.
c Fix matches root cause? Yes: the renderers fail closed (a non-String value is hidden whole, a secret disk(...) included, whose own masking keeps type), and the echo names only the type of a value that is not a plain scalar (composite, CustomType, number literal). No consumer-side guard.
d Test intent preserved / new tests added? 05153 keeps its three parts and gains a SET arm per setting that checks the query and the error in the server's log line, plus Map, Array and Tuple query-parameter, disk(...), AST JSON number-literal and legacy s3queue_ spelling arms; its nats_url = 4222 line is now '[HIDDEN]' by design.
e Both directions demonstrated? Yes: the test fails on master with the exact inverse diff and passes with the fix; builds that echo an Array, Tuple or number-literal value, carry only the core half of the disk(...) change, or look a rule up by the written name only, fail on exactly those arms.
f Fix is general across code paths? All three in-value engine rules and the core renderer (same shape); the whole-value rules already hide any type; every rule is also found under the legacy s3queue_ name. SET, CREATE ... SETTINGS, SHOW CREATE TABLE and ALTER ... MODIFY SETTING measured.
g Fix generalizes across inputs (params/datatypes/wrappers)? Map literals, Map/Array/Tuple query parameters, a disk(...) value, an AST JSON number literal and a number (nats_url = 4222) are hidden; the valueless form still prints a bare name; String values are masked exactly as before, and now also under the s3queue_ spelling; a Core setting starting with s3queue_ is printed as before.
h Backward compatible? (maintainer-approved exception only) Yes: only how a secret is displayed changes (logged query, error text, SHOW CREATE TABLE); stored metadata is written with secrets shown, and no setting, format or protocol changes.
i Invariants and contracts preserved? The renderers still never throw and still return a valid SQL literal; formatImpl and hasSecretParts still share one function; the error still names the setting; a disk(...) value of any other setting is masked as before.

Session id: cron:clickhouse-impl-slot-4:20260929-165500

@clickhouse-gh

clickhouse-gh Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [3dddb1a]

Summary: ✅


AI Review

Summary

This PR closes the non-String secret-setting leak in the current head by fixing the two relevant formatting paths: ASTSetQuery now hides non-String values of the affected secret-bearing settings before the query text is logged or shown, and BaseSettingsHelpers::formatValueForErrorMessage now degrades composite/opaque values to their type name so rejected values no longer echo nested credentials. I did not find a remaining correctness or masking gap in the current diff.

Final Verdict

Status: ✅ Approve

LLVM Coverage Report

Measured on commit 3dddb1a.

Metric Baseline Current Δ
Lines 88.20% 88.20% +0.00%
Functions 91.80% 91.80% +0.00%
Branches 79.60% 79.60% +0.00%

Changed lines: Changed C/C++ lines covered: 30/30 (100.00%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Sep 30, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-settings Settings & configuration infrastructure (server/user/query settings, profiles). label Sep 30, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 30, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 3dddb1a69 with master 6d87edd44 (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.

Compile time of recompiled translation units

16 translation units recompiled, 51 s compile time in total, 16 of them have a recent master baseline.

Job report

@Algunenano Algunenano self-assigned this Sep 30, 2026
@Algunenano

Copy link
Copy Markdown
Member

This is not a bug that needs to be fixed

@Algunenano Algunenano closed this Sep 30, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

Understood, I'll leave it closed. For context, @ evillique asked for this fix on the private report linked in the description.

One part does affect a valid statement, though: S3Queue accepts every setting with the documented legacy s3queue_ prefix, but the masking looks a setting up by the name as written. On master this is accepted, and SHOW CREATE TABLE, system.tables and system.query_log show the secret in cleartext, while the unprefixed name shows '[HIDDEN]':

CREATE TABLE q (a String) ENGINE = S3Queue('http://host/bucket/data/*', NOSIGN, 'CSV')
SETTINGS mode = 'unordered', s3queue_after_processing_move_secret_access_key = 'secret';

Do you want only that as a small PR (strip the prefix before the lookup in renderSecretChangeValue, plus a test), or should I leave it too?

@Algunenano

Copy link
Copy Markdown
Member

@groeneai Yes, that's a different issue than an obscure "if you put a map value in a string setting". Please open a PR specific to that problem

@groeneai

Copy link
Copy Markdown
Collaborator Author

Acknowledged. I'll open a separate PR for only the legacy s3queue_ prefix case and link it here.

@groeneai

Copy link
Copy Markdown
Collaborator Author

I opened #123060 for only the legacy s3queue_ prefix case: the masking lookup now drops the prefix, and the new test fails on master without the fix.

evillique pushed a commit to evillique/ClickHouse that referenced this pull request Sep 30, 2026
`S3Queue` and `AzureQueue` accept every setting with the legacy `s3queue_`
prefix: `ObjectStorageQueueSettings::loadFromQuery` renames the setting through
`adjustSettingName`, which strips the prefix from any name, and `alter()` does
the same. The masking of a `SETTINGS` clause looks the rule up by the name as
written, and every rule is keyed on the canonical name, so a secret written as
`s3queue_after_processing_move_secret_access_key`,
`s3queue_after_processing_move_connection_string` or
`s3queue_format_avro_schema_registry_url` matched no rule and was printed in
cleartext by `SHOW CREATE TABLE`, `system.tables` and, through
`hasSecretParts`, `system.query_log` and the server log.

`renderSecretChangeValue` now drops the prefix once and gives the unprefixed
name to both the query-level rules and the engine rules. No key of any masking
map starts with `s3queue_`, and the four query-level settings that do
(`s3queue_default_zookeeper_path`, `s3queue_migrate_old_metadata_to_buckets`,
`s3queue_enable_logging_to_s3queue_log`, `s3queue_keeper_fault_injection_probability`)
strip to names no map holds, so the only changes that render differently are
the `s3queue_`-prefixed spellings of a masked name.

Requested in ClickHouse#122997 (comment)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-settings Settings & configuration infrastructure (server/user/query settings, profiles). groeneai-origin-oranjeai PR origin: delegated from the OranjeAI sibling fleet pr-bugfix Pull request with bugfix, not backported by default

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants