fix public ip selfcheck logic
This commit is contained in:
1 parent
a6f9646da5
commit
67adc6670e
18 files changed
+209
-90
No files matched your search
@@ -139,7 +139,3 @@ func (s *Server) handleAgentComplete(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
writeJSON(w, http.StatusOK, okResponse{OK: true})
|
||||
}
|
||||
|
||||
func (s *Server) handleWhatsMyIP(w http.ResponseWriter, r *http.Request) {
|
||||
writeJSON(w, http.StatusOK, map[string]string{"ip": remoteIP(r)})
|
||||
}
|
||||
@@ -123,13 +123,10 @@ func TestEndToEndHTTPFlow(t *testing.T) {
|
||||
t.Fatalf("expected 1.2.3.4, got %s", assignment.IPAddress)
|
||||
}
|
||||
|
||||
// Self-check via /whatsmyip: in the real deployment this would equal
|
||||
// the FIP; here we just exercise the endpoint and always report success.
|
||||
resp, body = fc.do(http.MethodGet, "/api/v1/whatsmyip", nil)
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
t.Fatalf("whatsmyip: status=%d body=%s", resp.StatusCode, body)
|
||||
}
|
||||
|
||||
// Self-check: in the real deployment the agent queries an external
|
||||
// IP-echo service (see internal/agentcore.detectPublicIP) and compares
|
||||
// the result to the assigned FIP; the HTTP layer here just accepts
|
||||
// whatever outcome the caller reports.
|
||||
resp, body = fc.do(http.MethodPost, "/api/v1/agents/validator-1/self-check", selfCheckRequest{
|
||||
IPID: assignment.IPID, DetectedEgress: "1.2.3.4", Success: true, Detail: "matched",
|
||||
})
|
||||
|
||||
@@ -4,7 +4,6 @@ import "net/http"
|
||||
|
||||
func (s *Server) routes(mux *http.ServeMux) {
|
||||
mux.HandleFunc("GET /healthz", s.handleHealthz)
|
||||
mux.HandleFunc("GET /api/v1/whatsmyip", s.handleWhatsMyIP)
|
||||
|
||||
mux.HandleFunc("POST /api/v1/agents/register", s.handleAgentRegister)
|
||||
mux.HandleFunc("POST /api/v1/agents/{id}/heartbeat", s.handleAgentHeartbeat)
|
||||
|
||||
@@ -8,7 +8,6 @@ package httpapi
|
||||
import (
|
||||
"encoding/json"
|
||||
"log/slog"
|
||||
"net"
|
||||
"net/http"
|
||||
|
||||
"cloudipvalidator/internal/db"
|
||||
@@ -57,15 +56,3 @@ func readJSON(r *http.Request, v interface{}) error {
|
||||
dec := json.NewDecoder(r.Body)
|
||||
return dec.Decode(v)
|
||||
}
|
||||
|
||||
// remoteIP returns the caller's source IP with any port stripped. Used by
|
||||
// /whatsmyip — the validator-agent's self-check mechanism relies on this
|
||||
// being the actual TCP peer address (as SNAT'd by the newly associated
|
||||
// FIP), never a client-supplied header.
|
||||
func remoteIP(r *http.Request) string {
|
||||
host, _, err := net.SplitHostPort(r.RemoteAddr)
|
||||
if err != nil {
|
||||
return r.RemoteAddr
|
||||
}
|
||||
return host
|
||||
}
|
||||
Reference in new issue
Block a user