Skip to content

Declare secret arguments next to each engine instead of in the parser - #123364

Merged
Algunenano merged 39 commits into
ClickHouse:masterfrom
Algunenano:secret-arguments-registry
Oct 9, 2026
Merged

Algunenano merged 39 commits into
ClickHouse:masterfrom
Algunenano:secret-arguments-registry

Conversation

@Algunenano

@Algunenano Algunenano commented Oct 1, 2026 •

Copy link
Copy Markdown
Member

Closes: #123315
Related: #122770

Moves secret-argument masking out of src/Parsers/FunctionSecretArgumentsFinder.cpp (a name switch that re-implemented the argument grammar of every table function, engine and backup engine) into a SecretArgumentsSpec declared at each factory registration, next to the engine's own argument parser, as designed in the issue.

  • TableFunctionFactory, StorageFactory, DatabaseFactory, BackupFactory and DictionarySourceFactory take the spec as a mandatory parameter, so a new engine cannot be registered without deciding what is secret; FunctionFactory has an extra overload for encrypt, HMAC and friends. Shapes the fields cannot express are custom callbacks in the engine's translation unit (S3SecretArguments.cpp, AzureSecretArguments.cpp, StorageURL.cpp, TableFunctionRemote.cpp, StorageXDBC.cpp, StorageMongoDB.cpp, StorageBigQuery.cpp, DatabaseBackup.cpp, the backup engines).
  • The parser keeps only AbstractFunction, the result type and the ISecretArgumentsFinder interface (src/Parsers/SecretArguments.h). SecretArgumentsRegistry implements it by looking the spec up in the factories, and is installed by server, local and format (which now registers the factories before formatting). An unregistered table, database or backup engine has every argument hidden. The programs that don't register the engines (client, WebAssembly parser) install NoSecretArgumentsFinder and show engine secrets; formatting with secrets hidden and no finder installed is a LOGICAL_ERROR.
  • The spec also carries the engine SETTINGS to hide, replacing the Storages includes in ASTSetQuery, and the dictionary SOURCE keys, replacing the hardcoded list in ASTFunctionWithKeyValueArguments. Brokers (NATS, RabbitMQ, Kafka) mask their named-collection overrides with the same setting maskers, removing the duplicated key lists.
  • Specs decide which keys of a nested secret map stay visible (role_arn of extra_credentials), and EXPLAIN AST derives its structure-keeping functions from FunctionFactory, removing two more hand-kept lists. The [HIDDEN] placeholder is named once in Common/HiddenSecret.h.
  • The masking cases of gtest_Parser.cpp move to the stateless test 05316_secret_arguments_declared_by_engines.

Masking now depends on what the binary registers. In a build where a feature is compiled out (no MySQL, SSL, Kafka, NATS, RabbitMQ, DataLake, ...), the function, table function, dictionary source or engine does not exist, so its arguments, secret SETTINGS names and dictionary keys are no longer masked there, while the old name switch masked them in every build. This is deliberate: official builds have all of these, and an unregistered table, database or backup engine still has every argument hidden. Tests of these features are tagged no-fasttest because the fast test build lacks them.

The generic rules of #122770 (a positional after a named argument, and the value of a key that is not a literal, are hidden) now apply to every table function, table engine and database engine spec that has secrets. The standalone WebAssembly module shrinks by 26 KB (0.985x).

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

Workflow [PR]
Sync PR [sync-upstream/pr/123364]

Version info

  • Merged into: 26.10.1.1900-master (included in 26.10 and later)

Algunenano and others added 5 commits October 1, 2026 23:59
Secret masking for logging, `SHOW CREATE` and `EXPLAIN` lived in
`src/Parsers/FunctionSecretArgumentsFinder.cpp`, a switch on the name of
every table function, engine and backup engine that re-implemented their
argument grammar by hand and drifted from it.

Each registration now declares what is secret in its arguments with a
`SecretArgumentsSpec`, a mandatory parameter of `TableFunctionFactory`,
`StorageFactory`, `DatabaseFactory`, `BackupFactory` and
`DictionarySourceFactory` (and an extra `FunctionFactory` overload for
`encrypt`, `HMAC` and friends). Shapes the fields cannot express are
`custom` callbacks living in the translation unit of the engine's argument
parser. The spec also carries the engine `SETTINGS` to hide (replacing the
`SETTINGS_TO_HIDE` includes in `ASTSetQuery`) and the dictionary `SOURCE`
keys (replacing the hardcoded list in `ASTFunctionWithKeyValueArguments`).

