From b9c48e0ab0396cec7d6c4aff5fe3a1e4c5850969 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Wed, 22 Jan 2020 08:25:28 -0800 Subject: [PATCH] fix return appropriate error for MakeBucket in federation (#8878) --- README.md | 4 ++-- cmd/bucket-handlers.go | 13 +++++++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index cc34e81cc..0b5f9800d 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ docker run -p 9000:9000 minio/minio:edge server /data > NOTE: Docker will not display the default keys unless you start the container with the `-it`(interactive TTY) argument. Generally, it is not recommended to use default keys with containers. Please visit MinIO Docker quickstart guide for more information [here](https://docs.min.io/docs/minio-docker-quickstart-guide) ## macOS -### Homebrew +### Homebrew (recommended) Install minio packages using [Homebrew](http://brew.sh/) ```sh brew install minio/stable/minio @@ -74,7 +74,7 @@ minio.exe server D:\Photos ## FreeBSD ### Port -Install minio packages using [pkg](https://github.com/freebsd/pkg) +Install minio packages using [pkg](https://github.com/freebsd/pkg), MinIO doesn't officially build FreeBSD binaries but is maintained by FreeBSD upstream [here](https://www.freshports.org/www/minio). ```sh pkg install minio diff --git a/cmd/bucket-handlers.go b/cmd/bucket-handlers.go index fcb4897ed..74cefce4e 100644 --- a/cmd/bucket-handlers.go +++ b/cmd/bucket-handlers.go @@ -534,7 +534,8 @@ func (api objectAPIHandlers) PutBucketHandler(w http.ResponseWriter, r *http.Req } if globalDNSConfig != nil { - if _, err := globalDNSConfig.Get(bucket); err != nil { + sr, err := globalDNSConfig.Get(bucket) + if err != nil { if err == dns.ErrNoEntriesFound { // Proceed to creating a bucket. if err = objectAPI.MakeBucketWithLocation(ctx, bucket, location); err != nil { @@ -567,7 +568,15 @@ func (api objectAPIHandlers) PutBucketHandler(w http.ResponseWriter, r *http.Req return } - writeErrorResponse(ctx, w, errorCodes.ToAPIErr(ErrBucketAlreadyOwnedByYou), r.URL, guessIsBrowserReq(r)) + apiErr := ErrBucketAlreadyExists + if !globalDomainIPs.Intersection(set.CreateStringSet(getHostsSlice(sr)...)).IsEmpty() { + apiErr = ErrBucketAlreadyOwnedByYou + } + // No IPs seem to intersect, this means that bucket exists but has + // different IP addresses perhaps from a different deployment. + // bucket names are globally unique in federation at a given + // path prefix, name collision is not allowed. Return appropriate error. + writeErrorResponse(ctx, w, errorCodes.ToAPIErr(apiErr), r.URL, guessIsBrowserReq(r)) return }