Skip to content

Add S3 bucket to remote_url_allow_hosts - #124453

Merged
scanhex12 merged 8 commits into
masterfrom
remote-url-allow-hosts-url-prefix
Oct 9, 2026
Merged

scanhex12 merged 8 commits into
masterfrom
remote-url-allow-hosts-url-prefix

Conversation

@scanhex12

@scanhex12 scanhex12 commented Oct 7, 2026 •

Copy link
Copy Markdown
Member

closes: https://github.com/ClickHouse/clickhouse-private/issues/78644

Changelog category (leave one):

  • Improvement

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

Add S3 bucket to remote_url_allow_hosts


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

Version info

  • Merged into: 26.10.1.1913-master (included in 26.10 and later)
  • Backported to: 26.9.19.12, 26.8.27.12, 26.7.30.12, 26.3.52.3

@clickhouse-gh

clickhouse-gh Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [4f09f03]

Summary: ❌

job_name test_name status info comment
Build (arm_fuzzers) FAIL
Build ClickHouse FAIL cidb
Performance Comparison (arm_release, master_head, 5/6) FAIL Performance dashboard
logical_functions_medium #3 FAIL dashboard

AI Review

Summary

This PR adds bucket-scoped s3_bucket entries to remote_url_allow_hosts, threads the new check through the main S3 entrypoints, and fixes secret leakage from custom-disk exceptions. The overall direction looks right, but there are still correctness gaps: one around IPv6 bucket entries in the new host[:port]/bucket contract, and one documented-but-unfixed redirect path that still ignores bucket-scoped allowlists.

Findings
  • ⚠️ Majors
    • [src/Common/RemoteHostFilter.cpp:110] The new host[:port]/bucket lookup still compares against Poco::URI::getHost(), which strips IPv6 brackets. That means a canonical config entry such as <s3_bucket>[2001:db8::1]:9001/root</s3_bucket> can never match http://[2001:db8::1]:9001/root/..., so valid IPv6 S3 endpoints are still rejected under the new bucket-scoped allowlist. Suggested fix: canonicalize IPv6 hosts before building the lookup key, or parse/store s3_bucket entries as structured host + port + bucket instead of raw strings.
    • [dismissed by author -- https://github.com/ClickHouse/ClickHouse/pull/124453#discussion_r4209988176] [src/IO/S3/PocoHTTPClient.cpp:692] The 307 Temporary Redirect path still validates location with checkURL(Poco::URI(location)), so a bucket-only allowlist can still reject legitimate S3 redirects even though the original URL passed the new bucket-aware check. Documenting the limitation does not remove the runtime failure for deployments that hit this redirect path. Suggested fix: route the redirect target through S3::URI(location).checkRemoteHostFilter(...), the same way the 301 path does.
Final Verdict

⚠️ Needs changes before merge: the new bucket-scoped allowlist still breaks canonical IPv6 endpoints, and the 307 redirect path remains bucket-unaware.

LLVM Coverage Report

Measured on commit 4f09f03.

Metric Baseline Current Δ
Lines 88.30% 88.30% +0.00%
Functions 92.10% 92.10% +0.00%
Branches 79.70% 79.70% +0.00%

Changed lines: Changed C/C++ lines covered: 123/123 (100.00%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-improvement Pull request with some product improvements label Oct 7, 2026
@scanhex12 scanhex12 added pr-must-backport Pull request should be backported intentionally. Use this label with great care! and removed pr-improvement Pull request with some product improvements labels Oct 7, 2026
`RemoteHostFilter` only matches the host of a URL, so on a shared path-style
endpoint such as `s3.us-west-2.amazonaws.com` it can either allow every bucket
in the region or none. After #123114 made `BACKUP`/`RESTORE` to `S3` honor the
filter, Cloud instances with `remote_url_allow_hosts` could no longer reach the
platform backup bucket, and allowing the whole host would defeat the setting.

Add an `s3_bucket` entry of the form `host/bucket` or `host:port/bucket`. S3
URLs are checked through `S3::URI::checkRemoteHostFilter`, which accepts the
URL when the parsed endpoint host and bucket are listed, and otherwise falls
back to the host check. The bucket comes from the parser, so the entry matches
both path-style and virtual-hosted-style URLs. Used by the `s3` table
functions and engines, the `S3` database engine, `BACKUP`/`RESTORE` to `S3`
and the redirect check in `S3::Client`.

Related: #123114
Related: ClickHouse/clickhouse-private#78644

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@clickhouse-gh clickhouse-gh Bot added the comp-object-storage Object storage connectivity (S3/GCS/Azure) including credentials, retries, multipart, etc. label Oct 7, 2026
`DatabaseS3::isTableExist` and `getTableImpl` go through
`S3::URI::checkRemoteHostFilter` as well; check that a table in the allowed
bucket is visible and readable while the same path in another bucket on the
same endpoint is not.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@mintlify

mintlify Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated
ClickHouse-docs 🟢 Ready View Preview Oct 8, 2026, 3:54 PM

@clickhouse-gh clickhouse-gh Bot added the pr-improvement Pull request with some product improvements label Oct 7, 2026
Comment thread src/IO/S3/Client.cpp Resolved
Comment thread src/Common/RemoteHostFilter.cpp Resolved
Comment thread src/IO/S3/Client.cpp Resolved
scanhex12 and others added 2 commits October 8, 2026 08:57
`RemoteHostFilter::setValuesFromConfig` cleared the allow lists and refilled
them in place, so a malformed `<s3_bucket>` left only the entries preceding
it while the filter stayed initialized. Parse into local containers and
swap them in together with `is_initialized` only on success.

Also document that `307 Temporary Redirect` locations are checked only
against `<host>` and `<host_regexp>`, not `<s3_bucket>`.

#124453

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@scanhex12
scanhex12 requested a review from jkartseva October 8, 2026 09:59

std::lock_guard guard(hosts_mutex);
return s3_buckets.contains(endpoint_host + "/" + bucket)
|| s3_buckets.contains(endpoint_host + ":" + toString(endpoint_port) + "/" + bucket);

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 new host:port/bucket contract is broken for IPv6 endpoints. endpoint_host here is the bare host from the parsed URI, so for http://[2001:db8::1]:9001/root/... this lookup becomes 2001:db8::1:9001/root. But the only unambiguous config spelling is <s3_bucket>[2001:db8::1]:9001/root</s3_bucket>, which will never match.

Please canonicalize IPv6 hosts before building the key (or parse/store the config as structured host/port + bucket), and add a regression test for an explicit-port IPv6 endpoint.

Integration test `test_remote_host_filter_s3_bucket`:
- a second node with `<s3_bucket>minio1/root</s3_bucket>` checks the entry
  form without a port, which is the form for a cloud endpoint on port 443
- the `base_backup` of an incremental backup goes through the same check
- `SYSTEM RELOAD CONFIG` applies a new list without a restart, and a
  malformed entry placed first makes the reload fail and keeps the previous list
- the positive cases of the custom disk test use `query`, because
  `query_and_get_error` raises when the query succeeds
- a comment explains why the `S3` database test expects `UNKNOWN_TABLE`

Unit tests:
- `gtest_remote_host_filter`: entry format validation, port semantics of
  `isBucketAllowed`, absent section versus present but empty section
- `gtest_s3_uri`: `checkRemoteHostFilter` for the path-style and the
  virtual-hosted form of one bucket, another bucket, another port, and the
  fallback to a `<host>` entry

Docs and `config.xml`: a 301 redirect returned by S3 is checked against the
bucket entries, a 307 redirect is checked by host only.

Verified with the CI `build_amd_binary` of 7412e40: 10 of 12 tests pass;
the two custom disk cases need the disk check that 45f7386 adds.

Co-Authored-By: Claude Fable 5.1 <[email protected]>

@alexbakharew alexbakharew left a comment

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.

LGTM

@jkartseva jkartseva 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

`DiskFromAST::createCustomDisk` walked the disk AST with `InDepthNodeVisitor`,
which appends `While processing <ast>` to any exception. The `disk` function is
masked only as a setting value (`FieldFromASTImpl`), so the bare `ASTFunction`
was printed with its credentials. Any failure while creating a custom disk, such
as the new `UNACCEPTABLE_URL` check for S3 disks, put `secret_access_key` into the
error and the server log, and the test masking rule turned that into an abort.

Use a plain bottom-up traversal that does not decorate exceptions.

https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=124453&sha=7fb25dfd064ffe3ade1142182e171aba3f875e92&name_0=PR&name_1=Integration%20tests%20%28amd_asan_ubsan%2C%20flaky%29
#124453

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@scanhex12
scanhex12 enabled auto-merge October 9, 2026 06:55
@scanhex12
scanhex12 disabled auto-merge October 9, 2026 06:57
@scanhex12
scanhex12 added this pull request to the merge queue Oct 9, 2026
Merged via the queue into master with commit c873902 Oct 9, 2026
150 of 302 checks passed
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Oct 9, 2026
After the master merge, a query-created Azure disk is checked against
`remote_url_allow_hosts` through `run_remote_host_filter_check`, the flag
S3 disks use since ClickHouse#124453, so the check also runs when the table is
loaded from metadata. Before, it was keyed on `run_local_paths_check`,
which is false on FORCE_ATTACH: after a restart, a table whose disk host
had been removed from the allowlist loaded and wrote to that host.

The checked URL now keeps only the scheme, host and port. The connection
URL of a SAS connection string carries the token in its query, and
ClickHouse#124453 removed the `While processing disk(...)` suffix that used to
quote it anyway, so without this the error and the server log would be
the only place still showing `sig=`. The message now matches the one the
request-time check in `PocoAzureHTTPClient` uses.

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

Copy link
Copy Markdown
Contributor

@scanhex12 @alexbakharew @jkartseva — this PR looks backward incompatible but is categorized as Improvement.

Why: RegisterDiskObjectStorage.cpp:35 adds a remote_url_allow_hosts check for SQL-defined S3 disks that did not exist before and that also runs on ATTACH: objects created on 26.8 under an allow list fail to load after upgrade (integration test). The changelog entry is empty and the category is Improvement while the PR is pr-must-backport.

Suggested category: Backward Incompatible Change. Ignore if the change is intentionally non-breaking.

robot-ch-test-poll2 added a commit that referenced this pull request Oct 14, 2026
Cherry pick #124453 to 26.3: Add S3 bucket to `remote_url_allow_hosts`
robot-ch-test-poll2 added a commit that referenced this pull request Oct 14, 2026
Cherry pick #124453 to 26.7: Add S3 bucket to `remote_url_allow_hosts`
robot-ch-test-poll2 added a commit that referenced this pull request Oct 14, 2026
Cherry pick #124453 to 26.8: Add S3 bucket to `remote_url_allow_hosts`
robot-ch-test-poll2 added a commit that referenced this pull request Oct 14, 2026
Cherry pick #124453 to 26.9: Add S3 bucket to `remote_url_allow_hosts`
@robot-clickhouse robot-clickhouse added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Oct 14, 2026
alexbakharew added a commit that referenced this pull request Oct 14, 2026
Backport #124453 to 26.9: Add S3 bucket to `remote_url_allow_hosts`
alexbakharew added a commit that referenced this pull request Oct 14, 2026
Backport #124453 to 26.8: Add S3 bucket to `remote_url_allow_hosts`
alexbakharew added a commit that referenced this pull request Oct 14, 2026
Backport #124453 to 26.7: Add S3 bucket to `remote_url_allow_hosts`
alexbakharew added a commit that referenced this pull request Oct 14, 2026
Backport #124453 to 26.3: Add S3 bucket to `remote_url_allow_hosts`
alexbakharew added a commit that referenced this pull request Oct 14, 2026
Refresh the cherry-pick base: 26.3 now carries #124453 (via the merged
backport), which #124930 builds on.
alexbakharew added a commit that referenced this pull request Oct 14, 2026
Adapted to this branch, which carries #124453 on the pre-#110665 factory API:
the third `ObjectStorageFactory::create` parameter becomes
`RemoteHostFilterCheck remote_host_filter_check` next to `skip_access_check`,
and `registerDiskObjectStorage` derives it from its `attach` and `custom_disk`
arguments. `RemoteHostFilter::checkURL` keeps this branch's unmasked message
and only gains the early returns. `DatabaseFactory::Arguments` has no
`is_restore_from_backup` here, so only `isLoadingFromExistingMetadata` is added.

The backward-compatibility test starts from the pinned image `26.3.50.11`
(built 2026-10-13, before #124453 reached this branch) instead of the floating
`26.8` tag, which will soon include the check itself and would fail to create
the disks.

26.3 keeps its non-static `registerS3ObjectStorage`, its single-line
`storage_settings->loadFromQuery` call and has no `DistributedPlanExecutor.cpp`.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
alexbakharew added a commit that referenced this pull request Oct 14, 2026
Adapted to this branch, which carries #124453 on the pre-#110665 factory API:
the third `ObjectStorageFactory::create` parameter becomes
`RemoteHostFilterCheck remote_host_filter_check` next to `skip_access_check`,
and `registerDiskObjectStorage` derives it from its `attach` and `custom_disk`
arguments. `RemoteHostFilter::checkURL` keeps this branch's unmasked message
and only gains the early returns. `DatabaseFactory::Arguments` has no
`is_restore_from_backup` here, so only `isLoadingFromExistingMetadata` is added.

The backward-compatibility test starts from the pinned image `26.9.18.11`
(built 2026-10-13, before #124453 reached this branch) instead of the floating
`26.8` tag, which will soon include the check itself and would fail to create
the disks.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
alexbakharew added a commit that referenced this pull request Oct 14, 2026
Adapted to this branch, which carries #124453 on the pre-#110665 factory API:
the third `ObjectStorageFactory::create` parameter becomes
`RemoteHostFilterCheck remote_host_filter_check` next to `skip_access_check`,
and `registerDiskObjectStorage` derives it from its `attach` and `custom_disk`
arguments. `RemoteHostFilter::checkURL` keeps this branch's unmasked message
and only gains the early returns. `DatabaseFactory::Arguments` has no
`is_restore_from_backup` here, so only `isLoadingFromExistingMetadata` is added.

The backward-compatibility test starts from the pinned image `26.8.26.12`
(built 2026-10-13, before #124453 reached this branch) instead of the floating
`26.8` tag, which will soon include the check itself and would fail to create
the disks.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
alexbakharew added a commit that referenced this pull request Oct 14, 2026
Bring the resolved cherry-pick onto the refreshed base (26.3 with #124453).
No content change: the tree is the one already resolved.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
alexbakharew added a commit that referenced this pull request Oct 14, 2026
Adapted to this branch, which carries #124453 on the pre-#110665 factory API:
the third `ObjectStorageFactory::create` parameter becomes
`RemoteHostFilterCheck remote_host_filter_check` next to `skip_access_check`,
and `registerDiskObjectStorage` derives it from its `attach` and `custom_disk`
arguments. `RemoteHostFilter::checkURL` keeps this branch's unmasked message
and only gains the early returns. `DatabaseFactory::Arguments` has no
`is_restore_from_backup` here, so only `isLoadingFromExistingMetadata` is added.

The backward-compatibility test starts from the pinned image `26.7.29.12`
(built 2026-10-13, before #124453 reached this branch) instead of the floating
`26.8` tag, which will soon include the check itself and would fail to create
the disks.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Algunenano pushed a commit to Algunenano/ClickHouse that referenced this pull request Oct 16, 2026
….8.26.12

The test needs an old server that does not check SQL-defined disks against
`remote_url_allow_hosts`, and took it from the moving tag
`clickhouse/clickhouse-server:26.8`. Since `26.8.28.14` (2026-10-15) that tag
contains the 26.8 backports of ClickHouse#124453 (ClickHouse#125789) and ClickHouse#124930 (ClickHouse#125821), so the
old server rejects the test's first setup CREATE with `Code: 491
UNACCEPTABLE_URL` before any upgrade, and both tests fail on master.

Pin both instances to `26.8.26.12`, which predates both backports. This makes
the file byte-identical to the 26.8 branch copy, which already pins this tag.

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-object-storage Object storage connectivity (S3/GCS/Azure) including credentials, retries, multipart, etc. pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-improvement Pull request with some product improvements pr-must-backport Pull request should be backported intentionally. Use this label with great care! pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR 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.

6 participants