From 1039ed8f5173cac1e1d476e5b26911dccba0a203 Mon Sep 17 00:00:00 2001 From: yuliyang Date: Tue, 8 Oct 2019 13:30:08 +0800 Subject: [PATCH] rgw: fix SignatureDoesNotMatch when use ipv6 address in s3 client fix: https://tracker.ceph.com/issues/42218 Signed-off-by: yuliyang --- src/rgw/rgw_rest.cc | 14 +++++++++++--- src/rgw/rgw_rest_s3.h | 4 ++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/rgw/rgw_rest.cc b/src/rgw/rgw_rest.cc index a8fe2de62c85..1378dfc43b55 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 97bd1db3ff0a..f48f34f39ca5 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) { -- 2.47.3