Skip to content

Agent Mesh

router, node: accept Noise after TLS

Antonio Ojea9a0103e52de0
diff --git a/internal/node/node.go b/internal/node/node.go
index 07b77312..7ef2d962 100644
--- a/internal/node/node.go
+++ b/internal/node/node.go
@@ -61,6 +61,7 @@ import (
"github.com/libp2p/go-libp2p/p2p/host/autorelay"
"github.com/libp2p/go-libp2p/p2p/net/connmgr"
"github.com/libp2p/go-libp2p/p2p/net/swarm"
+ "github.com/libp2p/go-libp2p/p2p/security/noise"
libp2ptls "github.com/libp2p/go-libp2p/p2p/security/tls"
"github.com/libp2p/go-msgio"
"github.com/multiformats/go-multiaddr"
@@ -430,11 +431,15 @@ func (n *SamNode) Start(ctx context.Context) error {
return fmt.Errorf("failed to create connection manager: %w", err)
}
- // Layer 1: Establish FIPS-compliant Transports & NAT Services
+ // Layer 1: Transports & NAT Services. TLS first: Go peers and the
+ // Node/Python SDKs land on it. Noise is what a browser can speak, and a
+ // relayed connection from one is upgraded here, end to end; both bind
+ // the connection to the peer ID.
opts := []libp2p.Option{
libp2p.Identity(n.config.PrivKey),
libp2p.DefaultTransports,
libp2p.Security(libp2ptls.ID, libp2ptls.New),
+ libp2p.Security(noise.ID, noise.New),
libp2p.ConnectionGater(gater),
libp2p.ListenAddrStrings(n.config.ListenAddrs...),
libp2p.EnableNATService(),
diff --git a/internal/router/router.go b/internal/router/router.go
index 5f0e3f44..d2232849 100644
--- a/internal/router/router.go
+++ b/internal/router/router.go
@@ -51,6 +51,7 @@ import (
rcmgr "github.com/libp2p/go-libp2p/p2p/host/resource-manager"
"github.com/libp2p/go-libp2p/p2p/net/connmgr"
"github.com/libp2p/go-libp2p/p2p/protocol/circuitv2/relay"
+ "github.com/libp2p/go-libp2p/p2p/security/noise"
libp2ptls "github.com/libp2p/go-libp2p/p2p/security/tls"
libp2pquic "github.com/libp2p/go-libp2p/p2p/transport/quic"
"github.com/libp2p/go-libp2p/p2p/transport/tcp"
@@ -353,7 +354,10 @@ func (r *Router) Start() error {
libp2p.Identity(r.privKey),
r.transportOptions(),
libp2p.ListenAddrStrings(r.config.ListenAddrs...),
+ // TLS first: Go peers and the Node/Python SDKs land on it. Noise is
+ // what a browser can speak; both bind the connection to the peer ID.
libp2p.Security(libp2ptls.ID, libp2ptls.New),
+ libp2p.Security(noise.ID, noise.New),
libp2p.ConnectionManager(cm),
libp2p.EnableAutoNATv2(),
libp2p.EnableNATService(),
diff --git a/sdk/README.md b/sdk/README.md
index 1475825d..a4207a5a 100644
--- a/sdk/README.md
+++ b/sdk/README.md
@@ -226,9 +226,10 @@ messages in `api/sam.proto`. Bodies are capped at 1 MiB on both sides.
### libp2p host (`internal/node/node.go`)
- Transports: `libp2p.DefaultTransports` (TCP, QUIC, WebSocket).
-- Security: **TLS only** (`libp2p.Security(libp2ptls.ID, libp2ptls.New)`).
- There is no Noise on `sam-node` or `sam-router`. js-libp2p has TLS;
- py-libp2p gained it in
+- Security: TLS first, Noise accepted (`libp2p.Security` twice, in that
+ order, on `sam-node` and `sam-router`). Both bind the connection to the
+ peer ID. The Node and Python SDKs speak TLS and land on it; Noise is what
+ a browser can speak. js-libp2p has both; py-libp2p gained TLS in
[libp2p/py-libp2p#831](https://github.com/libp2p/py-libp2p/pull/831) and
has passed the libp2p transport interoperability suite against the other
implementations since
@@ -591,10 +592,9 @@ same commit as the Go components they talk to.
service, a DHT record or a catalog entry. That is `sam-node`'s job; see
[Agents, not services](#agents-not-services).
- A browser build. The JS SDK dials routers over WebSocket, which a browser
- can do, but it still runs on Node.js only: the routers and nodes accept
- libp2p TLS alone, which a browser cannot speak (it would need Noise on the
- Go side), and the SDK reads its state and speaks HTTP/1.1 on streams with
- Node's `fs` and `http`.
+ can do, and routers and nodes accept Noise, which a browser can speak, but
+ it still runs on Node.js only: it speaks libp2p TLS, and reads its state
+ and speaks HTTP/1.1 on streams with Node's `fs` and `http`.
- Any SDK-only wire protocol. If an SDK needs something the Go node does not
speak, the Go node learns it first.
diff --git a/sdk/js/src/host.ts b/sdk/js/src/host.ts
index cc1ddc73..39eb6d7b 100644
--- a/sdk/js/src/host.ts
+++ b/sdk/js/src/host.ts
@@ -13,10 +13,11 @@
// limitations under the License.
// The libp2p host a member joins the mesh with, configured the way
-// sam-node's is (internal/node/node.go): TLS is the only security
-// protocol, yamux the muxer, circuit relay v2 for reachability through
-// the routers. TCP and WebSocket are the transports: the testnets' routers
-// listen on TCP, sam-one's single port is a WebSocket listener.
+// sam-node's is (internal/node/node.go): TLS for the security protocol,
+// which every peer offers first, yamux the muxer, circuit relay v2 for
+// reachability through the routers. TCP and WebSocket are the transports:
+// the testnets' routers listen on TCP, sam-one's single port is a WebSocket
+// listener.
import { yamux } from "@chainsafe/libp2p-yamux";
import { circuitRelayTransport } from "@libp2p/circuit-relay-v2";
diff --git a/sdk/python/src/agent_mesh/host.py b/sdk/python/src/agent_mesh/host.py
index 9bb0504b..c91b7e79 100644
--- a/sdk/python/src/agent_mesh/host.py
+++ b/sdk/python/src/agent_mesh/host.py
@@ -13,8 +13,9 @@
# limitations under the License.
"""The libp2p host a member joins the mesh with, configured the way sam-node's
-is (internal/node/node.go): TLS is the only security protocol and yamux the
-muxer. py-libp2p is trio-based, so everything here is trio async."""
+is (internal/node/node.go): TLS for the security protocol, which every peer
+offers first, and yamux the muxer. py-libp2p is trio-based, so everything here
+is trio async."""
from __future__ import annotations
diff --git a/site/content/docs/concepts/networking.md b/site/content/docs/concepts/networking.md
index 9a8097b5..dda1d662 100644
--- a/site/content/docs/concepts/networking.md
+++ b/site/content/docs/concepts/networking.md
@@ -89,9 +89,11 @@ sends any request data.
## What travels where
-Every hop between two nodes is encrypted by libp2p's TLS 1.3 secure channel.
-TLS is the only security transport enabled, so that FIPS-validated
-cryptography can be used end to end. A relay forwards ciphertext and learns
+Every hop between two nodes is encrypted by a libp2p secure channel that
+binds the connection to the peer's identity: TLS 1.3, which Go peers and the
+Node and Python SDKs use, or Noise, which a browser can speak. Routers and
+nodes offer TLS first and accept Noise; two peers that both have TLS land on
+it. A relay forwards ciphertext and learns
only that the two peers are talking. The control plane sees enrollments,
refreshes, router leases, policy fetches and catalog reports. It never sees a
request.
diff --git a/site/content/docs/guides/native-sdks.md b/site/content/docs/guides/native-sdks.md
index 2b9f12f0..c7e6c71e 100644
--- a/site/content/docs/guides/native-sdks.md
+++ b/site/content/docs/guides/native-sdks.md
@@ -926,9 +926,9 @@ or a pattern) and the members it may reach; see
- They do not serve the discovery table. A member is a client of it; the
routers hold the records.
- They do not run in a browser. Node.js and CPython only. The JS SDK
- dials routers over WebSocket, which a browser can do, but routers and
- nodes accept libp2p TLS alone, which a browser cannot speak, and the SDK
- keeps its state and speaks HTTP on streams with Node's own modules.
+ dials routers over WebSocket, which a browser can do, and routers and
+ nodes accept Noise, which a browser can speak, but the SDK speaks libp2p
+ TLS and keeps its state and speaks HTTP on streams with Node's own modules.
The wire contract and the interoperability facts the tests pin are in
[`sdk/README.md`](https://github.com/google/sam/blob/main/sdk/README.md).
diff --git a/tests/integration/noise_test.go b/tests/integration/noise_test.go
new file mode 100644
index 00000000..18330b6e
--- /dev/null
+++ b/tests/integration/noise_test.go
@@ -0,0 +1,103 @@
+// Copyright 2026 Google LLC
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package integration_test
+
+import (
+ "context"
+ "crypto/ed25519"
+ "strings"
+ "testing"
+ "time"
+
+ "github.com/google/sam/api"
+ "github.com/google/sam/internal/identity"
+ "github.com/libp2p/go-libp2p"
+ "github.com/libp2p/go-libp2p/core/host"
+ "github.com/libp2p/go-libp2p/core/network"
+ "github.com/libp2p/go-libp2p/core/peer"
+ "github.com/libp2p/go-libp2p/p2p/security/noise"
+ "github.com/multiformats/go-multiaddr"
+)
+
+// TestNoiseOnlyPeer pins what a browser member is on the wire: a peer that
+// speaks Noise and no libp2p TLS. It authenticates with the router over
+// Noise, is relayed to a sam-node, and the relayed connection, upgraded end
+// to end between the two of them, is Noise as well, so the node's auth
+// handshake and a service call go through. A peer that speaks TLS still
+// lands on TLS: it is offered first.
+func TestNoiseOnlyPeer(t *testing.T) {
+ ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
+ defer cancel()
+ mesh := startSDKMesh(t)
+
+ h, err := libp2p.New(
+ libp2p.NoListenAddrs,
+ libp2p.Security(noise.ID, noise.New),
+ libp2p.EnableRelay(),
+ )
+ if err != nil {
+ t.Fatal(err)
+ }
+ t.Cleanup(func() { _ = h.Close() })
+ biscuit := goHostBiscuit(t, mesh.cpPriv, h.ID())
+
+ router, err := peer.AddrInfoFromString(mesh.routerAddr)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if err := h.Connect(ctx, *router); err != nil {
+ t.Fatalf("noise-only peer could not connect to the router: %v", err)
+ }
+ if got := securityOf(h, router.ID); got != noise.ID {
+ t.Fatalf("connection to the router is %q, want %q", got, noise.ID)
+ }
+ routerBiscuit := authHandshake(t, ctx, h, router.ID, biscuit)
+ if err := identity.VerifyBiscuitRole(routerBiscuit, mesh.cpPriv.Public().(ed25519.PublicKey), api.RoleRouter, 5*time.Second); err != nil {
+ t.Fatalf("router credential lacks the router role: %v", err)
+ }
+
+ nodeID := mesh.samNode.peerID
+ relayed := multiaddr.StringCast(mesh.routerAddr + "/p2p-circuit/p2p/" + nodeID.String())
+ // A relayed connection reports no security protocol in its ConnState;
+ // that this peer, which has Noise alone, gets one at all is the check.
+ if err := h.Connect(network.WithAllowLimitedConn(ctx, "test"), peer.AddrInfo{ID: nodeID, Addrs: []multiaddr.Multiaddr{relayed}}); err != nil {
+ t.Fatalf("noise-only peer could not reach the node through the router: %v", err)
+ }
+ nodeBiscuit := authHandshake(t, ctx, h, nodeID, biscuit)
+ if err := identity.VerifyBiscuitRole(nodeBiscuit, mesh.cpPriv.Public().(ed25519.PublicKey), api.RoleNode, 5*time.Second); err != nil {
+ t.Fatalf("node credential lacks the node role: %v", err)
+ }
+ // The MCP service answers a bare GET with its own 400 (the streamable
+ // HTTP transport wants an SSE Accept); an answer from the service is what
+ // shows the request crossed the noise connection into the node.
+ if status, body := libp2pHTTPGet(t, ctx, h, nodeID, biscuit, "/mcp/calc"); status != 200 && (status != 400 || !strings.Contains(body, "text/event-stream")) {
+ t.Fatalf("service call over the noise connection: %d %s", status, body)
+ }
+
+ // The TLS peer of the other tests is unchanged: TLS is offered first.
+ tlsPeer := newAdmittedGoPeer(t, ctx, mesh.cpPriv, mesh.routerAddr)
+ if got := securityOf(tlsPeer, router.ID); !strings.HasPrefix(got, "/tls/") {
+ t.Fatalf("TLS peer's connection to the router is %q, want /tls/...", got)
+ }
+}
+
+// securityOf is the security protocol of h's connection to p.
+func securityOf(h host.Host, p peer.ID) string {
+ conns := h.Network().ConnsToPeer(p)
+ if len(conns) == 0 {
+ return ""
+ }
+ return string(conns[0].ConnState().Security)
+}