Skip to content

Mask credentials of the Azure data lake table engines - #114963

Open
yussypu wants to merge 17 commits into
ClickHouse:masterfrom
yussypu:azure-lake-engines-secret-mask
Open

yussypu wants to merge 17 commits into
ClickHouse:masterfrom
yussypu:azure-lake-engines-secret-mask

Conversation

@yussypu

@yussypu yussypu commented Aug 15, 2026 •

Copy link
Copy Markdown

Closes: #114939
Related: #114964

IcebergAzure, DeltaLakeAzure and PaimonAzure take the same credential bearing arguments as AzureBlobStorage: an AccountKey= inside a connection string, a sig in a storage account url, or a positional account_key. None of the three was listed in the table engine dispatch of the secret argument finder, so the credential stayed verbatim in SHOW CREATE, in system.tables.engine_full and in the logged query text for every user able to read them.

The three engines now go through the Azure masker, which also learns the credential of the two argument signature (connection_string|storage_account_url, sas_token). AzureStorageParsedArguments::fromAST reads that second argument as a shared access signature, and it belonged to no masked slot before, so it leaked from every Azure table function and table engine.

This pull request is built on top of #114964 and contains its commits, so its diff shrinks to the data lake part once that one is merged. Both target master.

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 account keys and shared access signatures used by IcebergAzure, DeltaLakeAzure, and PaimonAzure table engines.


Workflow [PR]
Sync PR [sync-upstream/pr/114963]

@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 [b793cb5]

Summary: ✅


AI Review

Summary

This PR extends Azure secret masking to the data-lake engines and to several SAS-bearing URL forms. The original IcebergAzure / DeltaLakeAzure / PaimonAzure leak is addressed, but the current head still leaves four Azure credential carriers visible on real code paths, so it is not ready to merge.

Findings

❌ Blockers

  • [src/Parsers/FunctionSecretArgumentsFinder.cpp:654] Named-collection Azure overrides still leave sas_token visible. AzureStorageParsedArguments::fromAST treats the 2-argument shape as (connection_string|storage_account_url, sas_token), but this branch only masks account_key, client_id, and tenant_id, so azureBlobStorage(nc, sas_token = '...') and ENGINE = IcebergAzure(nc, sas_token = '...') still log the bearer token before override validation rejects it.
    Suggested fix: treat sas_token as a secret Azure override key here as well, ideally from the same shared key set that covers the 2-argument positional signature.
  • [src/Parsers/FunctionSecretArgumentsFinder.cpp:585-586] Direct Azure calls still stop after masking the first secret embedded in argument 0. A connection string plus slot-4 account_key, or a malformed connection string containing both AccountKey= and SharedAccessSignature= / duplicate keys, still logs the later secret(s) because maskAzureConnectionString returns after the first replacement and maskConnectionStringKey only hides one occurrence.
    Suggested fix: keep masking the remaining Azure credential carriers after rewriting argument 0 instead of returning immediately, and make the connection-string masking cover repeated / mixed secret keys.
  • [src/Parsers/FunctionSecretArgumentsFinder.cpp:46-50] The url / URL masking path still recognizes Azure SAS only on az://, azure://, abfs://, and abfss://. A plain https://account.blob.core.windows.net/...?...&sig=... URL still formats its raw SAS on url, urlCluster, ENGINE = URL, and the URL database engine even though it is the same bearer credential as the custom-scheme form.
    Suggested fix: make the Azure URL masker host-aware for the known Azure HTTPS hosts, or route those URLs through a shared helper that strips SAS credentials independently of the surface syntax.
  • [src/Parsers/FunctionSecretArgumentsFinder.cpp:652-656] Azure named-collection overrides no longer fail closed on non-literal values of visible keys. A malformed override such as azureBlobStorage(nc, format = headers('Authorization' = 'SEKRIT')) or ENGINE = IcebergAzure(nc, container = headers(...)) is formatted before tryGetNamedCollectionWithOverrides rejects it, and because maskNestedSecretMaps only records top-level headers(...) / extra_credentials(...), the nested secret is logged verbatim.
    Suggested fix: mirror the S3 / url logic here and hide any visible Azure override whose value is neither a plain literal / identifier nor a safe scalar literal.
Tests
  • ⚠️ The new regression suites do not cover sas_token named overrides, multi-secret Azure connection strings, plain https://...blob.core.windows.net url / URL inputs, or Azure named-collection failures of the form key = headers(...). Focused regressions for those cases would catch the remaining leak paths.
Final Verdict

Changes requested. The PR fixes the original data-lake engine leak, but the current head still exposes Azure credentials in several user-reachable failure paths and in the unified url / URL entrypoints.

LLVM Coverage Report

Measured on commit b793cb5.

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

Changed lines: Changed C/C++ lines covered: 165/179 (92.18%) · 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 b793cb56b 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

3 object files changed (+19.06 KiB total), 0 added.

Object file Master PR Δ
src/Parsers/CMakeFiles/clickhouse_parsers.dir/FunctionSecretArgumentsFinder.cpp.o 147.16 KiB 166.22 KiB +19.06 KiB (+12.95%)

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, 88 s compile time in total, 21 of them have a recent master baseline.

Job report

`IcebergAzure`, `DeltaLakeAzure` and `PaimonAzure` were listed in neither
branch of the table engine dispatch in
`FunctionSecretArgumentsFinder::findTableEngineSecretArguments`, so none
of their arguments was ever marked secret. The storage account key stayed
verbatim in `SHOW CREATE TABLE`, in `system.tables.engine_full` and in
the logged query text, at the default
`format_display_secrets_in_show_and_select = 0` and without the
`displaySecretsInShowAndSelect` privilege, in both the connection string
form and the five argument form.

The three engines take the same leading arguments as `AzureBlobStorage`,
whose finder already handles both forms, so route them to it. The Azure
table functions were already covered, which is why a view over
`icebergAzure` masked while the engine did not.

Closes: ClickHouse#114939
@yussypu
yussypu force-pushed the azure-lake-engines-secret-mask branch from 20c2335 to dce0111 Compare August 17, 2026 09:34
@PedroTadim

Copy link
Copy Markdown
Member

@arsenmuk maybe you can also review this PR?

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
AzureStorageParsedArguments::fromAST reads the second argument of the two
argument signature as a shared access signature, so it is a credential in
every Azure table function and table engine, the data lake ones included.
The masker only knew the account_key slot of the longer signatures, so the
token stayed verbatim in the logged query text.

Also carries the url named collection and URL database engine fixes, and the
04909 reference correction, from the same series.
}
if (key != "connection_string" && key != "storage_account_url")
{
if (key == "account_key" || key == "client_id" || key == "tenant_id")

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(..., argument_is_named = true) still leaves one Azure credential carrier visible in the named-collection path: sas_token. The same parser this PR mirrors reads the 2-argument signature as (connection_string/storage_account_url, sas_token) in src/Storages/ObjectStorage/Azure/Configuration.cpp:398-405, but here key == "sas_token" falls through the non-secret branch.

That means ENGINE = IcebergAzure(nc, sas_token = 'SEKRIT') still formats the raw bearer token into SHOW CREATE, system.tables.engine_full, and the logged query text, while SELECT * FROM azureBlobStorage(nc, sas_token = 'SEKRIT') still leaks it in the logged query text, before the named-collection machinery decides whether to use, ignore, or reject the override. Please treat sas_token as a secret key here as well, or share one Azure secret-key set between the positional and named-collection paths.


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.

This early return is still too strong for the Azure parser underneath it. maskAzureConnectionString returns true after hiding the first secret it sees in argument 0, and both callers stop checking the rest of the argument list (findAzureBlobStorageFunctionSecretArguments here and the table-engine copy at src/Parsers/FunctionSecretArgumentsFinder.cpp:1109). But AzureStorageParsedArguments::fromAST still consumes slot 4 as account_key on the 5+-argument forms based only on arity / the format check, even when slot 0 is a connection string rather than a plain storage-account URL (src/Storages/ObjectStorage/Azure/Configuration.cpp:446-455, 484-486, 545-547, 584-586, 614-615, 650-652).

So azureBlobStorage('DefaultEndpointsProtocol=http;AccountName=acct;AccountKey=K1;BlobEndpoint=http://127.0.0.1:1/acct;', 'cont', 'p', 'acct', 'K2') hides K1 inside the connection string but still logs the raw fifth argument K2. The same short-circuit also leaves any second secret inside the connection string visible (AccountKey=...;SharedAccessSignature=... or duplicated keys), because the helper masks only one field before telling the caller it is done. Please keep masking the remaining Azure credential carriers after the first replacement instead of short-circuiting here.

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.
return false;

const String scheme = url.substr(0, scheme_end);
if (!equalsCaseInsensitive(scheme, "az") && !equalsCaseInsensitive(scheme, "azure")

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.

findURLSecretArguments still misses the most common Azure SAS spelling for the url / URL surfaces: a plain https://account.blob.core.windows.net/...?...&sig=... URL. Here we only mask the generic userinfo password and then call maskDispatchedAzureURLCredentials, which returns false unless the scheme is az / azure / abfs*.

That means SELECT * FROM url('https://account.blob.core.windows.net/cont/data.csv?sp=r&sig=SECRET', 'CSV'), ENGINE = URL('https://account.blob.core.windows.net/...'), and CREATE DATABASE ... ENGINE = URL('https://account.blob.core.windows.net/...') still format the raw SAS into the query tree, SHOW CREATE, and the logged query text. Please treat Azure SAS on the known Azure HTTPS hosts the same way as the custom schemes (or share a host-aware Azure URL masker) so the leak does not depend on whether the user wrote az://... or the equivalent HTTPS URL.

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.

This named-collection branch no longer mirrors the fail-closed guard we already have in classifyS3Arguments and findURLSecretArguments. For every key other than connection_string, storage_account_url, account_key, client_id, and tenant_id, we just continue, even when the value is a non-literal expression.

That still leaks secrets on the error path because tryGetNamedCollectionWithOverrides evaluates override values only after the query has been formatted for logging. A query like SELECT * FROM azureBlobStorage(nc_04909_missing, format = headers('Authorization' = 'SEKRIT')) or CREATE TABLE ... ENGINE = IcebergAzure(nc, container = headers(...)) will print the nested header value verbatim: maskNestedSecretMaps only records top-level headers(...) / extra_credentials(...), and the nested equals(...) node has no masking rule of its own.

Please fail closed here for visible Azure overrides whose value is neither a plain literal / identifier nor a safe scalar literal, the same way the S3 and url named-collection paths do.

@clickhouse-gh clickhouse-gh Bot added the comp-sql-syntax SQL/grammar parsing, AST nodes, syntax-level features. label Sep 4, 2026
@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.

Azure data lake table engines (IcebergAzure, DeltaLakeAzure, PaimonAzure) do not mask credentials in SHOW CREATE TABLE and system.tables.engine_full

5 participants