Agent Mesh
Go a2aa2a-protocolagent-meshagentic-aiinferencemcpmeshmesh-networknetwork-securitynetworking-aip2p-network
examples: a mesh with Keycloak as its issuer, in compose
HosniBelfeki7da8a6c89f7c
diff --git a/development/examples/keycloak-idp/.gitignore b/development/examples/keycloak-idp/.gitignorenew file mode 100644index 00000000..1b6128f1--- /dev/null+++ b/development/examples/keycloak-idp/.gitignore@@ -0,0 +1 @@+.run/diff --git a/development/examples/keycloak-idp/compose.yaml b/development/examples/keycloak-idp/compose.yamlnew file mode 100644index 00000000..04df8b2c--- /dev/null+++ b/development/examples/keycloak-idp/compose.yaml@@ -0,0 +1,116 @@+# Keycloak as the identity provider of an Agent Mesh: two users in two+# Keycloak groups call one MCP service through one shared node, each with+# their own ID token. run.sh brings this up in order and runs the cases;+# see README.md.+#+# The agentmesh images are pinned to the commit the example was tested+# with. AGENTMESH_TAG selects another published commit or release, and+# AGENTMESH_REGISTRY another registry (for images built from this checkout).+name: agentmesh-keycloak-idp++x-agentmesh-node: &agentmesh-node+ image: ${AGENTMESH_REGISTRY:-ghcr.io/google}/agentmesh-node:${AGENTMESH_TAG:-a452621ded72a01ff03cd180a40b2c841d19d135}+ depends_on:+ - router+ volumes:+ - ./.run:/run/example:ro+ - ./node-provider.yaml:/etc/agentmesh/provider.yaml:ro++services:+ keycloak:+ image: quay.io/keycloak/keycloak:26.4.0+ # start-dev serves plain http and keeps its data in the container: for+ # this example only. Production Keycloak needs TLS, a database and a+ # fixed hostname (https://www.keycloak.org/server/configuration-production).+ command: ["start-dev", "--import-realm"]+ environment:+ KC_HEALTH_ENABLED: "true"+ volumes:+ - ./realm-mesh.json:/opt/keycloak/data/import/realm-mesh.json:ro+ - ./realm-elsewhere.json:/opt/keycloak/data/import/realm-elsewhere.json:ro+ healthcheck:+ # The image has no HTTP client: ask the management port with bash and+ # read the status line, so a 503 while the realms import is a failure.+ test: ["CMD", "bash", "-c", "exec 3<>/dev/tcp/127.0.0.1/9000 && printf 'GET /health/ready HTTP/1.1\\r\\nHost: localhost\\r\\nConnection: close\\r\\n\\r\\n' >&3 && read -r status <&3 && [[ $$status == *' 200 '* ]]"]+ interval: 5s+ timeout: 5s+ retries: 30+ start_period: 20s++ control-plane:+ image: ${AGENTMESH_REGISTRY:-ghcr.io/google}/agentmesh-control-plane:${AGENTMESH_TAG:-a452621ded72a01ff03cd180a40b2c841d19d135}+ command:+ - --issuer=http://keycloak:8080/realms/mesh+ - --allowed-audiences=agentmesh+ - --admin-token-path=/run/example/admin.token+ - --db-dsn=/data/control-plane.db+ # The router and the two nodes enroll with single-use bootstrap tokens+ # run.sh mints with the admin token; approving them as they arrive+ # spares the script an approval step. OIDC enrollment of users is+ # unaffected: it is decided by the policy bindings alone.+ - --auto-approve-enrollment+ volumes:+ - ./.run:/run/example:ro+ depends_on:+ keycloak:+ condition: service_healthy++ router:+ image: ${AGENTMESH_REGISTRY:-ghcr.io/google}/agentmesh-router:${AGENTMESH_TAG:-a452621ded72a01ff03cd180a40b2c841d19d135}+ command:+ - --control-plane=http://control-plane:8080+ - --insecure-control-plane+ - --bootstrap-token-path=/run/example/router.token+ - --keys-path=/data/router.key+ - --control-plane-sync-interval=10s+ volumes:+ - ./.run:/run/example:ro+ depends_on:+ - control-plane++ calc:+ build: ../calc-mcp+ image: agentmesh-keycloak-idp/calc-mcp:local++ # Publishes mcp://calc (node-provider.yaml).+ provider:+ <<: *agentmesh-node+ command:+ - run+ - --control-plane=http://control-plane:8080+ - --insecure-control-plane+ - --bootstrap-token-path=/run/example/provider.token+ - --config=/etc/agentmesh/provider.yaml+ - --data-dir=/data+ - --api-token-path=/run/example/provider-api.token+ - --discovery-interval=1s+ - --control-plane-sync-interval=10s++ # The shared node alice and bob call through, each with their own ID+ # token in X-Mesh-Authentication. Its own credential grants no service.+ gateway:+ <<: *agentmesh-node+ command:+ - run+ - --control-plane=http://control-plane:8080+ - --insecure-control-plane+ - --bootstrap-token-path=/run/example/gateway.token+ - --data-dir=/data+ - --bind-addr=0.0.0.0:8080+ - --api-token-path=/run/example/gateway-api.token+ - --control-plane-sync-interval=10s++ # A node a user enrolls with their own ID token; run.sh starts it with+ # the token file of each enrollment case.+ member:+ <<: *agentmesh-node+ profiles: ["cases"]+ restart: "no"++ # The HTTP client run.sh uses inside the network, so token issuers and+ # service names resolve exactly as the components see them.+ tools:+ image: curlimages/curl:8.11.1+ profiles: ["cases"]+ volumes:+ - ./:/example:rodiff --git a/development/examples/keycloak-idp/node-provider.yaml b/development/examples/keycloak-idp/node-provider.yamlnew file mode 100644index 00000000..9acaf6fc--- /dev/null+++ b/development/examples/keycloak-idp/node-provider.yaml@@ -0,0 +1,9 @@+# The node that publishes mcp://calc. Its credential comes from a bootstrap+# token, and the mesh policy grants mesh:role:node allowed_publish mcp://*.+version: "v1alpha1"++services:+ - type: mcp+ name: calc+ description: "add and multiply"+ target_url: "http://calc:7777/mcp"diff --git a/development/examples/keycloak-idp/policy-calc-to-ops.json b/development/examples/keycloak-idp/policy-calc-to-ops.jsonnew file mode 100644index 00000000..27170c9d--- /dev/null+++ b/development/examples/keycloak-idp/policy-calc-to-ops.json@@ -0,0 +1,10 @@+{+ "roles": [+ { "name": "mesh:role:node", "allowed_targets": ["*"], "allowed_publish": ["mcp://*"] },+ { "name": "calc-user", "allowed_services": ["mcp://calc"], "allowed_targets": ["*"] }+ ],+ "bindings": [+ { "role": "mesh:role:node", "members": ["group:devs"] },+ { "role": "calc-user", "members": ["group:ops"] }+ ]+}diff --git a/development/examples/keycloak-idp/policy.json b/development/examples/keycloak-idp/policy.jsonnew file mode 100644index 00000000..5224cd24--- /dev/null+++ b/development/examples/keycloak-idp/policy.json@@ -0,0 +1,10 @@+{+ "roles": [+ { "name": "mesh:role:node", "allowed_targets": ["*"], "allowed_publish": ["mcp://*"] },+ { "name": "calc-user", "allowed_services": ["mcp://calc"], "allowed_targets": ["*"] }+ ],+ "bindings": [+ { "role": "mesh:role:node", "members": ["group:devs"] },+ { "role": "calc-user", "members": ["group:devs"] }+ ]+}diff --git a/development/examples/keycloak-idp/realm-elsewhere.json b/development/examples/keycloak-idp/realm-elsewhere.jsonnew file mode 100644index 00000000..8eb68ce2--- /dev/null+++ b/development/examples/keycloak-idp/realm-elsewhere.json@@ -0,0 +1,23 @@+{+ "realm": "elsewhere",+ "enabled": true,+ "accessTokenLifespan": 60,+ "clients": [+ {+ "clientId": "agentmesh",+ "publicClient": true,+ "directAccessGrantsEnabled": true+ }+ ],+ "users": [+ {+ "username": "alice",+ "enabled": true,+ "email": "[email protected]",+ "emailVerified": true,+ "firstName": "Alice",+ "lastName": "Elsewhere",+ "credentials": [{ "type": "password", "value": "alice-test-only", "temporary": false }]+ }+ ]+}diff --git a/development/examples/keycloak-idp/realm-mesh.json b/development/examples/keycloak-idp/realm-mesh.jsonnew file mode 100644index 00000000..9ef093ec--- /dev/null+++ b/development/examples/keycloak-idp/realm-mesh.json@@ -0,0 +1,56 @@+{+ "realm": "mesh",+ "enabled": true,+ "accessTokenLifespan": 60,+ "groups": [{ "name": "devs" }, { "name": "ops" }],+ "clients": [+ {+ "clientId": "agentmesh",+ "publicClient": true,+ "standardFlowEnabled": true,+ "directAccessGrantsEnabled": true,+ "redirectUris": ["http://127.0.0.1/*", "http://localhost/*"],+ "protocolMappers": [+ {+ "name": "groups",+ "protocol": "openid-connect",+ "protocolMapper": "oidc-group-membership-mapper",+ "config": {+ "claim.name": "groups",+ "full.path": "false",+ "id.token.claim": "true",+ "access.token.claim": "true",+ "userinfo.token.claim": "true"+ }+ }+ ]+ },+ {+ "clientId": "other-app",+ "publicClient": true,+ "directAccessGrantsEnabled": true+ }+ ],+ "users": [+ {+ "username": "alice",+ "enabled": true,+ "email": "[email protected]",+ "emailVerified": true,+ "firstName": "Alice",+ "lastName": "Dev",+ "groups": ["/devs"],+ "credentials": [{ "type": "password", "value": "alice-test-only", "temporary": false }]+ },+ {+ "username": "bob",+ "enabled": true,+ "email": "[email protected]",+ "emailVerified": true,+ "firstName": "Bob",+ "lastName": "Ops",+ "groups": ["/ops"],+ "credentials": [{ "type": "password", "value": "bob-test-only", "temporary": false }]+ }+ ]+}