Skip to content

Translate GCS headers for every request, not only CopyObject - #119042

Merged
alexey-milovidov merged 10 commits into
masterfrom
s3-translate-gcs-headers
Sep 12, 2026
Merged

alexey-milovidov merged 10 commits into
masterfrom
s3-translate-gcs-headers

Conversation

@CheSema

@CheSema CheSema commented Sep 9, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Backward Incompatible Change

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

Headers that Google Cloud Storage spells with an x-goog- prefix are now translated for every request, not only for server-side copies. Custom object metadata written to GCS over the S3 API without HMAC credentials — how ClickHouse Cloud on GCP accesses object storage — previously did not take effect: GCS discards the x-amz- spelling silently, so the write succeeded and the metadata was not applied.

Backward incompatible: storage_class_name (also storage_class, s3_storage_class) set to an Amazon S3 class name such as GLACIER or STANDARD_IA against a GCS endpoint now fails the write with InvalidStorageClass, where it was previously accepted and the object silently stored as STANDARD. Such a configuration never did what it claimed; it now says so. Google Cloud Storage class names are STANDARD, NEARLINE, COLDLINE and ARCHIVE. Note that ClickHouse cannot yet send a GCS class either — GetStorageClassForName recognises only S3 names — so on a GCS endpoint the setting should be left unset until value mapping is added. To restore the old behaviour, remove the setting.

Description

A listing of what GCS spells differently is in Google's migration guide. GCS silently ignores the x-amz- form — request accepted, header dropped, nothing reported. Measured against a bucket over the XML API with an OAuth token, the mode Cloud uses on GCP:

CreateMultipartUpload with x-amz-meta-*    ->  200, object has no metadata
CreateMultipartUpload with x-goog-meta-*   ->  200, object has the metadata

ClickHouse already translates, but only on CopyObjectRequest — #48981 added it in 2023 to fix GCS native copy and it was never extended, because copy failed loudly while everything else fails silently.

The rename now happens in Client::BuildHttpRequest. That is where the SDK has merged both header carriers — the ones the request object generates and the extra_headers attached via SetAdditionalCustomHeaderValue — so an operator-set header / access_header is covered too. It runs before signing (AWSClient.cpp:564 vs :584), and only in ApiMode::GCS, where the request is unsigned anyway.

The response needs the mirror: GCS answers x-goog-meta-* while the SDK builds GetMetadata() only from x-amz-meta- (HeadObjectResult.cpp:188), so PocoHTTPClient adds that spelling alongside. One table drives both directions. The name is lower-cased whole, since the SDK turns whatever follows the prefix into a key in a case-sensitive map.

Server-side encryption is deliberately excluded: S3 uses x-amz-server-side-encryption plus a key id where GCS uses a single x-goog-encryption-kms-key-name with a different value, so a rename would be ignored just as silently. That needs a value mapping, as does the storage class.

Relationship to #118829

#118829 proves multipart authorship with an id in custom object metadata — the header GCS discards here — so it needs this to work on Cloud GCP. The two do not overlap. This one stands alone regardless: GCS users lose object metadata today either way.

Testing

gtest_gcs_header_translation.cpp covers both directions, headers left alone, the x-amz-metadata-directive near-miss, and mixed case — that last arm caught a real defect while being written. CI has no GCS, so the wire behaviour itself is measured, not automated.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

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

Version info

  • Merged into: 26.9.1.1270 (included in 26.9 and later)

GCS spells a handful of headers with an x-goog- prefix and silently ignores
the x-amz- one - the request is accepted, the header is dropped, nothing is
reported. ClickHouse translates them, but only on CopyObjectRequest, where
#48981 added it in 2023 to fix GCS native copy. That fix needed
x-amz-copy-source, and picked up metadata-directive, storage-class and
x-amz-meta-* alongside because a copy that replaces metadata needs all four to
agree. Nothing extended it since, because copy failed loudly while the rest
fail silently.

Measured against a GCS bucket over the XML API with an OAuth token, which is
the x-goog-only mode ClickHouse Cloud uses on GCP:

    CreateMultipartUpload with x-amz-meta-*   -> 200, object has no metadata
    CreateMultipartUpload with x-goog-meta-*  -> 200, object has the metadata

So the rename moves into translateHeadersToGCS, applied by ExtendedRequest for
every request type in ApiMode::GCS; CopyObjectRequest keeps no override of its
own. Of the four headers only storage-class and x-amz-meta-* occur outside the
copy path, and both were being dropped there, so custom object metadata and
storage_class_name start taking effect on GCS for ordinary writes.

The response needs the mirror. GCS answers x-goog-meta-* while the SDK builds
GetMetadata() only from x-amz-meta- (HeadObjectResult.cpp), so PocoHTTPClient
adds the x-amz- spelling alongside for the same closed set of names. Both
directions read one table, so they cannot drift. The translated name is
lower-cased whole: the SDK makes whatever follows the prefix a key in a
case-sensitive map, and a server that answers in mixed case would otherwise
produce a key no lookup finds.

Renaming after signing would invalidate SigV4. It is safe because this fires
only in ApiMode::GCS, where credentials are empty and authorization is a
bearer token from PocoHTTPClientGCPOAuth. The signed HMAC interop path is
never translated and does not need to be - GCS accepts and returns
x-amz-meta-* there, also measured.

Server-side encryption is deliberately excluded. Its mapping is not a rename:
S3 uses x-amz-server-side-encryption plus a key id, GCS a single
x-goog-encryption-kms-key-name with a different value, so a prefix rename
would be ignored exactly as silently as the header it replaced.
@clickhouse-gh

clickhouse-gh Bot commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [5f017ed]

Summary: ✅


AI Review

Summary

This PR moves the GCS header rewrite out of CopyObjectRequest and into Client::BuildHttpRequest, mirrors the translated names back in PocoHTTPClient so GetMetadata() can still see GCS metadata, and normalizes extra-header names so mixed-case X-Amz-* headers no longer bypass the rewrite. The code itself looks coherent, but the review still has one open concern: the new tests only cover the pure helpers, not the real request/response wiring that carries the user-visible contract.

Missing context / blind spots
  • ⚠️ Praktika currently exposes only the build-profile-diff report for this PR, so there is no CI signal here for the new GCS-path tests or for the PocoHTTPClient/AWS request wiring.
Tests
  • ⚠️ [src/IO/S3/tests/gtest_gcs_header_translation.cpp:21-130] The added suite validates translateHeadersToGCS, translateHeaderNameFromGCS, and normalizeHeaderNames in isolation, but the contract actually depends on the two integration points in Client::BuildHttpRequest and PocoHTTPClient. If either call site is dropped or moved, this file still stays green. Please add one focused boundary test through the real HTTP path (for example with TestPocoHTTPServer / PocoHTTPClientGCPOAuth) that proves a GCS-mode write emits x-goog-meta-* on the wire and that the response path still feeds the metadata back through GetMetadata().
Final Verdict

Needs changes: the remaining concern is insufficient end-to-end evidence for the new request/response wiring.

LLVM Coverage Report

Measured on commit 5f017ed.

Metric Baseline Current Δ
Lines 89.00% 89.00% +0.00%
Functions 91.80% 91.80% +0.00%
Branches 81.30% 81.30% +0.00%

Changed lines: Changed C/C++ lines covered: 105/115 (91.30%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Sep 9, 2026
@CheSema
CheSema marked this pull request as ready for review September 9, 2026 14:43
Renaming it can only do harm. The value sets share nothing but STANDARD, and
GetStorageClassForName knows no GCS class, so a GCS one never reaches the wire
whatever the header is called. An S3 one does, and measured against a bucket:

    x-amz-storage-class: GLACIER    -> 200, object stored STANDARD (ignored)
    x-goog-storage-class: GLACIER   -> 400 InvalidStorageClass
    x-goog-storage-class: COLDLINE  -> 200, object stored COLDLINE

So translating it turns a misconfiguration GCS quietly ignores into a failing
write, for a header that can never carry a usable value. A GCS storage class
needs a value mapping, not a rename, which is the same reason server-side
encryption stays out.

This also stops CopyObject translating it, which #48981 has done since 2023.
That path can only carry S3 values too, so all it achieved was a 400 on copies
where every other path silently ignored the same setting.
This reverts 76ef5a2. CopyObject has translated x-amz-storage-class since
#48981, and dropping it changed behaviour this pull request did not set out to
change. Google's own migration guide maps the name too.

The value caveat that prompted the removal is real and is now recorded next to
the table instead: the two clouds share no class name but STANDARD, so an S3
one renamed onto GCS answers 400 InvalidStorageClass, and no GCS class can be
sent at all because GetStorageClassForName maps unknown names to NOT_SET.
Making storage_class_name work on GCS means passing the user's string through
instead of the enum, which is a change of its own.
@azat azat self-assigned this Sep 9, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-object-storage Object storage connectivity (S3/GCS/Azure) including credentials, retries, multipart, etc. label Sep 9, 2026
CheSema added a commit that referenced this pull request Sep 9, 2026
… fix

The table is the sole source of truth for the request rename and the response
alias, and the failure mode is a header silently lost, so a missed entry
regresses GCS writes with no CI signal.

The test is the one written for #119042, brought here so the two copies of
these files do not diverge. Writing it there caught a real defect that this
branch still carried: translateHeaderNameFromGCS lower-cased the prefix but
kept the suffix's case, so a server answering X-Goog-Meta-Foo produced the
metadata key "Foo" and no lookup found it. Fixed with the test that catches it.

Both files are now identical to #119042's, which is the copy to keep when one
of the two merges.
Comment thread src/IO/S3/Requests.h Resolved
Comment thread src/IO/S3/Requests.cpp Resolved
CheSema added a commit that referenced this pull request Sep 9, 2026
It was duplicated here so this branch could be reviewed and tested whole, and
it had grown to a third of the diff. #119042 owns it, on its own merits: GCS
discards custom object metadata under the x-amz- spelling regardless of this
change.

Requests.h keeps the idempotency id constants and the setter on
CompleteMultipartUploadRequest, which belong to this fix rather than to the
translation, so the two pull requests still touch that file for their own
reasons.

Until #119042 merges the recovery is inactive on GCS with OAuth - the id is
discarded, the completion reports its error, and the data loss stays fixed.
Fail-closed, as the description says.
Doing it in ExtendedRequest::GetRequestSpecificHeaders only reached the headers
the request object generates. ClickHouse's `header` / `access_header` surface
goes in through SetAdditionalCustomHeaderValue, and AWSClient::BuildHttpRequest
merges that separately from GetAdditionalCustomHeaders(), so an operator-set
x-amz-meta-* still left with the x-amz- prefix and GCS still ignored it. The
contract said every request; it was every request, one carrier.

Client::BuildHttpRequest already does GCS header surgery and runs before
signing (AWSClient.cpp:564 vs :584), so renaming there covers both carriers at
one choke point and the per-request-type override goes away.

The pure collection function stays as the logic and its tests; the request
overload is a thin adapter over it.
Comment thread src/IO/S3/Client.cpp Resolved
@clickhouse-gh

clickhouse-gh Bot commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 5f017ed71 with master 7255d20cd (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.

Object file sizes

6 object files changed (-12.80 KiB total), 1 added.

Object file Master PR Δ
src/CMakeFiles/clickhouse_common_io.dir/IO/S3/Requests.cpp.o 238.06 KiB 219.57 KiB -18.49 KiB (-7.77%)

716 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.

Compile time of recompiled translation units

148 translation units recompiled, 1082 s compile time in total, 147 of them have a recent master baseline.

Job report

Two places decide whether an entry belongs on the SDK request by comparing
literally against "x-amz-": addAdditionalAMZHeadersToCanonicalHeadersList and
the late extra_headers pass in PocoHTTPClient. A mixed-case X-Amz-Meta-Owner
fails both tests, so it is not put on the request, is attached after signing as
an ordinary header, lower-cased on the wire, and never passes through
BuildHttpRequest where the rename happens. GCS drops it, silently.

Normalising once where extra_headers is assembled makes both comparisons right
by construction rather than by remembering to compare case-insensitively in two
places forever. HTTP header names are case-insensitive and Poco lower-cases them
on the wire anyway, so nothing observable changes.

checkAndNormalizeHeaders was the tempting place and is the wrong one: it only
sees the SQL headers(...) surface, while config <header> and <access_header>
come from getHTTPHeaders and never pass through it.
…aders

One conflict, in Requests.cpp: master added
RequestChecksum::getUploadChecksumAlgorithm exactly where this branch removed
CopyObjectRequest::GetRequestSpecificHeaders. Kept both sides - master's new
function, then the anonymous namespace holding the translation table - and
dropped the override, which this branch replaced with a plain alias.
@clickhouse-gh clickhouse-gh Bot added pr-backward-incompatible Pull request with backwards incompatible changes and removed pr-bugfix Pull request with bugfix, not backported by default labels Sep 10, 2026
The merge brought master's own <optional> into Requests.h next to the one this
branch added, and clang-tidy rejects the pair. Caught by Build (arm_tidy);
neither side is wrong alone, so a textual merge cannot see it.
Comment thread src/IO/S3/Client.cpp Resolved
Comment thread src/IO/S3/Requests.h Resolved
Comment thread src/IO/S3/Requests.h Resolved
Comment thread src/IO/S3/Requests.cpp Resolved
Comment thread src/IO/S3/Requests.cpp Resolved
Comment thread src/IO/S3/Requests.h Resolved
Comment thread src/IO/S3/Requests.h Resolved
BuildHttpRequest deleted the header at the call site while the rename happened
in the helper, so two halves of one job sat in two places. GCS_DROPPED_HEADERS
lists it next to GCS_TRANSLATED_HEADERS and the collection overload erases it;
the request overload already deletes any name the translation drops, so it
needed no change. The gtest covers the drop for free, and pins
amz-sdk-invocation-id and amz-sdk-request as survivors.

Review: #119042 (comment)
It mutates a generic type, so it does not belong in the S3 request layer.
Declared in IO/HTTPHeaderEntries.h with the body in a new .cpp, which the
existing add_headers_and_sources(clickhouse_common_io IO) glob picks up.

Not folded into HTTPHeaderEntry's constructor: HTTPHeaderFilter matches
<http_forbid_headers> regexps against the original-case name so an inline (?-i)
scope keeps its case-sensitive meaning. The constructor could not hold that
invariant anyway, since the filter assigns entry.name in place.

Review: #119042 (comment)
The blocks explained the change itself and restated that header names are
case-insensitive. What is left is what a reader cannot get from the identifier:
that GCS ignores the x-amz- spelling silently, that only the storage-class name
translates and not its value, and why the metadata name is lower-cased whole.
The storage-class note now sits on its own table entry.

Review: #119042 (comment)
Review: #119042 (comment)
Review: #119042 (comment)
Review: #119042 (comment)
Review: #119042 (comment)

@alexey-milovidov alexey-milovidov 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

@alexey-milovidov alexey-milovidov self-assigned this Sep 12, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Sep 12, 2026
Merged via the queue into master with commit 0bd4874 Sep 12, 2026
174 checks passed
@alexey-milovidov
alexey-milovidov deleted the s3-translate-gcs-headers branch September 12, 2026 12:36
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 12, 2026
pull Bot pushed a commit to Spencerx/ClickHouse that referenced this pull request Sep 14, 2026
The tests added in ClickHouse#119042 stop at the helper layer: `translateHeadersToGCS`,
`translateHeaderNameFromGCS` and `normalizeHeaderNames` are each checked in
isolation, but the two places the change actually depends on - the
`translateHeadersToGCS` call in `Client::BuildHttpRequest` and the response shim
in `PocoHTTPClient` - were unproven, so removing either left the file green.

Add two boundary tests that go through the real client and the real HTTP path
against a mock GCS on localhost. The API mode is GCS only for a
`storage.googleapis.com` endpoint with empty credentials, so the endpoint keeps
the real name and the request is routed to the mock through a proxy;
`HTTPConnectionPool` connects to the proxy without consulting the resolver, so
nothing is resolved over DNS.

Verified with a control binary: with the `translateHeadersToGCS` call and the
response shim removed, the six helper tests still pass while both new tests
fail.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

/// Lower-case every header name in place, for code that classifies a name by a literal prefix.
/// `HTTPHeaderFilter` needs the original case for `(?-i)` regexps, so this is not done on construction.
void normalizeHeaderNames(HTTPHeaderEntries & headers);

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.

I actually meant that push_back method of a class should do it

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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-backward-incompatible Pull request with backwards incompatible changes pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants