Skip to content

Fix custom disks to follow host allowlist when reused - #129061

Merged
arsenmuk merged 16 commits into
masterfrom
arsenmuk/hdfs-rhost-allowlist
Nov 18, 2026
Merged

arsenmuk merged 16 commits into
masterfrom
arsenmuk/hdfs-rhost-allowlist

Conversation

@arsenmuk

@arsenmuk arsenmuk commented Nov 3, 2026 •

Copy link
Copy Markdown
Member

HDFS disks defined in a query (disk(type = 'hdfs', ...)) now check their endpoint against remote_url_allow_hosts, the same way S3 and Azure disks and the HDFS table engine do. S3 and Azure disks were already checked when they were built, but not when a later definition reused a disk already in the cache. Such a disk was checked against an older remote_url_allow_hosts, or was loaded from metadata with only a warning, so an identical definition, a wrapper or its policy could still reach a host that is no longer allowed. Reused disks of all three types are now checked.

The check covers every way a fresh table or database definition can reach such a disk:

  • a new HDFS disk, before HDFSObjectStorage connects (new S3 and Azure disks were already checked in ObjectStorageFactory);
  • an identical definition that reuses a cached disk: the endpoint the disk was built with is checked, not the one its definition names now (macros or include may resolve differently by now). Every location of the disk is checked, including read_only disks and the disks under encrypted and cache wrappers;
  • a new encrypted or cache wrapper that names an existing custom disk;
  • a policy __<disk> selected with storage_policy in MergeTree (CREATE, ALTER) and Distributed;
  • a disk or policy selected by name in Log, TinyLog, StripeLog, Set and Join;
  • a disk selected by name with SETTINGS disk in data lake engines (Iceberg, DeltaLake, Paimon) and their table functions (icebergS3, deltaLake, ...); like for the other engines, a custom disk that uses the server's own credentials is refused there as well;
  • a database metadata disk (CREATE DATABASE ... SETTINGS disk = disk(...)).

The hosts that are checked match what the factory checks for each type: the endpoint for HDFS, the endpoint and bucket for S3 (so a <s3_bucket> entry allows the disk, as it does for the s3 table function), and the connection URL for Azure. For ADLS Gen2 (OneLake) the write endpoint is checked as well, and the query string is cut so that no SAS token appears in the error message. Disks from the server configuration are not checked, including when a custom cache or encrypted disk wraps one of them.

Disks loaded from existing metadata keep loading and only get a warning. A short ATTACH TABLE or ATTACH DATABASE uses its stored definition and is not checked either.

Tests:

  • test_merge_tree_hdfs: new HDFS disks, reuse before and after a restart, wrappers, include and macros, policies, the engines listed above, and the short ATTACH exemption;
  • test_merge_tree_azure_blob_storage: a reused Azure disk loaded with a warning is rejected, and a short ATTACH still works;
  • test_backward_compatibility/test_custom_s3_disk_remote_url_allow_hosts: after the upgrade, a reused S3 table disk and a reused database metadata disk are rejected, and the table disk is accepted once a <s3_bucket> entry allows it.

Related: #129044

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

HDFS disks created in a query now respect remote_url_allow_hosts. HDFS, S3 and Azure disks created in a query are now also checked when a table or database reuses an existing disk, wraps it, or selects it through storage_policy or by name. Previously, an S3 or Azure disk that was already loaded could be reused after its host was removed from the list. A definition whose host is not allowed is rejected with UNACCEPTABLE_URL. Existing tables and databases on such disks still load, with a warning in the log and in system.warnings.

🤖 Generated with Claude Code


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

Version info

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

@clickhouse-gh

clickhouse-gh Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [c815f03]

Summary: ✅


AI Review

Summary

The PR enforces remote_url_allow_hosts for new HDFS disks and reused custom HDFS, S3 and Azure disks, including wrappers, storage policies, named data lake disks and database metadata disks. The current implementation addresses the previously reported bypasses and includes focused regression coverage. No unresolved findings remain; the author's documented enforcement for an uncached disk on a short ATTACH is an accepted tradeoff.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Nov 3, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-object-storage-disks Object-storage disk layer: DiskObjectStorage, metadata storage adapters, transaction support for ... label Nov 3, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing c815f0398 with master f9796e981 (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

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.

Compile time of recompiled translation units

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

Job report

