Skip to content

Native Google Cloud Storage integration (google-cloud-cpp) - #109455

Open
alexey-milovidov wants to merge 286 commits into
masterfrom
native-gcs
Open

alexey-milovidov wants to merge 286 commits into
masterfrom
native-gcs

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Jul 5, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Experimental Feature

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

Added an experimental native Google Cloud Storage integration built on the Google Cloud C++ SDK (google-cloud-cpp, the GCS JSON API), as an alternative to the existing S3-compatibility path. Enable it with the new use_native_gcs setting for the gcs table function and dynamic disk(...) definitions, or configure a MergeTree storage disk with object_storage_type: gcs. Such a disk can also back an Iceberg table. Initial implementation by @tanner-bruce in #105505.

Documentation entry for user-facing changes

Documented in docs/reference/functions/table-functions/gcs.mdx (new "Native GCS integration" section) and in the server configuration page (new "Using Native Google Cloud Storage" section).


Description

ClickHouse currently talks to GCS only through its S3-compatible XML API (the AWS SDK against a storage.googleapis.com endpoint, plus a cluster of GCS quirk-toggles in the S3 client). This PR adds a first-class native backend on top of the already-vendored google-cloud-cpp storage client.

Opt-in, non-breaking. The gcs() table function and dynamic disks select the native backend only with the new experimental use_native_gcs setting (default false); otherwise they retain S3 compatibility and HMAC keys. ENGINE = GCS remains on the existing compatibility path.