The parser keeps only `AbstractFunction`, the result type and the
`ISecretArgumentsFinder` interface. `SecretArgumentsRegistry` implements it
by looking the spec up in the factories and is installed by `server`,
`local` and `format`; an unregistered engine has every argument hidden.
The WebAssembly parser no longer carries the finder.

The masking cases of `gtest_Parser.cpp` move to a stateless test.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
`ASTFunction` and the query-tree masking hardcoded that the `role_arn`
value of `extra_credentials(...)` stays visible, which is S3 knowledge in
the parser. `SecretArgumentsResult::nested_maps` now carries the visible
keys of each map, and the S3 spec declares them.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Every masking site wrote the `[HIDDEN]` literal itself, a few with a
local constant of their own, and six engine headers each defined the same
`DEFAULT_MASKING_RULE`. They now use `HIDDEN_SECRET`,
`HIDDEN_SECRET_LITERAL` and `hideSecretValue` from `Common/HiddenSecret.h`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…r specs

`EXPLAIN AST` keeps the expression structure of the secret span only for
functions such as `encrypt` and `HMAC`, and listed their names by hand
with a "keep in sync" comment. It now asks `FunctionFactory` whether the
function declares a `SecretArgumentsSpec`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
`NATS`, `RabbitMQ` and `Kafka` take their settings both in the `SETTINGS`
clause and as overrides of a named collection among the engine arguments,
so each listed its secrets twice: as `SETTINGS_TO_HIDE` and as argument
keys, with "keep in sync" comments. A spec now sets
`settings_as_arguments`, and the interpreter masks such an argument with
the masker of the same setting in `secret_settings`; the argument key
lists and `findBrokerSecretArguments` are gone. What remains for `NATS`
and `RabbitMQ` is hiding positional arguments after the collection name.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Algunenano Algunenano self-assigned this Oct 1, 2026
@clickhouse-gh

clickhouse-gh Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [eb4ed1b]

Summary: ✅


AI Review

Summary

This PR moves secret-argument masking out of the parser-wide name switch and into per-engine SecretArgumentsSpec registrations, which is a clear structural improvement and fixes most of the drift that had accumulated between masking rules and real argument parsers. I re-read the current diff and every prior review thread; the only substantive issue I still see is one remaining HTTP dictionary masking hole when a credential is split across url and endpoint. The other earlier findings that are still visible in the thread history now look fixed or are deliberate tradeoffs that I do not think should block this PR.

