From: yuliyang Date: Tue, 8 Oct 2019 05:30:08 +0000 (+0800) Subject: rgw: fix SignatureDoesNotMatch when use ipv6 address in s3 client X-Git-Tag: v14.2.10~223^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=29987aeff9677981ce2d0f9980cf4efb2c8bc643;p=ceph.git rgw: fix SignatureDoesNotMatch when use ipv6 address in s3 client fix: https://tracker.ceph.com/issues/42218 Signed-off-by: yuliyang (cherry picked from commit 1039ed8f5173cac1e1d476e5b26911dccba0a203) --- diff --git a/src/rgw/rgw_rest.cc b/src/rgw/rgw_rest.cc index d969b8f5102f..9a52af5d7bf5 100644 --- a/src/rgw/rgw_rest.cc +++ b/src/rgw/rgw_rest.cc @@ -2033,9 +2033,17 @@ int RGWREST::preprocess(struct req_state *s, rgw::io::BasicClient* cio) bool s3website_enabled = api_priority_s3website >= 0; if (info.host.size()) { - ssize_t pos = info.host.find(':'); - if (pos >= 0) { - info.host = info.host.substr(0, pos); + ssize_t pos; + if (info.host.find('[') == 0) { + pos = info.host.find(']'); + if (pos >=1) { + info.host = info.host.substr(1, pos-1); + } + } else { + pos = info.host.find(':'); + if (pos >= 0) { + info.host = info.host.substr(0, pos); + } } ldout(s->cct, 10) << "host=" << info.host << dendl; string domain; diff --git a/src/rgw/rgw_rest_s3.h b/src/rgw/rgw_rest_s3.h index 8031f9303e49..356d3f48ab6e 100644 --- a/src/rgw/rgw_rest_s3.h +++ b/src/rgw/rgw_rest_s3.h @@ -701,6 +701,10 @@ class RGWHandler_REST_Obj_S3Website; static inline bool looks_like_ip_address(const char *bucket) { + struct in6_addr a; + if (inet_pton(AF_INET6, bucket, static_cast(&a)) == 1) { + return true; + } int num_periods = 0; bool expect_period = false; for (const char *b = bucket; *b; ++b) {