Repository navigation
Conversation
…processes` `SettingsImpl::dumpToMapColumn` and `SettingsImpl::changedToMap` build the `Map(String, String)` settings column of those two tables by reading every changed setting's value raw and inserting it verbatim. The query text of the same row is masked before it is logged, so one row could show `query` as `... 'http://leakuser:[HIDDEN]@registry.invalid:8080/subjects'` while `Settings['format_avro_schema_registry_url']` held the password. There is no `display_secrets_in_show_and_select` gate on the map path, so a plain `SELECT(Settings) ON system.query_log` or `SELECT ON system.processes`, an ordinary monitoring grant, was enough to read another user's credential. Two value classes carry a credential into that map, and both are reachable on a server with no extra configuration. `format_avro_schema_registry_url` is `DECLARE(URI, ...)`, so its string form is `Poco::URI::toString()`, which preserves the `user:password@` userinfo. Putting a password there is what `AvroRowInputFormat` documents. `SettingFieldCustom::toString` is `Field::dump`, and `FieldVisitorDump::operator()(const CustomType &)` calls `x.toString()` with the default `show_secrets = true`, while `FieldFromASTImpl::isSecret` is `isDiskFunction`. The shipped `programs/server/config.xml` enables the `SQL_` custom-setting prefix, so `SET SQL_d = disk(type = 's3', secret_access_key = '...')` in an HTTP session put a ClickHouse-managed S3 credential into both sinks. A `disk(...)` definition has no URI userinfo, so masking by value shape alone does not reach it; matching by setting name alone would in turn miss any other value carrying a URI credential. The two mechanisms cover disjoint classes, so both are applied, in all four loops of the two functions. Both mirror what `ASTSetQuery` already does for the query text on these exact values: `custom.isSecret()` with `custom.toString(false)`, and `maskURIPassword` for the registry URL. Masking at these two call sites rather than in `SettingFieldCustom::toString` or `SettingFieldURI::toString` is deliberate. Those are the round-trip and functional forms: `parseFromString` is `Field::restoreFromDump`, `writeBinary` writes `toString()`, which is how a custom setting reaches remote shards, and the schema-registry client needs the real URL. Both maps are display only, so masking a copy there is safe: `changedToMap` has three callers and `dumpToMapColumn` one, all log elements. The masking is unconditional, because neither function has a `Context` and the map is built when the row is written, not when it is read. An admin holding `displaySecretsInShowAndSelect` therefore also sees `[HIDDEN]`, which matches how the `query` column of the same row already behaves. The new test covers both sinks and both classes, with an over-masking control on each path so that a change which mangled ordinary values could not pass. It is deterministic: a query sees its own `system.processes` row through `WHERE query_id = queryID()`, so the live sink needs no concurrent query. It is a shell test because a `disk(...)` custom setting cannot travel over the native protocol, where the client re-sends it as a `Field` dump that the server refuses with `CANNOT_RESTORE_FROM_FIELD_DUMP`; an HTTP session is the reachable path. Co-Authored-By: Claude Opus 5 <[email protected]>
Both standard-loop arms of `05054_settings_map_secret_mask` used `format_avro_schema_registry_url`, which is the only `DECLARE(URI, ...)` setting in the tree. So a gate on that one setting name would have kept every arm of the test green while still leaving any other setting whose value carries a URI credential unmasked. The test could not tell masking by value shape, which this change uses, from masking by setting name, which it does not. `url_base` is such a setting today. It is `DECLARE(String, ...)`, so only masking on the value shape reaches it, and ClickHouse's own tests set it to `http://user:[email protected]/dir/` (`04070_url_base_setting.sh`, `04652_url_wildcard_index_pages_userinfo.sql`). Two arms are added for it, one per sink, so each of the two standard loops has a witness that a name gate would miss. Building both standard loops with that gate now fails exactly the two new arms, with the password in plaintext, and leaves the five existing arms passing. On pristine master the new arms fail as well. No source change: `maskURIPassword` already masks the value, which the arms confirm by measurement rather than by inspection. Co-Authored-By: Claude Opus 5 <[email protected]>
`maskURIPassword` walks every `://` in the value. When no `@` follows one of
them, `find('@', ...)` scans the whole remaining suffix, returns npos, and the
loop moves to the next `://` and scans that same suffix again, so `a://`
repeated n times costs n suffix scans. Masking the settings map turns that from
one scan per request carrying the payload into a scan of every changed setting
value of every logged query: one session-scoped `SET` of a 256 KiB value makes
each later query in that session pay it, `log_query_settings` is on by default,
and a `system.processes` reader pays it once per live row.
Both npos branches now leave the loop, which cannot skip a substitution.
`separator` strictly increases, and `std::string::find(c, pos)` is
non-decreasing in `pos`, so `password_begin` never decreases from one iteration
to the next. If there is no `@` at or after `password_begin` there is none at or
after any later iteration's `password_begin` either, so every later iteration
would have found nothing to mask. The same argument holds for the colon search,
where a miss additionally means no further `://` exists at all. The worst case
becomes linear: the `@` search runs to completion at most once, and the colon
searches are bounded by the gaps between separators.
Measured with the old and the new body side by side: identical output and
identical return value over 4441419 inputs, being every string of length up to 9
over `{a : / @ x}`, 2000000 random strings of length up to 40, the test canaries
and the reported shapes. The same harness reports 2254 differences for a variant
that also leaves the loop on the scheme check, so it is able to see a regression
of this kind. `src/Common/tests/gtest_mask_uri_password.cpp`, which compares this
function against the regular expression it replaced, passes unchanged, and fails
on that same wrong variant.
`"a://" repeated 262144 times` in `url_base`, timed end to end over HTTP against
a server that masks the map: 1043.5 ms before this change and 5.7 ms after,
where a server that does not mask the map at all takes 5.9 ms for the same
query. The remaining cost is handling a 1 MiB query, not masking.
Co-Authored-By: Claude Opus 5 <[email protected]>
`maskedCustomSettingValue` has two paths and only one of them had a witness. `SQL_05054_disk` is a secret `CustomType`, so it returns from the `isSecret` branch, and `SQL_05054_plain` dumps to `'no-secret-here'`, which contains no `://`, so the `maskURIPassword` call on the fall-through ran but could not change anything. Removing only that call left every arm of the test green, while `SET SQL_x = 'http://u:pw@h/p'`, an ordinary plain `String` Field whose dump that call is the only thing masking, still put the password into both maps. A third custom setting carrying a URI password is added to the existing session, with one arm per sink. A build with only that call removed now fails exactly those two arms, with the password in plaintext, and leaves the other fourteen reference lines byte-identical. On pristine master the new arms fail as well. They also attribute per sink: removing the `dumpToMapColumn` custom loop fails only the `system.processes` arm and removing the `changedToMap` one fails only the `query_log` arm, so each of the four loops now has its own witness. Co-Authored-By: Claude Opus 5 <[email protected]>
Internal second-model reviewBefore opening this I ran an independent cold review of the diff plus a second-model review pass,
One thing my own review caught that this change does not address: these four loops are not the only |
|
Workflow [PR], commit [b279399] Summary: ❌
AI ReviewSummaryThis PR extends secret masking for the Final Verdict✅ No new findings. The earlier LLVM Coverage Report |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units17 translation units recompiled, 64 s compile time in total, 17 of them have a recent master baseline. |
`maskPresignedURLParameters` was quadratic in two independent ways, and putting it on the
settings map path in the next commit makes both reachable from every logged query.
It looked for the `=` of each parameter across the whole remaining string, so a value built
from separators rescanned the same suffix once per parameter: `"&" * n + "="` cost
0.818/3.011/13.725/62.838 ms at n = 2^14..2^17. A parameter name can contain no separator,
so the scan now stops at the first one: 0.021/0.043/0.085/0.178 ms.
It also replaced each value in place, which moves the whole remaining suffix once per match,
so a value of nothing but matches was quadratic too: `"&Signature=x" * n` cost
0.161/0.566/5.386/24.878/44.923 ms at n = 2048/4096/8192/16384/21800, the last being 261,600
bytes and so within `DBMS_DEFAULT_MAX_QUERY_SIZE`. The result is now built in one pass:
0.024/0.050/0.114/0.338/0.308 ms.
What is masked does not change. The old and new bodies agree on output and return value over
7,092,445 inputs: every curated shape, an exhaustive enumeration of {? & = x} up to length
11, and 1,500,000 assembled parameter lists. A control body carrying a real regression is
reported as differing on 541,891 of them, so the comparator is not blind. The differential
arms of `gtest_mask_uri_password` against the regular expressions this scan replaced pass
with the test file unedited, and fail when a regression is injected.
Co-Authored-By: Claude Opus 5 <[email protected]>
The map hid `user:password@` but not the credential a presigned URL carries in its query parameters, so `SETTINGS s3_base = 'https://bucket.s3.amazonaws.com/k?X-Amz-Signature=...'` reached `system.query_log.Settings['s3_base']` and `system.processes.Settings['s3_base']` verbatim. `s3_base` is `DECLARE(String, ...)` and is documented to hold exactly that form of URL. The map records the whole session's changed settings, so the credential repeats on every later query's row, and when the setting arrives by HTTP parameter or from a settings profile there is no `SET` text anywhere that a query-text masker could reach. `maskPresignedURLParameters` is the scan `FunctionSecretArgumentsFinder` already applies to S3 URLs, and its parameter set mirrors `BackupInfo::removeCredentialsFromS3URL`. The last query parameter of a presigned URL runs to the end of the text, so that scan is only sound on a string that is one whole URL. `isOneWholeURL` is that precondition: a scheme, and no whitespace, which a URL cannot contain. Both halves are load-bearing and each rejects one side of free text - the scheme test rejects text before the URL, the whitespace test rejects text after it. Without it `log_comment = 'see s3://b/k?X-Amz-Signature=abc and then some trailing words'` lost everything after the credential. The precondition is deliberately not pushed into `maskPresignedURLParameters` itself: that function's contract is to reproduce a regular expression which has no such precondition, `gtest_mask_uri_password` fuzzes it against re2, and narrowing it would also narrow masking at the existing `maskS3URICredentials` caller. Its remaining false positive is a value that begins with a scheme, holds no whitespace and continues past the credential, such as a comma-separated URL list; no setting is known to hold one. A value that is not one whole URL is masked in its leaves instead. A custom setting is stored as a `Field` and shown as its dump, and a `Map` setting serializes to more than one value, so in both the end of the text is punctuation that closes the value and its parents: scanning the serialized text consumed the closing quote, the brace, and every entry after the credential. Masking the `Field`'s String leaves also covers a credential nested in a custom map and restores masking of an `AggregateFunctionState`, which the dump-based form reached. A masked `Map` setting is re-serialized through `accessor.valueToStringUtil`, which funnels into the same `SettingFieldMap::toString` as `getValueString`; both `Map` settings, including an empty value, were measured byte-identical between the two, with a control showing the comparison can report a difference. I deliberately do not use `maskURIUserinfo`, the other half of that finder's S3 masking. It hides the whole userinfo, so `format_avro_schema_registry_url` would read `http://[HIDDEN]@host` in the map while `ASTSetQuery` prints `http://user:[HIDDEN]@host` in the `query` column of the same row. The test covers both sinks for the parameter form, one arm per half of the precondition (free text after the URL, rejected by the whitespace test, and free text before it, rejected by the scheme test), a credential as the last thing in a custom setting's value, one nested in a custom map, a `Map` setting whose second entry has to survive, parameters that name no credential, and a credential followed by a comma, which belongs to it because a parameter value ends only at `&` or `#`. Reverting any one masking decision, dropping either half of the precondition, or answering it `false` everywhere, reddens only the arms that witness it. `Array`, `Object` and `AggregateFunctionState` leaves are covered by a unit test instead. `SET` rejects those literals, and an HTTP parameter or the config stores the text as a `String`, so only the native wire format restores such a value and no stateless test can build a carrier. Co-Authored-By: Claude Opus 5 <[email protected]>
Internal review and validation for
|
| finding | verdict |
|---|---|
| the free-text control cannot prove either half of the new whole-URL guard independently | agreed, fixed: one arm per half, each with its own witness (see the matrix) |
the Array / AggregateFunctionState / Object leaf branches have no witness |
agreed, fixed: gtest_settings_map_secret_mask.cpp, since SET rejects those literals and an HTTP parameter or the config stores the text as a String, so only the native wire format restores such a value |
the query column still shows the same credential verbatim |
correct, and pre-existing: ASTSetQuery::hasSecretParts is name-gated and this PR does not touch it. A value-shaped predicate there would change "is this query secret?" for every query, so it is stated as a known limit instead. Reverting the map masking is the worse option: the map records the whole session, so the credential repeats on every later row and appears in system.processes, where the query text does not carry it at all |
| a value that begins with a scheme, holds no whitespace and continues past the credential loses its tail | correct, and it is the regular expression's own rule: a parameter value ends only at & or #, and , is legal inside one, so on a value that is one whole URL the tail belongs to the credential. Pinned by the last test arm and stated in the commit message. The two suggested alternatives are a declared type test, which does not establish that a value is a URL, and a second terminator for the scan, which would break the documented equivalence with the expression and its fuzz arms |
Validation (build 57eecabc, server identity asserted on every arm):
05054_settings_map_secret_mask: 50 randomized runs and 50 self-parallel-j8runs, 100/100. The
18 reference lines this PR already had are byte-identical.- 11 unit tests:
MaskURIPassword4/4 andMaskS3URLCredentials3/3 unedited, including the arms
that fuzz these scans against the regular expressions they replaced, plus the 4 new ones. e31fd36is behaviour-preserving: old and new bodies agree on output and return value over
7,092,445 inputs, with a deliberately broken control body reported as differing on 541,891.
"&"*n + "="at n=2^17: 63.6 ms to 0.17 ms."&Signature=x"*nat 261,600 bytes: 45.0 ms to 0.28 ms.accessor.valueToStringUtilwas measured byte-identical togetValueStringfor bothMap
settings including an empty value, with a control showing the comparison can report a difference.ci/jobs/scripts/check_style/various_checks.shandcheck_cpp.shclean, each with a positive
control that fires.
Mutation matrix: 13 source mutants plus 3 unit-test mutants, each reddening exactly its own arms
Reference line numbers, values only. 20/22 presigned from query_log / processes, 24 free text
after the URL, 26 free text before it, 28 custom setting ending in a credential, 30 custom setting
holding a map, 32 http_response_headers, 34 parameters naming no credential, 36 a credential
followed by a comma.
m-base-prefix (this PR without the two commits) 20,22,28,30,32,36
m-master (both files at the PR base) 2,6,8,10,12,14,16,18,20,22,28,30,32,36
m-uri-pw drop maskURIPassword 2,6,12,14,16,18
m-presigned drop the presigned scan 20,22,28,30,32,36
m-guard-off drop the whole precondition 24,26
m-guard-scheme-only drop the whitespace half 24
m-guard-ws-only drop the scheme half 26
m-guard-false precondition always false 20,22,28,30,32,36
m-map-branch drop the Map branch 32
m-leaf-dump mask the custom dump, not leaves 28,30
m-custom-scalar mask only a String custom value 30
m-no-recursion drop the Tuple recursion 30,32
hdr-inplace revert the one-pass build none, by design: it is output-preserving
drop-Array-case gtest MasksTheLeavesOfAnArray
drop-Object-case gtest MasksTheLeavesOfAnObject
drop-AggState-case gtest MasksBothMembersOfAnAggregateFunctionState
m-master is the state Bugfix validation reruns the changed test against, so the new arms do fail
there. Note the two Bugfix validation (functional tests, *) jobs on the previous head did not reach
a verdict: both died at ci/jobs/functional_tests.py assert build_urls, "Could not find master builds in S3" before downloading a binary.
Session id: cron:clickhouse-maint-slot-15:20260901-040003
CI finish ledger - b279399Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
Two notes on the None of these failures is caused by this PR, whose diff is Session id: cron:our-pr-ci-monitor:20260901-113000 |
|
Closing in favour of #117523, which covers the same two reports and is a superset of this one. Thanks for the analysis here — two of its findings went straight into #117523, with credit:
What #117523 additionally covers, most of it listed as a known limit here:
On the design difference: this PR matches on the value shape, so it scans the value of every changed setting. #117523 keeps the convention the other six settings classes already follow — a Two things from here worth keeping and not yet ported, happy to do either as a follow-up: the linearity fix to |
|
Thanks for the credit. Both leftovers are still absent from #117523, and the linearity one now has a reason to be there: It looks for each parameter's The gtest does not port as written: its four cases assert leaf masking inside a custom setting, which a name-keyed map does not do. I would send scaling and equivalence arms for Your call on who carries it. Say the word and I will open one small PR against master with the linear rewrite plus those arms once #117523 is in, or fold it in yourself and I will stay out of it. |
`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]>
|
Carried the linear rewrite in #117523, credited to you: measured 83.7 ms down to 2.9 ms at 120 KB, and I skipped the gtest arms: the equivalence one already exists there, and a wall-clock scaling assertion tends to be flaky in CI. |
|
Fixing PR for the The ladder had matched the registry error correctly and then run out of budget in 2 seconds: |
…t divisor `BUILDX_RETRIES` was both the attempt cap for the retry ladder and the divisor that sizes each invocation's `timeout` bound, so one number budgeted two error classes whose per-attempt costs differ by three orders of magnitude. Raising the cap shrinks every invocation's bound, which is why it went from 5 to 2 when the `timeout` wrapper was added. At 2 attempts the ladder for a cheap failure spans a single 2s backoff, so one transient registry error consumes the whole budget in 2 seconds. In the report below the `ubuntu:22.04` manifest returned `500 Internal Server Error` twice inside those 2 seconds, having resolved fine four times in the preceding two minutes, and the job then failed holding 17854 of its 18000s unused. Give each class its own bound: BUILDX_RETRIES = 4 attempt cap BUILDX_EXPENSIVE_ATTEMPTS = 2 the only input to the buildx_timeout divisor BUILDX_RETRY_DEADLINE = 30 wall clock the ladder may span `buildx_timeout` now divides by `BUILDX_EXPENSIVE_ATTEMPTS`, which is 2 exactly where `BUILDX_RETRIES` was 2, so it returns the same values as before and the per-invocation bound does not move. The deadline is what holds the expensive class at 2 attempts. It is anchored at the first retryable failure, because an attempt may legitimately run for its whole bound before failing, and enforced twice: once before the sleep against the nominal delay, and once after it by re-reading the clock, since `time.sleep` may return late on a loaded runner. `on_retry` fires after the second check, so it never announces an attempt that is then cancelled. `retry_deadline` is additive on `Shell.run` and `Result.from_commands_run`. Left at `None` the eligibility test reduces to the `retry < retries - 1` the three failure paths already used, and the printed transcript is unchanged. The worst case for one invocation grows by exactly `BUILDX_RETRY_DEADLINE` - 2 = 28s, independently of the bound, so at most 15 * 28 = 420s per job against a `BUILDX_JOB_RESERVE` of 3600s. Related: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=117419&sha=b27939921a57ea5d41e0eb5df09d1acdc4c7266f&name_0=PR&name_1=Docker%20keeper%20image Related: ClickHouse#117419 Related: ClickHouse#113869 Co-Authored-By: Claude Opus 5 <[email protected]>
…uild `test_docker_library` picked images by architecture suffix alone, so a build that had already failed was still handed to the official-images test, which then failed with `image does not exist!`. That is a second red row restating the first, and it fires for any failed build, not just a registry one. Skip the images whose build result is not ok. `Result.is_ok` counts `SKIPPED` and `XFAIL` as ok, so this cannot turn a green job red, and the build's own FAIL row still fails the job. A `SKIPPED` row for the untested image would be invisible in the workflow report anyway, since `Result._flat_failed_leaves` keeps only failing leaves. Related: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=117419&sha=b27939921a57ea5d41e0eb5df09d1acdc4c7266f&name_0=PR&name_1=Docker%20keeper%20image Related: ClickHouse#117419 Co-Authored-By: Claude Opus 5 <[email protected]>
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Mask credentials in the
Settingsmap column ofsystem.query_logandsystem.processes. A URI password in a setting such asformat_avro_schema_registry_urlorurl_base, theX-Amz-*parameters of a presigned URL in a setting such ass3_base, and adisk(...)definition in a custom setting were stored there in plaintext, so a user holding onlySELECT(Settings) ON system.query_logorSELECT ON system.processescould read another user's credential.Description
Requested by @ nikitamikhaylov; the report is not public, so there is no issue to link.
SettingsImpl::dumpToMapColumnandchangedToMapinsert every changed setting's value raw, and three classes carry a credential there:format_avro_schema_registry_urlisDECLARE(URI, ...)andurl_baseisDECLARE(String, ...), so the match is on the value shape, not a setting name.s3_baseis documented to hold that form and reached the map withX-Amz-Signature=...verbatim.SettingFieldCustom::toStringisField::dump, soSET SQL_d = disk(type = 's3', secret_access_key = '...')reached it (the shippedconfig.xmlenablesSQL_).All four loops now use the two scans
FunctionSecretArgumentsFinderalready applies to an S3 URL, pluscustom.toString(/* show_secrets */ false)whenisSecret()holds. A presigned parameter value ends only at&or#, so that scan is sound only on a value that is one whole URL: a scheme, and no whitespace. Anything else is masked in the String leaves of itsField, which keeps a custom setting's quotes and aMapsetting's later entries intact. These maps are display only (four callers, all log elements); the settings wire format and the query-result-cache key are untouched. The first commit makes the parameter scan linear, which the settings path makes reachable per logged query.Known limits:
querycolumn is name-gated byASTSetQuery::hasSecretParts, soSET s3_base = '<presigned>'still shows verbatim in its own row; making that predicate value-shaped would change "is this query secret?" for every query.system.session_log.settings,system.opentelemetry_span_log.attributeandsystem.settings_profile_elements.valuerender values unmasked through three other renderers, andlog_commenthas its own unmasked column.Context, and a secret custom setting shows masked AST text rather than aCustomType_('AST', ...)dump.