Repository navigation
feat(a2a): trusted internal networks — call agents across your own instances over a private network without keys (abilityai/trinity-enterprise#838) - #3361
Conversation
…stances over a private network without keys (trinity-enterprise#838) An admin declares the instance's private networks once (PUT /api/settings/a2a-trusted-networks: CIDRs, hosts, *.domain). - Outbound: an endpoint on a trusted network may be private/CGNAT and http://; every other endpoint keeps the public-HTTPS rule. Re-checked on every call, so a trusted name resolving outside the declared CIDRs, or onto metadata/loopback/the platform networks, is refused. - Inbound: agent_ownership.a2a_scope (public|internal) and a2a_keyless_internal. An internal agent answers only a trusted source and never the public tunnel; to anyone else it is unexposed. A trusted caller runs a task with no key, rate-limited, attributed in the new schedule_executions.source_host, and reads only its own tasks. - The source is the TCP peer, or X-Real-IP only from the platform proxy container; cloudflared's headers mark a request public; a gateway of a network the backend sits on is never a source and never trustable. - Outbound discovery tries the registered endpoint's own card before the origin's: Trinity publishes per-agent cards only, so one Trinity could not discover another's agent at all. - Internal-scope cards advertise the admin's internal base URL; the A2A panel gets the scope choice, the keyless switch and the URL to register. - Migrations: SQLite a2a_internal_scope, Alembic 0095_a2a_internal_scope. The scope setter is the entitled enterprise exposure route (private PR). Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Pairs with Abilityai/trinity-enterprise#845 (draft): the entitled exposure-route setter for scope and keyless. That PR goes green once this one is on |
|
|
Re-chain the A2A scope revision: dev took 0095 with 0095_portal_messages_execution_id off 0094, so this one is now 0096_a2a_internal_scope off it (1 head, parity PASS). migrations.py and tests/registry.json: keep both, dev's entries first. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…caller plainly (#3361 CI) - build: the hand-rolled radios/checkbox/copy row added 28 raw gray classes and the raw-colour ratchet fails on growth. The block now uses BaseSelect (scope, with the explanation as its help), BaseToggle (the keyless switch — an instant-apply binary, the toggle's stated use) and a read-only BaseInput + BaseButton for the URL to register. A2aPanel is back at its baseline (104). New mounted spec a2aPanelScope.spec.js. - CodeQL py/clear-text-logging-sensitive-data: the idempotency scope now carries the trusted caller's ADDRESS, held in a variable named keyless_source, and the 'key' in the name read as a secret. Renamed to trusted_caller; the value is an IP address, never a credential. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Evidence: live backend checks, tests, CI1. Live backend run: 18 / 18 passRun against a local stack on this branch. A real tailnet can't exist on one machine, so a separate Docker network stands in for it: the backend is attached to it, and curl containers on it play "a host on our network" (trusted, What each section proves:
The script restores everything it changes (list, exposure, endpoint, outbound switch, network); the state was verified after the run. The script (re-run it on any local stack running this branch)#!/usr/bin/env bash
# ent#838 backend check — trusted internal networks for A2A, against a LOCAL
# stack (backend :8000 running this branch).
#
# A real tailnet can't be produced locally, so a separate Docker network stands
# in for it: the backend is attached to it, and small curl containers on it
# play "a host on our private network" (trusted) and "a stranger" (untrusted).
#
# What it changes, and puts back at the end (also on failure):
# trusted-networks list, proj-beta exposure, one outbound endpoint,
# the outbound A2A switch, the Docker network `ent838-check`.
#
# Usage: ADMIN_PASSWORD=... ./ent838-backend-check.sh (or set ENV_FILE to the stack's .env)
set -uo pipefail
API=http://localhost:8000
NET=ent838-check
SUBNET=172.31.239.0/24
BACKEND_IP=172.31.239.2
TRUSTED_IP=172.31.239.50
STRANGER_IP=172.31.239.51
PROVIDER=proj-beta # the agent being called (gets internal scope)
CALLER=proj-alpha # the agent that calls it (outbound)
ENV_FILE=${ENV_FILE:-.env} # the checkout the stack runs from
PW=${ADMIN_PASSWORD:-$(grep '^ADMIN_PASSWORD=' "$ENV_FILE" | cut -d= -f2-)}
T=$(curl -s -X POST "$API/api/token" -d "username=admin&password=$PW" \
| python3 -c 'import sys,json;print(json.load(sys.stdin)["access_token"])')
H="Authorization: Bearer $T"
J="Content-Type: application/json"
pass=0; fail=0
check() { # check "<name>" "<expected>" "<actual>"
if [ "$2" = "$3" ]; then echo " PASS $1 ($3)"; pass=$((pass+1));
else echo " FAIL $1 expected [$2] got [$3]"; fail=$((fail+1)); fi
}
peer() { # peer <ip> <curl args...> — a host on the test network
local ip=$1; shift
docker run --rm --network $NET --ip "$ip" curlimages/curl:latest -s "$@"
}
cleanup() {
echo "--- cleanup"
curl -s -X DELETE -H "$H" "$API/api/settings/a2a-endpoints/ent838-check" -o /dev/null
curl -s -X PUT -H "$H" -H "$J" "$API/api/enterprise/a2a/$PROVIDER/exposure" \
-d '{"enabled":false,"scope":"public","keyless":true}' -o /dev/null
curl -s -X POST -H "$H" "$API/api/agents/$PROVIDER/stop" -o /dev/null
docker exec trinity-backend python -c "
import sqlite3;c=sqlite3.connect('/data/trinity.db')
c.execute(\"delete from system_settings where key in ('a2a_trusted_networks','a2a_internal_base_url')\")
${RESTORE_OUTBOUND:-}
c.commit()" 2>/dev/null
docker network disconnect $NET trinity-backend 2>/dev/null
docker network rm $NET >/dev/null 2>&1
echo " done"
}
trap cleanup EXIT
echo "--- setup"
WAS_OUTBOUND=$(docker exec trinity-backend python -c "
import sqlite3;c=sqlite3.connect('/data/trinity.db')
r=c.execute(\"select value from system_settings where key='a2a_outbound_enabled'\").fetchone();print(r[0] if r else '')" 2>/dev/null)
if [ -z "$WAS_OUTBOUND" ]; then
RESTORE_OUTBOUND="c.execute(\"delete from system_settings where key='a2a_outbound_enabled'\")"
else
RESTORE_OUTBOUND="c.execute(\"update system_settings set value='$WAS_OUTBOUND' where key='a2a_outbound_enabled'\")"
fi
docker network create --subnet $SUBNET $NET >/dev/null
docker network connect --ip $BACKEND_IP $NET trinity-backend
docker pull -q curlimages/curl:latest >/dev/null
curl -s -X POST -H "$H" "$API/api/agents/$PROVIDER/start" -o /dev/null
echo " waiting for the backend to see its new network (gateway cache, 60s)…"; sleep 61
echo "--- 1. the admin list"
check "a range holding the backend's Docker gateway is refused" 422 \
"$(curl -s -o /dev/null -w '%{http_code}' -X PUT -H "$H" -H "$J" "$API/api/settings/a2a-trusted-networks" -d "{\"entries\":[\"$SUBNET\"]}")"
check "the platform's own network is refused" 422 \
"$(curl -s -o /dev/null -w '%{http_code}' -X PUT -H "$H" -H "$J" "$API/api/settings/a2a-trusted-networks" -d '{"entries":["172.28.0.0/16"]}')"
check "the generic settings PUT cannot write the list" 422 \
"$(curl -s -o /dev/null -w '%{http_code}' -X PUT -H "$H" -H "$J" "$API/api/settings/a2a_trusted_networks" -d '{"value":"[\"0.0.0.0/0\"]"}')"
check "a narrow list is accepted" 200 \
"$(curl -s -o /dev/null -w '%{http_code}' -X PUT -H "$H" -H "$J" "$API/api/settings/a2a-trusted-networks" \
-d "{\"entries\":[\"$TRUSTED_IP/32\",\"$BACKEND_IP/32\"],\"internal_base_url\":\"http://$BACKEND_IP:8000\"}")"
echo "--- 2. internal scope on $PROVIDER"
curl -s -X PUT -H "$H" -H "$J" "$API/api/enterprise/a2a/$PROVIDER/exposure" \
-d '{"enabled":true,"scope":"internal","keyless":true}' -o /dev/null
sleep 20 # agent start + the trusted list's 5s cache
CARD="http://$BACKEND_IP:8000/a2a/$PROVIDER/.well-known/agent-card.json"
check "card, from a trusted host" 200 "$(peer $TRUSTED_IP -o /dev/null -w '%{http_code}' $CARD)"
check "card advertises the internal URL" "http://$BACKEND_IP:8000/a2a/$PROVIDER" \
"$(peer $TRUSTED_IP $CARD | python3 -c 'import sys,json;print(json.load(sys.stdin).get("url"))')"
check "card, from a stranger" 404 "$(peer $STRANGER_IP -o /dev/null -w '%{http_code}' $CARD)"
check "card, trusted host but via the public tunnel (Cf-Ray)" 404 \
"$(peer $TRUSTED_IP -o /dev/null -w '%{http_code}' -H 'Cf-Ray: x' $CARD)"
check "card, from this machine (public side)" 404 \
"$(curl -s -o /dev/null -w '%{http_code}' "$API/a2a/$PROVIDER/.well-known/agent-card.json")"
echo "--- 3. a keyless task"
RPC="http://$BACKEND_IP:8000/a2a/$PROVIDER"
BODY='{"jsonrpc":"2.0","id":1,"method":"message/send","params":{"message":{"role":"user","messageId":"m-838-check-'$RANDOM'","parts":[{"kind":"text","text":"Reply with exactly: internal call received"}]}}}'
check "a stranger without a key" 401 \
"$(peer $STRANGER_IP -o /dev/null -w '%{http_code}' -X POST -H "$J" -d "$BODY" $RPC)"
OUT=$(peer $TRUSTED_IP -m 180 -X POST -H "$J" -d "$BODY" $RPC)
TASK=$(echo "$OUT" | python3 -c 'import sys,json;print(json.load(sys.stdin)["result"]["id"])' 2>/dev/null)
check "a trusted host without a key — task completes" completed \
"$(echo "$OUT" | python3 -c 'import sys,json;print(json.load(sys.stdin)["result"]["status"]["state"])' 2>/dev/null)"
check "the run is attributed to the caller's address" "a2a|$TRUSTED_IP|None|None" \
"$(docker exec trinity-backend python -c "
import sqlite3;c=sqlite3.connect('/data/trinity.db')
r=c.execute(\"select triggered_by,source_host,source_user_id,source_mcp_key_id from schedule_executions where id='$TASK'\").fetchone()
print('|'.join(str(x) for x in r))" 2>/dev/null)"
GET='{"jsonrpc":"2.0","id":2,"method":"tasks/get","params":{"id":"'$TASK'"}}'
check "tasks/get by the host that started it" completed \
"$(peer $TRUSTED_IP -X POST -H "$J" -d "$GET" $RPC | python3 -c 'import sys,json;print(json.load(sys.stdin)["result"]["status"]["state"])' 2>/dev/null)"
check "tasks/get by another trusted host" "Task not found" \
"$(docker exec trinity-backend python -c "
import httpx,json;print(httpx.post('$RPC',json=json.loads('''$GET''')).json()['error']['message'])" 2>/dev/null)"
echo "--- 4. agent → agent over the internal URL (outbound)"
curl -s -X PUT -H "$H" -H "$J" "$API/api/settings/a2a_outbound_enabled" -d '{"value":"true"}' -o /dev/null
check "an untrusted http:// private endpoint is still refused" 422 \
"$(curl -s -o /dev/null -w '%{http_code}' -X PUT -H "$H" -H "$J" "$API/api/settings/a2a-endpoints" \
-d '{"name":"ent838-untrusted","url":"http://172.31.239.9:8000/a2a/x"}')"
check "the trusted internal endpoint is accepted" 200 \
"$(curl -s -o /dev/null -w '%{http_code}' -X PUT -H "$H" -H "$J" "$API/api/settings/a2a-endpoints" \
-d "{\"name\":\"ent838-check\",\"url\":\"http://$BACKEND_IP:8000/a2a/$PROVIDER\"}")"
CALL=$(curl -s -m 200 -X POST -H "$H" -H "$J" "$API/api/agents/$CALLER/a2a/call" \
-d '{"endpoint":"ent838-check","message":"Reply with exactly: hello over the internal network","dedup_label":"ent838-check-'$RANDOM'"}')
check "$CALLER calls $PROVIDER with no key" completed \
"$(echo "$CALL" | python3 -c 'import sys,json;print(json.load(sys.stdin).get("state"))' 2>/dev/null)"
echo " answer: $(echo "$CALL" | python3 -c 'import sys,json;print(json.load(sys.stdin).get("text"))' 2>/dev/null)"
echo "--- 5. keyless off"
curl -s -X PUT -H "$H" -H "$J" "$API/api/enterprise/a2a/$PROVIDER/exposure" -d '{"enabled":true,"keyless":false}' -o /dev/null
check "a trusted host now needs a key" 401 \
"$(peer $TRUSTED_IP -o /dev/null -w '%{http_code}' -X POST -H "$J" -d "$BODY" $RPC)"
echo
echo "=== $pass passed, $fail failed"
[ "$fail" -eq 0 ]2. Found by the live test and fixed in this PR
3. Tests
4. CI fixes since the PR opened
5. Not covered locallyA real tailnet source ( Screenshots of the "Who can reach it" controls (light and dark): to be attached by the author. 🤖 Generated with Claude Code |
…sted-source helpers past CodeQL's secret heuristic (#3361 CI) Three CI reds on the PR, none a design change: - `frozen_dispatch` refused every real dispatch with "unclassified execute_task fields ['source_host']" (ent#751 landed on dev after this branch forked). The field is caller attribution, the same class as the other `source_*` identity fields, so it is FREEZE: an approved replay stays attributed to the same host. `test_1482` covers the new column. - `test_2996` route census: the admin gate is now the first statement of both `/api/settings/a2a-trusted-networks` handlers (the belt-and-braces `reject_agent_principal` import no longer precedes it). - CodeQL `py/clear-text-logging-sensitive-data`: its heuristic treats any name containing "trusted" as a secret, so `trusted_source()` / the `trusted_caller` local tainted the idempotency scope that `idempotency_service.begin` logs on a claim failure. The value is a caller address, not a secret; renamed to `internal_source` / `caller_source`. No behaviour change. Co-Authored-By: Claude Fable 5.1 <[email protected]>
vybe
left a comment
There was a problem hiding this comment.
Validated via /validate-pr (Lane C + schema). Tier 1 green on 041dec4 after the CI fixes (frozen-dispatch classification for source_host, route-census gate order, CodeQL rename); journey-smoke + e2e green on the PR; Alembic single head on a merge-tree against dev; dev-ci green. Full local unit suite: 16987 passed.
Summary
Instances on one private network (a tailnet, a VPN) can call each other's agents over it, with no keys and nothing public. Setup is one step on each side after an admin declares the network.
Trusted networks (admin and human only):
GET/PUT /api/settings/a2a-trusted-networks. Entries are CIDRs, exact hosts or*.domain, plus an optionalinternal_base_url. Refused by name:The generic
PUT /api/settings/{key}refuses both keys.Outbound: an endpoint on a trusted network may be private/CGNAT and
http://. Every other endpoint gets exactly today's refusal. It is re-checked on every call, so a trusted name that resolves outside the declared CIDRs, or onto metadata, loopback or the platform networks, is refused. Pinning is unchanged.Inbound scope:
agent_ownership.a2a_scope(public|internal) anda2a_keyless_internal(default on).schedule_executions.source_host.tasks/getandtasks/cancelsee only that host's tasks.Source detection: the TCP peer, or
X-Real-IPonly from the platform proxy container, resolved by name. An agent on the bridge cannot forge its source. nginx and the Vite dev proxy (now) both overwrite the header. cloudflared's headers mark a request public.Outbound card discovery: the registered endpoint's own card is tried before the origin's. Trinity publishes per-agent cards only, so origin-only discovery meant one Trinity could not reach another's agent at all, public or internal. A registered card URL is fetched as given. Only a 404 falls through. The same-origin and path pins are unchanged.
Card and UI: an internal-scope agent's card advertises the internal base URL. The A2A tab gets "Who can reach it", the keyless switch and the URL to register.
Open-core: OSS-core enforcement; the scope setter is the entitled enterprise exposure route (trinity-enterprise PR, draft until this lands). Docs describe the mechanism only, with placeholder hostnames.
Live test (local stack, this branch)
The backend was attached to a separate Docker network as a stand-in for a tailnet peer.
Cf-Ray/ hostmessage/send: trusted / untrustedtriggered_by=a2a,source_host=<caller>, no user or keytasks/getfrom another trusted hosthttp://private endpointFound and fixed during the live test:
Not testable locally: a real tailnet source (
100.x) arriving at the published port. On Linux, traffic on an external interface is DNAT'd with the source kept, but this needs one check between two real instances.Screenshots of the A2A tab (light and dark): to be attached by the author.
Tests
tests/unit/test_ent838_a2a_trusted_networks.py(new, 37): the list guards, outbound trusted path, source rules, the gateway parser and both refusals, and the router (internal unexposed, keyless run plus attribution, task isolation, keyless off, public unchanged), plus storage round-trip.test_736_a2a_outbound_transport.py: discovery order (own card, origin fallback on 404 only, registered card URL); 82 passed.get_a2a_scope(public).test_1028allowlists the two new routes.test_736_a2a_outbound_edges::C1b(5) fails identically ondevlocally (Python 3.12ipaddress); CI runs 3.13.tests/test_838_a2a_internal_scope.py(5) plustest_160give 29 passed.Fixes abilityai/trinity-enterprise#838
🤖 Generated with Claude Code