Repository navigation
Conversation
|
Workflow [PR], commit [18ab953] Summary: ✅
AI ReviewSummaryThis PR broadens Azure SAS masking across Findings❌ Blockers
Tests
Final VerdictChanges requested. The remaining Azure masking gaps still expose credential material on failure paths, so the review contract is not closed yet. LLVM Coverage ReportMeasured on commit 18ab953.
Changed lines: Changed C/C++ lines covered: 154/168 (91.67%) · Uncovered code |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction. Object file sizes4 object files changed (+17.90 KiB total), 0 added.
737 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units21 translation units recompiled, 89 s compile time in total, 21 of them have a recent master baseline. |
A storage account url authenticates with the shared access signature in its query string: when the url contains a '?', `processURL` takes everything after it as `sas_auth`. `maskAzureConnectionString` skipped any argument starting with `http`, so that token stayed verbatim in `SHOW CREATE TABLE`, in `system.tables.engine_full` and in `system.query_log.query`, while the same credential spelled as a connection string (`SharedAccessSignature=`) was hidden. A shared access signature is a bearer credential: it grants the container access it was issued for until it expires. Mask the `sig` parameter, the HMAC over the signed fields and the only part of the token that cannot be guessed. The rest (version, permissions, expiry, resource) grants nothing on its own and stays visible for diagnostics, the same way `maskPresignedURLParameters` keeps a presigned S3 url readable. The url is replaced in place rather than hidden whole, so a positional `account_key` in the same call is still masked by the caller. This covers the `AzureBlobStorage` and `AzureQueue` engines and the `azureBlobStorage` table function with its cluster and named collection forms, which all reach the same finder. Closes: ClickHouse#114946
40b9fe8 to
74a39f2
Compare
|
@arsenmuk, maybe you can review this? |
…se engine After a named collection the parser rejects a positional argument and, with allow_named_collection_override_by_default, ignores an unexpected function. Both happen after the query is formatted, so hide such an argument whole. CREATE DATABASE ... ENGINE = URL(base_url) formats through findDatabaseEngineSecretArguments, which had no URL case, so a shared access signature in an Azure base url stayed visible in SHOW CREATE DATABASE. The reference of 04909 did not match the order of its queries and spelled several masked constants in a form the query tree dump never produces.
The named collection fail closed rule hid the one positional the Azure backup
locator accepts after a collection, which is the blob path and not a
credential, so test_backup_table_azure_named_collection stopped finding the
masked query text. The S3 locator already carries the same allowance; the
Azure one now takes it too, and anything past that first positional still
fails closed.
AzureBlobStorage::isConnectionString is a case sensitive starts_with("http"),
so a mixed case scheme is classified as a connection string and never
authenticates. The signature the user typed still reaches the log, so the sig
parameter is now masked in both spellings.
Carries the same fix as ClickHouse#114964: the named collection fail closed rule hid the one positional the Azure backup locator accepts after a collection, which is the blob path and not a credential, and a mixed case scheme left the sig parameter visible in the logged query.
| markSecretArgument(i, /* argument_is_named= */ true); | ||
| continue; | ||
| } | ||
| if (key != "connection_string" && key != "storage_account_url") |
There was a problem hiding this comment.
maskNestedSecretMaps only sees top-level arguments. For a readable non-secret override key this branch just continues, so something like azureBlobStorage(cfg, format = headers('Authorization' = 'SECRET')) or the table-engine equivalent is formatted verbatim even though tryGetNamedCollectionWithOverrides rejects the non-literal value only after logging. The S3 and url named-collection paths already fail closed on the same shape with a tryGetString / tryGetLiteralText check. Please mirror that here for the readable non-secret keys and hide the whole key = value argument when the value is not a plain literal, identifier, or scalar literal text.
|
|
||
| if (url_arg_idx >= positional.size()) | ||
| return; | ||
| if (maskAzureConnectionString(positional[url_arg_idx])) |
There was a problem hiding this comment.
maskAzureConnectionString returning true only means slot 0 itself was partially redacted; it does not mean the tail is safe to leave visible. AzureStorageParsedArguments::fromAST still validates the remaining positional arguments after the query has already been formatted, and the same stop-scanning pattern appears below when slot 3 is recognized as a format. So malformed mixed signatures like azureBlobStorage('DefaultEndpointsProtocol=https;AccountKey=IN_URL', 'c', 'p', 'acct', 'SECRET') and azureBlobStorage('https://acct.blob.core.windows.net', 'c', 'p', 'CSV', 'gzip', 'acct', 'SECRET') take one of these early returns and log the trailing SECRET verbatim before the parser throws on the bad signature. Please fail closed on every positional beyond the valid no-account_key form instead of returning immediately here and below.
|
|
||
| if (positional.empty()) | ||
| return; | ||
| if (maskAzureConnectionString(positional[url_arg_idx])) |
There was a problem hiding this comment.
The table-engine sibling still has the same fail-open tail handling as the azureBlobStorage function path above. Once maskAzureConnectionString(positional[url_arg_idx]) redacts a connection string here, or once slot 3 looks like a format, this helper returns before hiding any later positionals.
That still leaks credentials on engine paths. ENGINE = AzureBlobStorage('DefaultEndpointsProtocol=https;AccountKey=IN_URL', 'c', 'p', 'acct', 'SECRET') is accepted, and SHOW CREATE / system.tables.engine_full still print the trailing SECRET because this branch exits before markSecretArgument(positional[4]). The same stop-scanning path leaves a trailing secret visible in malformed format-prefixed forms before validation throws and system.query_log.query is written. Please mirror the fail-closed tail masking from the table-function helper here too; this code also covers AzureQueue.
`BACKUP ... TO AzureBlobStorage(...)` was masked by the rule that models the
table engine of the same name, but the backup destination reads a different
signature: a named collection with an optional filename, three arguments
(connection string or storage account URL, container, blob path), or five
(adding account_name and account_key). `resolveAzureBackupLocation` rejects
anything else, while `BackupInfo::fromAST` accepts any number of literals, and
the statement is formatted for logging before that rejection. An argument the
destination never reads therefore reached `system.query_log.query` and the
`Failed to make backup ...` server log holding whatever was written in it:
BACKUP TABLE t TO AzureBlobStorage('http://acct', 'cont', 'blob', 'SEKRIT')
BACKUP TABLE t TO AzureBlobStorage(nc, 'dir', 'SEKRIT')
The same rule left `account_key` visible in two more shapes: it returns early
when its fourth argument is a known format name (an account named `CSV` is
enough), and when the first argument is a connection string it masks that string
and stops, leaving the explicit key at the fifth slot. `AzureQueue` has no
registered backup engine at all, so it is rejected with `BACKUP_ENGINE_NOT_FOUND`
after being logged; it now falls through to the fail-closed branch the other
unregistered engine names already use.
An Azure backup locator is now masked by its own rule: a shape the destination
reads keeps its non-secret parts visible (URL, container, blob path, account
name) with the credential hidden, and anything else keeps its engine name and
arity visible with every argument hidden.
Measured on this branch: of 14 probe statements 7 leaked their canary into the
logged query text before the change and 0 after, while every valid destination
stays visible: a plain three-argument locator whole, a connection string with
only its `AccountKey` hidden, and the five-argument form with only `account_key`
hidden.
The five-argument control uses a URL fragment rather than a query string to fail
validation: an Azure SAS token carried in a URL query is a separate gap, tracked
in ClickHouse#114946 with a fix in flight (ClickHouse#114964) that changes exactly that spelling, so
pinning it as visible here would collide with it.
`05056_restore_duplicate_database_definition_secret_mask.sh` also gains the
archive-fidelity arm the masked-display assertions do not cover: attaching a
Backup database checks the backup with the credentials its locator carries, so a
definition archived through a secret-hiding formatter fails the restore with
ACCESS_DENIED instead of reading the source table. Verified by serializing the
archived definition with `formatForLogging()`, which reddens the new assertion.
The named-collection form of the AzureBlobStorage backup destination accepts
per-statement overrides, and `getNamedCollection` evaluates them as constant
expressions. The masking rule read a plain literal only, so an override it
could not read was treated as absent, and the locator reached
`system.query_log.query` and the `Failed to make backup ...` server log
verbatim:
BACKUP TABLE t TO AzureBlobStorage(nc,
connection_string = concat('...;AccountKey=', 'SEKRIT'))
BACKUP TABLE t TO AzureBlobStorage(nc,
concat('account_', 'key') = 'SEKRIT')
Hiding a connection string replaces the whole argument, which cannot be
combined with hiding a separate `account_key` override (`markSecretArgument`
asserts on it), so the second credential stayed visible:
BACKUP TABLE t TO AzureBlobStorage(nc,
connection_string = '...;AccountKey=K1;', account_key = 'K2')
All of those shapes now hide the locator whole, which is what the S3 branch
already does for an override it cannot reconstruct. A connection string on its
own still hides only its `AccountKey`, `account_key` on its own is still hidden
by itself, and an account URL override does not take the replacement path, so it
stays visible next to a hidden `account_key`.
The table function and table engine of the same name reach the same shared
helper and keep their existing behavior; that helper is being rewritten in
ClickHouse#114964 for ClickHouse#114946.
05056 also gains `no-encrypted-storage`: its restore arm reads the source table
through the restored Backup database, which gets no parts from a backup taken on
an encrypted disk, the same limitation 05055 already documents.
`connection_string` and `storage_account_url` are mutually exclusive, and
`resolveAzureBackupLocation` reads at most one of them
(`getAnyOrDefault<String>({"connection_string", "storage_account_url"}, "")`).
`getParamsMapFromAST` rejects a repeated key, but only once the overrides are
evaluated, which happens after the statement has been formatted for
`system.query_log.query` and the `Failed to make backup ...` server log.
`findNamedArgument` returns the first occurrence, so the rule read the benign
override and left the credential in the one the destination never reads:
BACKUP TABLE t TO AzureBlobStorage(nc, connection_string = 'http://ok',
storage_account_url = '...;AccountKey=SEKRIT;')
BACKUP TABLE t TO AzureBlobStorage(nc, connection_string = 'http://ok',
connection_string = '...;AccountKey=SEKRIT;')
Both logged `SEKRIT` verbatim, as did a repeated `SharedAccessSignature` and a
pairing where each key carries its own connection string.
Count the occurrences of both keys and hide the locator whole above one. A
connection string is masked by replacing its whole argument, which cannot be
combined with masking a second one, so no surgical mask can cover two carriers.
A key that carries no credential is unaffected: `container` stays visible
however often it is repeated, and every single-override shape keeps its existing
mask.
The `azureBlobStorage` table function reads the same two keys through the shared
helper and is unchanged here; that helper is being rewritten in ClickHouse#114964 for
ClickHouse#114946.
Closes: #114946
An Azure storage account url authenticates with the shared access signature in its query string whenever the url carries a
?. Thesigparameter is the signature itself and the only unguessable part of the token, but it stayed verbatim inSHOW CREATE, insystem.tables.engine_full, inSHOW CREATE DATABASEand insystem.query_log, while the same credential spelled as a connection string (SharedAccessSignature=) was already hidden.sigis now replaced in the storage account url ofazureBlobStorage,azureBlobStorageClusterand theAzureBlobStoragetable engine, in their named collection overrides, and in the unified url entrypoints, which dispatchaz,azure,abfssandabfsto Azure Blob Storage: theurlandurlClustertable functions, theURLtable engine and theURLdatabase engine. The rest of the token (version, permissions, expiry, resource) grants nothing on its own and stays visible.The Azure argument classification also fails closed now. A computed url, a computed override key, an unexpected
key = valuein a direct call, and a positional or unexpected function argument after a named collection are all formatted before the parser rejects or ignores them, so each is hidden whole instead of leaking.headers(...)andextra_credentials(...)are removed before positional slots are assigned, matchingAzureStorageParsedArguments::fromAST, so theaccount_keyslot no longer shifts when either appears before it.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):
Hide Azure shared access signatures passed in storage account URLs.
Workflow [PR]
Sync PR [sync-upstream/pr/114964]