Agent Mesh
Go a2aa2a-protocolagent-meshagentic-aiinferencemcpmeshmesh-networknetwork-securitynetworking-aip2p-network
controlplane: validate egress entries of allowed_publish like allowed_services
HosniBelfeki776ff049e493
diff --git a/api/egress.go b/api/egress.goindex bac8b2ec..f3476d72 100644--- a/api/egress.go+++ b/api/egress.go@@ -152,12 +152,13 @@ func ValidateEgressName(name string) error {return nil}-// ValidateEgressServicePattern checks an egress entry of allowed_services or-// http.service. The generic service validator accepts a path and any case,-// which for the other types name a service that may exist; an egress name is-// a hostname, matched against a lowercase destination name, so a path, a-// port, uppercase or a trailing dot would compile to a grant that matches-// nothing. Entries of other types pass through unchanged.+// ValidateEgressServicePattern checks an egress entry of allowed_services,+// allowed_publish or http.service. The generic service validator accepts a+// path and any case, which for the other types name a service that may+// exist; an egress name is a hostname, matched against a lowercase+// destination name, so a path, a port, uppercase or a trailing dot would+// compile to a grant that matches nothing. Entries of other types pass+// through unchanged.func ValidateEgressServicePattern(svc string) error {svcType, name := ParseServiceTarget(svc)if svcType != ServiceTypeStringEgress {diff --git a/internal/controlplane/resolve_roles_test.go b/internal/controlplane/resolve_roles_test.goindex f4fefe02..357b7304 100644--- a/internal/controlplane/resolve_roles_test.go+++ b/internal/controlplane/resolve_roles_test.go@@ -137,7 +137,10 @@ func TestValidatePolicyConfigAllowedPublish(t *testing.T) {t.Errorf("ValidatePolicyConfig rejected allowed_publish %q: %v", ok, err)}}- for _, bad := range []string{"calc", "mcp:calc", "mcp://calc?x=1", "mcp://calc#f", ""} {+ for _, bad := range []string{"calc", "mcp:calc", "mcp://calc?x=1", "mcp://calc#f", "",+ // An egress name is a lowercase hostname: these would mint a grant+ // that matches no destination.+ "egress://API.github.com", "egress://api.github.com.", "egress://api.github.com/v1"} {err := ValidatePolicyConfig(role(bad))if err == nil {t.Errorf("ValidatePolicyConfig accepted allowed_publish %q", bad)diff --git a/internal/controlplane/server.go b/internal/controlplane/server.goindex f90697c8..e8c2b8a8 100644--- a/internal/controlplane/server.go+++ b/internal/controlplane/server.go@@ -3574,6 +3574,9 @@ func validatePolicyConfig(req *api.PolicyConfig) error {if err := api.ValidateServiceFormat(svc); err != nil {return fmt.Errorf("invalid allowed_publish %q in role %s: %w", svc, r.Name, err)}+ if err := api.ValidateEgressServicePattern(svc); err != nil {+ return fmt.Errorf("invalid allowed_publish %q in role %s: %w", svc, r.Name, err)+ }}if err := api.ValidateHTTPGrants(r.Http, r.AllowedServices); err != nil {return fmt.Errorf("in role %s: %w", r.Name, err)