Findings
  • ⚠️ Major — [src/Dictionaries/HTTPDictionarySource.cpp:414] [dismissed by author -- https://github.com/ClickHouse/ClickHouse/pull/123364#discussion_r4183347894] The masking logic still treats url and endpoint independently even though the runtime credential carrier is their concatenation. A dictionary like SOURCE(HTTP(url 'https://host/path?' endpoint 'access_token=SECRET' format 'CSV')) or SOURCE(HTTP(url 'http://' endpoint 'user:[email protected]/data' format 'CSV')) leaves the secret visible in SHOW CREATE DICTIONARY / logged DDL because neither fragment looks secret on its own, so both partial maskers return false. Suggested fix: classify and mask the normalized combined URI (url + endpoint) instead of each key in isolation, or fail closed and hide both keys when only the concatenation can be classified safely.
Final Verdict

Changes requested: the refactor is close, but I would not merge it with the remaining HTTP dictionary url / endpoint split-credential leak.

LLVM Coverage Report

Measured on commit eb4ed1b.

Metric Baseline Current Δ
Lines 88.30% 88.30% +0.00%
Functions 92.10% 92.10% +0.00%
Branches 79.70% 79.70% +0.00%

Changed lines: Changed C/C++ lines covered: 2273/2329 (97.60%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added pr-not-for-changelog This PR should not be mentioned in the changelog comp-sql-syntax SQL/grammar parsing, AST nodes, syntax-level features. labels Oct 1, 2026
Algunenano and others added 3 commits October 2, 2026 02:49
The `mongodb` dictionary source is registered in every build, so the
`maskURIPassword` its `SecretArgumentsSpec` uses must be included outside
the `USE_MONGODB` guard.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The fast test build lacks most of the engines it covers, and an
unregistered engine has every argument hidden.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The fast test build has no S3, MongoDB, NATS, RabbitMQ, Kafka,
DataLakeCatalog or `encrypt`. Their secrets are now declared by their
registrations, so in that build those arguments are hidden whole or those
settings are not masked.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…sources

`SOURCE(ODBC(connection_string ...))`, `SOURCE(JDBC(datasource ...))` and
`SOURCE(YTSAURUS(oauth_token ...))` were shown in `SHOW CREATE DICTIONARY`
and in logged DDL, while the matching table engines and table functions
hide the same values. Their specs now declare these keys.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Comment thread src/Storages/StorageURL.cpp Resolved
Algunenano and others added 5 commits October 2, 2026 05:17
The parser-side finder masked `extra_credentials(...)` in `url`,
`urlCluster` and the `URL` engine too: they do not read it, but a query
carrying it is formatted for logging before validation rejects it. The
URL spec kept only `headers(...)`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The `DataLakeStorageSettings` credentials (`auth_header`,
`aws_secret_access_key`, ...) were hidden only through the spec of the
`DataLakeCatalog` database engine; every data lake table engine now
declares them itself. `IcebergAzure`, `PaimonAzure` and `DeltaLakeAzure`
also declare the Azure argument masking of `AzureBlobStorage`, which the
parser-side finder never applied to them.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Reported by clang-tidy (`readability-make-member-function-const`).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
`withDataLakeSecretSettings` is unused when every data lake engine is
compiled out, as in the fast test build.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Comment thread src/Parsers/ASTSetQuery.cpp Resolved
Algunenano and others added 3 commits October 2, 2026 07:05
`ASTPair::hasSecretParts` probed the masker with an empty value, so a
partly secret key such as the `mongodb` `uri` never counted as a
secret part, and `query_log` kept the original query text with the
password. It now asks about the actual formatted value.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Algunenano and others added 2 commits October 2, 2026 08:26
`StorageDistributed.cpp` (in `dbms`) registers the `Remote` engines with
`remoteSecretArguments`, which was defined in `TableFunctionRemote.cpp`,
outside `dbms`. It now lives in `StorageDistributed.cpp`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
`azureBlobStorage` and the Azure data lake table functions masked only a
connection string's `AccountKey`/`SharedAccessSignature` and the
`account_key` argument, so a storage account url carrying its own
credential (`?sig=...`, `user:key@`) was shown, positional or as a
named-collection override. Such a value, or one that is not a plain string
literal, is now hidden whole, as the `AzureBlobStorage` engine and the
backup destination already do.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
hanfei1991 pushed a commit that referenced this pull request Oct 20, 2026
The show_create and system.query_log checks test that the url of an HTTP
dictionary source is masked in the dictionary definition. On master that
comes from #123364, which is not in 26.3, so both checks fail here. The
runtime paths changed by #120407 stay covered.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
hanfei1991 pushed a commit that referenced this pull request Oct 20, 2026
The show_create and system.query_log checks test that the url of an HTTP
dictionary source is masked in the dictionary definition. On master that
comes from #123364, which is not in 26.3, so both checks fail here. The
runtime paths changed by #120407 stay covered.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
hanfei1991 pushed a commit that referenced this pull request Oct 20, 2026
The show_create and system.query_log checks test that the url of an HTTP
dictionary source is masked in the dictionary definition. On master that
comes from #123364, which is not in 26.3, so both checks fail here. The
runtime paths changed by #120407 stay covered.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
hanfei1991 pushed a commit that referenced this pull request Oct 20, 2026
The show_create and system.query_log checks test that the url of an HTTP
dictionary source is masked in the dictionary definition. On master that
comes from #123364, which is not in 26.3, so both checks fail here. The
runtime paths changed by #120407 stay covered.

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.9 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.9), 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.

05316_secret_arguments_declared_by_engines does not exist on 26.9, 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, so that hunk is dropped.

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.8 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.8), 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.

05316_secret_arguments_declared_by_engines does not exist on 26.8, 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, so that hunk is dropped.

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]>
nikitamikhaylov pushed a commit that referenced this pull request Nov 11, 2026
Resolve the conflicts by porting only the hunks of #116793. The
conflicting regions hold code of master PRs that are not on 26.9
(#125401 refreshExternalMetadata in TableFunctionLoop.cpp, #123364
SecretArgumentsSpec in TableFunctionViewIfPermitted.cpp); they are
left as on 26.9.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
leshikus pushed a commit that referenced this pull request Nov 13, 2026
Backport of d496566 from #123364,
which was not backported as a whole because it is a large refactoring.

`azureBlobStorage`, `azureBlobStorageCluster` and the Azure data lake table
functions masked only a connection string's `AccountKey`/`SharedAccessSignature`
and the `account_key` argument, so a storage account url carrying its own
credential (`?sig=...`, `user:key@`) was shown, positional or as a
named-collection override. A user granted only `SELECT` on a view over such a
table function, which implies `SHOW COLUMNS`, could read the SAS through
`SHOW CREATE TABLE`, `system.tables` and `EXPLAIN AST`. Such a value, or one
that is not a plain string literal, is now hidden whole, as the
`AzureBlobStorage` engine and the backup destination already do.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
leshikus pushed a commit that referenced this pull request Nov 13, 2026
Backport of d496566 from #123364,
which was not backported as a whole because it is a large refactoring.

`azureBlobStorage`, `azureBlobStorageCluster` and the Azure data lake table
functions masked only a connection string's `AccountKey`/`SharedAccessSignature`
and the `account_key` argument, so a storage account url carrying its own
credential (`?sig=...`, `user:key@`) was shown, positional or as a
named-collection override. A user granted only `SELECT` on a view over such a
table function, which implies `SHOW COLUMNS`, could read the SAS through
`SHOW CREATE TABLE`, `system.tables` and `EXPLAIN AST`. Such a value, or one
that is not a plain string literal, is now hidden whole, as the
`AzureBlobStorage` engine and the backup destination already do.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
leshikus pushed a commit that referenced this pull request Nov 13, 2026
Backport of d496566 from #123364,
which was not backported as a whole because it is a large refactoring.

`azureBlobStorage`, `azureBlobStorageCluster` and the Azure data lake table
functions masked only a connection string's `AccountKey`/`SharedAccessSignature`
and the `account_key` argument, so a storage account url carrying its own
credential (`?sig=...`, `user:key@`) was shown, positional or as a
named-collection override. A user granted only `SELECT` on a view over such a
table function, which implies `SHOW COLUMNS`, could read the SAS through
`SHOW CREATE TABLE`, `system.tables` and `EXPLAIN AST`. Such a value, or one
that is not a plain string literal, is now hidden whole, as the
`AzureBlobStorage` engine and the backup destination already do.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
mosya415 pushed a commit to mosya415/ClickHouse that referenced this pull request Nov 19, 2026
…e-local print

In non-interactive mode the client prints a failed statement after its error as
`(query: ...)`. It printed the typed text, so passwords and the secret arguments
of table functions, engines, backup destinations and dictionary sources appeared
in clear on stderr, while the server hides them in `system.query_log` and its
logs (ClickHouse#132436).

- ClientBase passes `formatForErrorMessage()` of the AST to the error printers
  when the AST has secret parts, as `executeQuery` does for `query_log`; any
  other query is printed as typed. This covers clickhouse-client,
  clickhouse-local and the server's embedded client, which all get the text
  from these call sites.
- clickhouse-client registers the table functions, databases, storages and
  dictionaries and installs `SecretArgumentsRegistry`, like clickhouse-local and
  clickhouse-format. With `NoSecretArgumentsFinder` (ClickHouse#123364) `hasSecretParts()`
  could not see engine secrets in the client at all.
- The AST fuzzer runs the text it formats, so it now formats with
  `formatWithSecretsOneLine()`, as BuzzHouse does; otherwise the registry would
  turn the secrets it executes into '[HIDDEN]'.

The test-hint mismatch messages (`-- { serverError }` of clickhouse-test) and
`--echo` are unchanged.

The test also covers a table engine, a database engine and a dictionary source.

Closes ClickHouse#132436

Co-Authored-By: Claude Opus 5.5 <[email protected]>
vincentbernat added a commit to akvorado/akvorado that referenced this pull request Nov 24, 2026
ClickHouse 26.3, 26.8 and 26.9 hide the dictionary URL to hide
credentials. This breaks our idempotency check. Handle this case and
"save" the URL as a comment (in a hash) to detect change. Also include
the password (if the password is weak, it can be brute forced, but this
looks OK).

Also handles password being hidden. Dictionary was recreated each time
because of that.

See:
- ClickHouse/ClickHouse#123364
- ClickHouse/ClickHouse#133043
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-not-for-changelog This PR should not be mentioned in the changelog 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.

Move secret-argument masking from FunctionSecretArgumentsFinder into each table function, engine and backup engine

2 participants