Skip to content

Mask the Azure shared access signature carried in a url argument - #114964

Open
yussypu wants to merge 13 commits into
ClickHouse:masterfrom
yussypu:azure-sas-url-secret-mask
Open

yussypu wants to merge 13 commits into
ClickHouse:masterfrom
yussypu:azure-sas-url-secret-mask

Conversation

@yussypu

@yussypu yussypu commented Aug 15, 2026 •

Copy link
Copy Markdown

Closes: #114946

An Azure storage account url authenticates with the shared access signature in its query string whenever the url carries a ?. The sig parameter is the signature itself and the only unguessable part of the token, but it stayed verbatim in SHOW CREATE, in system.tables.engine_full, in SHOW CREATE DATABASE and in system.query_log, while the same credential spelled as a connection string (SharedAccessSignature=) was already hidden.

sig is now replaced in the storage account url of azureBlobStorage, azureBlobStorageCluster and the AzureBlobStorage table engine, in their named collection overrides, and in the unified url entrypoints, which dispatch az, azure, abfss and abfs to Azure Blob Storage: the url and urlCluster table functions, the URL table engine and the URL database 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 = value in 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(...) and extra_credentials(...) are removed before positional slots are assigned, matching AzureStorageParsedArguments::fromAST, so the account_key slot 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]

@CLAassistant

CLAassistant commented Aug 15, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@yariks5s yariks5s added the can be tested Allows running workflows for external contributors label Aug 16, 2026
@clickhouse-gh

clickhouse-gh Bot commented Aug 16, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [18ab953]

Summary: ✅


AI Review

Summary

This PR broadens Azure SAS masking across azureBlobStorage and the unified URL entrypoints, and the new regression file covers many of the previously reported leaks. I still would not merge it yet: three fail-closed gaps remain, and two of them are on already-reported Azure paths that still leave credentials visible in formatted queries or engine definitions.

Findings

❌ Blockers

  • [src/Parsers/FunctionSecretArgumentsFinder.cpp:585-604] The direct azureBlobStorage / azureBlobStorageCluster path still stops scanning as soon as the first argument is recognized as a masked connection string, or as soon as slot 3 looks like a format. That violates the PR's fail-closed contract: malformed mixed signatures such as azureBlobStorage('DefaultEndpointsProtocol=https;AccountKey=IN_URL', 'c', 'p', 'acct', 'SECRET') or azureBlobStorage('https://acct.blob.core.windows.net', 'c', 'p', 'CSV', 'gzip', 'acct', 'SECRET') still leave the trailing SECRET visible in formatted query text before validation.
  • [src/Parsers/FunctionSecretArgumentsFinder.cpp:642-646] The named-collection Azure override path still assumes every readable non-secret key has a safe value. A query such as azureBlobStorage(cfg, format = headers('Authorization' = 'SECRET')) reaches this branch, skips masking because format itself is non-secret, and then formats the nested headers(...) verbatim even though the parser rejects that value only after logging. The S3 and url named-collection paths already fail closed on the same shape; Azure still leaks here.
  • [src/Parsers/FunctionSecretArgumentsFinder.cpp:1127-1145] The AzureBlobStorage / AzureQueue table-engine helper duplicates the same early-return pattern as the table-function helper. Accepted mixed forms can still leak into SHOW CREATE and system.tables.engine_full, and invalid format-prefixed tails still leak into system.query_log.query before parsing fails.
Tests
  • ⚠️ Add focused regression coverage for the remaining failure paths: a direct/table-engine Azure call with a masked connection string plus trailing positionals, a format-prefixed malformed Azure engine signature with a trailing secret, and a named-collection override such as format = headers('Authorization' = '...'). The current 04909 file exercises many valid and some invalid Azure forms, but not the cases that still leak today.
Final Verdict

Changes requested. The remaining Azure masking gaps still expose credential material on failure paths, so the review contract is not closed yet.

LLVM Coverage Report

Measured on commit 18ab953.

Metric Baseline Current Δ
Lines 88.40% 88.40% +0.00%
Functions 92.00% 92.00% +0.00%
Branches 80.70% 80.70% +0.00%

Changed lines: Changed C/C++ lines covered: 154/168 (91.67%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Aug 16, 2026
@clickhouse-gh

clickhouse-gh Bot commented Aug 16, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 18ab953f1 with master 6764095e2 (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes
Binary Master PR Δ
programs/clickhouse-stripped 712.37 MiB 709.32 MiB -3.05 MiB (-0.43%)

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 sizes

4 object files changed (+17.90 KiB total), 0 added.

Object file Master PR Δ
src/Parsers/CMakeFiles/clickhouse_parsers.dir/FunctionSecretArgumentsFinder.cpp.o 147.16 KiB 165.07 KiB +17.91 KiB (+12.17%)

737 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.

Compile time of recompiled translation units

21 translation units recompiled, 89 s compile time in total, 21 of them have a recent master baseline.

Job report

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
@yussypu
yussypu force-pushed the azure-sas-url-secret-mask branch from 40b9fe8 to 74a39f2 Compare August 17, 2026 09:34
@PedroTadim

Copy link
Copy Markdown
Member

@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.
yussypu added a commit to yussypu/ClickHouse that referenced this pull request Aug 28, 2026
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")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@clickhouse-gh clickhouse-gh Bot added the comp-sql-syntax SQL/grammar parsing, AST nodes, syntax-level features. label Sep 4, 2026
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Sep 5, 2026
`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.
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Sep 5, 2026
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.
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Sep 5, 2026
`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.
@maxknv maxknv added the external Author is not a member of the ClickHouse organization label Nov 2, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-sql-syntax SQL/grammar parsing, AST nodes, syntax-level features. external Author is not a member of the ClickHouse organization pr-bugfix Pull request with bugfix, not backported by default

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SAS token in the URL argument of AzureBlobStorage / azureBlobStorage is not masked in SHOW CREATE, engine_full and query_log

5 participants