Agent Mesh
Go a2aa2a-protocolagent-meshagentic-aiinferencemcpmeshmesh-networknetwork-securitynetworking-aip2p-network
test: validate policy documentation examples
Antonio Ojeaf781a51b29cd
diff --git a/cmd/sam-hub/config_test.go b/cmd/sam-hub/config_test.goindex 0b4d6135..66e4fe08 100644--- a/cmd/sam-hub/config_test.go+++ b/cmd/sam-hub/config_test.go@@ -30,6 +30,70 @@ func TestLoadPolicyConfig(t *testing.T) {wantErr boolverify func(t *testing.T, config *api.PolicyConfig)}{+ {+ name: "Valid comprehensive config from docs",+ yamlContent: `+version: "v1alpha1"++# Bindings map OIDC identities (sub/user, email, groups) to SAM Roles.+# Note: Kubernetes projected service account tokens do not carry 'groups' claims,+# so they must be bound explicitly using their 'user' claim format.+bindings:+ # 1. Global Admins (Infrastructure SAs, Lead Architects)+ - members: ["user:system:serviceaccount:sam-mesh:admin-sa"]+ role: "admin"+ - members: ["group:infrastructure-leads"]+ role: "admin"++ # 2. Software Developers+ - members: ["group:software-engineering-team"]+ role: "developer"++ # 3. Data Scientists & AI Engineers+ - members: ["group:data-science-team"]+ role: "data-scientist"++ # 4. Contractors / Read-Only Audits+ - members: ["email:[email protected]"]+ role: "auditor"++# Roles define the allowed destinations (allowed_targets) and tools (allowed_services)+roles:+ # Admins have full, unrestricted access to the entire mesh+ admin:+ allowed_targets:+ - "*"+ allowed_services:+ - "*"++ # Developers can call development tools on dev nodes+ developer:+ allowed_targets:+ - "group:dev-nodes" # Can only call nodes in the 'dev-nodes' target group+ allowed_services:+ - "mcp://code-reviewer" # Can call the code reviewer tool+ - "mcp://git-helper" # Can call git helper tools+ - "mcp://build-runner.*" # Wildcard: matches any build runner sub-service (e.g. build-runner.go)++ # Data Scientists can call database tools and all AI inference endpoints+ data-scientist:+ allowed_targets:+ - "group:data-nodes" # Can call nodes in the 'data-nodes' target group+ - "node:12D3KooWSpecialNode" # Can call a specific high-compute node directly+ allowed_services:+ - "mcp://db-reader" # Can query databases+ - "inference://*" # Wildcard: can access any LLM inference service++ # Auditors can only query metadata catalogs and cannot call operational tools+ auditor:+ allowed_targets:+ - "*"+ allowed_services:+ - "system://sam.catalog" # Strictly limited to tool discovery/metadata++`,+ wantErr: false,+ },{name: "Valid config with exact services",yamlContent: `diff --git a/cmd/sam-node/config_test.go b/cmd/sam-node/config_test.goindex 3f2f356a..bb3e11be 100644--- a/cmd/sam-node/config_test.go+++ b/cmd/sam-node/config_test.go@@ -14,6 +14,49 @@ func TestLoadNodeConfig(t *testing.T) {wantErr boolverify func(t *testing.T, config *NodeConfigComplete)}{+ {+ name: "Valid comprehensive config from docs",+ yamlContent: `+version: "v1alpha1"++# Static services hosted by this local node+services:+ - type: "mcp"+ name: "db-reader"+ description: "Read-only SQL execution tool"+ target_url: "http://127.0.0.1:5001/mcp"++ - type: "mcp"+ name: "db-writer"+ description: "Database modification tool"+ target_url: "http://127.0.0.1:5002/mcp"++# Local policies further restrict or override permissions on this specific node+attenuation:+ # local rules generate new facts based on existing ones+ rules:+ # e.g., 'is_off_hours() <- current_hour($h), $h >= 21;'++ # local checks must be satisfied for any connection to succeed+ checks:+ # 1. Enforce strict TLS certificate expiry limit+ - 'check if time($time), $time < 2026-12-31T23:59:59Z;'++ # local policies can contain deny rules (to restrict Hub grants) or allow rules (to override implicit denies)+ policies:+ # 2. Block db-writer calls during off-hours (9 PM to 6 AM)+ - 'deny if service("mcp", "db-writer"), current_hour($hour), $hour >= 21;'+ - 'deny if service("mcp", "db-writer"), current_hour($hour), $hour < 6;'++ # 3. Restrict contractors from accessing db-writer even if Hub granted it+ - 'deny if service("mcp", "db-writer"), role("contractor");'++ # 4. Explicitly allow local admin bypass+ - 'allow if user("local-admin");'++`,+ wantErr: false,+ },{name: "Valid config with multiple services and attenuation",yamlContent: `