HDDS-15776. Make S3 Gateway VirtualHostStyleFilter IPv6-safe#10809
Open
rich7420 wants to merge 1 commit into
Open
HDDS-15776. Make S3 Gateway VirtualHostStyleFilter IPv6-safe#10809rich7420 wants to merge 1 commit into
rich7420 wants to merge 1 commit into
Conversation
checkHostWithoutPort used host.lastIndexOf(':') to strip the port, which
mangles IPv6 literals (e.g. [2001:db8::1] or a bare 2001:db8::1). Use Guava
HostAndPort.fromString(host).getHost() for bracket-aware host/port separation,
matching HddsUtils. Add tests for hostname/IPv4/IPv6 Host headers with and
without a port, plus a malformed-host fallback.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changes were proposed in this pull request?
VirtualHostStyleFilter.checkHostWithoutPort()stripped the port from theHostheader withhost.lastIndexOf(':'). That mangles IPv6 literals, becausetheir address segments also contain colons:
[::1]:9878/[2001:db8::1]:9878— the address itself gets truncated2001:db8::1— the last address segment is mistaken for a portAs a result an S3 Gateway reachable on an IPv6 address rejects otherwise valid
requests when a domain is configured.
This change parses the host with Guava
HostAndPort.fromString(host).getHost(),which is bracket-aware:
[::1]:9878and[::1]both yield::1, and a bare2001:db8::1is returned unchanged. This matches howHddsUtilsalready parseshost/port elsewhere. A malformed
Hostvalue (for example an unbalancedbracket) falls back to the raw value, so it is rejected with the existing
"no matching domain" error rather than failing with an internal error.
Part of the IPv6 support epic HDDS-15763.
What is the link to the Apache JIRA
https://issues.apache.org/jira/browse/HDDS-15776
How was this patch tested?
mvn -pl :ozone-s3gateway test -Dtest=TestVirtualHostStyleFilter
https://github.com/rich7420/ozone/actions/runs/29688355419