From 7cea3f7da4794a285fb35c079e298d3a4ed8858d Mon Sep 17 00:00:00 2001 From: Anis Elleuch Date: Mon, 29 Jun 2020 20:31:07 +0100 Subject: [PATCH] madmin: Strip 80/443 from the endpoint when http/https (#9937) Users having endpoints with this format http://url:80 or http://url:443 will face signature mismatch error. The reason is that S3 spec ignores :80 or :443 port in the endpoint when calculating the signature, so this PR will just strip them. --- pkg/madmin/utils.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pkg/madmin/utils.go b/pkg/madmin/utils.go index 125ebf9f8..035bb636f 100644 --- a/pkg/madmin/utils.go +++ b/pkg/madmin/utils.go @@ -67,12 +67,22 @@ func getEndpointURL(endpoint string, secure bool) (*url.URL, error) { return nil, ErrInvalidArgument(msg) } } + // If secure is false, use 'http' scheme. scheme := "https" if !secure { scheme = "http" } + // Strip the obvious :443 and :80 from the endpoint + // to avoid the signature mismatch error. + if secure && strings.HasSuffix(endpoint, ":443") { + endpoint = strings.TrimSuffix(endpoint, ":443") + } + if !secure && strings.HasSuffix(endpoint, ":80") { + endpoint = strings.TrimSuffix(endpoint, ":80") + } + // Construct a secured endpoint URL. endpointURLStr := scheme + "://" + endpoint endpointURL, err := url.Parse(endpointURLStr)