Repository navigation
Declare secret arguments next to each engine instead of in the parser - #123364
Conversation
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]>
|
Workflow [PR], commit [eb4ed1b] Summary: ✅
AI ReviewSummaryThis PR moves secret-argument masking out of the parser-wide name switch and into per-engine Findings
Final VerdictChanges requested: the refactor is close, but I would not merge it with the remaining LLVM Coverage ReportMeasured on commit eb4ed1b.
Changed lines: Changed C/C++ lines covered: 2273/2329 (97.60%) · Uncovered code |
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]>
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]>
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]>
`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]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…05316` Co-Authored-By: Claude Opus 5.5 <[email protected]>
`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]>
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]>
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]>
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]>
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]>
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]>
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]>
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]>
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]>
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]>
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]>
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]>
…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]>
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
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 aSecretArgumentsSpecdeclared at each factory registration, next to the engine's own argument parser, as designed in the issue.TableFunctionFactory,StorageFactory,DatabaseFactory,BackupFactoryandDictionarySourceFactorytake the spec as a mandatory parameter, so a new engine cannot be registered without deciding what is secret;FunctionFactoryhas an extra overload forencrypt,HMACand friends. Shapes the fields cannot express arecustomcallbacks 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).AbstractFunction, the result type and theISecretArgumentsFinderinterface (src/Parsers/SecretArguments.h).SecretArgumentsRegistryimplements it by looking the spec up in the factories, and is installed byserver,localandformat(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) installNoSecretArgumentsFinderand show engine secrets; formatting with secrets hidden and no finder installed is aLOGICAL_ERROR.SETTINGSto hide, replacing the Storages includes inASTSetQuery, and the dictionarySOURCEkeys, replacing the hardcoded list inASTFunctionWithKeyValueArguments. Brokers (NATS,RabbitMQ,Kafka) mask their named-collection overrides with the same setting maskers, removing the duplicated key lists.role_arnofextra_credentials), andEXPLAIN ASTderives its structure-keeping functions fromFunctionFactory, removing two more hand-kept lists. The[HIDDEN]placeholder is named once inCommon/HiddenSecret.h.gtest_Parser.cppmove to the stateless test05316_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
SETTINGSnames 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 taggedno-fasttestbecause 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):
Workflow [PR]
Sync PR [sync-upstream/pr/123364]
Version info
26.10.1.1900-master(included in26.10and later)