Skip to content

Mask secrets in the Settings map of system.query_log and system.processes - #117419

Closed
groeneai wants to merge 6 commits into
ClickHouse:masterfrom
groeneai:mask-secrets-in-settings-map
Closed

groeneai wants to merge 6 commits into
ClickHouse:masterfrom
groeneai:mask-secrets-in-settings-map

Conversation

@groeneai

@groeneai groeneai commented Aug 31, 2026 •

Copy link
Copy Markdown
Collaborator

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

Mask credentials in the Settings map column of system.query_log and system.processes. A URI password in a setting such as format_avro_schema_registry_url or url_base, the X-Amz-* parameters of a presigned URL in a setting such as s3_base, and a disk(...) definition in a custom setting were stored there in plaintext, so a user holding only SELECT(Settings) ON system.query_log or SELECT ON system.processes could read another user's credential.

Description

Requested by @ nikitamikhaylov; the report is not public, so there is no issue to link.

SettingsImpl::dumpToMapColumn and changedToMap insert every changed setting's value raw, and three classes carry a credential there:

  • a URI password: format_avro_schema_registry_url is DECLARE(URI, ...) and url_base is DECLARE(String, ...), so the match is on the value shape, not a setting name.
  • a presigned URL, whose credential sits in the query parameters: s3_base is documented to hold that form and reached the map with X-Amz-Signature=... verbatim.
  • a custom setting: SettingFieldCustom::toString is Field::dump, so SET SQL_d = disk(type = 's3', secret_access_key = '...') reached it (the shipped config.xml enables SQL_).

All four loops now use the two scans FunctionSecretArgumentsFinder already applies to an S3 URL, plus custom.toString(/* show_secrets */ false) when isSecret() 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 its Field, which keeps a custom setting's quotes and a Map setting'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:

  • the query column is name-gated by ASTSetQuery::hasSecretParts, so SET 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.attribute and system.settings_profile_elements.value render values unmasked through three other renderers, and log_comment has its own unmasked column.
  • masking is unconditional, since these functions have no Context, and a secret custom setting shows masked AST text rather than a CustomType_('AST', ...) dump.

groeneai and others added 4 commits August 31, 2026 15:46
…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]>
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-oranjeai PR origin: delegated from the OranjeAI sibling fleet labels Aug 31, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author
Internal second-model review

Before opening this I ran an independent cold review of the diff plus a second-model review pass,
over three rounds, and adjudicated every finding against the recorded evidence. Verdicts below,
including the ones I disagreed with.

