Repository navigation
Fix credential leak when a named argument precedes positional ones in engines and table functions - #122770
Conversation
…t secret finders A `key = value` argument written before the positional ones shifts them by one, but seven finders masked a fixed raw index, so the password was logged in cleartext and `[HIDDEN]` landed on a neighbouring argument (`mongodb`, `redis`, `remote`, `ArrowFlight`, `ExternalDistributed`, `YTsaurus`, `Redis`). Run the fail-closed classification once, before any table function, table engine or database engine finder: every positional after the first named argument is hidden. Replace the fixed-slot finders by one signature-driven `findPositionalAndNamedSecretArguments`, which also hides the values of unreadable `key = value` overrides for every such engine. Co-Authored-By: Claude Fable 5.1 <[email protected]>
|
Workflow [PR], commit [9444a54] Summary: ❌
AI ReviewSummaryThis PR centralizes the fail-closed masking for secret-bearing engine and table-function arguments when a named argument appears before later positionals, and it extends the coverage to the Final Verdict✅ No new review findings. LLVM Coverage ReportMeasured on commit 9444a54.
Changed lines: Changed C/C++ lines covered: 160/160 (100.00%) · Uncovered code |
The explicit form constant-folds its positionals, so
`Redis('host:port', 0, 'password' = 'x')` is valid and carries the secret
as the left operand of the `equals` at the password slot.
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes8 object files changed (+37.59 KiB total), 0 added.
716 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units14 translation units recompiled, 54 s compile time in total, 14 of them have a recent master baseline. |
An identifier first argument does not prove a named collection (`redis(localhost, ...)`), so an `equals` at the secret slot is now hidden whole unless its left operand is an identifier, which does not fold. `remote`/`Remote` read `password` only after an identifier and never hid an override with an unreadable key; both scans now start at index 0. Co-Authored-By: Claude Opus 5.5 <[email protected]>
It reads the same as a named password written in the wrong place, so it is hidden even where it could be a sharding key. Co-Authored-By: Claude Opus 5.5 <[email protected]>
alexey-milovidov
left a comment
There was a problem hiding this comment.
Ok.
FunctionsSecretArgumentsFinder is a design mistake.
The logic should be encapsulated inside each table function.
I couldn't agree more. Each function or table function should know and handle its own secrets, with common helpers if possible. I've discussed it with Claude and create a proposal that makes sense and should avoid bloating the parser: #123315 |
Resolve the conflict with ClickHouse#122770, which rewrote findMongoDBSecretArguments and moved the per-engine finders into std::function dispatch. - findMongoDBSecretArguments is master's version, with maskURIPassword replaced by maskMongoDBConnectionString for the first argument and every `uri` override, so an argument it rewrites keeps no secret option. - findMongoDBConnectionStringSecretArguments still runs after it, now from both `find_secrets` lambdas. Its first-argument branch hides an unreadable value: master already hides a computed first argument whole. - 05315: the positionals after a named argument (f06, f07, f08) are now hidden by master's classifyPositionalArguments, and an unreadable key (e07) keeps the key and hides the value, as master does for other engines. - 05258: the collection argument after a backquoted URI identifier is hidden, since this PR hides every positional after a named-collection identifier. The statement is rejected as an unknown named collection either way. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Backport #122770 to 26.9: Fix credential leak when a named argument precedes positional ones in engines and table functions
Backport #122770 to 26.8: Fix credential leak when a named argument precedes positional ones in engines and table functions
Cherry pick #122770 to 26.3: Fix credential leak when a named argument precedes positional ones in engines and table functions
…recedes positional ones in engines and table functions
Cherry pick #122770 to 26.7: Fix credential leak when a named argument precedes positional ones in engines and table functions
…recedes positional ones in engines and table functions
Backport #122770 to 26.3: Fix credential leak when a named argument precedes positional ones in engines and table functions
Backport #122770 to 26.7: Fix credential leak when a named argument precedes positional ones in engines and table functions
…ats test The backport of ClickHouse#122770 refactored findTableEngineSecretArguments() to dispatch through a std::function find_secrets, but the Iceberg branch kept calling findIcebergTableEngineSecretArguments() directly without assigning find_secrets and without returning. Execution then fell through to the trailing find_secrets() call with an empty std::function, so masking any CREATE TABLE ... ENGINE=Iceberg(...) (via hasSecretParts() during query logging) threw std::bad_function_call. Assign the lambda like every sibling branch so classifyPositionalArguments() still runs before it. This crashed test_storage_iceberg_disks in integration tests. The upstream 26.8.27 merge moved Iceberg data-file column sizes from an in-memory byteSize() estimate in update() to the real on-disk sizes reported by the output format at finalize() (addColumnSizesOnDisk()). The gtest still expected update() alone to populate column sizes, so getColumnSizes() was empty. Populate sizes via addColumnSizesOnDisk() to match the new design (addColumnSizesOnDisk uses +=, so restoring byteSize() in update() would double-count). Co-Authored-By: Claude Opus 4.8 <[email protected]> Signed-off-by: blau-ai <[email protected]>
Backport ClickHouse#122770 added a generic fail-closed pass, classifyPositionalArguments(), run before each engine/function's own finder: it hides every positional argument that appears after the first `key = value` argument. The Altinity-only `storage_type = ...` argument of the Iceberg engine and table function is exactly such a leading named argument, so for Iceberg(storage_type = 's3', <url>, <access_key>, <secret>) the generic pass marked <url>, <access_key> AND <secret> as secret before the Iceberg finder (which skips storage_type and delegates to the S3/Azure finder) could classify them, producing Iceberg(storage_type = 's3', '[HIDDEN]', '[HIDDEN]', '[HIDDEN]') instead of hiding only the secret. Bypass the generic pass for Iceberg by returning right after its finder, exactly as BigQuery already does; the Iceberg finder skips storage_type and delegates to findS3*/findAzure*, which run their own positional-after-named fail-close (classifyS3Arguments), so the security property is preserved. The database-engine Iceberg path uses a different finder (findDataLakeCatalogSecretArguments) and is left unchanged. Fixes test_mask_sensitive_info/test.py::test_create_table and ::test_table_functions. Validated by CI on this PR, not locally (no build in this environment). Signed-off-by: blau-ai <[email protected]> Co-Authored-By: Claude Opus 4.8 <[email protected]>
After merging master, the `extra_credentials` arms of `05291_azure_blob_storage_partition_strategy_key_value` failed for two reasons that have nothing to do with the key-value arguments: - Since 3b7f7be a user query may use the server's workload identity only with `s3_allow_server_credentials_in_user_queries = 1`; without it the initiator answers `ACCESS_DENIED` before rewriting the arguments (05218 enables the setting the same way). - Since ClickHouse#122770 the query log shows `extra_credentials(...)` as '[HIDDEN]', so the old `LIKE '%extra_credentials(client_id%'` oracle matched nothing. Enable the setting for the cluster arms, and make the oracle match the forwarded arguments ending in `partition_strategy = 'none', '[HIDDEN]')`: the key-value arguments first, then `extra_credentials`. Swapping that order in the rewrite turns the result from 3 into 0. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Port of #123651 onto the 26.3 secret arguments finder. The Azure rules it changes live in src/Parsers/FunctionSecretArgumentsFinder.cpp here (#123364 moved them to src/Storages/ObjectStorage/Azure/AzureSecretArguments.cpp on master and is not on 26.3), so they are ported as member functions, with the slot counting of #123364 they build on: the SETTINGS clause, extra_credentials(...) and key = value arguments take no positional slot, and a positional argument after a named collection is hidden. 26.3 also lacks two pieces 26.8 and 26.9 have from the backport of #122770, which the slot counting needs: AbstractFunction::Argument::isSettings(), and hiding a positional argument written after a key = value one (called from the two Azure rules only). The connection string regular expressions of the finder and of AzureQueue are replaced by maskAzureConnectionStringSecrets. 05316_secret_arguments_declared_by_engines does not exist on 26.3, so its Azure lines are a new test, 05458_azure_credentials_hidden_in_logged_queries. test_allowed_url_from_config has no test_rejected_url_credentials_masked here and test_backup_restore_azure_blob_storage has no node_legacy_native_copy, so those hunks are dropped. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Related: #121425
Related: #121467
A
key = valueargument written before the positional arguments of an engine or table function shifts every later positional by one, but seven secret finders masked a fixed raw index, so the password itself was written in cleartext tosystem.query_logwhile[HIDDEN]landed on a neighbouring argument:SELECT * FROM mongodb(foo = 1, '127.0.0.1:27017', 'db', 'coll', 'user', 'PASSWORD')was logged asmongodb(foo = 1, '127.0.0.1:27017', 'db', 'coll', '[HIDDEN]', 'PASSWORD'). Affected:mongodb/MongoDB,redis/Redis,remote/remoteSecure/Remote,ArrowFlight,ExternalDistributed,YTsaurus. The statement is formatted for logging before validation rejects it, so the leak does not require a valid query. #121425 fixed the same shape formysql/postgresqlonly.Instead of patching seven finders, the fail-closed rule now runs once before any table function, table engine or database engine finder: every positional argument after the first named one is hidden (the intended slot is unknowable at that point).
encrypt/HMAC(expression arguments) andbigquery(interleaving is valid and modelled) are exempt. The eight fixed-slot finders are replaced by a single signature-drivenfindPositionalAndNamedSecretArguments, so each engine is one line declaring its secret slot and its secret keys; it also hides the value of anykey = valueoverride whose key is not a plain literal, whichRedis,ArrowFlight,YTsaurus,MongoDBandKafkadid not do. TheMongoDBuri handling is reworked on the way: a namedurinot at index 1, auribeside apassword, and the 3/4-argument uri forms were not masked either. Whole-argument masks now take precedence over partial ones in the formatter (urlCluster(foo = 1, url)hides the url whole), and aSETTINGSclause among the arguments is no longer counted as a positional.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix a credential written in cleartext to
system.query_logand the server log when akey = valueargument precedes the positional arguments of themongodb,redis,remote,arrowFlightandytsaurustable functions or theMongoDB,Redis,Remote,ArrowFlight,ExternalDistributedandYTsaurustable engines. A positional argument after a named one is now always hidden, and the value of a named-collection override whose key is written as an expression is hidden for every such engine.Workflow [PR]
Sync PR [sync-upstream/pr/122770]
Version info
26.10.1.1216-master(included in26.10and later)26.9.18.14,26.8.26.14,26.7.30.7,26.3.51.5