Comment thread src/Disks/DiskFromAST.cpp Resolved
arsenmuk added a commit that referenced this pull request Nov 5, 2026
A user short `ATTACH TABLE` or `ATTACH DATABASE` reads its stored definition
with `attach = false`, so the reuse check added for fresh definitions also
rejected `DETACH` + `ATTACH` of an existing table or database on an HDFS disk
after `remote_url_allow_hosts` was tightened. The S3 counterpart keeps that
working (`test_custom_s3_disk_remote_url_allow_hosts`). Pass whether the
definition is stored down to `DiskFromAST::createCustomDisk` and skip the reuse
check for it; the first build of such a disk is still enforced by the factory.

Related: #129061

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@arsenmuk
arsenmuk force-pushed the arsenmuk/hdfs-rhost-allowlist branch from 48ca874 to e8a1979 Compare November 5, 2026 09:40
arsenmuk added a commit that referenced this pull request Nov 5, 2026
The reuse check expanded the endpoint from the definition again, but the
disk name is a hash of the definition before macro expansion, while the
reused `HDFSObjectStorage` keeps the URL it was built with. After a macro
such as `{hdfs_host}` changed to an allowed host, an identical definition
passed the check and kept writing to the forbidden one. Check the URL held
by the disk instead.

Related: #129061 (comment)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
arsenmuk added a commit that referenced this pull request Nov 5, 2026
The reuse check was gated on the root `type` or `object_storage_type` of the
definition, so a disk with `type = 'object_storage'` whose HDFS backend comes
from `locations` (for example through `include`) was reused without a check.
Check the HDFS endpoints of all object storages the disk holds; wrappers that
name another disk are left to their own check.

Related: #129061 (comment)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
arsenmuk added a commit that referenced this pull request Nov 5, 2026
A wrapper such as `encrypted` or `cache` takes the disk it names directly from
the disks map, so `disk(type = 'encrypted', disk = 'old_hdfs', ...)` built a new
disk over an HDFS endpoint that `remote_url_allow_hosts` no longer allows:
neither the HDFS factory check nor the reuse check ran, and `cache` even starts
the wrapped disk. Check the endpoints of the named custom disk and the custom
disks it wraps before the wrapper is built, under `storage_policies_mutex`, and
again when the wrapper itself is reused. Disks from the server config are
exempt.

Related: #129061 (comment)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Comment thread src/Disks/DiskFromAST.cpp Resolved
arsenmuk added a commit that referenced this pull request Nov 8, 2026
A user short `ATTACH TABLE` or `ATTACH DATABASE` reads its stored definition
with `attach = false`, so the reuse check added for fresh definitions also
rejected `DETACH` + `ATTACH` of an existing table or database on an HDFS disk
after `remote_url_allow_hosts` was tightened. The S3 counterpart keeps that
working (`test_custom_s3_disk_remote_url_allow_hosts`). Pass whether the
definition is stored down to `DiskFromAST::createCustomDisk` and skip the reuse
check for it; the first build of such a disk is still enforced by the factory.

Related: #129061

Co-Authored-By: Claude Opus 5.5 <[email protected]>
arsenmuk added a commit that referenced this pull request Nov 8, 2026
The reuse check expanded the endpoint from the definition again, but the
disk name is a hash of the definition before macro expansion, while the
reused `HDFSObjectStorage` keeps the URL it was built with. After a macro
such as `{hdfs_host}` changed to an allowed host, an identical definition
passed the check and kept writing to the forbidden one. Check the URL held
by the disk instead.

Related: #129061 (comment)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
arsenmuk added a commit that referenced this pull request Nov 8, 2026
The reuse check was gated on the root `type` or `object_storage_type` of the
definition, so a disk with `type = 'object_storage'` whose HDFS backend comes
from `locations` (for example through `include`) was reused without a check.
Check the HDFS endpoints of all object storages the disk holds; wrappers that
name another disk are left to their own check.

Related: #129061 (comment)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
arsenmuk added a commit that referenced this pull request Nov 8, 2026
A wrapper such as `encrypted` or `cache` takes the disk it names directly from
the disks map, so `disk(type = 'encrypted', disk = 'old_hdfs', ...)` built a new
disk over an HDFS endpoint that `remote_url_allow_hosts` no longer allows:
neither the HDFS factory check nor the reuse check ran, and `cache` even starts
the wrapped disk. Check the endpoints of the named custom disk and the custom
disks it wraps before the wrapper is built, under `storage_policies_mutex`, and
again when the wrapper itself is reused. Disks from the server config are
exempt.

Related: #129061 (comment)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@arsenmuk
arsenmuk force-pushed the arsenmuk/hdfs-rhost-allowlist branch from e8a1979 to a9b9c51 Compare November 8, 2026 20:35
@arsenmuk arsenmuk added the ignore-unresolved-threads Do not limit CI and block merge on unresolved review threads label Nov 9, 2026
Comment thread src/Disks/DiskFromAST.cpp Resolved
arsenmuk added a commit that referenced this pull request Nov 9, 2026
A user short `ATTACH TABLE` or `ATTACH DATABASE` reads its stored definition
with `attach = false`, so the reuse check added for fresh definitions also
rejected `DETACH` + `ATTACH` of an existing table or database on an HDFS disk
after `remote_url_allow_hosts` was tightened. The S3 counterpart keeps that
working (`test_custom_s3_disk_remote_url_allow_hosts`). Pass whether the
definition is stored down to `DiskFromAST::createCustomDisk` and skip the reuse
check for it; the first build of such a disk is still enforced by the factory.

Related: #129061

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@arsenmuk
arsenmuk force-pushed the arsenmuk/hdfs-rhost-allowlist branch from a9b9c51 to 5fea75c Compare November 9, 2026 10:16
arsenmuk added a commit that referenced this pull request Nov 9, 2026
The reuse check expanded the endpoint from the definition again, but the
disk name is a hash of the definition before macro expansion, while the
reused `HDFSObjectStorage` keeps the URL it was built with. After a macro
such as `{hdfs_host}` changed to an allowed host, an identical definition
passed the check and kept writing to the forbidden one. Check the URL held
by the disk instead.

Related: #129061 (comment)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
arsenmuk added a commit that referenced this pull request Nov 9, 2026
The reuse check was gated on the root `type` or `object_storage_type` of the
definition, so a disk with `type = 'object_storage'` whose HDFS backend comes
from `locations` (for example through `include`) was reused without a check.
Check the HDFS endpoints of all object storages the disk holds; wrappers that
name another disk are left to their own check.

Related: #129061 (comment)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
arsenmuk added a commit that referenced this pull request Nov 9, 2026
A wrapper such as `encrypted` or `cache` takes the disk it names directly from
the disks map, so `disk(type = 'encrypted', disk = 'old_hdfs', ...)` built a new
disk over an HDFS endpoint that `remote_url_allow_hosts` no longer allows:
neither the HDFS factory check nor the reuse check ran, and `cache` even starts
the wrapped disk. Check the endpoints of the named custom disk and the custom
disks it wraps before the wrapper is built, under `storage_policies_mutex`, and
again when the wrapper itself is reused. Disks from the server config are
exempt.

Related: #129061 (comment)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
arsenmuk added a commit that referenced this pull request Nov 9, 2026
`Context::getStoragePolicyFromDisk` registers the policy `__<disk>` for a
custom disk, so a fresh `CREATE TABLE ... SETTINGS storage_policy = '__<disk>'`
reached that disk without `ensureDiskIsNotCustom` or the
`remote_url_allow_hosts` check. A fresh definition now rejects a policy that
contains a custom disk; stored metadata is still loaded as before.

Related: #129061 (comment)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
arsenmuk and others added 6 commits November 10, 2026 10:39
A user short `ATTACH TABLE` or `ATTACH DATABASE` reads its stored definition
with `attach = false`, so the reuse check added for fresh definitions also
rejected `DETACH` + `ATTACH` of an existing table or database on an HDFS disk
after `remote_url_allow_hosts` was tightened. The S3 counterpart keeps that
working (`test_custom_s3_disk_remote_url_allow_hosts`). Pass whether the
definition is stored down to `DiskFromAST::createCustomDisk` and skip the reuse
check for it; the first build of such a disk is still enforced by the factory.

Related: #129061

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The reuse check expanded the endpoint from the definition again, but the
disk name is a hash of the definition before macro expansion, while the
reused `HDFSObjectStorage` keeps the URL it was built with. After a macro
such as `{hdfs_host}` changed to an allowed host, an identical definition
passed the check and kept writing to the forbidden one. Check the URL held
by the disk instead.

