From d765b89a63c225ca271ef6d031a7bcc8fe9137df Mon Sep 17 00:00:00 2001 From: Poorna Date: Fri, 28 Oct 2022 23:21:33 -0700 Subject: [PATCH] improve validation for replication resync API (#15964) --- cmd/bucket-replication-handlers.go | 8 +++++++- internal/bucket/replication/replication.go | 9 ++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/cmd/bucket-replication-handlers.go b/cmd/bucket-replication-handlers.go index 75edd0a19..7df242d30 100644 --- a/cmd/bucket-replication-handlers.go +++ b/cmd/bucket-replication-handlers.go @@ -276,7 +276,13 @@ func (api objectAPIHandlers) ResetBucketReplicationStartHandler(w http.ResponseW writeErrorResponse(ctx, w, toAPIError(ctx, err), r.URL) return } - if !config.HasExistingObjectReplication(arn) { + hasARN, hasExistingObjEnabled := config.HasExistingObjectReplication(arn) + if !hasARN { + writeErrorResponse(ctx, w, errorCodes.ToAPIErr(ErrRemoteTargetNotFoundError), r.URL) + return + } + + if !hasExistingObjEnabled { writeErrorResponse(ctx, w, errorCodes.ToAPIErr(ErrReplicationNoExistingObjects), r.URL) return } diff --git a/internal/bucket/replication/replication.go b/internal/bucket/replication/replication.go index 43954eba0..4e82267cb 100644 --- a/internal/bucket/replication/replication.go +++ b/internal/bucket/replication/replication.go @@ -162,15 +162,18 @@ type ObjectOpts struct { } // HasExistingObjectReplication returns true if any of the rule returns 'ExistingObjects' replication. -func (c Config) HasExistingObjectReplication(arn string) bool { +func (c Config) HasExistingObjectReplication(arn string) (hasARN, isEnabled bool) { for _, rule := range c.Rules { if rule.Destination.ARN == arn || c.RoleArn == arn { + if !hasARN { + hasARN = true + } if rule.ExistingObjectReplication.Status == Enabled { - return true + return true, true } } } - return false + return hasARN, false } // FilterActionableRules returns the rules actions that need to be executed