From 4f5d38a4b1d8c14b9b692c0c434b8ae8e540fd34 Mon Sep 17 00:00:00 2001 From: Poorna Date: Thu, 3 Nov 2022 16:23:45 -0700 Subject: [PATCH] site replication edit: validate endpoint belongs to deployment (#16000) --- cmd/site-replication.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/cmd/site-replication.go b/cmd/site-replication.go index 57edaa18f..20fa35e3d 100644 --- a/cmd/site-replication.go +++ b/cmd/site-replication.go @@ -3477,6 +3477,9 @@ func (c *SiteReplicationSys) EditPeerCluster(ctx context.Context, peer madmin.Pe ) for _, v := range sites.Sites { + if peer.Endpoint == v.Endpoint { + return madmin.ReplicateEditStatus{}, errSRInvalidRequest(fmt.Errorf("Endpoint %s entered for deployment id %s already configured in site replication", v.Endpoint, v.DeploymentID)) + } if peer.DeploymentID == v.DeploymentID { found = true if peer.Endpoint == v.Endpoint { @@ -3487,8 +3490,12 @@ func (c *SiteReplicationSys) EditPeerCluster(ctx context.Context, peer madmin.Pe return madmin.ReplicateEditStatus{}, errSRPeerResp(fmt.Errorf("unable to create admin client for %s: %w", v.Name, err)) } // check if endpoint is reachable - if _, err = admClient.ServerInfo(ctx); err != nil { - return madmin.ReplicateEditStatus{}, errSRPeerResp(fmt.Errorf("Endpoint %s not reachable: %w", peer.Endpoint, err)) + info, err := admClient.ServerInfo(ctx) + if err != nil { + return madmin.ReplicateEditStatus{}, errSRInvalidRequest(fmt.Errorf("Endpoint %s not reachable: %w", peer.Endpoint, err)) + } + if info.DeploymentID != v.DeploymentID { + return madmin.ReplicateEditStatus{}, errSRInvalidRequest(fmt.Errorf("Endpoint %s does not belong to deployment expected: %s (found %s) ", v.Endpoint, v.DeploymentID, info.DeploymentID)) } } }