# Finding Verdict
❌ Masking the map runs maskURIPassword on every changed value of every logged query, and on a miss that scan re-walked the same suffix once per ://. One session-scoped SET of a 256 KiB value then made each later query in that session pay it, and a system.processes reader pay it once per live row. Agreed, fixed (second commit). Both misses now leave the loop. Proved output-identical over 4441419 inputs with 0 differences, and the same harness reports 2254 differences for a variant that also leaves on the scheme check, so it can see a regression of this shape. gtest_mask_uri_password, which pins this function against the regular expression it replaced, passes unedited and fails on that variant. End to end: 1043.5 ms to 5.7 ms, against 5.9 ms with no masking at all.
⚠️ Inside maskedCustomSettingValue, the maskURIPassword call on the non-secret path had no observing arm: deleting only that line left every assertion green, while SET SQL_x = 'http://u:pw@h/p' still put the password in both maps. Agreed, fixed. Added a third custom setting carrying a URI password, with one arm per sink. A build with only that line removed now fails exactly those two arms; all four loops have their own witness.
⚠️ The test could not distinguish the shipped design (mask by value shape) from the narrower one it rejects (mask by setting name): both standard arms used format_avro_schema_registry_url, the tree's only DECLARE(URI, ...) setting, so a name-gated build would have kept every assertion green while still leaking url_base. Agreed, fixed. Added url_base arms on both sinks and pinned them with a mutant applying the rejected name-gated design: it reddens the new arms and only those.
❌ maskURIPassword masks only the first credential in a value, so a value holding two credentialed URLs leaves the second in plaintext. Disagreed. Confirmed as a mechanism, but it is the property that defines the parity this change restores: ASTSetQuery masks the same setting with the same primitive and the same first-occurrence-only semantics, so after this change the query column and the Settings map agree byte for byte on such a value. Masking further only in the map would recreate the asymmetry in the opposite direction. Stated as a known limit. (A while (maskURIPassword(&value)) {} loop does not terminate: the next pass takes the : before [HIDDEN] as the separator and replaces [HIDDEN] with itself.)
❌ The same scan can run past the URI authority: http://h:8080/p?c=a@b becomes http://h:[HIDDEN]@b, mangling a value that holds no password. Disagreed for this change. Confirmed by hand, and it is a real limit, so it is stated in the description. It is a defect of the shared primitive's match semantics, which are pinned by a re2-equivalence test across ten call sites, so a fix belongs there and must move all of them together. The second commit deliberately does not touch that: it changes only when the loop exits, which is why the equivalence run above shows zero output differences. A locally bounded variant here is worse, not better: bounding to the authority of the first :// leaves a credentialed URL nested in a query string (x://a/b?u=http://p:q@r) entirely unmasked, trading over-masking of a non-secret for under-masking of a real one. Not asserted in the test either, so the reference does not bake the current behaviour in.
❌ This is a write-time fix, so rows already in system.query_log keep what they stored, and the default configuration sets no TTL. Either sanitize them or add residual-exposure and rotation guidance. Disagreed, happy to be overruled. Both facts confirmed, including that <ttl> is commented out in the shipped config.xml. Sanitizing is out: it would delete or rewrite rows of a user's log table on upgrade, unlogged and with no migration path. Guidance is a judgement I do not think is mine to make here: the five comparable masking fixes in CHANGELOG.md carry none, including the one that masked credentials in the query log itself, and whether an installation should rotate is a call for whoever owns the report rather than something to assert in a patch description. Say the word and I will add it.
💡 Use Critical Bug Fix (crash, data loss, RBAC) rather than Bug Fix. Disagreed, happy to be overruled. Every access check here was honoured: a reader holding SELECT(Settings) ON system.query_log is entitled to that column, and the defect is that the column contained a secret, so the boundary crossed is the secret-display one rather than the grant system. The credential is a third-party registry or object-storage credential and confers no ClickHouse privilege. Retag if you see it the other way.
💡 For a secret custom setting the map value changes shape, from the CustomType_('AST', ...) dump to the bare masked AST text. Accepted as-is. Both maps are display only and nothing parses these values back; Field::restoreFromDump cannot restore a CustomType_(...) dump at all. Stated as a known limit.

One thing my own review caught that this change does not address: these four loops are not the only
place core settings are serialised for a user-readable sink. The others go through different
serialisers in different files and each needs its own reproducer, so folding them in would make one
change carry several unrelated root causes. They are being handled separately.

@clickhouse-gh

clickhouse-gh Bot commented Aug 31, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [b279399]

Summary: ❌

job_name test_name status info comment
Docker keeper image FAIL
clickhouse/clickhouse-keeper:head-distroless-amd64 FAIL cidb
docker library image test (clickhouse/clickhouse-keeper:head-distroless-amd64) FAIL cidb
Docs examples FAIL
Documentation examples FAIL cidb
Finish Workflow FAIL
python3 ./ci/jobs/scripts/workflow_hooks/new_tests_check.py FAIL
Bugfix validation (functional tests, amd64) ERROR
Bugfix validation (functional tests, aarch64) ERROR
Integration tests (amd_asan_ubsan, db disk, old analyzer, 6/6) ERROR
Container memory budget exceeded (/docker) ERROR cidb

AI Review

Summary

This PR extends secret masking for the Settings map exposed through system.query_log and system.processes: it now covers URI passwords, presigned X-Amz-* query parameters on whole-URL values, and nested custom / Map-typed carriers that are re-serialized for display. After checking the current diff, the touched callers, and the existing review thread, I did not find any remaining correctness or security issue strong enough to block merge.

Final Verdict

✅ No new findings. The earlier s3_base settings-map leak reported on this PR is fixed in the current head, so I resolved that thread and did not post a new batched inline review.

LLVM Coverage Report

⚠️ No coverage measurement for commit b279399: incomplete coverage measurement: 1 of 21 shard profiles are missing: LLVM_COVERAGE_FILE_it_7.profdata.

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Aug 31, 2026
Comment thread src/Core/Settings.cpp Resolved
@clickhouse-gh

clickhouse-gh Bot commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing b27939921 with master 38a9ca207 (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of 9f35a2b2a; 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

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

Job report

groeneai and others added 2 commits September 1, 2026 04:52
`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]>
@groeneai

groeneai commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator Author

Internal review and validation for b279399

Two commits added: e31fd36 makes the presigned parameter scan linear, b279399 masks presigned
parameters in the Settings map. Description and changelog entry updated; the entry no longer claims
parity with the query column, which does not hold for s3_base.

Internal second-model review, 3 rounds. Findings and how each was handled:

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 -j8 runs, 100/100. The
    18 reference lines this PR already had are byte-identical.
  • 11 unit tests: MaskURIPassword 4/4 and MaskS3URLCredentials 3/3 unedited, including the arms
    that fuzz these scans against the regular expressions they replaced, plus the 4 new ones.
  • e31fd36 is 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"*n at 261,600 bytes: 45.0 ms to 0.28 ms.
  • accessor.valueToStringUtil was measured byte-identical to getValueString for both Map
    settings including an empty value, with a control showing the comparison can report a difference.
  • ci/jobs/scripts/check_style/various_checks.sh and check_cpp.sh clean, 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

@groeneai

groeneai commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - b279399

Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
whose fixing-PR link will be posted here when it opens.

Check / test Reason Owner / fixing PR
Bugfix validation (functional tests, amd64) not a validation verdict: the job aborted before it ran anything, on assert build_urls, "Could not find master builds in S3" (ci/jobs/functional_tests.py:734) #117433 (mine, open)
Bugfix validation (functional tests, aarch64) same Could not find master builds in S3 abort as the row above #117433 (mine, open)
Finish Workflow / Post Hooks (new_tests_check.py) cascade of the two rows above: the hook reds when no per-arch bugfix job reports OK or XFAIL, and its own output quotes both aborts verbatim #117433 (mine, open)
Docs examples / Documentation examples trunk bug, not this PR: the toYYYYMM doc example asserts a hardcoded 202608, so it reds on every tree since the Sept 1 US/Eastern month rollover (77 rows across 74 distinct PRs in 30d, none before 2026-09-01 04:10:16Z) #117459 (mine, open)
Integration tests (amd_asan_ubsan, db disk, old analyzer, 6/6) / Container memory budget exceeded (/docker) infra capacity, not this PR: the unreclaimable /docker cgroup leaf is sized after the other two, so the kernel kills processes inside it and the job errors with no test attributed #117412 (external, merged 2026-09-01T11:31:33Z)
Docker keeper image / clickhouse/clickhouse-keeper:head-distroless-amd64 transient docker.io registry error, not this PR: HEAD https://registry-1.docker.io/v2/library/ubuntu/manifests/22.04 returned 500, and the buildx retry ladder matched the error but spent both of its attempts in 2 seconds (09:25:16 to 09:25:18). Signature is 3 rows over 3 unrelated carriers in 30d, 0 on master a fix task is created (investigating at full effort, fixing-PR link to follow here)
Docker keeper image / docker library image test (clickhouse/clickhouse-keeper:head-distroless-amd64) fallout of the row above: the image was never built, so the library image test reports image does not exist! the same fix task is created for both rows (fixing-PR link to follow here)

Two notes on the /docker row, so no later run re-derives it. Its owner #117412 merged about two
hours AFTER this job ran, so the failing tree predates the fix rather than failing with it present
(compare reports diverged, and the symbol the fix introduces is absent from this head against a
passing positive control at the fix commit). I am deliberately not merging master to pick it up: two
of the rows above are owned by PRs that are still open, so a fresh run would red on them again and the
merge would cost a maintainer a workflow approval for no new signal. The earlier candidate #117411 is
closed unmerged, so it is not cited as the owner.

None of these failures is caused by this PR, whose diff is src/Common/maskURIPassword.h,
src/Core/Settings.cpp, one gtest and one stateless test.

Session id: cron:our-pr-ci-monitor:20260901-113000

@Algunenano

Copy link
Copy Markdown
Member

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:

  • Presigned URLs. s3_base is documented to hold that form, and the X-Amz-* parameters were reaching the logs intact. Mask credentials in setting values in logs and system tables #117523 now masks both the userinfo and the presigned parameters. It also masks them in the query column, which this PR lists as a known limit.
  • A secret disk(...) in a custom setting, via custom.toString(/* show_secrets */ false) when isSecret() holds.

What #117523 additionally covers, most of it listed as a known limit here:

  • system.session_log.settings, system.opentelemetry_span_log, system.settings_profile_elements.value, system.settings, query_log.formatted_query, SHOW CREATE USER / SHOW CREATE SETTINGS PROFILE, and the changed-settings line the fatal signal handler writes.
  • system.distributed_ddl_queue, where both the statement and its settings were returned verbatim, so a CREATE ... ON CLUSTER carrying a credential handed it to anyone with SELECT on that table.
  • ALTER TABLE t MODIFY SETTING kafka_sasl_password = '...', which wrote the password to system.query_log.query in cleartext while SHOW CREATE TABLE masked it. hasSecretParts checks the per-engine SETTINGS_TO_HIDE maps ungated, but formatImpl only consulted them when FormatStateStacked::create_engine_name matched, and the MODIFY SETTING path never sets it.
  • Masking is optional wherever the reader is known, gated like SHOW CREATE TABLE on the display_secrets_in_show_and_select server setting, the format_display_secrets_in_show_and_select format setting and the displaySecretsInShowAndSelect grant, so an operator who is allowed to see a secret still can.

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 SETTINGS_TO_HIDE map keyed by setting name with a per-setting masking function, as in Kafka_fwd.h, NATS_fwd.h, RabbitMQ_fwd.h, S3Queue_fwd.h, AzureQueue_fwd.h and DataLakeConstants.h. That keeps one answer to "which settings are secret" for both the query text and the value sinks; the divergence between the two is what the MODIFY SETTING bug above was. It also removes the need for the isOneWholeURL guard, since a name-keyed list only applies the parameter scan to settings that hold one whole URL, so the precondition holds by construction.

Two things from here worth keeping and not yet ported, happy to do either as a follow-up: the linearity fix to maskPresignedURLParameters, and the gtest.

@Algunenano Algunenano closed this Sep 1, 2026
@groeneai

groeneai commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator Author

Thanks for the credit. Both leftovers are still absent from #117523, and the linearity one now has a reason to be there: SettingsSecrets.h inherits maskPresignedURLParameters unchanged, and that helper is quadratic in two independent ways.

It looks for each parameter's = across the whole remaining string, so "&" * n + "=" costs 62.8 ms at 256 KiB, and it replaces each value in place, so "&Signature=x" * n costs 44.9 ms at 261,600 bytes, which is within DBMS_DEFAULT_MAX_QUERY_SIZE. One SET s3_base of such a value then makes every sink you route through maskURLCredentials pay it: I measured a bare SELECT 1 in that session at 47.6 ms against a 2.0 ms baseline, and 2.9 ms with the name scan bounded at the first separator and the result built in one pass. Old and new bodies agree on output and return value over 7,092,445 inputs, a control body carrying a real regression differs on 541,891 of them, and gtest_mask_uri_password passes unedited.

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 maskPresignedURLParameters in gtest_mask_uri_password instead, which is where that helper's coverage already lives.

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.

Algunenano added a commit to Algunenano/ClickHouse that referenced this pull request Sep 1, 2026
`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]>
@Algunenano

Copy link
Copy Markdown
Member

Carried the linear rewrite in #117523, credited to you: measured 83.7 ms down to 2.9 ms at 120 KB, and gtest_mask_uri_password passes unedited. No need for a follow-up PR on your side.

I skipped the gtest arms: the equivalence one already exists there, and a wall-clock scaling assertion tends to be flaky in CI.

@groeneai

groeneai commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator Author

Fixing PR for the Docker keeper image ledger line (both rows, the distroless leg and its library image test): #117578

The ladder had matched the registry error correctly and then run out of budget in 2 seconds: BUILDX_RETRIES was simultaneously the attempt cap and the divisor sizing each invocation's timeout, so one number budgeted a 1 second registry error and a 2700 second mirror wedge alike. #117578 splits that into three constants and adds a wall-clock deadline.

pull Bot pushed a commit to admariner/ClickHouse that referenced this pull request Sep 13, 2026
…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]>
pull Bot pushed a commit to admariner/ClickHouse that referenced this pull request Sep 13, 2026
…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]>
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 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.

3 participants