Repository navigation
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces native Signed Egress capabilities to Agent Mesh, implementing RFC 9421 HTTP Message Signatures, RFC 9530 Content-Digest, and signed read-only Kademlia DHT ingress documents with zero external sidecars. Feedback on the changes highlights a compilation error in internal/httpsig/httpsig.go where ecdsa.PublicKey lacks a Bytes() method, a peer ID comparison style guide violation in api/ingress_documents.go, a swallowed error from rand.Read in internal/node/egress_transform.go, and missing peer ID identifiers in log lines in internal/node/egress_signing.go and internal/node/node.go.
| if bundle.GetPeerId() != expectedPeer.String() { | ||
| return nil, fmt.Errorf("ingress document bundle peer_id %q does not match %s", bundle.GetPeerId(), expectedPeer) | ||
| } |
There was a problem hiding this comment.
The bundle.GetPeerId() is a raw string from protobuf, which might not be in the canonical base58 form (e.g., it could be in CIDv1 base32 form). Comparing it directly with expectedPeer.String() violates Rule 1.5 of the style guide, which requires decoding both sides and comparing peer.ID values.
bundlePeer, err := peer.Decode(bundle.GetPeerId())
if err != nil {
return nil, fmt.Errorf("invalid peer_id in bundle: %w", err)
}
if bundlePeer != expectedPeer {
return nil, fmt.Errorf("ingress document bundle peer_id %q does not match %s", bundle.GetPeerId(), expectedPeer)
}References
- Peer IDs must be canonicalized at the boundary. Raw string compared for identity must decode both sides and compare peer.ID values. (link)
|
|
||
| func newUUIDv4() string { | ||
| var b [16]byte | ||
| _, _ = rand.Read(b[:]) |
There was a problem hiding this comment.
The error from rand.Read is swallowed here. According to Rule 6.3 of the style guide, errors must not be swallowed. Since a failure of crypto/rand is a catastrophic system failure, panicking is appropriate.
| _, _ = rand.Read(b[:]) | |
| if _, err := rand.Read(b[:]); err != nil { | |
| panic(fmt.Sprintf("crypto/rand failed: %v", err)) | |
| } |
References
- Errors are not swallowed. Flag the bare form of swallowed errors. (link)
| logger.Warnf("[Directory] Truncating ingress documents from %d to max %d", len(out), api.MaxIngressDocumentsPerPeer) | ||
| out = out[:api.MaxIngressDocumentsPerPeer] | ||
| } | ||
| return out |
There was a problem hiding this comment.
This log line does not carry the peer ID identifier, which violates Rule 6.4 of the style guide. Log lines about a peer must name the peer ID.
if len(out) > api.MaxIngressDocumentsPerPeer {
peerID := "unknown"
if n.Host != nil {
peerID = n.Host.ID().String()
}
logger.Warnf("[Directory] %s: truncating ingress documents from %d to max %d", peerID, len(out), api.MaxIngressDocumentsPerPeer)
out = out[:api.MaxIngressDocumentsPerPeer]
}References
- Log lines carry the identifier. A line about a peer names the peer ID. (link)
| if docErr != nil { | ||
| logger.Warnf("[Directory] Building signed ingress documents: %v", docErr) | ||
| } |
There was a problem hiding this comment.
This log line does not carry the peer ID identifier, which violates Rule 6.4 of the style guide. Log lines about a peer must name the peer ID.
| if docErr != nil { | |
| logger.Warnf("[Directory] Building signed ingress documents: %v", docErr) | |
| } | |
| if docErr != nil { | |
| logger.Warnf("[Directory] %s: building signed ingress documents: %v", n.Host.ID(), docErr) | |
| } |
References
- Log lines carry the identifier. A line about a peer names the peer ID. (link)
… declarative transforms Adds three zero-dependency native primitives for signed outbound egress (Web Bot Auth, UCP REST & MCP, and signed APIs) without external sidecars: - Pure-stdlib RFC 9421 + RFC 9530 HTTP message signing (internal/httpsig) wired onto EgressDestination.signing (ES256 P-256 and Ed25519 PEM bundles from --secrets-dir, multi-key rotation, Web Bot Auth tag + Signature-Agent). - Generic signed read-only ingress documents (SignedIngressDocuments) published under PeerKey into the Kademlia directory, verified offline via peerID.ExtractPublicKey() with rollback protection, strict non-executable media type allowlist, nosniff + CSP sandbox headers, and served directly by routers at GET/HEAD /ingress/<peer_id>/<path> with zero inbound stream to the PEP. - Stateless declarative EgressTransform rules (headers + JSON body mutations) applied after inspection and before credential brokering and signing. - Trimmed live UCP/WBA example (zero Go plugin binary), external PAP 1.0 reference packages, recorded site demo video (site/static/demo-signed-egress.mp4), and updated site documentation.
e50682c to
e15a896
Compare
… egress transform, and external-pap audit findings
e15a896 to
003d1af
Compare
|
Rebased onto PR Review Comments Addressed
RFC 9421 / 8941 / 9530 / WBA / UCP Hardening (
|
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request implements signed ingress documents for peer records, enabling routers to serve static documents (e.g., JWKS, UCP profiles) directly from the Kademlia DHT without requiring inbound streams to the node. It introduces RFC 9421 HTTP message signing, declarative egress transforms for header and JSON body mutations, and robust anti-rollback watermarks for ingress documents. The review feedback identified a compilation error in the record store logic, suggested more idiomatic hex formatting for UUID generation, and recommended expanding the SSRF blocklist to include Azure metadata IPs.
| var oldestExp time.Time | ||
| for k, existing := range s.docWatermarks { | ||
| if oldestKey == "" || existing.expireTime.Before(oldestExp) { | ||
| oldestKey = k |
| } | ||
| b[6] = (b[6] & 0x0f) | 0x40 | ||
| b[8] = (b[8] & 0x3f) | 0x80 | ||
| return fmt.Sprintf("%08x-%04x-%04x-%04x-%012x", b[0:4], b[4:6], b[6:8], b[8:10], b[10:16]), nil |
There was a problem hiding this comment.
Since %x on a slice of bytes already formats it as a hex string of the exact length (e.g., 4 bytes becomes 8 hex characters), the width modifiers (like 08, 04, 12) are redundant. Using a simpler format string is more idiomatic in Go.
| return fmt.Sprintf("%08x-%04x-%04x-%04x-%012x", b[0:4], b[4:6], b[6:8], b[8:10], b[10:16]), nil | |
| return fmt.Sprintf("%x-%x-%x-%x-%x", b[0:4], b[4:6], b[6:8], b[8:10], b[10:16]), nil |
| if addr.IsLinkLocalUnicast() || addr.IsLinkLocalMulticast() || addr.IsUnspecified() || | ||
| addr == netip.MustParseAddr("100.100.100.200") || addr == netip.MustParseAddr("fd00:ec2::254") { |
There was a problem hiding this comment.
To prevent SSRF attacks against Azure Instance Metadata Service (IMDS), consider adding the Azure metadata IP 168.63.129.16 to the forbidden IP list. Since it is a public IP owned by Microsoft, it is not covered by IsPrivate() or IsLinkLocalUnicast().
| if addr.IsLinkLocalUnicast() || addr.IsLinkLocalMulticast() || addr.IsUnspecified() || | |
| addr == netip.MustParseAddr("100.100.100.200") || addr == netip.MustParseAddr("fd00:ec2::254") { | |
| if addr.IsLinkLocalUnicast() || addr.IsLinkLocalMulticast() || addr.IsUnspecified() || | |
| addr == netip.MustParseAddr("100.100.100.200") || addr == netip.MustParseAddr("fd00:ec2::254") || | |
| addr == netip.MustParseAddr("168.63.129.16") { |
frostyhand
left a comment
There was a problem hiding this comment.
Thanks for this, it's a big step up from the ext_proc example. I focused my review on Web Bot Auth conformance, since that's the part I know well, and checked it against draft-ietf-webbotauth-httpsig-protocol-01.
What I ran on 003d1af
go test -raceforinternal/httpsig,internal/node,api,internal/routerand the signing/ingress integration tests: all pass.- Signed a GET and a POST with
httpsig.SignRequestusing the RFC 9421 B.1.4 Ed25519 key, then verified both with Cloudflare's published verifier (web-bot-auth0.2.0 from npm). Both verify, includingcontent-digestandcontent-typeon the POST. keyidequals the draft'spoqkLGiymh_W0uP6PZFw-dvez3QJT5SolqXBCW38r0U,ComputeContentDigestmatches the draft's directory vector, andSignature-Agentuses the dictionary form keyed to the label. The body the signer hashes is the body that's sent, including gzip passthrough when no transform runs.
So request signing looks right to me. Three things on the edges:
1. The directory response signature covers repr-digest, but -01 requires content-digest
SignDirectoryResponse signs ("@authority";req "repr-digest"). Appendix B of -01 says the directory server MUST cover @authority;req and content-digest, and a verifier MUST check Content-Digest against the body. A verifier written to the draft won't accept this signature, even though the bytes are right.
I get why you picked Repr-Digest (HEAD). A simpler fix is to sign content-digest and, on HEAD, drop Signature and Signature-Input along with Content-Digest in the router. Verifiers fetch the directory with GET, so HEAD loses nothing.
Smaller point: -01 recommends one signature per key in the directory. Only primaryKey signs today, so during a rotation the second key has no possession proof.
2. Do peer-scoped directories need the authority binding at all?
The directory lives at /ingress/<peer_id>/.well-known/http-message-signatures-directory on a shared router. -01 only applies the domain binding (Appendix B) when the Signature-Agent value is the registered well-known URI, at the root of the origin. For a path under /ingress/<peer_id>/, a conformant verifier resolves the URL as a plain JWK Set and ignores the binding.
The other side of this: any peer on a router can publish a pre-signed response bound to that router's @authority, because @authority doesn't cover the path. A verifier that recognises the directory by its path suffix (the draft lets verifiers "recognise the shape of the URL") would then credit the router's domain for every tenant's keys. I'd consider skipping SignDirectoryResponse for peer-scoped paths, and maybe not using .well-known inside the /ingress/<peer_id>/ prefix at all. Happy to be told the router is always single-operator and this is fine.
3. VerifyRequest is stricter than -01 and rejects the draft's own test vector
validateWebBotAuthRequirements:
- The 24h lifetime cap is a hard error, but -01 only RECOMMENDS 24h. The draft's dictionary-form Ed25519 vector (
expires=4889289600) fails withlifetime 3153600000s exceeds maximum 86400s. Re-signing the same base with a 1h expiry verifies. - It requires
@authority, while -01 says agents MUST cover "at least one of"@authorityor@target-uri. A valid@target-uri-only signature fails withmust cover "@authority".
Since the verifier is only used in tests right now, this is low impact. Making the cap an option, and accepting either component, would let the draft's vectors run as regression tests. I have the dictionary, legacy and signed-directory vectors from -01 Appendix E wired up locally against internal/httpsig and can send them as a follow-up PR once this lands, if that's useful.
Summary
Adds three zero-dependency native primitives to
agentmesh-nodeandagentmesh-routerso outbound signed HTTP protocols (Web Bot Auth, UCP2026-08-25REST & MCP, and signed APIs) run end-to-end without external sidecars or newgo.moddependencies:Native RFC 9421 + RFC 9530 Outbound Signing (
EgressDestination.signing,internal/httpsig):ES256(raw 64-byter||s) andEd25519signing, RFC 9530Content-Digest, RFC 7638 JWK thumbprints, multi-key PEM bundle rotation (--secrets-dir), and Web Bot Auth (tag: "web-bot-auth",created/expires/nonce,Signature-Agent).egressSigningRoundTripperafter content inspection (ModelArmor/ext_proc), declarative transforms, andCredentialBroker, stripping caller-spoofedSignature*/Content-Digestheaders and failing closed (413on oversized bodies,502+signing_failedmetric on signing errors).Generic Signed Read-Only Ingress Documents in Kademlia DHT (
SignedIngressDocuments):PeerKey(peerID)inDirectoryProvide/PeerRecord, signed with the owning node's Ed25519 libp2p identity key (peerID.ExtractPublicKey()).Provide, KademliaPlace,FindPeer(LookupPeerDocuments), and before HTTP serving, with monotonicsign_timerollback protection and Datalog policy gating (granted_ingress_documents(true)derived automatically for destinations withpublish_public_key: trueoringress_documents, plusPolicyRole.allow_ingress_documents).GET/HEAD /ingress/<peer_id>/<path>directly from the Kademlia directory (zero inbound stream opened to the PEP node), enforcing a strict non-executable media type allowlist (application/json,application/*+json,text/plain), header allowlist,X-Content-Type-Options: nosniff,Content-Security-Policy: default-src 'none'; sandbox, IP rate limiting, and banned-peer404.signing.publish_public_key: true,agentmesh-nodeauto-publishes.well-known/jwks.jsonand pre-signed.well-known/http-message-signatures-directory. Custom templated documents (EgressDestination.ingress_documents, e.g.,.well-known/ucp-profile.json) expand{{ingress_url}},{{peer_id}},{{destination}},{{key_id}},{{public_jwk}}, and{{public_jwks}}.Stateless Declarative Egress Transforms (
EgressDestination.transforms):set_headers,default_headers) and JSON object field (set_json) mutations filtered by HTTP method, path prefix, andjson_equalsbefore credential brokering and signing. Rejects protected headers (Authorization,Cookie,Host,Signature*,Content-Digest,X-Mesh-*) at policy validation.Example, Live Demo Video, & Site Docs:
development/examples/egress-commerce/(policy.json,run.sh,record.sh), keeping stateful PAP 1.0 (which requires per-user OAuth token storage and browser/oauth/callback) clearly separated underdevelopment/examples/egress-commerce/external-pap/.site/static/demo-signed-egress.mp4) and updated site docs (site/content/docs/use-cases/signed-egress-commerce.md,site/content/docs/guides/egress-destinations.md,site/content/docs/guides/external-ingress.md).api/agentmesh.proto.Relates to #990.
Verification
git diff go.mod go.sumis empty (0 new dependencies).make,go vet ./...,gofmt,golangci-lint run(0 issues),./hack/verify-secrets.sh,./hack/gen-sdk-proto.sh,go run ./hack/gen-sdk-docs -check sdk site/content/docs.-race):api/ingress_documents_test.gointernal/httpsig/httpsig_test.gointernal/node/egress_signing_test.gointernal/router/ingress_documents_test.go(2-router Kademlia replication + HTTP ingress)tests/integration/egress_signing_ingress_docs_test.go(standalone+ PEP + peerLookupPeerDocuments+ verifying mock merchant, 3/3 PASS at ~0.65s)development/examples/egress-commerce/external-pap/...flowers.ucpsandbox.comover Cloudflare HTTPS tunnel, zero sidecars):GET /ingress/<peer_id>/.well-known/{jwks.json,http-message-signatures-directory,ucp-profile.json}→HTTP/2 200directly from router DHT withSignature,Content-Digest,nosniff, andCSP: default-src 'none'; sandbox.POST /egress/flowers.ucpsandbox.com/mcp(search_catalog+create_checkout) →200 OK(24 live products + livecontinue_url).POST /egress/flowers.ucpsandbox.com/ucp/checkout-sessions→HTTP/1.1 201 Created.