From 626362fbad15d4c478531b1842fe4ff6c8faa9a4 Mon Sep 17 00:00:00 2001 From: liugq Date: Fri, 9 Jun 2023 20:53:00 +0800 Subject: [PATCH] update agent node validate logic --- modules/agent/api/instance.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/modules/agent/api/instance.go b/modules/agent/api/instance.go index 8b8d8385..4bf805e0 100644 --- a/modules/agent/api/instance.go +++ b/modules/agent/api/instance.go @@ -491,16 +491,25 @@ 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) + host, port, 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) && !net.ParseIP(host).IsLoopback() { + if !util.StringInArray(inst.IPS, host) && !net.ParseIP(host).IsLoopback() { h.WriteError(w, fmt.Sprintf("got node host %s not match any ip of %v", host, inst.IPS), http.StatusInternalServerError) return } + if oldNodeInfo.HttpPort != port { + h.WriteError(w, fmt.Sprintf("port mismatch, got: %s,expected: %s", port, oldNodeInfo.HttpPort), http.StatusInternalServerError) + return + } + if oldNodeInfo.ProcessInfo.PID != nodeInfo.ProcessInfo.PID { + h.WriteError(w, fmt.Sprintf("process id mismatch, got: %s,expected: %s", nodeInfo.ProcessInfo.PID, oldNodeInfo.ProcessInfo.PID), http.StatusInternalServerError) + return + } + nodeInfo.ID = oldNodeInfo.ID nodeInfo.AgentID = inst.ID err = orm.Save(nil, nodeInfo)