Skip to content

Hold S3 header-name normalization in the type - #120014

Merged
CheSema merged 10 commits into
masterfrom
s3-normalized-header-entries
Sep 21, 2026
Merged

CheSema merged 10 commits into
masterfrom
s3-normalized-header-entries

Conversation

@CheSema

@CheSema CheSema commented Sep 14, 2026 •

Copy link
Copy Markdown
Member

Related: #119042

Follow-up to a review comment on #119042: the normalization should belong to the
collection, not to a function the caller must remember.

NormalizedHTTPHeaderEntries lower-cases a name in push_back, and S3AuthSettings::headers
and access_headers hold that type, so names are normalized where the config or the query is
read rather than at each use. eraseByName answers lookups the same way, which removes the
case-sensitive h.name == "Authorization" comparison from the GCS token refresh.

What it fixes on the wire: a mixed-case X-Amz-Meta-Foo fails the starts_with("x-amz-")
test in addAdditionalAMZHeadersToCanonicalHeadersList, so it skips the canonical header list
and never reaches the GCS x-goog- translation. Normalized at the source, it does.

The <http_forbid_headers> case handling is no longer part of this PR, per review.
HTTPHeaderFilter keeps only an overload accepting the new type. One assertion is appended to
its existing (?-i) test to record what the split costs: such a rule cannot reach an S3 header,
whose name now arrives lower-cased. Detecting that properly needs the parsed pattern rather than
a substring check, which is left to a follow-up.

Changelog category (leave one):

  • Improvement

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

Custom HTTP headers configured for S3 are now handled case-insensitively by name, so a header spelled X-Amz-Meta-Foo reaches Google Cloud Storage translated to x-goog-meta-foo, as x-amz-meta-foo already did.


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

Version info

  • Merged into: 26.10.1.361-master (included in 26.10 and later)

`normalizeHeaderNames` was a step the caller had to remember before assigning
`extra_headers`. The S3 client sorts headers by the literal prefix `x-amz-`,
before signing and again after, so a name that arrives in the operator's
spelling is sent unsigned and untranslated.

`PocoHTTPClientConfiguration::extra_headers` now holds a
`NormalizedHTTPHeaderEntries`, whose `push_back` lower-cases the name. The
collection cannot be built any other way, so the step cannot be skipped.

Normalizing further upstream is not possible: `HTTPHeaderFilter` matches
`<http_forbid_headers>` regexps against the original case for `(?-i)` scopes,
and the GCS token refresh finds the header to replace by comparing the name to
`Authorization`.
@clickhouse-gh

clickhouse-gh Bot commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [0264ea9]

Summary: ✅


AI Review

Summary

This PR moves S3 header-name normalization into NormalizedHTTPHeaderEntries, which does fix the reported GCS translation regression and now has an end-to-end test for the mixed-case configured-header path. The remaining problem is that S3 headers now arrive lower-cased before HTTPHeaderFilter evaluates header_regexp, so an existing case-sensitive (?-i) blocklist silently stops protecting the S3 path.

Findings

⚠️ Majors

  • src/IO/S3AuthSettings.cpp:92-93 src/IO/S3AuthSettings.cpp:281-292 src/Disks/DiskObjectStorage/ObjectStorages/S3/diskSettings.cpp:238 src/Common/tests/gtest_http_header_filter.cpp:151-156 [dismissed by author -- https://github.com/ClickHouse/ClickHouse/pull/120014#discussion_r4035538201] The new container lower-cases every S3 header at config load, SQL-header merge, and metadata deserialize time, and getClient now passes only that normalized spelling into HTTPHeaderFilter. That weakens the existing header_regexp contract for any rule that deliberately re-enables case-sensitive matching with (?-i): the generic path still proves Authorization is blocked, but the new S3-only assertion documents that the same rule now forbids nothing there. Because the normalization happens before both fresh config load and persisted-metadata deserialize, this is a silent behavior change on upgrade, not just for newly written configs. Suggested fix: preserve the original spelling until after checkAndNormalizeHeaders, or teach the S3 path to carry both the original and normalized spellings so regex checks still see the original-case name while the later S3/GCS logic uses the normalized one.
Final Verdict

Not ready to merge as-is: the S3 path still weakens existing http_forbid_headers header_regexp protections for (?-i) rules.

LLVM Coverage Report

Measured on commit 0264ea9.

Metric Baseline Current Δ
Lines 88.00% 88.00% +0.00%
Functions 91.80% 91.80% +0.00%
Branches 79.30% 79.30% +0.00%

Changed lines: Changed C/C++ lines covered: 43/62 (69.35%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label Sep 14, 2026
@azat azat self-assigned this Sep 14, 2026
Comment thread src/IO/S3/Client.cpp Resolved
Comment thread src/IO/HTTPHeaderEntries.h Resolved
Comment thread src/IO/HTTPHeaderEntries.h Resolved
Comment thread src/IO/S3/Client.cpp Resolved
@clickhouse-gh clickhouse-gh Bot added the comp-object-storage Object storage connectivity (S3/GCS/Azure) including credentials, retries, multipart, etc. label Sep 14, 2026
`<http_forbid_headers>` matched a regexp against the original-case header
name, so that an inline `(?-i)` scope kept working. That scope is a bypass,
not a feature: `(?-i)Authorization` blocks `Authorization` and lets
`authorization` through, and both name the same header. The regexps now
match the lower-cased name, as the exact set already did, and a pattern
that turns case insensitivity off is reported at config load.

Nothing on the way to the S3 client needs the original case any more, so
`S3AuthSettings::headers` and `access_headers` hold normalized names from
the moment the config or the query is read, and `ClientFactory::create`
converts nothing. The GCS token refresh looks its header up with
`eraseByName`, which normalizes the name it searches for, so the
`Authorization` spelling can no longer drift.

A new test drives a configured `X-Amz-Meta-Owner` through the real client
and the mock GCS server. It fails when the name reaches the wire unchanged,
which the helper tests alone did not catch.
An operator may write a forbidden header in upper case. Nothing covered
that spelling: the exact-set tests configure `Authorization` and
`authorization`, and the regexp tests configure lower case only.

Both forms already block every case variant, by different means. The
exact set holds the configured name lower-cased. A regexp pattern is
left as written, because lower-casing it would corrupt a metacharacter
such as `\D` or `[A-Z]`, and takes its case insensitivity from the RE2
option instead.
Several restated the identifier they sat on, described what would happen
if the normalization were absent, or duplicated the class doc.
Two patterns were accepted while blocking nothing: one whose inline
`(?-i)` scope asks for case-sensitive matching, which a name matched in
lower case cannot honour, and one that does not compile, which was
skipped with a warning. Both now throw at config load.

`setValuesFromConfig` cleared the blocklist and then repopulated it under
the lock, so throwing part-way would have left fewer rules in force than
the config asks for. It builds both containers first and swaps them at
the end, which also keeps config reading off the lock.
@CheSema CheSema changed the title Hold S3 header-name normalization in the type Match <http_forbid_headers> patterns in lower case and hold S3 header normalization in the type Sep 15, 2026
@clickhouse-gh clickhouse-gh Bot added pr-backward-incompatible Pull request with backwards incompatible changes and removed pr-not-for-changelog This PR should not be mentioned in the changelog labels Sep 15, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 0264ea9cc with master acd853b6e (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of 27a1c524b; 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

24 object files changed (+7.65 KiB total), 0 added.

Object file Master PR Δ
src/CMakeFiles/clickhouse_common_io.dir/IO/HTTPHeaderEntries.cpp.o 4.15 KiB 30.62 KiB +26.47 KiB (+637.44%)

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, 1099 s compile time in total, 148 of them have a recent master baseline.

Job report

Comment thread src/Common/HTTPHeaderFilter.cpp Resolved
Comment thread src/IO/HTTPHeaderEntries.cpp Resolved
Comment thread src/Common/HTTPHeaderFilter.cpp Resolved
The `NormalizedHTTPHeaderEntries` overload lower-cased every name again after
running the check, on the grounds that the check edits names in place. It
cannot matter: the check throws on CR/LF, strips control and whitespace
characters from the name, and matches a local lower-cased copy, so it never
writes case back. Every name entering it is already lower-cased by `push_back`,
`append` or the converting constructor, so the loop was a no-op.

The overload stays, and stays mutable, because the strip is a real edit of the
caller's data. `HTTPHeaderFilter.ChecksNormalizedEntries` already pins the
outcome the removed loop pretended to guarantee.
Per review: the filter's case handling is a separate concern from holding
normalization in the type, and the `(?-i` substring check that guarded it misses
`(?s-i`, `(?m-i)` and partial scopes. `HTTPHeaderFilter` goes back to master
except for the overload that accepts `NormalizedHTTPHeaderEntries`, which
`diskSettings` needs to pass the new type.

The three tests that pinned the rejection go with it. Two characterization tests
take their place: an inline `(?-i)` scope and an uncompilable pattern are both
accepted and then forbid nothing, and a `(?-i)` rule cannot block an S3 header at
all, since that name now arrives lower-cased. Doing this properly needs the parsed
pattern rather than a substring check, which is the follow-up.
Restores master's `RegexpInlineCaseSensitiveScopeStillBlocksOriginalCase`
verbatim and appends the one assertion this PR adds: a `(?-i)` rule cannot reach
an S3 header, because that name arrives lower-cased whatever the caller wrote.

Drops the two tests documenting case handling master already has, and the one
characterizing an uncompilable pattern. Neither is this PR's business now that
the filter itself goes back to master.

The test file is additive against master again -- the `isForbiddenForS3` helper,
that one assertion, and `ChecksNormalizedEntries` for the new overload -- with
nothing renamed or deleted.
@CheSema CheSema changed the title Match <http_forbid_headers> patterns in lower case and hold S3 header normalization in the type Hold S3 header-name normalization in the type Sep 18, 2026
@clickhouse-gh clickhouse-gh Bot added pr-improvement Pull request with some product improvements and removed pr-backward-incompatible Pull request with backwards incompatible changes labels Sep 18, 2026
`NormalizedHTTPHeaderEntries` exposes no `operator[]`, so three tests copied it
into an `HTTPHeaderEntries` just to index it. Two assert a single entry and need
only `size()` and `begin()`; the third compares three ordered entries, which now
collects names and values into vectors and compares each in one assertion.

That also widens what it checks: one of the three values was asserted before,
all three are now, so "values are untouched" is tested rather than sampled.

void setValuesFromConfig(const Poco::Util::AbstractConfiguration & config);
void checkAndNormalizeHeaders(HTTPHeaderEntries & entries) const;
void checkAndNormalizeHeaders(NormalizedHTTPHeaderEntries & entries) const;

@azat azat Sep 18, 2026 •

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.

Do we need this? Is it really used in S3 code? (except for gtest here)

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.

here

context->getHTTPHeaderFilter().checkAndNormalizeHeaders(headers);

headers comes out of S3Settings::auth_settings which I did changed.

…r-entries

# Conflicts:
#	src/IO/S3AuthSettings.cpp
@CheSema
CheSema added this pull request to the merge queue Sep 21, 2026
Merged via the queue into master with commit 505337e Sep 21, 2026
177 checks passed
@CheSema
CheSema deleted the s3-normalized-header-entries branch September 21, 2026 15:37
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 21, 2026
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-improvement Pull request with some product improvements 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.

3 participants