Related: #129061 (comment)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The reuse check was gated on the root `type` or `object_storage_type` of the
definition, so a disk with `type = 'object_storage'` whose HDFS backend comes
from `locations` (for example through `include`) was reused without a check.
Check the HDFS endpoints of all object storages the disk holds; wrappers that
name another disk are left to their own check.

Related: #129061 (comment)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A wrapper such as `encrypted` or `cache` takes the disk it names directly from
the disks map, so `disk(type = 'encrypted', disk = 'old_hdfs', ...)` built a new
disk over an HDFS endpoint that `remote_url_allow_hosts` no longer allows:
neither the HDFS factory check nor the reuse check ran, and `cache` even starts
the wrapped disk. Check the endpoints of the named custom disk and the custom
disks it wraps before the wrapper is built, under `storage_policies_mutex`, and
again when the wrapper itself is reused. Disks from the server config are
exempt.

Related: #129061 (comment)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@arsenmuk
arsenmuk force-pushed the arsenmuk/hdfs-rhost-allowlist branch from 5fea75c to 37180cb Compare November 10, 2026 11:36
Comment thread src/Storages/StorageFactory.cpp Resolved
@alesapin alesapin self-assigned this Nov 10, 2026
Comment thread src/Disks/DiskFromAST.cpp Resolved
@arsenmuk arsenmuk changed the title Fix HDFS disk to follow host allowlist Fix custom disks to follow host allowlist when reused Nov 11, 2026
alesapin and others added 2 commits November 13, 2026 17:43
- `IObjectStorage::checkRemoteHostFilter` replaces the switch over object
  storage types in `checkCustomDiskRemoteHosts`: S3, HDFS and Azure check the
  hosts they connect to, and `CachedObjectStorage` forwards to the storage it
  wraps. This removes the `dynamic_cast` that skipped the S3 check silently
  for any other implementation, the HDFS URL taken from `getDescription`, and
  the backend headers included in `DiskFromAST.cpp`.
- `AzureObjectStorage::getURIsForRemoteHostFilter` is used both by
  `ObjectStorageFactory` and by the check of a reused disk, so the Azure hosts
  (the connection URL and the ADLS Gen2 endpoint, without the SAS token) are
  defined in one place.
- The host check is a part of `DiskFromAST::ensureDiskIsAllowed` and
  `DiskFromAST::ensureStoragePolicyIsAllowed`, which were already called at the
  same places, instead of separate functions.
- `getOrCreateCustomDisk` decides once whether hosts are checked. A new wrapper
  of a custom disk in a short `ATTACH` is now exempt too, like a reused disk.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@alesapin alesapin 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.

LGTM

Comment thread src/Storages/StorageFactory.cpp Resolved
arsenmuk and others added 2 commits November 17, 2026 09:52
…-allowlist

# Conflicts:
#	src/Databases/DatabaseMetadataDiskSettings.cpp
#	src/Databases/DatabaseMetadataDiskSettings.h
`allowed_disks_for_table_engines` allows a disk by name, and a custom disk with that
name could be built before `remote_url_allow_hosts` was tightened. Data lake engines
and table functions took such a disk in `DataLakeConfiguration::fromDisk` without a
check, so a fresh `Iceberg`, `DeltaLake` or `Paimon` definition could reach a host
that is no longer allowed. `DiskFromAST::ensureDiskIsAllowed` now runs there, like
for the other engines that select a disk by name; a replayed definition is exempt.

Related: #129061 (comment)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The `deltaLake` table function is not built with MSan, because `delta-kernel-rs` is
disabled there. The check is in `DataLakeConfiguration::fromDisk`, shared by all data
lake engines and table functions, so the `Iceberg` engine and `icebergS3` cover it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@arsenmuk
arsenmuk added this pull request to the merge queue Nov 18, 2026
Merged via the queue into master with commit efa91c7 Nov 18, 2026
193 checks passed
@arsenmuk
arsenmuk deleted the arsenmuk/hdfs-rhost-allowlist branch November 18, 2026 10:51
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-object-storage-disks Object-storage disk layer: DiskObjectStorage, metadata storage adapters, transaction support for ... ignore-unresolved-threads Do not limit CI and block merge on unresolved review threads pr-bugfix Pull request with bugfix, not backported by default 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.

3 participants