Repository navigation
Do not let a setting masking rule throw - #119028
Conversation
The masking rules for `nats_url`, `rabbitmq_address` and `after_processing_move_connection_string` mask the credential inside a URL or a connection string, so they read the value with `safeGet<std::string>`. Masking runs before the setting is validated, so the value need not be a String: `SETTINGS nats_url = 4222` reached the rule and threw `BAD_GET`. The throw escaped `hasSecretParts`/`formatForLogging`, and `executeQueryImpl` then fell back to logging the raw statement text, which put every other credential in the same statement in the server log in cleartext. Writing the port where the URL goes was enough to publish the `nats_password` next to it. A masking rule must not throw. The rules now return `std::optional<std::string>` and the three that need the value as a string read it with `tryGet`, masking nothing when it is not a String. This is the guard `CoreSettings::renderSecretSettingValue` already has for the same reason. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
Workflow [PR], commit [371210c] Summary: ✅
AI ReviewSummaryThis PR fixes the Findings❌ Blockers
Tests
Final VerdictChanges requested. LLVM Coverage ReportMeasured on commit 371210c.
Changed lines: Changed C/C++ lines covered: 23/23 (100.00%) · Uncovered code |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units37 translation units recompiled, 289 s compile time in total, 37 of them have a recent master baseline. |
Cherry pick #119028 to 26.3: Do not let a setting masking rule throw
Cherry pick #119028 to 26.6: Do not let a setting masking rule throw
Cherry pick #119028 to 26.7: Do not let a setting masking rule throw
Backport #119028 to 26.8: Do not let a setting masking rule throw
Backport #119028 to 26.6: Do not let a setting masking rule throw
Backport #119028 to 26.7: Do not let a setting masking rule throw
Backport #119028 to 26.3: Do not let a setting masking rule throw
…)` arguments `key = value` parses into `equals(key, value)`, but `equals` can also be written explicitly with a single argument, e.g. `disk(equals(password))`. Both consumers of `disk(...)` arguments checked only that the argument is an `equals` call with a non-empty argument list and then indexed `children[1]`: - `DiskConfigurationMasker::visit` overwrote `children[1]` with `'[HIDDEN]'` for a secret key. It runs while the query is masked for logging, before the statement is interpreted, so even `SET max_threads = disk(equals(password))` reached it. - `getDiskConfigurationFromASTImpl` read `children[1]` for any key on the `CREATE`/`ATTACH` path. Debug builds abort on the boost bounds assertion, ASan reports a heap-buffer-overflow, and official 26.8/26.9 builds die with a segmentation fault on `CREATE TABLE ... SETTINGS disk = disk(type = 'local', path = 'x/', equals(name))`. The masker now hides every value of a secret key (an explicit `equals(password)` has none); before, it hid only the first value, so `'b'` in `equals(password, 'a', 'b')` was logged. It also no longer throws on an argument that is not `key = value` (a positional value, `equals()`, a key that is not an identifier) and hides such an argument whole instead. The throw happened while the query was masked for logging, so the whole query was logged unmasked, with every other secret in it, as ClickHouse#119028 fixed for the setting masking rules. The disk configuration parser rejects all of these arguments, and now also a key without a value, with `BAD_ARGUMENTS`. Extra values stay accepted and ignored, as in released versions, so table definitions stored with them keep loading. Because extra values stay accepted, `ServerCredentialMarkerInjector` now strips a user-supplied `_server_credentials_allowed` marker with extra values as well. It stripped only the two-argument form, while the parser honors the marker's first value, so `equals(_server_credentials_allowed, 1, 'x')` was stored and exempted the disk from the S3 credential restriction on reload. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Closes: #118950
Related: #117523
Follow-up to #117523.
The masking rules for
nats_url,rabbitmq_addressandafter_processing_move_connection_stringmask the credential inside a URL or a connection string, so they read the value withsafeGet<std::string>. Masking runs before the setting is validated, so the value need not be aString:SETTINGS nats_url = 4222reached the rule and threwBAD_GET.The throw escaped
hasSecretParts/formatForLogging, andexecuteQueryImplthen fell back to logging the raw statement text. That put every other credential in the same statement into the server log in cleartext, so writing the port where the URL goes was enough to publish thenats_passwordnext to it:Both statements fail, but the second one leaves
nats_password = 'hunter2'insystem.query_log.queryand in the server log, while the first one correctly storesnats_password = '[HIDDEN]'.A masking rule must not throw. The rules now return
std::optional<std::string>, and the three that need the value as a string read it withtryGetand mask nothing when it is not aString. This is the guardCoreSettings::renderSecretSettingValuealready has, for exactly this reason. The rules that hide the value whole are unchanged, so a non-Stringvalue for them is still masked.Also checked, and clean:
FunctionSecretArgumentsFinderAST::tryGetStringalready checks the field type beforesafeGet;ASTSettingsProfileElementroutes through the guarded core function;ASTAuthenticationData::hasSecretPartsdecides from the authentication type without reading a value; dictionarySOURCE(...)masking is keyed on the argument name. Two sweeps found no remaining leak: 30 masked setting names against 10 value types, and 18 table function shapes with wrong types,NULLand non-literal arguments.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
...
Workflow [PR]
Sync PR [sync-upstream/pr/119028]
Version info
26.9.1.1116(included in26.9and later)26.8.3.93,26.7.7.81,26.6.5.110,26.3.33.60