Skip to content

Agent Mesh

examples: substrate-actor: a second actor and a check for per-actor grants

Ignacio Janeiroc1697092acf6
diff --git a/development/examples/substrate-actor/Makefile b/development/examples/substrate-actor/Makefile
index 654cc594..a1bb6e4e 100644
--- a/development/examples/substrate-actor/Makefile
+++ b/development/examples/substrate-actor/Makefile
@@ -7,6 +7,7 @@
# make call NAME=demo from inside the actor: tools, calc allowed, payroll refused
# make rogue an actor the mesh policy does not bind: refused
# make policy push the mesh policy after editing manifests/mesh.yaml.tmpl
+# make check two actors, different grants: assert each reaches only its own tool
# make down remove the actors, the mesh and the provider
# make clean delete the kind cluster
#
@@ -68,7 +69,7 @@ endif
KUBECTL_CONTEXT := $(CTX)
export KIND_CLUSTER_NAME KUBECTL_CONTEXT KO_DOCKER_REPO
-.PHONY: cluster up issuer-docs actor call gemini rogue policy status down clean
+.PHONY: cluster up issuer-docs actor call gemini rogue policy check status down clean
cluster:
@for t in docker kind ko kubectl go python3; do command -v $$t >/dev/null || { echo "$$t not found"; exit 1; }; done
@@ -198,13 +199,29 @@ policy:
--data-binary "$$($(KUBECTL) -n agentmesh get configmap mesh-config -o jsonpath='{.data.policy\.json}')"
@echo
+# check asserts the mesh keeps two authorized actors with different grants
+# apart: demo (the `actor` role, mcp://calc) and ledger (the `ledger` role,
+# mcp://payroll) each reach only their own tool. It pushes the policy first so
+# the ledger binding is live, brings both actors up, then restarts the
+# credential provider so its in-memory cache is empty and the actors' next
+# request is minted under the policy just pushed, without waiting out
+# --cache-ttl. The worker pool holds two actors, so a `rogue` left over from
+# `make rogue` must be suspended first.
+check:
+ $(MAKE) policy
+ $(MAKE) actor NAME=demo
+ $(MAKE) actor NAME=ledger
+ $(KUBECTL) -n agentmesh rollout restart deployment/credential-provider
+ $(KUBECTL) -n agentmesh rollout status deployment/credential-provider --timeout=90s
+ ROUTER_PORT=$(ROUTER_PORT) ATESPACE=$(ATESPACE) KUBE_CONTEXT=$(CTX) ./check.sh
+
status:
$(KUBECTL) -n agentmesh get pods
$(KATE) get actors -a $(ATESPACE)
$(KUBECTL) -n ate-system logs deployment/atenet-egress -c ext-proc --tail=20 2>/dev/null | grep -iE 'agentmesh|credential|denied' || true
down:
- -for a in demo rogue; do $(KATE) suspend actor $$a -a $(ATESPACE) >/dev/null 2>&1; $(KATE) delete actor $$a -a $(ATESPACE) >/dev/null 2>&1; done
+ -for a in demo ledger rogue; do $(KATE) suspend actor $$a -a $(ATESPACE) >/dev/null 2>&1; $(KATE) delete actor $$a -a $(ATESPACE) >/dev/null 2>&1; done
# The namespace and the credential-provider Service stay: the egress gateway
# was installed with that Service's address and holds its ClusterIP.
-$(KUBECTL) -n agentmesh delete deployment,configmap,secret,networkpolicy --all --timeout=120s
diff --git a/development/examples/substrate-actor/README.md b/development/examples/substrate-actor/README.md
index 3c870702..357f9193 100644
--- a/development/examples/substrate-actor/README.md
+++ b/development/examples/substrate-actor/README.md
@@ -24,10 +24,20 @@ make call NAME=demo # tools, calc allowed, payroll refu
make rogue # an actor the policy does not bind: refused
make gemini NAME=demo GCP_PROJECT=<project> # Gemini on Vertex AI through the mesh; see the guide
make policy # push the policy after editing manifests/mesh.yaml.tmpl
+make check # demo and ledger, different grants: each reaches only its own tool
make down # the actors and the agentmesh namespace
make clean # the kind cluster
```
+`make check` runs two actors bound to different roles: `demo` to `actor`
+(`mcp://calc`) and `ledger` to `ledger` (`mcp://payroll`). `check.sh` prints
+one line per case and exits non-zero on a mismatch. A refusal counts only
+when the serving node refuses the call (`mcp.py` exit 3), not when the mesh
+offers the actor no provider at all (exit 4). `make check` restarts the
+credential provider so the policy it pushes applies at once instead of
+waiting out the cache. The worker pool of the demo template holds two actors,
+so suspend `rogue` before `make check`.
+
The provider has its own Go module (`credential-provider/go.mod`) that
depends on the Substrate release it builds against. `go test ./...` in that
directory runs its unit tests without a cluster.
diff --git a/development/examples/substrate-actor/check.sh b/development/examples/substrate-actor/check.sh
new file mode 100755
index 00000000..b5671ad4
--- /dev/null
+++ b/development/examples/substrate-actor/check.sh
@@ -0,0 +1,98 @@
+#!/usr/bin/env bash
+# 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.
+
+# Two authorized actors with different grants, and the mesh keeps them apart.
+# demo is bound to the `actor` role (mcp://calc); ledger to the `ledger` role
+# (mcp://payroll). The check asserts that each reaches only its own tool and
+# that the other tool is refused by the serving node, not skipped by the
+# client.
+#
+# `make check` is the turnkey entry point: it pushes the policy, brings both
+# actors up and restarts the credential provider so its cache is empty before
+# calling this script. To run it on its own, first make sure the
+# ledger binding is live and both actors are running and holding a credential
+# minted under it:
+#
+# make up
+# make actor NAME=demo
+# make actor NAME=ledger # the worker pool holds two actors; suspend a
+# # third (make rogue leaves `rogue` suspended)
+# make policy # push the ledger binding to the control plane
+# kubectl -n agentmesh rollout restart deployment/credential-provider
+# # drop the provider cache so the next mint uses
+# # the policy just pushed (or wait out --cache-ttl)
+# ./check.sh # or: make check, which does all of the above
+#
+# mcp.py exits 0 when the tool answers, 3 when a provider is reached and the
+# node refuses the call, and 4 when the mesh offers this actor no provider at
+# all. A real isolation deny is 3: the node saw the call and said no.
+set -uo pipefail
+cd "$(dirname "${BASH_SOURCE[0]}")" || exit 1
+
+ROUTER_PORT="${ROUTER_PORT:-8000}"
+ATESPACE="${ATESPACE:-ate-demo-sandbox}"
+KUBE_CONTEXT="${KUBE_CONTEXT:-kind-kind}"
+KUBECTL=(kubectl --context "${KUBE_CONTEXT}")
+
+if (exec 3<>"/dev/tcp/127.0.0.1/${ROUTER_PORT}") 2>/dev/null; then
+ echo "127.0.0.1:${ROUTER_PORT} is in use; free it or set ROUTER_PORT" >&2; exit 1
+fi
+"${KUBECTL[@]}" -n ate-system port-forward service/atenet-router "${ROUTER_PORT}:80" >/dev/null 2>&1 &
+pf=$!; trap 'kill $pf 2>/dev/null' EXIT INT TERM HUP
+# The port-forward is backgrounded and silenced, so a failed start (wrong
+# context, namespace, or no permission) would otherwise surface only as
+# confusing call errors below. Poll the port until it accepts a connection,
+# bounded (5s) and aborting early if the process dies, instead of a fixed sleep.
+ready=false
+for _ in {1..50}; do
+ if (exec 3<>"/dev/tcp/127.0.0.1/${ROUTER_PORT}") 2>/dev/null; then ready=true; break; fi
+ kill -0 "$pf" 2>/dev/null || break
+ sleep 0.1
+done
+if [[ "${ready}" != "true" ]]; then
+ echo "kubectl port-forward to atenet-router did not start or bind the port" >&2
+ exit 1
+fi
+
+failures=0
+# expect NAME WANT-EXIT ACTOR SERVICE: run one call and check its exit code.
+# 0 allowed, 3 refused by the serving node, 4 no provider offered.
+expect() {
+ local name=$1 want=$2 actor=$3 service=$4 out got
+ out=$(ROUTER_PORT="${ROUTER_PORT}" ATESPACE="${ATESPACE}" python3 mcp.py add "${actor}" "${service}" 2 3 2>&1)
+ got=$?
+ local tail="${out##*$'\n'}"
+ if [[ "${got}" == "${want}" ]]; then
+ printf ' PASS %-40s exit %s %s\n' "${name}" "${got}" "${tail}"
+ else
+ printf ' FAIL %-40s got exit %s, want %s %s\n' "${name}" "${got}" "${want}" "${tail}"
+ failures=$((failures + 1))
+ fi
+}
+
+echo "== each actor reaches its own tool"
+expect "demo -> calc (its grant)" 0 demo calc
+expect "ledger -> payroll (its grant)" 0 ledger payroll
+echo "== neither can borrow the other's grant (the serving node refuses)"
+expect "demo -> payroll (not its grant)" 3 demo payroll
+expect "ledger -> calc (not its grant)" 3 ledger calc
+
+echo
+if [[ "${failures}" -eq 0 ]]; then
+ echo "OK: the two actors are isolated."
+else
+ echo "FAIL: ${failures} case(s) did not match."
+fi
+exit $(( failures > 0 ? 1 : 0 ))
diff --git a/development/examples/substrate-actor/manifests/mesh.yaml.tmpl b/development/examples/substrate-actor/manifests/mesh.yaml.tmpl
index c87d564b..a571e2fe 100644
--- a/development/examples/substrate-actor/manifests/mesh.yaml.tmpl
+++ b/development/examples/substrate-actor/manifests/mesh.yaml.tmpl
@@ -19,10 +19,14 @@ data:
{"name": "mesh:role:router", "allowed_services": ["*"], "allowed_targets": ["*"]},
{"name": "actor",
"allowed_services": ["system://mesh.catalog", "mcp://calc"],
+ "allowed_targets": ["*"]},
+ {"name": "ledger",
+ "allowed_services": ["system://mesh.catalog", "mcp://payroll"],
"allowed_targets": ["*"]}
],
"bindings": [
- {"role": "actor", "members": ["user:spiffe://substrate-actor.local/actor/ate-demo-sandbox/demo"]}
+ {"role": "actor", "members": ["user:spiffe://substrate-actor.local/actor/ate-demo-sandbox/demo"]},
+ {"role": "ledger", "members": ["user:spiffe://substrate-actor.local/actor/ate-demo-sandbox/ledger"]}
]
}
office.yaml: |
diff --git a/development/examples/substrate-actor/mcp.py b/development/examples/substrate-actor/mcp.py
index 3c099834..cc2ed7fe 100755
--- a/development/examples/substrate-actor/mcp.py
+++ b/development/examples/substrate-actor/mcp.py
@@ -93,14 +93,20 @@ def add(actor, service, a, b):
print(f" (no tool of mcp://{service} is visible to this actor; calling the office node directly)")
peers = {r["peer_id"] for r in rpc(actor, "discover_remote_services", {"type": "mcp"})[0] or []}
if not peers:
+ # The mesh shows this actor no provider of the service: no role binds
+ # its identity to it, so discovery returns nothing and no node ever
+ # sees a call. Exit 4 keeps this apart from a server-side refusal (3),
+ # so a caller cannot mistake "never asked" for "asked and denied".
print(f"mcp://{service}/add({a}, {b}) -> refused: the mesh shows this actor no MCP provider at all (no role binds its identity)")
- sys.exit(3)
+ sys.exit(4)
peer = sorted(peers)[0]
result, text = rpc(actor, "call_remote_tool", {
"peer_id": peer, "tool_name": f"mcp://{service}/add",
"arguments": {"a": float(a), "b": float(b)},
})
if result is None:
+ # A provider was reached and the serving node refused the call. This is
+ # the enforced deny: exit 3, distinct from the no-provider case above.
print(f"mcp://{service}/add({a}, {b}) -> refused: {text}")
sys.exit(3)
print(f"mcp://{service}/add({a}, {b}) = {text}")