Skip to content

Agent Mesh

api, router: canonical node: allow entries and name the plaintext risk

Antonio Ojeac5562280c39e
diff --git a/api/ingress.go b/api/ingress.go
index 58b20ac4..84bb4451 100644
--- a/api/ingress.go
+++ b/api/ingress.go
@@ -83,7 +83,10 @@ func ParseIngressAuthMode(s string) (IngressAuthMode, error) {
}
// ServiceIngressFromConfig converts a YAML IngressConfig into a validated
-// protobuf ServiceIngress message.
+// protobuf ServiceIngress message. This is the boundary where operator text
+// enters the mesh, so a "node:<peer_id>" allow entry is rewritten to the
+// canonical peer ID string here: the record a router stores and replicates
+// never carries the form the operator happened to type.
func ServiceIngressFromConfig(svcType ServiceType, cfg *IngressConfig) (*ServiceIngress, error) {
if cfg == nil {
return nil, nil
@@ -99,6 +102,14 @@ func ServiceIngressFromConfig(svcType ServiceType, cfg *IngressConfig) (*Service
if err := ValidateServiceIngress(svcType, ing); err != nil {
return nil, err
}
+ for i, member := range ing.Allow {
+ if prefix, val, ok := strings.Cut(member, ":"); ok && prefix == FactNode {
+ // Validated above, so Decode cannot fail here.
+ if id, err := peer.Decode(val); err == nil {
+ ing.Allow[i] = FactNode + ":" + id.String()
+ }
+ }
+ }
return ing, nil
}
diff --git a/api/ingress_test.go b/api/ingress_test.go
index 13ada69a..14472b38 100644
--- a/api/ingress_test.go
+++ b/api/ingress_test.go
@@ -17,6 +17,7 @@ package api
import (
"crypto/ed25519"
"crypto/rand"
+ "slices"
"testing"
"github.com/eclipse-biscuit/biscuit-go/v2"
@@ -130,6 +131,24 @@ func TestServiceIngressFromConfig(t *testing.T) {
if _, err := ServiceIngressFromConfig(ServiceType_SERVICE_TYPE_A2A, &IngressConfig{AuthMode: "bogus"}); err == nil {
t.Fatal("expected error for invalid auth_mode")
}
+
+ // A node: entry is stored in canonical form whatever the operator typed:
+ // the CIDv1 spelling of a peer ID decodes to the same ID as its base58
+ // spelling, and the record carries the latter.
+ id := testPeerID(t)
+ cidForm := peer.ToCid(id).String()
+ if cidForm == id.String() {
+ t.Fatalf("test needs a non-canonical spelling; ToCid gave %q", cidForm)
+ }
+ got, err = ServiceIngressFromConfig(ServiceType_SERVICE_TYPE_A2A, &IngressConfig{
+ Allow: []string{"node:" + cidForm, "email:[email protected]"},
+ })
+ if err != nil {
+ t.Fatalf("ServiceIngressFromConfig with CID peer ID: %v", err)
+ }
+ if want := []string{"node:" + id.String(), "email:[email protected]"}; !slices.Equal(got.Allow, want) {
+ t.Fatalf("Allow = %v, want canonical %v", got.Allow, want)
+ }
}
func TestValidateIngressGrants(t *testing.T) {
diff --git a/cmd/agentmesh-router/main.go b/cmd/agentmesh-router/main.go
index 5f880e55..5b702fe1 100644
--- a/cmd/agentmesh-router/main.go
+++ b/cmd/agentmesh-router/main.go
@@ -185,7 +185,7 @@ func main() {
rootCmd.Flags().StringVar(&ingressURL, "ingress-url", "", "Public base URL advertised for external HTTP ingress on this router (e.g. https://bananas.sam-mesh.dev/ingress)")
rootCmd.Flags().StringVar(&ingressTLSCertPath, "ingress-tls-cert-path", "", "Path to TLS certificate file for --ingress-addr")
rootCmd.Flags().StringVar(&ingressTLSKeyPath, "ingress-tls-key-path", "", "Path to TLS private key file for --ingress-addr")
- rootCmd.Flags().BoolVar(&allowInsecureIngressHTTP, "allow-insecure-ingress-http", false, "Allow --ingress-addr on a non-loopback interface without TLS (only when behind a TLS-terminating L7 load balancer) and allow http:// in --ingress-url")
+ rootCmd.Flags().BoolVar(&allowInsecureIngressHTTP, "allow-insecure-ingress-http", false, "Allow --ingress-addr on a non-loopback interface without TLS and allow http:// in --ingress-url. Risk: every caller's bearer Biscuit and request body then cross the network in plaintext between the client and this router; set it only when a TLS-terminating L7 load balancer in front of the router is the only thing that can reach --ingress-addr")
rootCmd.Flags().StringVar(&publicControlPlaneURL, "public-control-plane", "", "Optional public URL of the control plane advertised in RFC 9728 and A2A OAuth metadata when --control-plane uses a cluster-internal address")
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)