site replication edit: validate endpoint belongs to deployment (#16000)

This commit is contained in:
Poorna 2022-11-03 16:23:45 -07:00 committed by GitHub
parent 7e73fc2870
commit 4f5d38a4b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3477,6 +3477,9 @@ func (c *SiteReplicationSys) EditPeerCluster(ctx context.Context, peer madmin.Pe
) )
for _, v := range sites.Sites { 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 { if peer.DeploymentID == v.DeploymentID {
found = true found = true
if peer.Endpoint == v.Endpoint { 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)) return madmin.ReplicateEditStatus{}, errSRPeerResp(fmt.Errorf("unable to create admin client for %s: %w", v.Name, err))
} }
// check if endpoint is reachable // check if endpoint is reachable
if _, err = admClient.ServerInfo(ctx); err != nil { info, err := admClient.ServerInfo(ctx)
return madmin.ReplicateEditStatus{}, errSRPeerResp(fmt.Errorf("Endpoint %s not reachable: %w", peer.Endpoint, err)) 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))
} }
} }
} }