Repository navigation
Hide Azure credentials that were logged in clear in system.query_log - #123651
Conversation
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 4 rounds, 5 findings, all fixed; the last round found none).
Severity: ❌ blocker / Session id: cron:clickhouse-review-self-slot-58:20261003-041000 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-self-slot-57:20261003-033029 |
|
Workflow [PR], commit [5fdb925] Summary: ✅
AI ReviewSummaryPR #123651, reviewed at Missing context / blind spots
Final VerdictStatus: ✅ Approve. No additional code changes requested. |
Build profile diff (arm_release)Commit See the job log for details. |
CI finish ledger - cd4a3a7Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
All 157 check runs completed and Session id: cron:our-pr-ci-monitor:20261003-143124 |
|
Fixing PR for 05237_with_expression_alias_scope_descendant (DBReplicated): #123774 |
Algunenano
left a comment
There was a problem hiding this comment.
Holding of until the refactor in #123364 is merged
|
Understood, holding until #123364 is merged. For the port: I ran this PR's test
Once #123364 is merged I'll rebase onto it, keep only the remaining cases in the per-engine declarations, and re-request review. |
|
@groeneai Please rebase/merge master now. Patch should be much smaller or innecessary |
…still log Rebased onto ClickHouse#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]>
cd4a3a7 to
06a327e
Compare
|
Rebased onto master (c873902, with #123364) and cut the PR down to what still leaks there: 06a327e. The source diff is now
#114946 (SAS in the url) is fixed by #123364, so this PR no longer closes it. |
CI finish ledger - 06a327eEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
The Session id: cron:our-pr-ci-monitor:20261009-163012 |
Algunenano
left a comment
There was a problem hiding this comment.
🤖 Two things: the connection string masker should point to its source of truth, and there is a SAS leak in a path this PR does not cover.
1. Document what maskAzureConnectionStringSecrets is modelled on
There is no ClickHouse spec for Azure connection strings: the docs only link to Microsoft, and the real reader is the SDK's Azure::Storage::_internal::ParseConnectionString (contrib/azure/sdk/storage/azure-storage-common/src/storage_credential.cpp). It is used by every consumer (CreateFromConnectionString of the blob, container and data lake clients, Delta Lake's KernelHelper.cpp, ConnectionParams::getConnectionURL). Its rules: the key runs to the next = (searched across ;), the value to the next ;, pairs go into a std::map (last copy of a repeated key wins), keys match exactly and case-sensitively without trimming, and the *Endpoint values become Azure::Core::Url, so a query in them is a working SAS.
I checked the new masker against that tokenizer (copied verbatim) with 20M random strings made of ;, =, ?, @, #, spaces, key names and URL pieces, tagging each value with a marker: no secret (AccountKey, SharedAccessSignature, an endpoint's query or userinfo) survived masking. The same harness finds leaks in master's maskConnectionStringKey immediately, e.g. DfsEndpoint=?<sas>;AccountKey=<key> keeps the SAS. So the logic looks right, but the code is hard to follow because none of its rules are tied to that parser. Please:
- Add a short comment on
maskAzureConnectionStringSecretsnamingParseConnectionStringas the reference, with one example string per rule (secret keys, repeated keys, endpoint with a query or userinfo, the whole-string fallback). - Either drop the case-insensitive key match and the whitespace trimming, or justify them: the SDK ignores
accountkey, so they only over-mask.
2. A SAS in a connection string still leaks through getConnectionURL
For the connection string form, ConnectionParams::getConnectionURL returns the SDK's BlobServiceUrl, to which ParseConnectionString has appended ?<sas>. (The https://...?sig= URL form is fine: the SAS is split off into endpoint.sas_auth.) That URL reaches:
StorageAzureConfiguration::check→RemoteHostFilter::checkURL, which throwsUNACCEPTABLE_URLwith the URL in the message. Its masking (maskURIUserinfo,maskPresignedURLParameters) knows only S3/GCS parameter names, so Azure'ssigpasses through: running both onhttps://acc.blob.core.windows.net/?sv=2022-11-02&sr=c&sp=r&se=2026-12-01&sig=SECRETSIGreturns it unchanged. On a server withremote_url_allow_hostsset,azureBlobStorage('BlobEndpoint=https://not-allowed.host/;SharedAccessSignature=...&sig=...', ...)would put the SAS into the client error,system.query_log.exceptionand the server log. I verified the masking functions directly, not end to end.BackupReaderAzureBlobStorage::copyFileToDisk, whoseLOG_TRACEprintsdata_source_description.description(the same URL), so a restore from an Azure backup with a SAS connection string logs the SAS at trace level (server log,system.text_log). Traced in code only.
Could you verify both end to end and fix them? One option is to strip the query in getConnectionURL, as getAzureDestinationIdentity already does for backups, after checking that Delta Lake still gets its SAS through azure_storage_sas_key and nothing else relies on the query in that URL. A line in 05316_secret_arguments_declared_by_engines (or a small test with remote_url_allow_hosts) for the exception path would be good too.
…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]>
|
Thanks, done in 1fb5186. 1. 2. Verified end to end on master
Fixed as you suggested: The test is a case in |
Backport #123651 to 26.10: Hide Azure credentials that were logged in clear in `system.query_log`
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]>
Cherry pick #123651 to 26.3: Hide Azure credentials that were logged in clear in `system.query_log`
…clear in `system.query_log`
Cherry pick #123651 to 26.8: Hide Azure credentials that were logged in clear in `system.query_log`
…clear in `system.query_log`
Cherry pick #123651 to 26.9: Hide Azure credentials that were logged in clear in `system.query_log`
…clear in `system.query_log`
Backport #123651 to 26.8: Hide Azure credentials that were logged in clear in `system.query_log`
Backport #123651 to 26.9: Hide Azure credentials that were logged in clear in `system.query_log`
Backport #123651 to 26.3: Hide Azure credentials that were logged in clear in `system.query_log`
The Azure SDK reads the last copy of a repeated `AccountKey` or `SharedAccessSignature`, so every copy must be hidden. Since ClickHouse#123651 the `after_processing_move_connection_string` rule masks every segment, and the system tables use the same rule. A first-only masker leaks the later copies in both new rows. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…clear in `system.query_log`
…clear in `system.query_log`
…clear in `system.query_log`
… clear in `system.query_log`
The key of a `key = value` argument that the parser rejects can be the secret itself (`'secret' = 'x'`, `password_<secret> = 1`), so hide such an argument whole instead of only its value. The same holds for a key that is not a plain literal. This matches the masking of Azure named-collection overrides (#123651). Co-Authored-By: Claude Opus 5.5 <[email protected]>
A key of `extra_credentials(...)` can be written as anything, a credential too
(`extra_credentials('secret' = 'x')`), and the nested-map masking kept every key
visible. Hide the whole map in every S3 form, `url` and the `Backup` database
engine, the same as the Azure engines
(#123651). The whole-argument mask
covers the formatter, `EXPLAIN QUERY TREE` and `EXPLAIN AST`.
The `extra_credentials` parser no longer repeats an invalid key in its
exception. `isNonSecretExtraCredentialsKey` has no users left and is removed.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Follow #123651 where this masking still differed: - The explicit-url S3 form ignores a `key = value` argument it does not read: an unknown key hides the whole argument, a valid S3 key that this form does not read hides its value. - MySQL, PostgreSQL and `Remote`: the value of an accepted key that is not a plain literal or identifier is hidden, as it can nest a secret. - In the named-collection form of a table or database engine, an override hidden by these rules (and, for `S3`, a positional argument after the collection name) hides every argument (`SecretArgumentsSpec::hide_every_argument_if_override_hidden`). - An explicit S3 form with more than one `extra_credentials(...)` hides every argument: the parser strips only the first, so the others shift the slots. Also update the references of `04510` and `05255`, whose logged query text includes the comments changed in the previous commit. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Related: #123364
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed secret masking of the Azure table functions and engines: a SAS token, account key or client secret was logged in clear in
system.query_logfor theazureBlobStorage(url, sas_token)form, argument lists with akey = valueargument,extra_credentials(...)(now hidden whole), connection strings with a second or repeated secret key or an endpoint url with a query, named-collection overrides with a key Azure does not accept, andafter_processing_move_connection_string. A SAS is no longer shown in theremote_url_allow_hostserror andsystem.schema_inference_cache, nor a SAS or a disk's account key in the backup log.Description
On 26.9.1.1629 and 26.8.10.6,
azureBlobStorage('<url>', '<sas_token>'),'...;AccountKey=...;SharedAccessSignature=<sas>'andextra_credentials(client_secret = '...')log the secret in clear insystem.query_log.On top of #123364, this fixes what leaks on master
c873902b:azureCredentialArgument), including(url, sas_token).azureSlotArgumentsgivesSETTINGSand akey = valueno slot, and hides its value unless the explicit form reads the key, or all of it for an unknown key (also inEXPLAIN QUERY TREE); a secondextra_credentials(...)hides everything; a*Clustercall keeps its cluster name.extra_credentials(...)is hidden whole, keys included.maskAzureConnectionStringSecretsreplacesmaskConnectionStringKeyand follows the SDK'sParseConnectionString: everyAccountKeyandSharedAccessSignature(exact keys) and any value with?or@is hidden, and the whole string if a url query or userinfo is left or sits outside the pairs.after_processing_move_connection_stringuses it too.ConnectionParams::getConnectionURLWithoutQuerydrops the url query (a SAS) for theremote_url_allow_hostscheck,getDataSourceDescriptionand the backup description;getConnectionURL, which builds clients, keeps it. The backup log masks aconnection_stringdisk's description, that string.Validation: 35 new lines in
05316_secret_arguments_declared_by_engines(32 leak on master, 3 pin shapes master hides), twotest_allowed_url_from_configcases and atest_backup_restore_azure_blob_storagecase (SAS backup of a key disk) fail on master and pass with the fix;04510,05338and thetest_mask_sensitive_infoAzure tests pass.Workflow [PR]
Sync PR [sync-upstream/pr/123651]
Version info
26.11.1.232-master(included in26.11and later)