Repository navigation
Hide secret MongoDB connection options in SHOW CREATE, query_log and system.dictionaries - #123240
Conversation
…system.dictionaries The values of `tlsCertificateKeyFilePassword`, `sslClientCertificateKeyPassword` and `authMechanismProperties` were printed as written wherever ClickHouse shows a MongoDB connection string or option list: every MongoDB display site masked only the URI password (`maskURIPassword`), and `MongoDBDictionarySource::toString` masked nothing, password included. `ASTPair::hasSecretParts` did not report `uri`/`options`, so a `CREATE DICTIONARY` was logged unformatted and the `ASTPair` masking never reached `query_log`. `maskMongoDBConnectionString` reads the option grammar the way the driver does (`_mongoc_uri_apply_query_string`: split on '&', name before the first '=', compared case-insensitively and not percent-decoded) and hides the secret option values together with the password range of `maskURIPassword`. Both ranges are located in the original string and hidden as their union: the driver allows '?', '=' and '&' in a password, and an '@' in an option value moves the end of the userinfo that `maskURIPassword` finds, so running two scans one after the other leaks whichever runs second. `maskURIPassword` keeps its exact behaviour: its scan moved into `findURIPasswordRange`, which the re2 comparison gtest guards. Sites: - `ASTPair::formatImpl` masks the raw `uri`/`options` value and prints it through a new literal or identifier, so quoting is unchanged; any other value is an expression that is evaluated only after the query is logged, so it is hidden whole. - `MongoDBDictionarySource::toString` masks the URI it shows. - `findMongoDBSecretArguments` masks its legacy replacement with the new function, and a new `findMongoDBConnectionStringSecretArguments`, called after it, covers the argument roles that carry a connection string or an option list: argument 0, the positional `options`, the named `uri`/`options` overrides (key read case-insensitively; a key that is an expression can name `options`, so such an argument is hidden whole), and any positional after a named argument. It never overrides an argument already masked, and hides through `replaced_arguments` because the named-collection `uri` override sets `result.replacement`. Related: ClickHouse#120407 (comment) Co-Authored-By: Claude Opus 5.5 <[email protected]>
When an argument before it is missing, the mongodb() table function binds a named oid_columns to the options slot, which is appended to the connection URI, so its secret options were shown as written in query_log and SHOW CREATE. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…gument The mongodb() table function appends options and oid_columns to the positionals before index 5, so a named argument there can move a plain password into the user or password slot. In that case the named options and oid_columns and every positional after structure are hidden whole; this replaces the oid_columns key term. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Condense the maskMongoDBConnectionString doc and the replaced_arguments note; drop two comments that narrate the code. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 3 findings over three rounds, the last one clean) plus my own review (nits only).
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-8:20261001-104900 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-7:20261001-075800 |
|
Workflow [PR], commit [45c755c] Summary: ✅
AI ReviewSummaryThis PR adds Findings
Final Verdict❌ Changes requested — the direct LLVM Coverage ReportMeasured on commit 45c755c.
Changed lines: Changed C/C++ lines covered: 160/165 (96.97%) · Uncovered code |
…roperties `findMongoDBSecretArguments` put the masked `uri` override of a named collection at index 1, so in `MongoDB(nc, collection = 'c2', uri = '...')` the display overwrote `collection` with the URI, and on master (and 26.8.10.6) printed the `uri` override itself unmasked. Use the index `findNamedArgument` returns. `authMechanismProperties` was hidden whole. The driver accepts seven properties and only `AWS_SESSION_TOKEN` is a secret, so hide the value of every property except the six public ones (`SERVICE_NAME`, `CANONICALIZE_HOST_NAME`, `SERVICE_REALM`, `SERVICE_HOST`, `ENVIRONMENT`, `TOKEN_RESOURCE`, case-insensitive like the driver), an entry without a colon whole, and the whole option when it contains '%', since the driver percent-decodes the value before splitting it on ',' and ':'. Both raised by the AI review on ClickHouse#123240. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Only `key = value` overrides may follow the collection name in `MongoDB(nc, ...)` and `mongodb(nc, ...)`. `tryGetNamedCollectionWithOverrides` rejects a literal positional there (and ignores a function one), but only after the statement has been formatted for `system.query_log`, so `MongoDB(nc, 'mongodb://usr:pw@host/db?tlsCertificateKeyFilePassword=x')` was logged verbatim. Hide such positionals whole, as `findS3NamedCollectionSecretArguments` does for S3. Rows e10 (engine, URI before any override) and f09 (table function, bare secret after an override) fail on the previous head and pass with this change. Co-Authored-By: Claude Opus 5.5 <[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 (+79.44 KiB total), 0 added.
719 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 units30 translation units recompiled, 139 s compile time in total, 30 of them have a recent master baseline. |
|
@groeneai, fix conflicts. |
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]>
|
Merged master in 45c755c. The conflict was with #122770's rewrite of |
`check_named_collection_dependencies` makes `DROP NAMED COLLECTION` throw `NAMED_COLLECTION_IS_USED` only for tables that registered a dependency, and a table engine registers by passing its `StorageID` to `tryGetNamedCollectionWithOverrides`. `StorageMongoDB`'s `getConfigurationImpl` had `table_id` in scope but did not pass it: ClickHouse#96181 added the argument in 2311e59, and its branch merge 468aaca with ClickHouse#89616 (which rewrote the function) kept master's line without it. Every other table engine passes its id. So the drop succeeded under a live MongoDB table, the table could not be attached on the next restart (669), its database became unusable, and with `async_load_databases = 0` the server did not start. The new line is identical to the hunk in ClickHouse#112805. `05315_mongodb_connection_options_secrets` (ClickHouse#123240) dropped its two collections while `e06`, `e07` and `e08` still used them. Stateless CI drops the test database, but Stress keeps it and restarts the server, so master Stress jobs failed with `Cannot start clickhouse-server`. The test now expects the drop to be refused while the tables exist, drops the tables first, and pins `ast_fuzzer_any_query = 0` on every statement that names a collection: the stress profile fuzzes DDL, and a fuzzed `DETACH` of such a table hides it from the catalog, so its dependency is pruned and the collection drop succeeds (the generic detached-table hole, ClickHouse#121519); `__fuzz_N` clones would otherwise also hold the collection and make the final drop fail. Not changed: table functions (`CREATE TABLE ... AS mongodb(nc)`) register no dependency for any engine except `bigquery`; the experimental `MaterializedPostgreSQL` engine has the same omission. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
The values of MongoDB connection options that carry a secret (
tlsCertificateKeyFilePassword,sslClientCertificateKeyPassword,AWS_SESSION_TOKENinauthMechanismProperties) are now hidden inSHOW CREATE,system.query_logandsystem.dictionaries.sourcefor theMongoDBtable engine, themongodbtable function and the MongoDB dictionary source,system.dictionaries.sourceno longer shows the MongoDB password, and a named-collectionurioverride after another override is no longer shown as written.Description
Related: #120407 (asked in #120407 (comment)).
On 26.8.10.6,
SHOW CREATE,system.query_logandsystem.dictionaries.sourceprint the value of a MongoDB connection option that carries a secret, such astlsCertificateKeyFilePassword, given in a URI or inoptions, andsystem.dictionaries.sourcealso prints the password.Every MongoDB display site masked only the URI password, and
ASTPair::hasSecretPartsdid not reporturi/options, so aCREATE DICTIONARYreachedquery_logas written.Change:
maskMongoDBConnectionStringhides the values of those three options together with the passwordmaskURIPasswordfinds.URI/OPTIONS,MongoDBDictionarySource::toString, and the engine and table function arguments that carry a URI or an option list. A value that is an expression is hidden whole, and so are the table function'soptions/oid_columnswhen a named argument before the fifth positional one moves them into the password slot.ASTPair::hasSecretPartsreportsuriandoptions.urioverride is masked at its own index; it was masked into the argument at index 1 and printed as written (also on 26.8.10.6). A positional after the collection name is hidden whole: it is rejected or ignored only after logging.In
authMechanismPropertiesthe six properties the driver accepts besidesAWS_SESSION_TOKENstay visible; any other value, and a percent-encoded list, is hidden.With #120407, its userinfo rule for these sites would move into
maskMongoDBConnectionString; note thatmaskURIUserinfodoes not hide a MongoDB password containing?or#. The merge with #122770 masks the URI in itsfindMongoDBSecretArgumentswithmaskMongoDBConnectionString; #121466 needs the same if it merges later (the password rows catch it).Test:
05315_mongodb_connection_options_secretsfails on master and passes here.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/123240]
Version info
26.10.1.1312-master(included in26.10and later)