Agent Mesh
Go a2aa2a-protocolagent-meshagentic-aiinferencemcpmeshmesh-networknetwork-securitynetworking-aip2p-network
node: canonicalize the peer ID at the egress floor gate
Antonio Ojea1b3662ff8a58
diff --git a/internal/node/proxy_test.go b/internal/node/proxy_test.goindex afa3c267..b17885fd 100644--- a/internal/node/proxy_test.go+++ b/internal/node/proxy_test.go@@ -934,6 +934,22 @@ func TestEgressProxyEnforcesFloor(t *testing.T) {t.Fatalf("egress inside the floor must pass: status %d, body %q", resp.StatusCode, body)}+ // A non-canonical spelling of the same peer (CID form) is canonicalized at+ // the gate boundary, so the verdict and the dial name the same peer.+ cidURL := fmt.Sprintf("%s/sam/%s/mcp/dummy-tool/api/v1/test", proxyServer.URL, peer.ToCid(nodeA.Host.ID()))+ resp, err = http.Get(cidURL)+ if err != nil {+ t.Fatal(err)+ }+ body, err = io.ReadAll(resp.Body)+ _ = resp.Body.Close()+ if err != nil {+ t.Fatal(err)+ }+ if resp.StatusCode != http.StatusOK || string(body) != expectedBody {+ t.Fatalf("a CID-spelled peer inside the floor must pass: status %d, body %q", resp.StatusCode, body)+ }+// One pair short of the floor: refused at the chokepoint, nothing forwarded.nodeB.nodeConfig = &NodeConfigComplete{EgressRequireLabels: map[string]string{"jurisdiction": "eu", "compliance": "gdpr"}}resp = get()diff --git a/internal/node/sidecar.go b/internal/node/sidecar.goindex 2a0e2e3b..c8a2ffa6 100644--- a/internal/node/sidecar.go+++ b/internal/node/sidecar.go@@ -727,8 +727,18 @@ func createEgressProxy(node *SamNode) http.Handler {http.Error(w, "Bad Request: invalid peer ID", http.StatusBadRequest)return}+ // The verdict is for the canonical peer, so the dial must name the+ // same form: rewrite the segment the Director will re-parse rather+ // than let a non-canonical spelling travel past the gate.+ if canonical := pid.String(); route.peerID != canonical {+ parts := strings.SplitN(r.URL.Path, "/", 6)+ if len(parts) >= 3 {+ parts[2] = canonical+ r.URL.Path = strings.Join(parts, "/")+ }+ }if err := node.VerifyPeerLabels(r.Context(), pid, nil); err != nil {- logger.Warnf("[Egress] floor gate refused egress to %s: %v", route.peerID, err)+ logger.Warnf("[Egress] floor gate refused egress to %s: %v", pid, err)http.Error(w, "Forbidden: provider does not attest the egress floor", http.StatusForbidden)return}