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: v15.1.0~39^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=1039ed8f5173cac1e1d476e5b26911dccba0a203;p=ceph.git rgw: fix SignatureDoesNotMatch when use ipv6 address in s3 client fix: https://tracker.ceph.com/issues/42218 Signed-off-by: yuliyang --- diff --git a/src/rgw/rgw_rest.cc b/src/rgw/rgw_rest.cc index a8fe2de62c8..1378dfc43b5 100644 --- a/src/rgw/rgw_rest.cc +++ b/src/rgw/rgw_rest.cc @@ -2032,9 +2032,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 97bd1db3ff0..f48f34f39ca 100644 --- a/src/rgw/rgw_rest_s3.h +++ b/src/rgw/rgw_rest_s3.h @@ -727,6 +727,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) {