What's added

  • ObjectStorageType::GCS + GCSObjectStorage : IObjectStorage (src/Disks/DiskObjectStorage/ObjectStorages/GCS/), with ReadBufferFromGCS/WriteBufferFromGCS over the SDK's ObjectReadStream/ObjectWriteStream (ranged seeks, parallel ranged reads of one object, single-request InsertObject uploads of objects up to max_single_part_upload_size and resumable uploads of larger ones), lazily paged listing, RewriteObject-based copy, DeleteObject, GetObjectMetadata.
  • Registered as the gcs object-storage type + a gcs disk-type alias, so MergeTree data can live natively on GCS (type: object_storage, object_storage_type: gcs).
  • StorageGCSConfiguration (reuses StorageS3Configuration's argument parsing) and a TableFunctionGCS selector that picks native vs S3-compat by the use_native_gcs setting.
  • Auth mirrors the compat surface on the native side: Application Default Credentials, service-account JSON, the google_adc_* OAuth refresh-token flow, anonymous (NOSIGN or use_environment_credentials = 0), and a REST endpoint override for the GCS emulator. The google_adc_* access token is renewed as it nears expiry, so the mode is usable by a long-lived disk as well as by a query; a disk may point the exchange at a private endpoint with google_adc_token_uri (validated against remote_url_allow_hosts).
  • An Iceberg table can live on a native GCS disk: the Iceberg engine and the iceberg table function dispatch on the disk setting's backend, and ObjectStorageType::GCS is wired into both. GCSObjectStorage::readSmallObjectAndGetObjectMetadata returns the object generation alongside the data, which is what makes the version-hint.text compare-and-swap on the Iceberg write path safe.
  • The Poco-based REST transport that replaces libcurl keeps idle keep-alive sessions pooled per endpoint-and-proxy, with the retained-session cap taken from each request's max_connections rather than from process-wide state.
  • The S3 request-rate throttlers (s3_max_get_rps, s3_max_get_burst, s3_max_put_rps, s3_max_put_burst) apply to the native client too, per HTTP request and by method as in PocoHTTPClient, with GCS*RequestThrottler* / DiskGCS*RequestThrottler* profile events.
  • USE_GOOGLE_CLOUD is now exposed in system.build_options.

Testing

  • Every changed/new translation unit compiles against the real headers and the vendored SDK (USE_GOOGLE_CLOUD=1, USE_AWS_S3=1).
  • Unit tests for endpoint parsing, object-name encoding, conditional writes, proxy identity and the credential priority order (including the refresh-token mode and the completeness of the triple).
  • Stateless tests for the setting wiring, the credential rejections that remain (HMAC keys, role_arn, SSE, metadata-service OAuth, presigned URLs, service_account_key_file on a dynamic disk), and the two anonymous forms.
  • Integration test test_native_gcs runs against a fake-gcs-server emulator (a new with_gcs helper in cluster.py): gcs() INSERT/SELECT + glob, a MergeTree-on-GCS-disk round trip, profile events, the filesystem cache, parallel ranged download, dynamic-disk credential validation, an Iceberg table on a GCS disk, and the refresh-token flow against a stub token endpoint (both the renewal and the caching of a long-lived token). Note: fake-gcs-server speaks the GCS API (unlike minio, which is S3-only). The module is skipped on builds without the SDK.

🤖 Generated with Claude Code


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

@clickhouse-gh

clickhouse-gh Bot commented Jul 5, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [f5d269f]

Summary: ❌

job_name test_name status info comment
Integration tests (amd_asan_ubsan, db disk, targeted) FAIL
test_merge_tree_hdfs/test.py::test_sql_hdfs_disk_remote_host_filter FAIL cidb
Stateless tests (amd_asan_ubsan, db disk, distributed plan, targeted) FAIL
05621_documentation_no_docusaurus_syntax FAIL cidb
05621_documentation_no_docusaurus_syntax FAIL cidb
05621_documentation_no_docusaurus_syntax FAIL cidb
05621_documentation_no_docusaurus_syntax FAIL cidb
05621_documentation_no_docusaurus_syntax FAIL cidb
Too many test failures FAIL cidb
Finish Workflow FAIL
python3 ./ci/jobs/scripts/workflow_hooks/can_be_merged.py --review-threads FAIL

AI Review

Summary

Adds an experimental native Google Cloud Storage backend for gcs, dynamic disks, and disk-backed Iceberg, together with a Poco transport and credential handling. Reviewed head f5d269f74b82b197a0ef893850ef22f8b24eb742 and all prior discussions. Five findings remain: three blockers and two majors. One new finding was posted in a batched review; two earlier bot threads were reopened after verifying that their claimed fixes remain incomplete.

Findings

❌ Blockers

  • getDiskConfigurationFromAST.cpp:445: The GCS ADC guard rejects an indirectly selected S3 backend even when it supplies complete literal S3 keys and use_native_gcs = 0. For example, type = 's3', object_storage_type = '${type}' is treated as potentially credential-less GCS before substitution. The same unconditional guard runs during metadata loading, so existing S3 tables without a server-credential marker can stop attaching after an upgrade. Defer the ADC decision until the backend is resolved, preserving the explicit S3 credential path. Inline finding.

  • poco_rest_client.cc:1268: CR/LF validation covers only the transport's own authorization token. The pinned SDK also obtains a token through its separate legacy credentials and adds it through unchecked request.headers. An inline service-account credential selecting OAuth can use an allowed token endpoint that returns a malicious token first and a normal token second; the checked token passes, then the unchecked one reaches Poco verbatim. This still bypasses http_forbid_headers and permits request splitting. Validate every final header or use one sanitized authorization carrier. Reopened thread and source trace.

  • DatabaseDataLake.cpp:258: Catalog location conversion inspects a native GCS disk before either disk authorization check runs. A mismatching catalog location exposes the disk's real bucket and key prefix in an exception even when that disk is disallowed. Enforce allowed_disks_for_table_engines and DiskFromAST::ensureDiskIsAllowed before selecting or inspecting the disk. Cover a disallowed disk with a mismatching location. Existing unresolved finding.

⚠️ Majors

  • getDiskConfigurationFromAST.cpp:882: Short ATTACH TABLE still requires repeating use_native_gcs = 1 for an already stored dynamic GCS definition. It passes is_loading_from_existing_metadata = false and the separate stored_definition = true, but the feature gate receives only the former. Honor stored definitions at this gate and test anonymous GCS CREATE, DETACH, then short ATTACH with default settings. Reopened thread.

  • WriteBufferFromGCS.cpp:175: Single-request upload staging still uses String pending_data, whose generic allocations count memory without enforcing the configured memory limit. Each writer can accumulate up to s3_max_single_part_upload_size (32 MiB by default, configurable higher), and concurrent column writers amplify the overshoot. Use an enforced buffer such as StringWithMemoryTracking and cover accumulation under a low memory limit. Existing unresolved finding.

Tests
  • ⚠️ Add focused regressions for the paths above, including metadata reload of the explicitly credentialed S3 disk and a malicious token returned through the SDK's legacy service-account carrier.
  • ⚠️ Runtime reproductions were not executed: this CI job has no ClickHouse binary. The fetched head CI report contains passing fast tests and tidy builds, but no completed GCS integration/unit results. Those results are still needed after the fixes.
Final Verdict

Status: ❌ Block

Fix the three blockers before merge. Address the two majors and add the focused regression coverage described above.

@clickhouse-gh clickhouse-gh Bot added the pr-experimental Experimental Feature label Jul 5, 2026
@mintlify

mintlify Bot commented Jul 5, 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 Nov 24, 2026, 11:57 PM

@alexey-milovidov

Copy link
Copy Markdown
Member Author

CI triage for the native GCS integration

I looked at the red integration tests (test_native_gcs) on 8ee87cc9. There are two distinct problems.

1. gcs(...) table function threw Not found: gcs..endpoint — fixed

test_table_function_insert_select / test_table_function_glob failed with:

Code: 1000. DB::Exception: Not found: gcs..endpoint
 ... GCSObjectStorageSettings::loadFromConfig
 ... GCSObjectStorage::applyNewSettings
 ... StorageObjectStorageConfiguration::update

The table engine / table function build GCSObjectStorage with all settings already derived from the URL and arguments. StorageObjectStorageConfiguration::update then calls applyNewSettings with config_prefix = gcs., and loadFromConfig tried to read a non-existent gcs..endpoint server-config key. Fixed by skipping the config reload when <config_prefix>.endpoint is absent (the storage / table-function path), mirroring how S3ObjectStorage keeps its URL-derived settings — only the object_storage_type = gcs disk has an endpoint under config_prefix. Pushed as 17285d52b51.

2. localeconv SIGILL in debug/sanitizer builds — needs a decision

test_mergetree_on_gcs_disk crashed the server with Illegal instruction (4) while IDisk::checkAccess wrote its probe blob:

 base/harmful/harmful.c:109: localeconv          <-- TRAP(localeconv), fires in DEBUG_OR_SANITIZER_BUILD
 contrib/nlohmann-json/.../json.hpp:7168: get_decimal_point
 ... nlohmann ... ::parser(...)
 google::cloud::storage::internal::ObjectMetadataParser::FromString
 google::cloud::storage::internal::RestStub::UploadChunk
 ... WriteBufferFromGCS::finalizeImpl
 ... IDisk::checkAccessImpl

google-cloud-cpp parses every JSON response through ClickHouse's shared contrib/nlohmann-json (aliased as nlohmann_json::nlohmann_json in contrib/google-cloud-cpp-cmake/CMakeLists.txt). nlohmann's lexer (get_decimal_point) and float serializer call localeconv(), which base/harmful/harmful.c traps as non-thread-safe in debug/sanitizer builds → SIGILL. This is why it doesn't reproduce in a local release compile — the trap is only active in DEBUG_OR_SANITIZER_BUILD. Once problem 1 is fixed the table-function tests will hit the same trap as soon as they do any I/O (they parse ObjectMetadata JSON too), so both need this.

We already carry the exact fix for the copy of nlohmann vendored inside the Azure SDK — contrib/azure/sdk/core/azure-core/inc/azure/core/internal/json/json.hpp:

static char get_decimal_point() noexcept
{
    // ClickHouse always uses the C locale where the decimal point is '.'.
    // localeconv() is non-thread-safe and is prohibited by ClickHouse's
    // harmful function list in debug/sanitizer builds.
    return '.';
}
// serializer ctor: loc(nullptr), thousands_sep('\0'), decimal_point('.')

The clean fix is to apply that same patch to the shared contrib/nlohmann-json (JSON numbers are always . regardless of locale, so this is correct for every consumer and removes a latent SIGILL for all nlohmann parsing in sanitizer builds). That means forking nlohmann-json into the ClickHouse org (it currently points at upstream nlohmann/json.git) and bumping the submodule — an architectural call I left to you rather than deciding it here. I did not vendor a patched copy only for google-cloud-cpp: that would put a patched and an unpatched json_abi_v3_12_0 in the same binary, i.e. an ODR violation on get_decimal_point.

3. AI review threads (unresolved)

All four are genuine but are design / completeness items on the experimental feature, so I left them for you:

  • GCSObjectStorage.cpp readObject drops object.etag — no mid-read overwrite protection. GCS uses object generation/metageneration rather than HTTP If-Match, so this needs mapping the stored etag to gcs::IfGenerationMatch on ReadObject, not a one-liner.
  • gcsSettings.cpp resolveGCSCredentialsToken — the refresh-token triple is exchanged for a one-shot access token at init; the long-lived client never refreshes after expires_in. Not exercised by the NOSIGN tests.
  • registerStorageObjectStorage.cpp backend selection — configuration = StorageGCSConfiguration is chosen from the session setting use_native_gcs at CREATE time. For a persisted ENGINE = GCS(...) table the choice isn't stored, so after a restart (setting defaults off) it reloads through StorageS3Configuration.
  • GCS/Configuration.cpp — only no_sign_request and google_adc_* are copied out of the S3 parser; there's no SQL / named-collection path filling service_account_key, service_account_key_file, or access_token, and StorageS3Configuration::fromNamedCollection still rejects google_adc_*.

Comment thread src/CMakeLists.txt Resolved
alexey-milovidov added a commit that referenced this pull request Jul 20, 2026
With `dynamic_disk_allow_from_env` / `dynamic_disk_allow_from_zk` enabled, a
user-created native GCS disk could supply `service_account_key`,
`access_token`, or `google_adc_*` as a `from_env`/`from_zk` placeholder. The
placeholder resolves on the server, so `getGCSClient` would authenticate the
query with server-managed auth material (an environment secret or a ZooKeeper
node), even though `service_account_key_file` was already rejected.

Track indirect values of the native GCS credential fields in
`getDiskConfigurationFromASTImpl` and fail closed for a (possibly indirect)
GCS backend, mirroring the existing `service_account_key_file` rejection,
with the same `system`-database exemption. The check fires on the AST before
any object storage is constructed, so it is safe in all build types.

Extends `04549_gcs_disk_service_account_key_file_rejected` with negative
cases for each field and for an indirect backend type.

Addresses the review finding on getDiskConfigurationFromAST.cpp in
#109455

Co-Authored-By: Claude Fable 5 <[email protected]>
@alexey-milovidov alexey-milovidov added the pr-autogenerated-docs PR that regenerates docs artifacts from source; exempt from the autogenerated-region edit guard label Jul 20, 2026
alexey-milovidov and others added 4 commits July 25, 2026 10:39
…tings sub-page

The Docs check (lychee `--include-fragments`) failed on `gcs.mdx` because
`/reference/settings/session-settings#use_native_gcs` has no such fragment:
the `session-settings` page is now a `SessionSettingsExplorer` component
page without static anchors. Link to the per-prefix generated page
`/reference/settings/session-settings/use#use_native_gcs` instead, which is
the convention used by other setting cross-references. The autogenerated
region of `gcs.mdx` and `gcs_description` in `TableFunctionObjectStorage.cpp`
are updated together to stay byte-identical.

Report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=109455&sha=0d102b0dce8ce42707f2e45e367cbb0392c73fb5&name_0=PR&name_1=Docs%20check%20%28Mintlify%29

Co-Authored-By: Claude Fable 5 <[email protected]>
…GCS mode

The S3-compatibility path can authenticate through the GCP metadata service
(`http_client = gcp_oauth` with `service_account`, `metadata_service`,
`request_token_path`), requesting a token for the *named* service account.
`StorageGCSConfiguration::createObjectStorage` neither copied nor rejected
these settings, so with `use_native_gcs = 1` they silently fell through to
Application Default Credentials, which only ever use the VM's default service
account — a silent change of the requested identity. Fail close, like the
existing rejections of HMAC keys, `role_arn`, and SSE settings. The throw
happens while the configuration is built, before any network client is
constructed, so the new test is safe in every build type.

Co-Authored-By: Claude Fable 5 <[email protected]>
…gs as one snapshot

Two review findings on `GCSObjectStorage`:

1. `iterate` materialized the entire listing into memory before returning the
   first object, so globs over large prefixes scaled with the total object
   count instead of the page size. Replace it with `GCSIteratorAsync` (modeled
   on the S3 and Azure backends' `IObjectStorageIteratorAsync` subclasses),
   which pages through `ListObjectsReader` lazily, prefetching one batch at a
   time on a single listing thread. `start_after` keeps its exclusive
   semantics on top of the inclusive `StartOffset` request option. Adds the
   `ObjectStorageGCSThreads*` metrics and the `GCS_LIST_POOL` thread name.

2. `applyNewSettings` published the new client and the new settings in two
   separate steps, so `copyObjectToAnotherObjectStorage` could validate
   `describesSameClientAs` against the old settings and then fetch the new
   client, reintroducing the wrong-endpoint/wrong-identity rewrite the guard
   exists to prevent. The client and the settings it was built from are now
   one immutable `MultiVersion` snapshot; the copy fast path validates and
   issues the rewrite through the same snapshot.

Co-Authored-By: Claude Fable 5 <[email protected]>
The `Stress test (amd_tsan)` run of this PR crashed with the known
`localeconv` SIGILL: the positive control of
`04549_gcs_disk_service_account_key_file_rejected.sh` constructed a native
GCS client (whose credential parsing goes through the shared nlohmann-json)
on a TSan build. The gate that is supposed to skip the positive control on
debug/sanitizer builds compared `$debug_or_sanitizer = 1`, so when the
detection query failed transiently under stress load (empty output), the
dangerous branch ran anyway. Invert the comparison: run the positive control
only when the server definitively reported a release-type build.

Report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=109455&sha=0d102b0dce8ce42707f2e45e367cbb0392c73fb5&name_0=PR&name_1=Stress%20test%20%28amd_tsan%29

Co-Authored-By: Claude Fable 5 <[email protected]>
alexey-milovidov and others added 2 commits November 9, 2026 04:54
… token-request options

The SDK builds the REST clients of Application Default Credentials and of a service-account
key from the options handed to the credentials, so the `PocoRestSessionStaleCheckOption`
installed only on the storage client's options did not reach them: a pooled token-request
session closed by the peer, or holding an unsolicited response, could be reused.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…URI` validates the bucket

The previous fix rewrote the bucket and key of `https://<bucket>.storage.googleapis.com/<key>`
after `StorageS3Configuration::fromAST` / `fromNamedCollection` had already constructed an `S3::URI`.
With `s3_uri_style = 'AUTO'` that parser takes the first path component as the bucket and
`S3::URI::validateBucket` rejects it when it is shorter than 3 or longer than 63 bytes, so e.g.
`gcs('https://my-bucket.storage.googleapis.com/a/b', ...)` failed with `BAD_ARGUMENTS` before the
correction was reached.

`S3StorageParsedArguments` now builds the URI through `parseURI`. When the native GCS configuration
asks for it (`recognize_gcs_virtual_hosted_urls`), a URL on the virtual-hosted form of the default
GCS host is rewritten to the equivalent path-style URL of `storage.googleapis.com` and parsed with
`S3UriStyle::PATH`, so the bucket (which may contain dots) comes from the host and the key from the
whole path. The post-parse `applyGCSVirtualHostedStyle` and the `fromNamedCollection` override that
only existed for it are removed.

This also fixes the `arm_tidy` build: `StorageGCSConfiguration` wrote the `paths_mutex`-guarded
`keys` directly (in `fromDisk` and `applyGCSVirtualHostedStyle`); `fromDisk` now uses `setPaths`.

https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=109455&sha=823ac00591190d7bac97cf49cb19afeae9a1f4cb&name_0=PR&name_1=Build%20%28arm_tidy%2C%201%2F4%29
#109455

Co-Authored-By: Claude Opus 5.5 <[email protected]>
alexey-milovidov and others added 6 commits November 11, 2026 10:19
Conflicts were in the dynamic disk credential checks, which `master` reworked
(`S3_SERVER_CREDENTIALS_MARKER`, `resolveDiskConfiguration`, `diskUsesServerCredentials`,
identity-preserving credentials markers in `flattenDiskConfiguration`). Resolution:
- `getOrCreateCustomDisk` takes the structure from `master` and keeps the PR's
  `validateResolvedGCSDiskCredentials` re-check after `include` resolution.
- `ServerCredentialMarkerInjector` writes the S3 marker only when the PR's
  `resolvedDiskConfigReliesOnServerCredentials` confirms it on the resolved configuration;
  the Azure marker follows `master` (decided on the resolved configuration).
- `has_substituted_value` is dropped, as on `master`; the PR's `collectResolvedBackendPrefixes`
  replaces `master`'s `getS3BackendPrefixes`.
- `uses_server_credentials` also covers native GCS Application Default Credentials, and
  `diskUsesServerCredentials` uses `resolvedDiskConfigReliesOnServerCredentials`, so a wrapper
  over a GCS disk with server credentials is treated like one over an S3 disk.
…must reach object storage

After the merge of `master`, `SELECT sum(a)` over a `MergeTree` table is answered from column
statistics (`use_statistics_for_sum_avg_aggregation`), so the reads in `test_profile_events`,
`test_request_rate_throttler_disk` and `test_dynamic_gcs_disk_renews_a_refresh_token_credential`
no longer issued any GCS request: `GCSGetObject` and `GCSGetRequestThrottlerCount` were 0 and the
access token was not renewed. The server log shows
`Aggregation from column statistics is applied: 1 parts with 10000 rows are answered from statistics`.

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

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…date native GCS bucket names by the GCS rules

`S3StorageParsedArguments::parseURI` matched `https://<bucket>.storage.googleapis.com` case-sensitively on
the raw string, while `S3::URI` and `isDefaultGCSEndpoint` see the host as `Poco::URI` normalizes it. So
`HTTPS://bucket-a.STORAGE.GOOGLEAPIS.COM/bucket-b/file.tsv` was not rewritten, was parsed as path-style
and addressed `bucket-b/file.tsv` at the default endpoint instead of `bucket-a/bucket-b/file.tsv`.
Now the origin of the URL is parsed with `Poco::URI` and the scheme, host and port are compared in their
normalized form (a trailing dot of the host is ignored); user information with such a host is rejected.

Native GCS bucket names are now validated by the GCS rules (`S3::URI::validateGCSBucket`: 3 to 63
characters, or up to 222 for a dotted name with components of at most 63) instead of the S3 limit of 63
characters, in the shared argument parser, in `StorageGCSConfiguration::fromDisk` (used by `Iceberg` over a
native GCS disk) and in `validateNamespace`. `S3::URI` takes a `validate_bucket_name` argument for that.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Conflicts: kept the native GCS fields of `DynamicS3DiskCredentialInfo` with the updated comment from master
(the ADC flag now also covers `google_service_account_key`), and kept both `parseURI` and master's
`explicit_request_setting_names` in `S3/Configuration.cpp`.
… by older versions

This PR writes `_server_credentials_allowed` into a stored dynamic disk definition only when the resolved
configuration relies on server credentials. Older versions (26.7 to 26.11) wrote it to any definition with
`include`, `from_env` or `from_zk`, and 26.11 the Azure marker after it, so declaring such a disk again
(for example `type = 'from_env T'` with `T=local`) produced a different name and did not reuse the
existing disk. Try those forms too, the same way the forms without markers are tried.

`05494_custom_disk_identity_without_credentials_marker` emulated older versions by stripping the markers,
which no longer exist for a `local` disk: in the `permanently_detached` case the second disk was never
created, `legacy_disk` was empty, and the test removed the whole `disks` directory. Emulate the older
versions by adding the markers instead.

https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=109455&sha=90f73a4c87bdcfd0856e689acb0ccdfb8b069389&name_0=PR&name_1=Fast%20test
#109455

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

alexey-milovidov commented Nov 14, 2026 •

Copy link
Copy Markdown
Member Author

🕵 This push (e152ac4) merges master and fixes the Fast test failure of 05494_custom_disk_identity_without_credentials_marker, a semantic conflict with the dynamic disk identity logic that came from master:

  • This PR writes _server_credentials_allowed only when the resolved disk relies on server credentials, while 26.7 to 26.11 wrote it to any definition with include / from_env / from_zk (and 26.11 the Azure marker after it). So re-declaring such a disk (e.g. type = 'from_env T' with T=local) after an upgrade did not find the existing disk. flattenDiskConfiguration now also tries the forms with the S3 marker and with both markers, the same way it tries the forms without markers.
  • The test emulated older versions by stripping markers, which a local disk no longer has: legacy_disk came out empty and the test removed the whole disks directory (mv: cannot stat). It now emulates them by adding the markers. It passes locally; clickhouse builds on the merged tree.

All review threads are resolved.

alexey-milovidov and others added 5 commits November 16, 2026 04:32
Conflict in src/Disks/getDiskConfigurationFromAST.cpp: master added a generic
repeated-key check (`seen_keys` / `is_list_key`) that tolerates repeats in stored
definitions; it supersedes the PR's `is_singleton_key` check, which is dropped.
`parseLiteralConfigBool` is replaced by master's equivalent `parseDiskConfigurationBool`.
A `204 No Content` (and `1xx` / `304`) response need not carry `Content-Length`
(RFC 9110, section 8.6), and Poco reads it as a zero-length body. The SDK drops
such payloads unread (`RestStub::DeleteObject` through `ReturnEmptyResponse`),
so `FinishForReuse` saw an unknown length and the connection was closed after
every object deletion. Treat bodyless statuses as finished, keeping the
keep-alive and buffered-data checks.

Add a transport test that issues two deletions answered with `204` without
`Content-Length` and checks they go over one connection.

Addresses review: #109455 (comment) PRRT_kwDOA5dJV863ZuFZ

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…the original URL for endpoint settings

- `S3StorageParsedArguments::parseURI` now applies `url_scheme_mappers` (new
  `S3::URI::applySchemeMapper`, shared with the `S3::URI` constructor) before
  recognizing `https://<bucket>.storage.googleapis.com/<key>`. A mapper such as
  `gs` -> `https://{bucket}.storage.googleapis.com` previously produced that form
  inside `S3::URI`, after the check, so the first path component was taken as
  the bucket.
- The `<s3>` endpoint section is selected by the URL as written (after scheme
  mapping), not by the rewritten path-style URL of `storage.googleapis.com`, so
  a section for `https://<bucket>.storage.googleapis.com/` keeps applying on the
  native path, as it does on the S3-compatibility path.

Addresses review threads on `src/Storages/ObjectStorage/GCS/Configuration.cpp`
and `src/Storages/ObjectStorage/S3/Configuration.cpp`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Master marked `IcebergPathResolver::resolve` as `[[nodiscard]]`, so the
`EXPECT_THROW` checks added by this PR now discard its result explicitly.

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

A `url_scheme_mappers` entry that produces `https://<bucket>.storage.googleapis.com`
must take the bucket from the host, and the `<s3>` endpoint section for that host
must still be selected on the native path. Added to the existing `test_native_gcs`
module (a server configuration is needed for both), using `EXPLAIN` so that
nothing is sent to GCS.

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

Copy link
Copy Markdown
Member Author

🕵 Pushed 34528d0:

  • Merged master. Conflict in src/Disks/getDiskConfigurationFromAST.cpp: master added a generic repeated-key check (seen_keys / is_list_key, tolerant for stored definitions), which supersedes the PR's is_singleton_key check, so that one is dropped; parseLiteralConfigBool is replaced by master's parseDiskConfigurationBool. Docs conflict in use.mdx resolved by keeping both settings.
  • Semantic conflict: IcebergPathResolver::resolve became [[nodiscard]] on master; the new EXPECT_THROW checks now use std::ignore.
  • Addressed the three open review threads (scheme-mapped virtual-hosted URLs, endpoint-section lookup URL, connection reuse after bodyless 204).

Locally: clickhouse and unit_tests_dbms build; 188 GCS / Iceberg / S3 URI unit tests pass; the new integration test case passes; 20 of the 21 PR stateless tests pass against a local server (05331 needs tests/config/config.d/disable_s3_env_credentials.xml, which my ad-hoc server did not load).

clickhouse-gh[bot]
clickhouse-gh Bot previously approved these changes Nov 16, 2026

@clickhouse-gh clickhouse-gh Bot 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.

AI review approves this commit, see the AI Review comment.

alexey-milovidov and others added 5 commits November 19, 2026 04:54
Conflict resolutions:
- `DiskObjectStorage::getObjectStoragesByLocation` is replaced by the identical `getObjectStorages` from master.
- `S3::URI` takes `std::string_view` (from master) and keeps the `validate_bucket_name` parameter of this PR.
- Kept both the native GCS tests and the new `StorageIdentity` test in `gtest_iceberg_path_resolver`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- `Poco::Net::HTTPClientSession::ProxyConfig::password` is now a no-dump buffer.
- Mark `describesSameClientAs`, `hasChangesAffectingClient` and `getGCSObjectStorageSettings` `[[nodiscard]]`.
- Initialize `reject_foreign_namespaces` in the `StorageIdentity` test from master.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
`Poco::Util::XMLConfiguration` names repeated siblings `header`, `header[1]`, ..., so the
post-`include` check rejected the second literal `header` as an included one. Record the
literal headers under their occurrence-indexed names.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- `secret_access_key`, `session_token`, `server_side_encryption_customer_key_base64`,
  `google_adc_client_secret` and `google_adc_refresh_token` of `S3AuthSettings` are
  `SecretString` on master, but `Storages/ObjectStorage/GCS/Configuration.cpp` still
  declared them as `S3AuthSettingsString`. Declare them with the right type.
- Mark the overrides of `getGCSObjectStorageSettings` in `CachedObjectStorage` and
  `GCSObjectStorage` `[[nodiscard]]` (`modernize-use-nodiscard`).

CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=109455&sha=d6919f3bbd782794dcfdda3060fc8db56b9e1131&name_0=PR
PR: #109455

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Pushed 9f9ace1: merged master (clean merge, no conflicts) and fixed the two red checks.

  • Style check: secret_access_key, session_token, server_side_encryption_customer_key_base64, google_adc_client_secret and google_adc_refresh_token of S3AuthSettings became SecretString on master, while Storages/ObjectStorage/GCS/Configuration.cpp still declared them as S3AuthSettingsString. They are now declared with the right type.
  • Build (arm_tidy, 1/4, 2/4, 4/4): the overrides of getGCSObjectStorageSettings in CachedObjectStorage and GCSObjectStorage are now [[nodiscard]] (modernize-use-nodiscard).
  • CH Inc sync (Failed. Needs manual intervention): the sync branch conflicted with private master. I pushed a manual merge of private master and this head to the sync branch. It keeps the private-only native GCS distributed-cache adaptations. The sync PR is MERGEABLE again.

Locally: clickhouse builds on the merged tree and the unit test sources of this PR compile; check-settings-style is clean; 16 of the 21 stateless tests of this PR pass through clickhouse local. The other 5 (05045, 05046, 05331, 05431, 05452) check the refusal of server credentials, which only a server with the test configuration enforces, so they were not verified locally. unit_tests_dbms was not linked or run.

All review threads are resolved.

alexey-milovidov and others added 2 commits November 24, 2026 16:50
Conflict in `src/Storages/ObjectStorage/StorageObjectStorageSource.cpp`:
`master` added `reads_explicit_object_version` and `pin_read_to_etag_for_page_cache`
next to the lines where this branch adds `ObjectStorageType::GCS`. Both are kept.

Semantic conflict: `master` does not use the page cache for S3 and Azure when
the read is not validated against the etag. The native GCS backend shares
`s3_validate_etag_on_read`, so it is added to that condition.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
The version on `master` became 26.12, so the `settings_changes_history` style
check requires the record of the new setting `use_native_gcs` to be under
`26.12` instead of `26.11`. The generated documentation page is updated to match.

https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=109455&sha=9f9ace19540091243b2e8389630251460c1b8803&name_0=PR&name_1=Style%20check
#109455

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Pushed 9081bed: merged master and fixed the red Style check.

  • Merge conflict in src/Storages/ObjectStorage/StorageObjectStorageSource.cpp: master added reads_explicit_object_version and pin_read_to_etag_for_page_cache next to the lines where this PR adds ObjectStorageType::GCS. Both are kept.
  • Semantic conflict: master no longer uses the page cache for S3 and Azure when the read is not validated against the etag. The native GCS backend shares s3_validate_etag_on_read, so ObjectStorageType::GCS is added to that condition.
  • Style check (settings_changes_history): the version on master became 26.12, so the record of use_native_gcs moved from 26.11 to 26.12 (and in the generated settings page).

Locally: clickhouse builds on the merged tree; the 11 unit test sources of this PR pass -fsyntax-only (unit_tests_dbms was not linked or run); 15 of the 20 stateless tests added by this PR pass through clickhouse local. The other 5 (05045, 05046, 05331, 05431, 05452) check the refusal of server credentials, which only a server with the test configuration enforces, so they were not verified locally. The integration test test_native_gcs was not run.

No unresolved review threads.

/// a location outside of the disk's bucket and key prefix instead of reading another object.
String getGCSDiskRelativeTableLocation(const String & table_location, const String & disk_name)
{
const auto disk_settings = Context::getGlobalContextInstance()->getDisk(disk_name)->getObjectStorage()->getGCSObjectStorageSettings();

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.

[Blocker] Authorize the catalog's disk before inspecting its settings

tryGetTableImpl calls this before StorageObjectStorageConfiguration::initialize reaches the checks in DataLakeConfiguration::fromDisk. A catalog database with disk = 'private_gcs_disk' and a table location outside that disk's bucket therefore gets the exception at lines 269–271, including the disk's actual bucket and key prefix, even when the disk is absent from allowed_disks_for_table_engines or would fail DiskFromAST::ensureDiskIsAllowed. Neither validateSettings nor buildTableEngineArgs checks disk access earlier. This exposes server configuration to a caller who cannot use the disk.

Enforce both disk checks before the configuration selection/location conversion reads the disk. Please cover a disallowed native GCS disk with a mismatching catalog location: the result should be the generic disallowed-disk exception without the private bucket or prefix. The existing REST-catalog fixture can exercise this without successful GCS I/O.

{
if (pending_data.size() + bytes_to_write <= max_single_part_upload_size)
{
pending_data.append(working_buffer.begin(), bytes_to_write);

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.

[Major] Enforce the memory limit while buffering a single-request upload

pending_data is a String (std::string), so this growth uses generic allocations that, with the default allocation settings, count memory without enforcing MemoryTracker limits. The writer accumulates an entire object up to s3_max_single_part_upload_size (32 MiB by default, configurable much larger). Formatting a small constant input repeatedly can grow this buffer without another enforced allocation; multiple open column writers amplify the overshoot. Unlike the Memory buffers in WriteBufferFromS3, this allocation cannot stop at the query/server memory limit.

Use an enforced buffer such as StringWithMemoryTracking. The SDK's InsertObject accepts absl::string_view, so passing the tracked buffer's data and size preserves the existing copy behavior. A focused upload test with a low max_memory_usage and a larger single-request threshold should fail while accumulating the data.

/// Native GCS uses Application Default Credentials when the dynamic disk does not supply an explicit
/// credential. This can resolve the server identity just like the S3 credential-provider chain does.
const bool gcs_relies_on_server_credentials
= maybe_gcs_disk && (has_indirect_gcs_header || !has_explicit_gcs_credentials);

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.

[Blocker] Keep explicitly credentialed S3 disks loadable

maybe_gcs_disk is true for every indirect backend type, but this expression recognizes only native GCS credentials. For example, this existing S3 definition supplies its own literal keys:

disk(type = 's3', object_storage_type = '${type}',
     endpoint = 'http://minio1:9001/root/data/',
     access_key_id = 'minio', secret_access_key = 'minio123',
     skip_access_check = 1)

The property resolves to s3, and the S3 credential check permits the complete key pair. However, the new GCS check sets gcs_relies_on_server_credentials and throws ACCESS_DENIED at line 490 before resolution, even with use_native_gcs = 0. It also runs during metadata loading: an existing table with this definition has no server-credential marker and stops attaching after an upgrade under the default credential restriction.

Defer the ADC decision for an unresolved backend to the resolved GCS validator, so an explicitly credentialed S3 backend retains its behavior. Add a positive case for this S3 definition alongside the negative case for an indirect GCS backend without credentials. This is source-traced; no runnable ClickHouse binary is available in this job.

This branch was successfully deployed

1 active deployment
staging - docs — f5d269f7 Deployed Nov 24, 2026 by mintlify[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci-relocation-headroom-ok Accept an expected decrease of the relocation headroom in the build check comp-object-storage Object storage connectivity (S3/GCS/Azure) including credentials, retries, multipart, etc. pr-autogenerated-docs PR that regenerates docs artifacts from source; exempt from the autogenerated-region edit guard pr-experimental Experimental Feature submodule changed At least one submodule changed in this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants