feat(api): prevent endpoint creation with already paired agent (#3159)

pull/3181/head
Anthony Lapenna 5 years ago committed by GitHub
parent 07505fabcc
commit 1f68aad07f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -2,12 +2,12 @@ package endpoints
import ( import (
"errors" "errors"
"log"
"net" "net"
"net/http" "net/http"
"net/url" "net/url"
"runtime" "runtime"
"strconv" "strconv"
"strings"
httperror "github.com/portainer/libhttp/error" httperror "github.com/portainer/libhttp/error"
"github.com/portainer/libhttp/request" "github.com/portainer/libhttp/request"
@ -344,8 +344,10 @@ func (handler *Handler) snapshotAndPersistEndpoint(endpoint *portainer.Endpoint)
snapshot, err := handler.Snapshotter.CreateSnapshot(endpoint) snapshot, err := handler.Snapshotter.CreateSnapshot(endpoint)
endpoint.Status = portainer.EndpointStatusUp endpoint.Status = portainer.EndpointStatusUp
if err != nil { if err != nil {
log.Printf("http error: endpoint snapshot error (endpoint=%s, URL=%s) (err=%s)\n", endpoint.Name, endpoint.URL, err) if strings.Contains(err.Error(), "Invalid request signature") {
endpoint.Status = portainer.EndpointStatusDown err = errors.New("agent already paired with another Portainer instance")
}
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to initiate communications with endpoint", err}
} }
if snapshot != nil { if snapshot != nil {

Loading…
Cancel
Save