Skip to content

Validate S3 and Azure URLs before client creation and schema inference - #114357

Merged
serxa merged 52 commits into
ClickHouse:masterfrom
rorylshanks:fix/s3-schema-inference-host-validation
Sep 11, 2026
Merged

serxa merged 52 commits into
ClickHouse:masterfrom
rorylshanks:fix/s3-schema-inference-host-validation

Conversation

@rorylshanks

@rorylshanks rorylshanks commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

Validate SQL-supplied S3 and Azure endpoints before schema inference, data-lake metadata access, or Azure container probes and creation. The checks cover object-storage table functions, including s3, s3Cluster, icebergS3, icebergS3Cluster, and azureBlobStorage, together with their persistent table creation paths.

Azure client creation can issue a container existence check before the storage constructor runs. Validate the Azure configuration before constructing that client, so a blocked endpoint receives no container requests. Regression coverage checks both the rejected query and the Azure API-call counters for CREATE TABLE and INSERT INTO TABLE FUNCTION.

Server-configured S3 disks remain operator-trusted. Selecting an explicitly allowed configured S3 disk from SQL does not turn its endpoint into a user-provided URL.

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

Apply remote_url_allow_hosts before SQL-supplied S3 and Azure endpoints send schema, metadata, or container requests.


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

Version info

  • Merged into: 26.9.1.1220 (included in 26.9 and later)
  • Backported to: 26.8.3.97, 26.7.7.86, 26.6.7.18, 26.3.33.80

Run the object-storage configuration check before `DESCRIBE s3` infers a schema, so `remote_url_allow_hosts` rejects the initial URL before any request.
@rorylshanks
rorylshanks marked this pull request as ready for review August 11, 2026 16:30
@george-larionov george-larionov added the can be tested Allows running workflows for external contributors label Aug 26, 2026
@clickhouse-gh

clickhouse-gh Bot commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [da5825d]

Summary: ✅


AI Review

Summary

This PR moves remote_url_allow_hosts validation ahead of schema inference, data-lake metadata access, and Azure client/container probing for SQL-supplied object-storage endpoints. On the current head, the earlier review gaps are closed: the Azure create/write path now checks the URL inside StorageAzureConfiguration::createObjectStorage before getContainerClient, the S3 configured-disk exemption stays scoped to trusted server disks, and the added integration coverage exercises the new S3 and Azure guard paths. I did not find any remaining correctness, security, or evidence gaps in the current diff.

Final Verdict

✅ No remaining findings on the current head.

LLVM Coverage Report

Measured on commit da5825d.

Metric Baseline Current Δ
Lines 88.80% 88.80% +0.00%
Functions 91.80% 91.80% +0.00%
Branches 81.20% 81.10% -0.10%

Changed lines: Changed C/C++ lines covered: 31/31 (100.00%) · 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 26, 2026
# Conflicts:
#	tests/integration/test_storage_s3/test.py
Run configuration checks before `resolveSchemaAndFormat` in `StorageObjectStorageCluster`, preventing blocked hosts from being contacted by `s3Cluster` during schema inference.
@rorylshanks rorylshanks changed the title Check s3 URLs before schema inference Check s3 and s3Cluster URLs before schema inference Aug 27, 2026
@clickhouse-gh

clickhouse-gh Bot commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing da5825d32 with master 7b90949ea (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

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

Job report

@rorylshanks

Copy link
Copy Markdown
Contributor Author

🕵 @groeneai, investigate the unrelated integration-test timeout: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=114357&sha=eefc929addb540d12c2d2fae25de47bbbe9bcd9f&name_0=PR&name_1=Integration%20tests%20%28amd_asan_ubsan%2C%20flaky%29 and provide a fix in a separate PR. All completed tests passed; three concurrent test_storage_s3/test.py::test_query_condition_cache runs stalled until the job-level timeout. No matching tracking issue exists. If the fix is already in progress, link it here.

@rorylshanks

Copy link
Copy Markdown
Contributor Author

🕵 The unrelated test_query_condition_cache timeout now has a separate fix: #116660

@groeneai

Copy link
Copy Markdown
Collaborator

The stall is not caused by test_query_condition_cache. The flaky job over-commits its own container, and that test is where the aggregate crosses the limit.

Integration tests (*, flaky) runs --dist=each and sizes workers as min(ncpu // MAX_CPUS_PER_WORKER, mem_gb // mem_per_worker) (ci/jobs/integration_test_job.py:930, with mem_per_worker = MAX_MEM_PER_WORKER_DIST_EACH = 20). mem_gb comes from Utils.physical_memory(), which returns SC_PAGE_SIZE * SC_PHYS_PAGES (ci/praktika/utils.py:561), that is the host's RAM and not the job container's cgroup limit. This run logged ncpu: 16, mem_gb: 61, created: 3/3 workers, so it budgeted 3 x 20 = 60 GiB against a container limit of 59.78 GiB. It is over-committed by construction.

The dmesg.log in that report shows the consequence. All three workers reach test_query_condition_cache at 07:41:21 and none of them ever reports it. At 07:43:37 the container cgroup is pinned at memory: usage 62679004kB, limit 62679004kB, and six oom-kill:constraint=CONSTRAINT_MEMCG events follow through 08:31:08. The victims are not only the three per-worker servers (pids 59859, 59860, 59861) but also dockerd and the python3.13 xdist workers, so the run can no longer fail cleanly: --session-timeout=2343 never reports, the harness backstop fires (Timeout exceeded [2943]) and the job exits 137.

That also answers the missing tracking issue. The job never reached its result assembly, so the OOM in dmesg row was never produced and CIDB holds only a job-level error row for this check. The failure has been arriving without a per-test signal to search for.

A fix is already in progress: I opened #112984 on 2026-08-02. Its stated behaviour change is precisely this case, --dist=each dropping from 3 workers to 2 with concurrency derived from the nested budget instead of host memory, and it also prints the counters and dmesg ahead of the archive so a run the backstop kills still reports. It carries manual approve, so it is waiting on a maintainer to approve its workflow.

Lowering the row group count in the test would move the crossing point without removing the over-commit, and the next module to peak on that runner would wedge the same way.

@rorylshanks

Copy link
Copy Markdown
Contributor Author

🕵 @groeneai, investigate the unrelated AlignStreams stress-test exception: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=114357&sha=7616f93d116c444b3d83d519c9777aac96778e1e&name_0=PR&name_1=Stress%20test%20%28arm_asan_ubsan%29 and provide a fix in a separate PR. The failure is in 05042_streaming_queries_lazy_materialization and src/Storages/MergeTree/Streaming/ReadingPlan/AlignStreams.cpp; PR 114357 changes only object-storage URL validation and test_storage_s3. No matching open issue or PR was found. If the fix is already in progress, link it here.

@groeneai

Copy link
Copy Markdown
Collaborator

Not caused by this PR. It is a trunk regression, and the fix is already in flight: #116531

The window is merged #116128 ("Split Streaming Read Round into Aligned Metadata and Data Streams", merged 2026-08-26 08:46:40Z). CIDB has 0 rows carrying that assertion between 2026-07-01 and that merge, and 24 since: 21 different PRs plus one master run (Stress test (arm_release), f62e739a, three commits after the merge commit), spread over 10 Stress configurations on both amd and arm. The commit tested here (7616f93d) is 467 commits ahead of that merge, and this PR is three one-line changes on the object-storage path plus test_storage_s3/test.py, none of it on the streaming read path.

AlignStreams requires the metadata stream to be a superset of the data stream: it throws when a data row's (block number, block offset) has no metadata match (AlignStreams.cpp:101 on master today) and when the metadata input finishes with data rows still pending (:333). #116531 removes the read and sort limits that the per-round metadata and data sub-plans inherit from the outer query (makeStreamingContext, makeStreamingSelectQueryInfo, and the SortingStep size limits in buildPartitionCommitOrderReadPlan) and applies them once in MergeTreeCommitOrderSource::prepare over the cumulative read progress, so the two sub-plans can no longer stop at different points. It is by @ Michicosun, who also wrote #116128, so I am not opening a competing PR for this.

Two notes: #116706 touches the same file but is a micro-optimization of the aligner, not a fix; and the assertion was still firing at 13:44Z today, so re-running CI here will not clear it until #116531 lands.

@rorylshanks

Copy link
Copy Markdown
Contributor Author

🕵 The current Integration tests (amd_asan_ubsan, flaky) failure has the same unrelated cgroup-overcommit signature: the job created 3 workers from host-reported mem_gb: 61, hit the 62,679,008 KiB container limit repeatedly, and OOM-killed three clickhouse processes, a python3.13 worker, dockerd, and the harness before the timeout. Report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=114357&sha=57d300ec4c37f7c73476ed5b0d3814e2e941d9f3&name_0=PR&name_1=Integration%20tests%20%28amd_asan_ubsan%2C%20flaky%29

The existing fix is #112984; no change to PR 114357 is needed for this failure.

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

This is nice, thank you!

@serxa
serxa added this pull request to the merge queue Sep 11, 2026
@serxa serxa added the pr-must-backport Pull request should be backported intentionally. Use this label with great care! label Sep 11, 2026
Merged via the queue into ClickHouse:master with commit 552c7f6 Sep 11, 2026
175 checks passed
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 11, 2026
@robot-ch-test-poll robot-ch-test-poll added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Sep 11, 2026
@rorylshanks
rorylshanks deleted the fix/s3-schema-inference-host-validation branch September 11, 2026 21:24
clickhouse-gh Bot pushed a commit that referenced this pull request Sep 11, 2026
clickhouse-gh Bot added a commit that referenced this pull request Sep 11, 2026
Backport #114357 to 26.8: Validate S3 and Azure URLs before client creation and schema inference
clickhouse-gh Bot pushed a commit that referenced this pull request Sep 11, 2026
clickhouse-gh Bot added a commit that referenced this pull request Sep 11, 2026
Backport #114357 to 26.7: Validate S3 and Azure URLs before client creation and schema inference
PedroTadim added a commit that referenced this pull request Sep 14, 2026
Keep master's `format != "auto"` guard in `checkFormat`. It is unchanged context
in #114357's diff, but it comes from a commit that is not on 26.3, and this change
moves `check()` ahead of schema inference where `format` is still `auto`; without
it every `format = auto` table would fail with UNKNOWN_FORMAT.

Drop the post-inference `configuration->check(context)` the merge left behind in
StorageObjectStorage.cpp. 26.3 has no comment above that call, so the removal
hunk did not match and the new early call was simply added alongside it.

In the tests, take only what belongs to this change: `remote_servers.xml` for
`restricted_dummy` (not `allow_server_credentials.xml`, which does not exist on
26.3) and the new `remote_url_allow_hosts` block in test_storage_iceberg_disks.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
PedroTadim added a commit that referenced this pull request Sep 14, 2026
Cherry pick #114357 to 26.3: Validate S3 and Azure URLs before client creation and schema inference
PedroTadim added a commit that referenced this pull request Sep 14, 2026
Keep master's `format != "auto"` guard in `checkFormat`. It is unchanged context
in #114357's diff, but it comes from a commit that is not on 26.6, and this change
moves `check()` ahead of schema inference where `format` is still `auto`; without
it every `format = auto` table would fail with UNKNOWN_FORMAT.

Drop the post-inference `configuration->check(context)` the merge left behind in
StorageObjectStorage.cpp. 26.6 has no comment above that call, so the removal
hunk did not match and the new early call was simply added alongside it.

For `restricted_dummy`, add only `remote_servers.xml`; the other side also lists
`allow_server_credentials.xml`, which does not exist on 26.6.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
PedroTadim added a commit that referenced this pull request Sep 14, 2026
Cherry pick #114357 to 26.6: Validate S3 and Azure URLs before client creation and schema inference
robot-clickhouse added a commit that referenced this pull request Sep 14, 2026
robot-clickhouse added a commit that referenced this pull request Sep 14, 2026
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Sep 14, 2026
PedroTadim added a commit that referenced this pull request Sep 14, 2026
Backport #114357 to 26.3: Validate S3 and Azure URLs before client creation and schema inference
PedroTadim added a commit that referenced this pull request Sep 15, 2026
Backport #114357 to 26.6: Validate S3 and Azure URLs before client creation and schema inference
nihalzp pushed a commit to nihalzp/ClickHouse that referenced this pull request Oct 16, 2026
S3::PocoHTTPClientConfiguration stores the remote host filter as a reference
member (src/IO/S3/PocoHTTPClient.h:69), and so does the HTTP client built from
it (:229, bound at PocoHTTPClient.cpp:221). The configuration is a freely copied
value type: S3::Client keeps a whole copy (Client.h:323) and
S3CredentialsProviderChain forwards it into three more configurations
(Credentials.cpp:1025/1044/1096). Because the member is a reference, every copy
re-binds the same referent instead of owning anything, so the filter must
outlive the configuration, every copy of it, and every client and credentials
provider derived from it, including providers parked for the life of the process
in CredentialsProviderCache::instance() (Credentials.cpp:180-184), whose key
does not include the filter.

Four call sites pass a filter that dies first. Reading it afterwards is
undefined behaviour; the read is the std::atomic_bool is_initialized in
RemoteHostFilter::checkForDirectEntry (RemoteHostFilter.cpp:64), reached from
checkURL at PocoHTTPClient.cpp:685 on a 307 and at Client.cpp:1073 on a 301.
Both sit behind a redirect, which is why the class is mostly latent today.

Give the filter static storage duration at each site and pass it by name.
Static storage duration is process lifetime, so it dominates every retention
path, including the process-wide provider cache, rather than patching one
deref. Behaviour is unchanged: a default-constructed filter has
is_initialized == false, so checkForDirectEntry returns true unconditionally
(RemoteHostFilter.cpp:62-66) and checkURL cannot throw, which is exactly what
the previously valid read would have answered. Only the storage duration
changes, never the filter's contents. Same idiom as
src/IO/AzureBlobStorage/PocoHTTPClient.cpp:628.

Exit-time safety does not rest on static destruction order: nothing on the
retention chain dereferences the filter while unwinding.
~PocoHTTPClient() is defaulted (PocoHTTPClient.h:167) and
src/IO/S3/Credentials.cpp defines no destructor bodies at all.

Validated under ASan with -fsanitize-address-use-after-scope. Making the read
unconditional reproduces the published stack-use-after-return at
__cxx_atomic_load<bool> (c11.h:81:10) with ASan naming the dead filter and its
declaration line, and a two-directions arm over the credentials-provider cache
aborts with a scope-local filter and passes with a static one while reaching the
same read in both arms. In that ASan binary the three test sites construct the
dangling binding but never read it: their clients are mocks that issue no HTTP
request, or the cached provider's key is a per-test ephemeral endpoint. The
production Kafka site is not bounded that way: the chain is retained in
StorageKafka::oauth_context and in the process-wide provider cache, and
PocoHTTPClient.cpp:545 runs its body once even at that site's
s3_max_redirects = 0, so the 307 read at :685 is reachable.

No new test ships. The read needs a 307/301 redirect, which no unit test
induces, and detection additionally requires a sanitizer, so no shipped test
can distinguish this fix.

Two further call sites with the same defect,
src/Coordination/KeeperSnapshotManagerS3.cpp:119 and the createTestS3Client
helper in src/IO/S3/tests/gtest_aws_s3_client.cpp, are already fixed by the
open PR ClickHouse#114357 and are deliberately left to it. This change touches neither of
its hunks.
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-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-bugfix Pull request with bugfix, not backported by default 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.

8 participants