Skip to content

Fix credential leak when a named argument precedes positional ones in engines and table functions - #122770

Merged
Algunenano merged 5 commits into
ClickHouse:masterfrom
Algunenano:secret-arguments-unify
Oct 1, 2026
Merged

Algunenano merged 5 commits into
ClickHouse:masterfrom
Algunenano:secret-arguments-unify

Conversation

@Algunenano

@Algunenano Algunenano commented Sep 28, 2026 •

Copy link
Copy Markdown
Member

Related: #121425
Related: #121467

A key = value argument 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 to system.query_log while [HIDDEN] landed on a neighbouring argument: SELECT * FROM mongodb(foo = 1, '127.0.0.1:27017', 'db', 'coll', 'user', 'PASSWORD') was logged as mongodb(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 for mysql/postgresql only.

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) and bigquery (interleaving is valid and modelled) are exempt. The eight fixed-slot finders are replaced by a single signature-driven findPositionalAndNamedSecretArguments, so each engine is one line declaring its secret slot and its secret keys; it also hides the value of any key = value override whose key is not a plain literal, which Redis, ArrowFlight, YTsaurus, MongoDB and Kafka did not do. The MongoDB uri handling is reworked on the way: a named uri not at index 1, a uri beside a password, 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 a SETTINGS clause among the arguments is no longer counted as a positional.

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

Fix a credential written in cleartext to system.query_log and the server log when a key = value argument precedes the positional arguments of the mongodb, redis, remote, arrowFlight and ytsaurus table functions or the MongoDB, Redis, Remote, ArrowFlight, ExternalDistributed and YTsaurus table 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

  • Merged into: 26.10.1.1216-master (included in 26.10 and later)
  • Backported to: 26.9.18.14, 26.8.26.14, 26.7.30.7, 26.3.51.5

…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]>
@clickhouse-gh

clickhouse-gh Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [9444a54]

Summary: ❌

job_name test_name status info comment
Integration tests (amd_llvm_coverage, 1/8) FAIL
test_storage_iceberg_no_spark/test_iceberg_inverted_manifest_bounds.py::test_iceberg_narrow_manifest_bounds FAIL cidb IGNORED

AI Review

Summary

This 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 mongodb, redis, remote, ArrowFlight, YTsaurus, and related engine variants. I did not find any remaining correctness or secret-leak issues in the current diff; the previously reported identifier-first hole is fixed in the current code, and the new functional coverage matches the changed masking paths.

Final Verdict

✅ No new review findings.

LLVM Coverage Report

Measured on commit 9444a54.

Metric Baseline Current Δ
Lines 88.20% 88.20% +0.00%
Functions 91.80% 91.80% +0.00%
Branches 79.60% 79.60% +0.00%

Changed lines: Changed C/C++ lines covered: 160/160 (100.00%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Sep 28, 2026
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]>
@clickhouse-gh clickhouse-gh Bot added the comp-sql-syntax SQL/grammar parsing, AST nodes, syntax-level features. label Sep 28, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 9444a547a with master 92b13954a (stripped binary size, per-symbol sizes and ThinLTO time; 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.

Object file sizes

8 object files changed (+37.59 KiB total), 0 added.

Object file Master PR Δ
src/Parsers/CMakeFiles/clickhouse_parsers.dir/FunctionSecretArgumentsFinder.cpp.o 163.24 KiB 199.21 KiB +35.98 KiB (+22.04%)

716 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.

Compile time of recompiled translation units

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

Job report

Algunenano and others added 2 commits September 29, 2026 12:19
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 alexey-milovidov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok.

FunctionsSecretArgumentsFinder is a design mistake.
The logic should be encapsulated inside each table function.

@alexey-milovidov alexey-milovidov self-assigned this Oct 1, 2026
@Algunenano

Algunenano commented Oct 1, 2026 •

Copy link
Copy Markdown
Member Author

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

Merged via the queue into ClickHouse:master with commit 8114534 Oct 1, 2026
@Algunenano
Algunenano deleted the secret-arguments-unify branch October 1, 2026 21:47
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 1, 2026
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Oct 1, 2026
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]>
@Algunenano Algunenano added the pr-must-backport Pull request should be backported intentionally. Use this label with great care! label Oct 13, 2026
@robot-clickhouse robot-clickhouse added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Oct 13, 2026
clickhouse-gh Bot added a commit that referenced this pull request Oct 13, 2026
Backport #122770 to 26.9: Fix credential leak when a named argument precedes positional ones in engines and table functions
clickhouse-gh Bot added a commit that referenced this pull request Oct 13, 2026
Backport #122770 to 26.8: Fix credential leak when a named argument precedes positional ones in engines and table functions
robot-ch-test-poll4 added a commit that referenced this pull request Oct 13, 2026
Cherry pick #122770 to 26.3: Fix credential leak when a named argument precedes positional ones in engines and table functions
robot-clickhouse added a commit that referenced this pull request Oct 13, 2026
…recedes positional ones in engines and table functions
robot-ch-test-poll4 added a commit that referenced this pull request Oct 13, 2026
Cherry pick #122770 to 26.7: Fix credential leak when a named argument precedes positional ones in engines and table functions
robot-clickhouse added a commit that referenced this pull request Oct 13, 2026
…recedes positional ones in engines and table functions
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Oct 13, 2026
Algunenano added a commit that referenced this pull request Oct 13, 2026
Backport #122770 to 26.3: Fix credential leak when a named argument precedes positional ones in engines and table functions
clickhouse-gh Bot added a commit that referenced this pull request Oct 13, 2026
Backport #122770 to 26.7: Fix credential leak when a named argument precedes positional ones in engines and table functions
blau-ai added a commit to Altinity/ClickHouse that referenced this pull request Oct 16, 2026
…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]>
blau-ai added a commit to Altinity/ClickHouse that referenced this pull request Oct 16, 2026
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]>
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Oct 31, 2026
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]>
Algunenano pushed a commit that referenced this pull request Nov 3, 2026
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-sql-syntax SQL/grammar parsing, AST nodes, syntax-level features. pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-bugfix Pull request with bugfix, not backported by default pr-must-backport Pull request should be backported intentionally. Use this label with great care! pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants