From 5acc2a6db1fae9923139dfdfab6faa5de48deb73 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Mon, 23 Jul 2018 10:16:56 -0700 Subject: [PATCH] S3 gateway signature probe use a unique bucket (#6190) This fixes an issue because someone is using `probe-bucket-sign` bucket name in region 'eu-central-1' --- cmd/gateway/s3/gateway-s3.go | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/cmd/gateway/s3/gateway-s3.go b/cmd/gateway/s3/gateway-s3.go index 82e05bc76..e49f8f379 100644 --- a/cmd/gateway/s3/gateway-s3.go +++ b/cmd/gateway/s3/gateway-s3.go @@ -20,7 +20,9 @@ import ( "context" "encoding/json" "io" + "math/rand" "strings" + "time" "github.com/minio/cli" miniogo "github.com/minio/minio-go" @@ -121,6 +123,31 @@ func (g *S3) Name() string { return s3Backend } +const letterBytes = "abcdefghijklmnopqrstuvwxyz01234569" +const ( + letterIdxBits = 6 // 6 bits to represent a letter index + letterIdxMask = 1<= 0; { + if remain == 0 { + cache, remain = src.Int63(), letterIdxMax + } + if idx := int(cache & letterIdxMask); idx < len(letterBytes) { + b[i] = letterBytes[idx] + i-- + } + cache >>= letterIdxBits + remain-- + } + return prefix + string(b[0:30-len(prefix)]) +} + // newS3 - Initializes a new client by auto probing S3 server signature. func newS3(url, accessKey, secretKey string) (*miniogo.Core, error) { if url == "" { @@ -137,13 +164,13 @@ func newS3(url, accessKey, secretKey string) (*miniogo.Core, error) { if err != nil { return nil, err } - - if _, err = clnt.BucketExists("probe-bucket-sign"); err != nil { + probeBucketName := randString(60, rand.NewSource(time.Now().UnixNano()), "probe-bucket-sign-") + if _, err = clnt.BucketExists(probeBucketName); err != nil { clnt, err = miniogo.NewV2(endpoint, accessKey, secretKey, secure) if err != nil { return nil, err } - if _, err = clnt.BucketExists("probe-bucket-sign"); err != nil { + if _, err = clnt.BucketExists(probeBucketName); err != nil { return nil, err } }