From 56d1b227cfbdfe4d6dd0c4b83f4619c20f2f56d1 Mon Sep 17 00:00:00 2001 From: Poorna Krishnamoorthy Date: Wed, 30 Sep 2020 13:36:37 -0700 Subject: [PATCH] Handle changes to versioning config for replication (#10598) Disallow versioning suspension on a bucket with pre-existing replication configuration If versioning is suspended on the target,replication should fail. --- cmd/bucket-versioning-handler.go | 8 ++++++++ cmd/object-api-options.go | 7 +++++++ 2 files changed, 15 insertions(+) diff --git a/cmd/bucket-versioning-handler.go b/cmd/bucket-versioning-handler.go index da7620507..bc14e1d2b 100644 --- a/cmd/bucket-versioning-handler.go +++ b/cmd/bucket-versioning-handler.go @@ -70,6 +70,14 @@ func (api objectAPIHandlers) PutBucketVersioningHandler(w http.ResponseWriter, r }, r.URL, guessIsBrowserReq(r)) return } + if _, err := getReplicationConfig(ctx, bucket); err == nil && v.Suspended() { + writeErrorResponse(ctx, w, APIError{ + Code: "InvalidBucketState", + Description: "A replication configuration is present on this bucket, so the versioning state cannot be changed.", + HTTPStatusCode: http.StatusConflict, + }, r.URL, guessIsBrowserReq(r)) + return + } configData, err := xml.Marshal(v) if err != nil { diff --git a/cmd/object-api-options.go b/cmd/object-api-options.go index 7f3ee5778..859a34274 100644 --- a/cmd/object-api-options.go +++ b/cmd/object-api-options.go @@ -151,6 +151,13 @@ func putOpts(ctx context.Context, r *http.Request, bucket, object string, metada VersionID: vid, } } + if !versioned { + return opts, InvalidArgument{ + Bucket: bucket, + Object: object, + Err: fmt.Errorf("VersionID specified %s, but versioning not enabled on %s", opts.VersionID, bucket), + } + } } mtime := strings.TrimSpace(r.Header.Get(xhttp.MinIOSourceMTime)) if mtime != "" {