validate node publish address with agent instance ip list

This commit is contained in:
liugq 2023-06-08 20:31:42 +08:00
parent 4d56a1121f
commit 365dd690ab
1 changed files with 11 additions and 0 deletions

View File

@ -21,6 +21,7 @@ import (
"infini.sh/framework/core/util"
elastic2 "infini.sh/framework/modules/elastic"
"infini.sh/framework/modules/elastic/common"
"net"
"net/http"
"strconv"
"time"
@ -491,6 +492,16 @@ func (h *APIHandler) authESNode(w http.ResponseWriter, req *http.Request, ps htt
h.WriteError(w, err.Error(), http.StatusInternalServerError)
return
}
host, _, err := net.SplitHostPort(nodeInfo.PublishAddress)
if err != nil {
log.Error(err)
h.WriteError(w, err.Error(), http.StatusInternalServerError)
return
}
if !util.StringInArray(inst.IPS, host) {
h.WriteError(w, fmt.Sprintf("got node host %s not match any ip of %v", host, inst.IPS), http.StatusInternalServerError)
return
}
nodeInfo.ID = oldNodeInfo.ID
nodeInfo.AgentID = inst.ID
err = orm.Save(nil, nodeInfo)