Skip to content

Restrict server-managed Azure credentials - #120343

Merged
SmitaRKulkarni merged 38 commits into
masterfrom
Azure_restrict_credentials
Oct 22, 2026
Merged

SmitaRKulkarni merged 38 commits into
masterfrom
Azure_restrict_credentials

Conversation

@SmitaRKulkarni

@SmitaRKulkarni SmitaRKulkarni commented Sep 16, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Backward Incompatible Change

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Azure Blob Storage access from user SQL no longer uses the server's own workload or managed identity unless allow_server_credentials_in_user_queries (formerly s3_allow_server_credentials_in_user_queries) is enabled; provide explicit credentials instead: account_name and account_key, a connection string, or a SAS token.

Details:

  • Covered: the azureBlobStorage table function, the AzureBlobStorage and AzureQueue engines, Azure named collections (including ones defined in the server configuration), dynamic disk(type = azure_blob_storage, ...) definitions, BACKUP/RESTORE TO AzureBlobStorage, and data-lake reads over Azure. Without explicit credentials they're rejected with ACCESS_DENIED.
  • Settings: the S3 credential settings now also cover Azure, and are renamed with the old names kept as aliases:
    • s3_allow_server_credentials_in_user_queries → allow_server_credentials_in_user_queries
    • s3_load_table_anonymously_if_credentials_restricted → load_table_anonymously_if_credentials_restricted
    • s3_allow_server_credentials_for_system_table_disks → allow_server_credentials_for_system_table_disks
  • Restoring the old behaviour: enable allow_server_credentials_in_user_queries for the users that need it. The compatibility setting can't restore it, and enabling the setting also lifts the S3 restriction for those users.
  • Checked for each session: a table created with the setting enabled doesn't use the server's identity for sessions that have it disabled.
  • Existing tables: a table that relied on the server's identity still loads at startup but stays inaccessible, except for sessions that enable the setting. Set load_table_anonymously_if_credentials_restricted = 0 to fail the load instead.
  • Dynamic disks: a disk created while the setting is enabled records that, and keeps the server's identity after a restart. Disks of tables in the system database may use the server's identity with allow_server_credentials_for_system_table_disks.
  • AzureQueue: the after_processing = 'move' destination must carry its own credentials, like an S3Queue move destination.
    Similar to this s3 pr Restrict server-managed S3 credentials in user queries (chokepoint, alternative to #104889) #106855

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

Version info

  • Merged into: 26.11.1.534-master (included in 26.11 and later)

@clickhouse-gh

clickhouse-gh Bot commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [fef05a0]

Summary: ✅


AI Review

Summary

The change restricts server-managed Azure credentials in user SQL, adds credential-setting aliases, and handles existing metadata and dynamic-disk opt-ins. At head fef05a0573947f52943af603456a341b5d8b8b15, two previously reported credential-isolation bypasses remain. Both already have inline threads; no duplicate comments were posted.

Missing context / blind spots
  • ⚠️ The remaining bypasses were verified by tracing the current code; no local runtime reproduction was performed. The focused regressions below would provide runtime validation.
Findings

❌ Blockers

  • src/Disks/getDiskConfigurationFromAST.cpp:542: Reusing a dynamic disk must validate every backing location. getCustomDiskServerIdentity checks only DiskObjectStorage::getObjectStorage, which returns the local location. If an opted-in disk has explicit credentials locally and managed identity on another enabled location, a restricted session can reference it through an encrypted or cache wrapper: the helper returns no restricted identity, but DiskObjectStorageTransaction::writeFileImpl writes to every enabled location, including the credentialed backend. Inspect all backing locations when accepting disk references. Existing open thread; its latest reply already describes this remaining case.

  • src/Disks/DiskObjectStorage/ObjectStorages/AzureBlobStorage/AzureObjectStorage.cpp:793: A restricted query must retain its credential policy throughout execution. After startup loads a table with an anonymous client, a restricted query passes this early return because forbid_implicit_credentials is already true. An overlapping opted-in query can then publish a credentialed client at line 800. ReadFromObjectStorageStep retains the shared object storage, and deferred AzureObjectStorage::readObject calls obtain its current client, allowing the restricted query to send the server's bearer token. Pin a client or private object-storage instance for each query. [dismissed by author -- Restrict server-managed Azure credentials #120343 (comment)] The author deferred isolation to a follow-up; the current denial on later restricted queries still does not protect a query prepared before the client changes. The corresponding app-authored thread remains resolved.

Tests
  • ⚠️ Extend the disk-reuse regression with an opted-in disk whose local location has an explicit key and whose other enabled Azure location uses server identity. A restricted wrapper creation must fail before authenticated I/O.
  • ⚠️ Extend the existing identity-mock test with a startup-loaded anonymous table and overlapping restricted and opted-in reads. Pause the restricted read after its policy check, run the opted-in read, then verify that the restricted read sends no bearer-authenticated requests. Sequential session tests do not establish this invariant.
Final Verdict

Status: ❌ Block. Validate every backing location during disk reuse and isolate credentials for each query's lifetime, with focused regressions for both bypasses.

@clickhouse-gh clickhouse-gh Bot added the pr-backward-incompatible Pull request with backwards incompatible changes label Sep 16, 2026
Comment thread src/Core/Settings.cpp Resolved
Comment thread src/Core/Settings.cpp Resolved
@clickhouse-gh clickhouse-gh Bot added the comp-azure Azure Blob Storage integration (credentials, multipart, Azure-specific IO). label Sep 16, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing fef05a057 with master 31d10e5ef (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of 10106881f; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Object file sizes

27 object files changed (+202.72 KiB total), 0 added.

Object file Master PR Δ
src/CMakeFiles/dbms.dir/Disks/getDiskConfigurationFromAST.cpp.o 154.67 KiB 244.23 KiB +89.56 KiB (+57.91%)
src/CMakeFiles/dbms.dir/Core/ServerSettings.cpp.o 1.13 MiB 1.16 MiB +28.25 KiB (+2.45%)

719 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

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

Job report

@arsenmuk

Copy link
Copy Markdown
Member

I think we should also add check around here:

config->load(xml_document);
/// Applied after `processIncludes`. If the pre-resolution check already decided the disk must load
/// anonymously, enforce it now (an `include` cannot re-introduce server credentials). Otherwise
/// re-validate the resolved config, so an `include` that injects an S3 backend with server-managed
/// auth (past a literal non-S3 `type` in the AST) is still caught.
if (s3_disk_info.load_anonymously)
forceAnonymousS3DiskConfig(*config);
else
validateResolvedS3DiskCredentials(*config, context, attach, s3_disk_info);
}

It's needed to prevent an untrusted profile from using an already configured Azure disk

Comment on lines +264 to +265
.forbid_implicit_credentials = remote_host_filter_check != RemoteHostFilterCheck::None
&& context->shouldRestrictUserQueryAzureCredentials(),

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.

[P1] Enforce the Azure restriction when reusing a dynamic disk

This check only runs inside the disk creator. getOrCreateCustomDisk in DiskFromAST.cpp calls Context::getOrCreateDisk, which returns an existing disk without invoking that creator. If a trusted session first creates a dynamic Azure disk with azure_allow_server_credentials_in_user_queries = 1, a session pinned to 0 can create another table with the identical disk(type = azure_blob_storage, ...) definition. The definition has the same hash, passes the existing-disk checks, and reuses the authenticated client with forbid_implicit_credentials = false. Its writes therefore still authenticate with the server's identity despite the restriction.

Validate the current session's Azure credential policy before accepting an existing dynamic disk, including wrapped disks. Please add a two-session regression that creates the disk with the opt-in and then attempts to reuse the same definition under the restricted profile.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

addressed it

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 direct Azure definition is now checked, but reuse through a wrapper still bypasses the restriction in the current code. After a trusted session creates a dynamic Azure disk named trusted_azure, a restricted session can specify:

CREATE TABLE wrapped (x UInt8) ENGINE = MergeTree ORDER BY tuple()
SETTINGS disk = disk(type = encrypted, disk = 'trusted_azure',
                     key = '0123456789abcdef', path = 'restricted/');

validateResolvedAzureDiskCredentials returns at src/Disks/getDiskConfigurationFromAST.cpp:535 because this configuration has type encrypted, with no Azure prefixes. getDiskAndPathFromConfig then takes the existing disk directly from the map at src/Disks/DiskEncrypted.cpp:232-237, without checking its credential policy. Writes through the wrapper retain the underlying authenticated Azure client. A cache wrapper can likewise reference the existing disk by name. Validate the underlying dynamic disk's policy when accepting these references, or require its full definition so it is revalidated.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

addressed

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 wrapper-reuse bypass is still present for a disk with multiple locations at head 1e69b80a2255f8c379e7e79466595e7a1d8fac44. At src/Disks/getDiskConfigurationFromAST.cpp:542-547, getCustomDiskServerIdentity checks only DiskObjectStorage::getObjectStorage, which returns the local location's backend (src/Disks/DiskObjectStorage/DiskObjectStorage.cpp:82). It returns no identity when that backend has explicit credentials, without examining the other locations.

For example, let an opted-in session create a named dynamic disk trusted_multi with a local Azure location using an explicit account key and a second enabled Azure location using managed identity. A restricted session can then create:

CREATE TABLE wrapped (x UInt64) ENGINE = MergeTree ORDER BY tuple()
SETTINGS disk = disk(type = encrypted, disk = 'trusted_multi',
                     key = '0123456789abcdef', path = 'restricted/');

The new check accepts the explicitly authenticated local backend. However, an insert through the wrapper reaches DiskObjectStorageTransaction::writeFileImpl, which opens a writer for every enabled location (src/Disks/DiskObjectStorage/DiskObjectStorageTransaction.cpp:291-334), including the cached managed-identity client. The restricted session therefore still writes using the server's identity.

Inspect all backing locations when validating reuse, and add a two-session case where only a non-local location uses server credentials.

Comment thread src/Core/ServerSettings.cpp Resolved

@arsenmuk arsenmuk left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

solid rework, it's good to go with a few comments

and please re-check why the settings changes history is flagged

Comment thread src/Core/ServerSettings.cpp Resolved
@SmitaRKulkarni

Copy link
Copy Markdown
Member Author

and please re-check why the settings changes history is flagged

yes, the upgrade check failed for alias, I have made a fix to upgrade check #127183

@Algunenano Algunenano left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Good job

@SmitaRKulkarni
SmitaRKulkarni added this pull request to the merge queue Oct 22, 2026
Merged via the queue into master with commit dccf74c Oct 22, 2026
179 checks passed
@SmitaRKulkarni
SmitaRKulkarni deleted the Azure_restrict_credentials branch October 22, 2026 12:10
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 22, 2026
@clickgapai

Copy link
Copy Markdown
Contributor

@SmitaRKulkarni @arsenmuk — ClickGap found the following in this PR:

Close anything that's wrong or already addressed.

groeneai added a commit to groeneai/ClickHouse that referenced this pull request Oct 23, 2026
…ed-object

Conflict in the WriteBufferFromAzureDataLakeStorage constructor: master
(ClickHouse#120343) added `drop_credentials` to makeAdlsGen2FileClient, while this
branch replaced that client with the staging and publish file system
clients. `drop_credentials` is now passed to makeAdlsGen2FileSystemClient
and handled the same way, so both clients send no credentials when the
server's own identity must not be used.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
omar12eladawy added a commit to omar12eladawy/ClickHouse that referenced this pull request Nov 1, 2026
Since ClickHouse#120343 a SQL-defined Azure storage that uses the server's identity
follows the restriction of each accessing session. AzureKernelHelper kept a
copy of the connection params taken when the metadata was created, so a
restricted session could still forward the workload identity to
delta-kernel. Read the params from the object storage in createBuilder, as
S3KernelHelper does, and fingerprint the session restriction so a cached
kernel engine is rebuilt when it changes.

Add a DeltaLakeAzure case to test_azure_workload_identity: after an
opted-in read, a restricted session gets ACCESS_DENIED without a token
request, and the opt-in still signs its requests.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Algunenano added a commit that referenced this pull request Nov 10, 2026
The release has no Azure server credentials marker (#120343), so only the form without
`_server_credentials_allowed` is tried, and the Azure test is dropped. The `storage_policy`
check of `ALTER` runs in the per-setting loop of the release.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Algunenano added a commit that referenced this pull request Nov 10, 2026
The release has no Azure server credentials marker (#120343), so only the form without
`_server_credentials_allowed` is tried, and the Azure test is dropped. The `storage_policy`
check of `ALTER` runs in the per-setting loop of the release.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Algunenano added a commit that referenced this pull request Nov 10, 2026
The release has no Azure server credentials marker (#120343), so only the form without
`_server_credentials_allowed` is tried, and the Azure test is dropped. The `storage_policy`
check of `ALTER` runs in the per-setting loop of the release.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-azure Azure Blob Storage integration (credentials, multipart, Azure-specific IO). pr-backward-incompatible Pull request with backwards incompatible changes pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants