Repository navigation
Translate GCS headers for every request, not only CopyObject - #119042
Conversation
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.
|
Workflow [PR], commit [5f017ed] Summary: ✅
AI ReviewSummaryThis PR moves the GCS header rewrite out of Missing context / blind spots
Tests
Final VerdictNeeds changes: the remaining concern is insufficient end-to-end evidence for the new request/response wiring. LLVM Coverage ReportMeasured on commit 5f017ed.
Changed lines: Changed C/C++ lines covered: 105/115 (91.30%) · Uncovered code |
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.
… 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.
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.
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes6 object files changed (-12.80 KiB total), 1 added.
716 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units148 translation units recompiled, 1082 s compile time in total, 147 of them have a recent master baseline. |
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.
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.
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)
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); |
There was a problem hiding this comment.
I actually meant that push_back method of a class should do it
Changelog category (leave one):
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 thex-amz-spelling silently, so the write succeeded and the metadata was not applied.Backward incompatible:
storage_class_name(alsostorage_class,s3_storage_class) set to an Amazon S3 class name such asGLACIERorSTANDARD_IAagainst a GCS endpoint now fails the write withInvalidStorageClass, where it was previously accepted and the object silently stored asSTANDARD. Such a configuration never did what it claimed; it now says so. Google Cloud Storage class names areSTANDARD,NEARLINE,COLDLINEandARCHIVE. Note that ClickHouse cannot yet send a GCS class either —GetStorageClassForNamerecognises 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: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 theextra_headersattached viaSetAdditionalCustomHeaderValue— so an operator-setheader/access_headeris covered too. It runs before signing (AWSClient.cpp:564vs:584), and only inApiMode::GCS, where the request is unsigned anyway.The response needs the mirror: GCS answers
x-goog-meta-*while the SDK buildsGetMetadata()only fromx-amz-meta-(HeadObjectResult.cpp:188), soPocoHTTPClientadds 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-encryptionplus a key id where GCS uses a singlex-goog-encryption-kms-key-namewith 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.cppcovers both directions, headers left alone, thex-amz-metadata-directivenear-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
Workflow [PR]
Sync PR [sync-upstream/pr/119042]
Version info
26.9.1.1270(included in26.9and later)