Repository navigation
Cherry pick #123651 to 26.3: Hide Azure credentials that were logged in clear in system.query_log - #128985
Merged
Conversation
Rebased onto #123364, which moved the Azure secret rules to `AzureSecretArguments.cpp` and fixed the `extra_credentials(...)` slot shift, the SAS-url form and the named-collection `storage_account_url`. On master c873902 these statements still log a SAS token, account key or client secret in clear in `system.query_log`: - the `(url, sas_token)` table function form, also `*Cluster` and the data lake functions: the table function never had the engine's two-argument credential slot. It now uses the same `azureCredentialArgument` as the engine, and hides it before the connection string, since hiding that sets a whole-argument replacement. - a `key = value` argument or a second `extra_credentials(...)` among the positionals: `azureSlotArguments` gave them a slot. A `key = value` now takes none and its value is hidden unless the explicit form reads the key; with two `extra_credentials(...)` the slots are unknowable and everything is hidden. A `*Cluster` call keeps its first argument as the cluster name, whatever it is. - `extra_credentials(client_secret = ...)`: Azure registered no nested secret map. Only `client_id` and `tenant_id` are shown now. - a named-collection override with a key `StorageAzureConfiguration` does not accept (`client_secret`, `sas_token`, `AccountKey`) or with a value that is no plain literal: the table function hides its value, the engine and backup forms hide everything. The table function also hides every connection override when there are several (only one is read, and only one can be partly shown), and no longer skips `account_key` when a connection string was masked. - connection strings: `maskConnectionStringKey` hid only the first `AccountKey=` or `SharedAccessSignature=`, but the Azure SDK keeps the last copy of a repeated key (case-insensitively), uses both keys, and reads `BlobEndpoint` with its query. `maskAzureConnectionStringSecrets` hides every such value and any value with `?` or `@`, and the whole string when a url query, fragment or userinfo is left. It also replaces the rule of `after_processing_move_connection_string`, whose `http` value is read as a url with its SAS after `?`. Tests: 22 lines in 05316, each logging a secret on master and none with the fix. Two cluster calls in test_mask_sensitive_info used `container_name`/`blobpath`, which Azure does not accept, so their values are now hidden; renamed to `container`/`blob_path`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…g keys exactly For a connection string, `ConnectionParams::getConnectionURL` returned the SDK's `BlobServiceUrl`, to which `ParseConnectionString` appends `SharedAccessSignature` as the query. That url is checked by `RemoteHostFilter::checkURL` (its `UNACCEPTABLE_URL` message masks only S3 and GCS parameters), printed by the Azure backup reader and writer at trace level, and used as the schema inference cache key (`system.schema_inference_cache.source`). No client is built from it: the SDK clients use the connection string, and Delta Lake gets the SAS as `azure_storage_sas_key`. So it is returned without the query. `maskAzureConnectionStringSecrets` now matches `AccountKey` and `SharedAccessSignature` exactly, without trimming, as `ParseConnectionString` does, and its comment names that parser and gives one example per rule. The `remote_url_allow_hosts` rejection gets a case in `test_allowed_url_from_config`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…slot `TableFunctionObjectStorage::parseArguments` removes the `SETTINGS` clause before the Azure arguments are parsed, but `azureSlotArguments` gave it a slot. So `azureBlobStorage(url, sas, SETTINGS ...)` had three slots instead of two, and the SAS token of the two-argument form was logged in clear. The same for `azureBlobStorageCluster`, `deltaLakeAzure`, `icebergAzure` and `paimonAzure`. Skip it, as `classifyPositionalArguments` already does. Engines are not affected: their arguments cannot hold `SETTINGS`. Found by the AI review on the PR. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…etConnectionURL A `key = value` argument whose left operand is not an Azure key, e.g. `'sp=r&sig=...' = 'x'` in the SAS or `account_key` slot, showed that operand: the slot rule and the named-collection override rule hid only the value. Its left operand can be the credential itself, so such an argument is now hidden whole; a known key still shows its name. `maskAzureConnectionStringSecrets` read `https://user:pass=word@host/` as the pair `https://user:pass` = `word@host/` and hid only the value, leaving the start of the password in the table function argument and in `after_processing_move_connection_string`. No connection string key holds ':' or '/', so a string with such text outside the pair values and any '?', '#' or '@' is now hidden whole, like a url with a SAS. `getConnectionURL` is back to returning `BlobServiceUrl` with the SAS of a connection string, because the value is also used to build clients. The query is dropped only where the url names the endpoint, through the new `getConnectionURLWithoutQuery`: the `remote_url_allow_hosts` check (its error message), `getDataSourceDescription` (the schema cache key and `system.schema_inference_cache.source`) and the backup reader/writer description (trace logs). It also drops a query written in the url itself, which the explicit `account_name`/`account_key` and `extra_credentials` forms keep as written, so `https://host/?sig=...` read beside an account key no longer reaches the host filter error either. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…perand
`forEachSecretArgumentNode` ignored the `masked_arguments` flag and always
narrowed an `equals` argument to its right operand, while `ASTFunction::formatImpl`
and the `EXPLAIN AST` dump hide such an argument whole unless it is marked as a
named `key = value`. So `EXPLAIN QUERY TREE` kept the left operand the finder
had decided to hide, e.g. the SAS in
`azureBlobStorage('https://.../blob.csv', 'sp=r&sig=...' = 'x')` and in the
named-collection form.
05316 also checks that the AzureBlobStorage engine hides an `extra_credentials`
`role_arn`, as the table function does.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…y trace lines An Azure disk configured with `connection_string` uses that whole string as its description, so `BackupWriterAzureBlobStorage::copyFileFromDisk` and `BackupReaderAzureBlobStorage::copyFileToDisk` logged its `AccountKey` / `SharedAccessSignature` at trace level (server log and `system.text_log`) on every BACKUP from and RESTORE onto such a disk. Measured with azurite: 21 of 21 "Source description" lines carry the account key on master and on the previous head of this PR, 0 after this change. The description is masked where it is logged, with the same `maskAzureConnectionStringSecrets` as the query text. It is not changed at the disk: the description is part of the disk identity (`DataSourceDescription::operator==` / `sameKind`), which decides whether `DiskObjectStorage::copyFile` copies inside the object storage. The new integration test backs up a table on an account key connection string disk to a SAS connection string and restores it, then reads a file through the same SAS connection string. It checks that neither the account key nor the SAS reaches the trace lines of either copy direction, and that the SAS is not in `system.schema_inference_cache.source`. It fails on master, and separately on each of: this masking removed, the backup descriptions back on `getConnectionURL`, the Azure configuration description back on `getConnectionURL`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Requested by the reviewer: hide anything inside `extra_credentials(...)`
by default and err on the safe side.
The Azure finders registered `extra_credentials` as a nested secret map
with `client_id` and `tenant_id` visible. A nested map always prints the
key of every entry, and a key can be written as anything, including the
credential itself (`extra_credentials('<secret>' = 'x')` is formatted
for query logging before `collectCredentials` rejects it). The finders
now mask every `extra_credentials(...)` argument whole instead, at any
position: the formatter, `EXPLAIN AST` and `EXPLAIN QUERY TREE` already
hide a whole-argument mask completely, so the argument is shown as
'[HIDDEN]' on all three surfaces.
The S3 `extra_credentials(...)` map, which keeps `role_arn` visible as on
master, is unchanged.
05316: five existing lines now expect '[HIDDEN]' in place of the map; one
new formatter line and two new explain lines (`EXPLAIN AST`, `EXPLAIN
QUERY TREE`) with an unknown key and a `client_id` value fail on the
previous head and on master, and pass with this change.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Hide Azure credentials that were logged in clear in `system.query_log`
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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Original pull-request #123651
Do not merge this PR manually
This pull-request is a first step of an automated backporting.
It contains changes similar to calling
git cherry-picklocally.If you intend to continue backporting the changes, then resolve all conflicts if any.
Otherwise, if you do not want to backport them, then just close this pull-request.
The check results does not matter at this step - you can safely ignore them.
Before you resolve anything
Conflicts are often caused by a prerequisite change that has not been backported yet, rather than by a real divergence. The bot re-tries this cherry-pick against the release branch on every run, so if that is the case here it will merge itself as soon as the prerequisite lands, and you will see a comment saying so. Manual resolution is only needed while the conflict persists.
Troubleshooting
If the conflicts were resolved in a wrong way
If this cherry-pick PR is completely screwed by a wrong conflicts resolution, and you want to recreate it:
pr-cherrypicklabel from the PRYou also need to check the Original pull-request for
pr-backports-createdlabel, and delete if it's presented thereThe PR source
The PR is created in the CI job