# Cross-cloud federation contract (spec 198, FR-016, tasks T025-T027) Status: implemented, negative-tested and live-qualified on November24. All twelve local/cross-group cells through all six Borders, the Azure-entered physical GCP NetBox read and a GCP successor operation completed with independently verified signed results and durable ACKs. Actual HUD and native Code review/recovery passed using the signed ingress-to-receiving-principal binding. See [closure](../closure-20261124.md), including retained-artifact and member-process recovery limits. Code: `mcp-servers/protocol-mcp/bgp/federation/ha/federation.py`, generator `labs/ha/r10_group.py peer-config`. Tests: `tests/n2n/test_ha_federation_198.py` (28), `tests/n2n/test_ha_policy_198.py` (federation egress cases), `labs/ha/test_r10_group.py`. ## Goal An operation entered on ANY of six Borders (two three-Border groups, each with its own manifest, etcd, authority epoch and ledger) can be executed by ANY member of EITHER group, with protected mode ON. There is no six-voter authority and no legacy eN2N execution. The legacy routes stay refused exactly as before (`service.py` is untouched). ## Model ``` owner HUD/VS Code -> Border A1 (group X) Border B* (group Y) -> member M (group Y) | authenticate owner in X's scope ^ re-authorize in Y's OWN ledger | sign peer-relay envelope --------------> new op id, Y review, Y approval, | (send once, 30 s TTL, pinned mTLS) Y lease/epoch, Y admission, Y durable ACK <-- signed response (op DTO) -------------- origin recorded on the row ``` * Group Y never trusts X's principal as Y authority. It trusts only X's signature, under an explicit grant, and then makes its own decisions. X and Y each keep their own audit trail; both name both operation references. * Members stay attached to ONE group (outbound, as before). Cross-group reach comes from the relay, not from sharing a member identity or an etcd. (Attaching a member to both groups with two identities still works unchanged and is not needed.) ## Trust, pinning and enrollment Each Border has an optional private file `peer-federation.json` in its state directory (generated by `r10_group.py peer-config`, 0600, change-detected by the factory's `current()` hash set like every other config file). Without the file nothing in this contract is active. ``` { schema_version: 1, listen: {host: , port: 7445}, # sandbox-local bind; forwarded to the VM dial_port: 7445, transport_certificate_file, private_key_file, # this Border's existing transport cert/key peer_ca_bundle_file, # concatenated transport CAs of every pinned peer group peers: [ { label, cluster_id, generation, manifest_file, anchor_certificate_file, anchor_key_id, # the PEER group's offline-anchor-signed manifest transport_ca_file, grant: {actions, members, tools} } ], # INBOUND: what that peer may do on THIS group revoked?: [cluster_id] } ``` * A peer is pinned by its **signed manifest** (`verify_manifest` against the pinned anchor certificate and key id), never by trust-on-first-use. Its three node certificates and key ids come only from that manifest. A different cluster id/generation, a manifest signed by another anchor, the local cluster as a peer, or a key shared with the local cluster is refused at load. * Enrollment is operator-time: `peer-config` reads the other group's public prepare output (`summary.json`, `identity/manifest.json`, `identity/root.crt`, `transport/transport-ca.crt`). The anchor **private** key is never read. * Rotation/revocation: a manifest revision change or a peer-file edit changes the file hash set, so `current()` fails closed until the Border is restarted with the new pin. In-process `PeerRegistry.revoke(cluster_id)` and the `revoked` list refuse that peer immediately on every path and close its channels (`peer_revoked`). ## Wire Port 7445 (own listener; the intra-group 7443 and member 7444 listeners are unchanged). Standard NCFED framing, TLS 1.3 mutual auth (`ncfed-cluster-mtls-v1`), then a `PeerChannel` hello: both sides sign (`peer-hello`) a transcript that binds the local and peer cluster/generation/manifest hash/node/installation, both nonces, a fresh incarnation and the TLS exporter. The TLS peer certificate's key id must equal the pinned manifest node key (`peer_tls_mismatch`). Only two methods exist: `n2n/peer/relay` and `n2n/peer/catalog`; anything else, and any notification, is refused. Each call and each frame re-checks liveness (peer not revoked, node certificate valid, local node still an active, quorum-backed member). One dial direction per pair (the lexicographically smaller cluster id dials); both sides use the accepted/dialed channels. ## Signing domains (new, `ha/signatures.py`) `peer-hello`, `peer-relay`, `peer-catalog`, `peer-relay-response`, `peer-catalog-response`. Requests and responses use different domains and exact field sets, so one can never be replayed as the other. ## Delegation envelope (`peer-relay`, `peer-catalog`) ``` origin: {cluster_id, generation, manifest_revision, node_id, installation_id} # the signing ingress Border target: {cluster_id, generation} # the receiving group action: prepare | decision | status | reconcile | revoke (catalog uses peer-catalog) params: the exact existing HUD fields for that action (no auth_context, no extras) params_sha256 principal: the ORIGIN group's open-lab principal (subject = uuid5(origin cluster, 'netclaw.open-lab.operator')) origin_epoch, nonce, issued_at_ms, expires_at_ms (<= 30 s after issued) ``` Verification order at the receiver (`PeerGuard.verify`, fixed error code each): pinned peer (`peer_unpinned`) -> not revoked (`peer_revoked`) -> generation/manifest revision match (`peer_audience_mismatch`) -> node pinned and signing key is that node's key (`peer_unpinned`) -> signature (`invalid_ha_proof`) -> node certificate valid -> transport channel identity equals `origin` (`peer_channel_mismatch`) -> target equals this group (`peer_audience_mismatch`) -> action allowed for this kind (`peer_action_refused`) -> params have exactly the action's fields (`invalid_peer_envelope`) -> `params_sha256` (`peer_digest_mismatch`) -> principal is the origin group's open-lab principal; **device-key principals never cross** (`peer_principal_refused`) -> not expired / not future (`peer_envelope_expired`) -> `origin_epoch` not below the highest accepted for that group (`stale_origin_epoch`) -> nonce unused (`peer_replay`) -> grant allows (`peer_grant_denied`). ## Grants Default is **no access**. A grant lists actions (never `*`; at most the six real ones), members (`*` or exact member ids) and tools (`*` or exact tool names). `prepare` checks member and tool; the union catalog advertises a member only if its tools are granted; every later action (`decision`, `status`, `reconcile`, `revoke`) is bound to the operation row's recorded origin. ## Action semantics at the receiving group * `catalog` (ingress, read only): the receiving Border returns its local catalog filtered by the grant, signed (`peer-catalog-response`) with its own epoch and local catalog revision. The delegating Border validates every entry with the existing `validate_catalog_entry`, refuses member-id collisions (`ambiguous_catalog`), tags entries with `remote:{cluster_id, generation, label}`, caches 15 s, and **never serves a stale remote entry** (a failing or ungranted peer contributes no entries and is reported under `federation.peers[]`). The local `revision` is unchanged. * `prepare`: forwarded to the receiving group's leader (new FORWARDED action `peer_relay`); the leader **re-verifies the envelope itself** (a local ingress cannot fabricate one) and runs the normal `_local_prepare` in ITS ledger with `origin={cluster_id, generation, node_id, principal_subject, relay_sha256, origin_epoch}`. The client nonce is namespaced (`peer-` + hash of origin cluster and nonce) so a peer can neither collide with nor pre-claim native nonces. * `decision`/`status`/`reconcile`/`revoke`: allowed only if the row's recorded origin cluster and principal subject match the envelope; native operations and other peers' operations are indistinguishable from "not found" (404). The owner's decision is relayed; the receiving Border signs its OWN approval and dispatch for its own member exactly as for a local operation. * Results: durable ACK, resource fences and member-wide reservations are the receiving group's, unchanged. A failed or unknown result keeps its fence (no auto release), as everywhere else. ## Send-once and recovery No relay write is retried. A lost reply leaves the remote operation observable: the delegating Border records an index (`peer-ops/.json`, plus a nonce index for recovery by client nonce) and `status` is relayed on demand. If another delegating Border has no index entry it asks each pinned peer; the answer is only ever for operations that this principal originated. The receiving leader holds the nonce/epoch cache (in memory, bounded 4096 per peer); after a leader change the cache restarts empty, so replay protection across a failover is bounded by the 30 s TTL **and** by ledger idempotency (prepare is keyed by principal+nonce, decision/revoke/reconcile are state-machine idempotent, dispatch is claimed once). ## Responses and audit The receiving ingress signs each response (`peer-*-response`: request nonce, receiving cluster, serving node, epoch, SHA-256 of the result). The delegating Border verifies key, nonce, cluster and digest before it believes anything (`peer_response_invalid`), then re-labels the DTO: `authority` is its own group's observation (the owner's HUD keeps its own cluster identity) and the receiving group's authority, serving node and response digest go under `remote`. Audit (mandatory, GAIT `protected_*` events): delegating group writes `protected_peer_relay_sent` (before sending: relay hash, nonce hash, origin epoch) and `protected_peer_relay_result` (remote operation id, response digest, remote epoch). The receiving group's existing approval/dispatch/result events now also carry the `origin` object. Together they correlate by operation id and `relay_sha256`. ## Failure modes | Condition | Result | |---|---| | No `peer-federation.json` | feature inert; HUD/operations unchanged | | Peer group unreachable / channel down | peer listed `unavailable`; relay `peer_transport_unavailable` (503); local members unaffected | | Peer revoked, unpinned, wrong audience, replay, stale epoch, expired, tampered | fixed refusal code above; nothing executes | | Reply lost after the remote group acted | `ConnectionError` to the caller, one relay on the wire, remote op recoverable by `status` | | Delegating group loses quorum | relay refused (`no_quorum`/`node_retired`); no relay leaves a non-quorum Border | | Receiving group degraded (2 of 3, far leader) | same admission-window limit as any operation there (known R09 limit) | | Member failure after dispatch | receiving group's fence stays (`resource_recovery_required`); re-enroll a fresh member | ## Qualified-code changes for owner review (FR-017) | File | Change | Behaviour when federation is not configured | |---|---|---| | `ha/node.py` | `FORWARDED` gains `peer_relay` | `ClusterBorderOperations._local_peer_relay` refuses (`cluster_method_refused`) | | `ha/border.py` | `federation=None` attribute; `_route` -> optional `federation.route`, old body renamed `_route_core`; `_local_prepare(params, origin=None)` passes origin; `_dto`/`_audit` add `origin` only when a row has one; new `_local_peer_relay` | identical | | `ha/operations.py` | `OperationLedger.prepare(..., origin=None)` adds `row['origin']` only when given | native rows are byte-identical | | `ha/signatures.py` | five new signing kinds | none | | `ha/factory.py` | load `peer-federation.json` if present (file set joins the change-detection hashes); start/close the peer listener; `getattr` guards | none | | `labs/ha/r09a_policy.py` | optional `federation_peers` spec key: exact `-.automateyournetwork.com:7445`, exact **public** /32, qualified python only; validator refuses private/metadata/loopback addresses, other ports, IP literals, wildcards | none | | `labs/ha/r10_group.py`, `r10_payload.py` | `peer-config`, `node-spec --peer-summary`, `--peer-dir` | none | | `tests/n2n/test_ha_r09_member.py` | stale string assertion updated (`1 <=` nodes), a spec-198 change that predates this work | n/a | | `service.py`, `protected_*`, member code, manifest schema | **unchanged** | n/a | ## Open decisions (most conservative choice taken) 1. **Device-key principals do not cross groups.** Only the open-lab owner scope of the delegating group does. Crossing a device principal needs a re-verifiable device proof at the receiving group. 2. **Replay/epoch cache is in memory on the receiving leader.** A durable cross-leader nonce store would add authority-store keys (qualified code). The bounded TTL and ledger idempotency are the compensating controls. 3. **Default grant in the generated lab files is `*` members, `*` tools, all six actions** to satisfy "any member of any cloud". Production use should narrow it with `--members`/`--tools`. 4. **The delegated operation is attributed to the receiving group's own open-lab principal**; the delegating principal is only on `origin`. This is the same assurance as open-lab itself (no per-owner cryptographic identity); the signed attestation is the delegating Border's. 5. **Peer revocation of a running Border**: in-process `revoke()` is immediate; the file-based path is "edit + restart" by design. 6. **Public exposure of 7445.** Authentication is mutual pinned mTLS plus signed envelopes; restricting the firewall to the other cloud's three public addresses is required, not optional (see below). ## Live requirements (what the build script must do; not yet done) 1. Prepare BOTH groups first (each `summary.json` and bundle must exist); DNS records exist before policy rendering (their names and public IPs are inputs). Certificates are needed only at start. 2. Policy: render each node's spec with the **other group's** `summary.json`: `r10_group.py node-spec ... --peer-summary /summary.json` (adds the six-or-three `federation_peers` endpoints and their public-IP `resolve` entries). Re-render and recreate sandboxes when a peer's IPs change. 3. Peer files: per group `r10_group.py peer-config --local-root --peer-root --label --out [--members ... --tools ...]`, then `r10_payload.py ... --peer-dir ` so `home/netclaw-federation/peer-federation.json` and `peer/*` land under `/sandbox/nc182`. Run `refreeze`-style digests only for source; the peer file is outside the pinned `ha-config` digest by design. 4. Forwarding: add `0.0.0.0:7445` to the `openshell forward` list (and `7445` to the stop loop) in `ha-r10-node-recreate.sh`. 5. Firewalls: Azure NSG and GCP firewall allow inbound `tcp/7445` only from the other cloud's three public /32s (and nothing else). No change to 7443/7444/443. 6. Members: unchanged. Enroll per group; the union catalog shows every group's members at every Border. 7. Prove live: operation entered on each of the six Borders against a member of the OTHER group (both directions), durable ACK, both audit trails, then peer loss/rejoin, replay refusal, revoked-peer refusal, and the HUD rendering of a `remote` operation (the HUD client compares cluster identity from headers; the relabelled `authority` is meant to keep that stable but this is the first thing to check live). ## Not verifiable offline Real WAN latency vs the 30 s relay timeout and 4500 ms admission; sandbox egress on 7445 through OpenShell; the HUD UI rendering of remote members/`remote` DTOs; the hosted-model member path executing a relayed operation; firewall rules; behavior across a receiving-leader change mid-operation. ## Live findings (2026-11-16, runs r10g/r10h and r10i/r10j) 1. **Follower epoch (fixed).** `authority.epoch` is only set on the lease-holding node. The first implementation signed that value, so a follower ingress built a null-epoch envelope and every peer call from ew1/ase1 failed with `peer_error`; only the leader ingress worked. Fixed by reading the quorum epoch (`authority.current()`), refusing a non-integer epoch at the sender, with a regression test. Verified live: all six Borders list the peer group's members. 2. **Relay and re-authorization work.** An operation entered on one group and relayed to the other was authorized in the receiving group's own ledger with `origin` recorded, and the signed response returned; the federation survived an authority change (epoch 33 -> 85). 3. **Member admission path (open, not changed).** A member sends model/tool admissions through the lowest-sorted Border node id with a 5 s timeout (`ha/internal.py`). For a member host far from that Border, over an unstable link, operations are refused (`agent_produced_no_tool_evidence`). Recommended change for owner review: nearest-authenticated-Border selection. Not made. ## Qualified-code change added offline after the live runs (for owner review; not live-verified) | File | Change | Why | |---|---|---| | `ha/internal.py` | `MemberAttachments` records one measured attestation round trip per Border (`channel.rtt_ms`); new `nearest_channels()` orders authenticated attachments nearest-first (node id as tiebreak; unmeasured channels sort last, preserving the old lowest-id order); `send_admission` uses it | Live finding r10h/r10j: the lowest node id was the far Border for one group, starving the 4.5 s admission window | | `ha/member.py` | `_execution_channel` uses `nearest_channels()` | same ordering for result/ack traffic | Authorization is unchanged: every Border is manifest-verified and forwards to the leader; the call is still sent once with no retry. Tests: `tests/n2n/test_ha_nearest_admission_198.py` (3) and the full HA/protected suites (1481 passed). Because the source manifest is signed, the change only takes effect after a fresh prepare/rebuild of both groups. ## November24 correction and bounded repair The frozen r10l source contains the same nearest-Border implementation as the resumed checkout. Its attestation RTT includes a quorum read; it is a latency preference, never authority. The signed4500ms expiry is shorter than the measured follower admission path. See `../resume-20261124.md` for the controlled15-quorum-call reproduction and historical source hashes. The selected repair lets the single RPC wait at least the signed admission window, with a proposed fresh9000ms manifest. All original freshness, effect, quorum, identity, revocation and unknown/fence controls remain. This change is not live-qualified until T037. Qualified-code delta: `ha/internal.py:MemberAttachments.send_admission` derives its wait from the already-verified signed manifest; no retries or new schema fields. The9000ms preparation is explicit for the resumed run, not a silent change to old signed manifests or the original R09 defaults. ## November24 client binding repair (fresh deployment required) Actual HUD preparation exposed that a receiving-group review cannot satisfy the origin client's local-cluster/principal checks. Clients must not disable those checks or relabel the immutable receiving review as local. Each remote DTO now includes `remote.client_binding`: the receiving group's already verified public manifest/anchor and a domain-separated `peer-client` endorsement signed by the serving ingress node. Its exact payload binds the origin cluster/generation/node, original principal, peer anchor key, public manifest digest and SHA256 of the complete DTO before adding the binding. The existing peer-response signature is still verified before producing this endorsement. No private anchor material is exported. This evidence does not authorize an effect or replace receiving-ledger approval/admission. HUD and VS Code verify the endorsement against their pinned local manifest, verify the endorsed peer manifest and certificates, and bind the immutable review to the receiver's derived open-lab principal and issuer. They also require the signed origin to name the original local operator and nonce. A remote review becomes decision-eligible only after successful verification, unchanged DTO/review bytes, local quorum/current epoch and matching receiving review/epoch. Server-side grant, quorum, freshness, fencing and approval checks remain intact. Unsigned, substituted, foreign-principal and stale data fail closed. The receiving row now retains the original nonce in its signed `origin` metadata; its ledger nonce remains namespaced. All relay responses restore the original client nonce, including status through a different ingress without a local index. Older rows lacking this provenance are not retroactively certified as new client acceptance. Unknown records are never reset or replayed.