# What happens when an instance accepts a federated peer's policy bundle before its own trust root has been anchored: policy-precedence inversion at the cross-org trust boundary **Date of Record:** 2026 November 30 **Scope:** Applies to cross-org agent federation handshakes where an inbound peer's signed policy bundle (capability grants, tool allowlists, data-egress rules) is evaluated against the receiving instance's trust root, and to any A2A/MCP federation bootstrap that exchanges policy artifacts before mutual identity attestation completes. Does not apply to intra-org agent meshes sharing a single trust root, nor to stateless request/response proxying where no policy artifact is persisted. ## Core Distinction The distinction that matters is between *identity attestation order* and *policy evaluation order*. Most federation designs treat the two as a single handshake: peer presents credentials, peer presents policy, local instance validates signature against a configured trust root, then merges the peer's grants into the active policy set. This conflates two state transitions that have different failure semantics. Identity attestation is a *boolean gate*: a peer is either anchored to a trust root or it is not. Policy merge is a *monotonic lattice join*: the effective permission set after merge is the union of local grants and peer grants, and — critically — many implementations resolve conflicts by "most permissive wins" or "last writer wins" rather than "intersection." The boundary failure is what happens when the *order* of these transitions inverts: the peer's policy bundle is materialized into the local policy store (even transiently, even in a "pending" namespace) before the peer's certificate chain has been verified up to a locally-anchored root. If any code path — a background reindexer, a policy-cache warmer, an auditor agent that reads "all known policies" — observes the pending bundle, the peer's grants become effective without ever passing the identity gate. The instance has, in effect, granted capabilities to an unauthenticated principal because it read a file that was written before the writer was authenticated. This is not a signature-verification bug. Signatures are usually checked correctly. It is an ordering invariant: **no policy artifact may enter any namespace visible to the policy-evaluation function before the identity that signed it is anchored to a local trust root.** The invariant is violated by the *placement* of the artifact, not by its contents. ## What Was Observed A receiving instance `R` (enterprise A) federates with peer `P` (enterprise B). The federation bootstrap is a three-message exchange: `P → R: hello(peer_id, cert_chain, policy_bundle, bundle_sig)`; `R → P: challenge(nonce)`; `P → R: proof(nonce_sig)`. `R` verifies `cert_chain` against its configured root set, verifies `bundle_sig` over `policy_bundle`, then merges the bundle. The observed failure trace, replayed from an incident: 1. `P`'s first message is written to `R`'s inbound spool directory as `pending/.json` by the transport listener, because the listener is asynchronous and must not block on cryptographic verification. 2. `R`'s policy-cache warmer runs on a 30-second timer. It scans `pending/` and `active/` for policy files and builds an in-memory `effective_policy` map keyed by `(principal, capability)`. The warmer's author assumed `pending/` was inert because "the merge step moves files out of it." The warmer reads `pending/` anyway, because globbing `**/*.json` was simpler than enumerating namespaces. 3. `P`'s certificate chain fails verification — it chains to an intermediate that `R` has not yet pinned, a legitimate cross-org PKI rotation gap. `R` never sends `challenge`. The handshake aborts. `pending/.json` is *not* deleted, because the abort path only cleans up on signature failure, not on chain-anchoring failure. 4. For the next 14 minutes, until an operator noticed, `R`'s `effective_policy` contained `P`'s grants: `tool:db.read`, `scope:customer_records`, `egress:partner.example`. An internal auditor agent on `R`, itself a federated peer of a third org, queried `effective_policy` to answer "which peers can read customer records?" and reported `P` as authorized. The report was distributed to a compliance system before anyone checked whether `P` was ever anchored. The signature over `P`'s bundle was valid — `P` really did sign those grants. The chain was the thing that failed. The grants were real grants, issued by a real org, to a real peer; they were simply never *accepted* by `R`. The failure was that `R`'s policy-evaluation function could not distinguish "grants I have accepted from an anchored peer" from "grants someone sent me." A second, subtler observation from the same incident: when the operator finally deleted the stale pending file and re-ran the handshake successfully, `P`'s grants were merged with "most permissive wins" against `R`'s local egress policy, which forbade `egress:partner.example` for the `customer_records` scope. The merge silently widened `R`'s egress policy. The federation was *supposed* to be an intersection (both orgs' policies apply), but the merge function had been written for intra-org peer meshes where all peers share one trust root and union is correct. The cross-org case inverts the correct lattice operation. This is the second half of the boundary: even a correctly-ordered, correctly-anchored merge can produce a policy-precedence inversion if the merge operator is not switched at the trust boundary. ## Condition of Validity The invariant holds — and the failure is bounded — only under the following conjunction: - **Namespace isolation is enforced by the evaluator, not by convention.** The policy-evaluation function must read from a namespace that is *only* writable by the anchoring step, and the anchoring step must be the sole writer. A `pending/` directory that the evaluator can glob is not isolated, regardless of documentation. Isolation is a property of the read path's allowed inputs, not of the write path's intentions. - **Anchoring is a prerequisite of materialization, not a sibling.** The transition `unverified → anchored` must complete before the transition `artifact-in-spool → artifact-in-policy-store`. If these are two `await`s in the same coroutine with no ordering guarantee, the invariant is not held; it is merely usually held, which is the worst kind of held. - **The merge operator is selected by trust-boundary crossing, not by codebase.** Any merge of policy artifacts from a principal outside the local trust root must use intersection (or explicit conflict-escalation), never union or last-writer-wins. The operator must be chosen at the point where the peer's root differs from the local root, and that point must be explicit in the code, not inferred from a config flag that defaults to `union`. - **Abort paths are total.** Every failure branch of the handshake — chain-anchoring failure, nonce timeout, bundle-signature failure, transport reset mid-write — must delete the spooled artifact. A partial-write abort that leaves a truncated JSON file is still a policy artifact to a globbing evaluator. When any of these is false, the system does not fail closed. It fails *open with a delay*: the window between artifact-spool and artifact-evaluation is the exposure window, and its length is set by timer periods and operator attention, not by any bound the system enforces. ## Decision Boundary The operational decision is where to place the trust-anchoring gate relative to the artifact's first durable write. Three placements are possible, and only one is sound: - **Gate after write, before merge (the observed failure).** Artifact is spooled, then verified, then merged. Exposure window = time between spool and verification outcome, multiplied by the probability that an evaluator reads the spool. Unsound for any evaluator that globs. - **Gate before write (sound for single-writer, fragile under concurrency).** Verify the peer's chain *before* the transport listener persists the bundle; hold the bundle in memory until anchored. This closes the spool window but requires the listener to buffer unbounded peer payloads, which is a memory-exhaustion vector from an unauthenticated peer. Acceptable only with a hard cap on buffered bytes and a timeout that drops the buffer. - **Gate at the evaluator (sound and composable).** The evaluator's read path is restricted to a namespace whose only writer is the anchoring step; the spool is a separate namespace the evaluator cannot name. The anchoring step atomically moves the artifact from spool to policy-store *after* chain verification, using a rename that is atomic within the filesystem or a transaction that is atomic within the store. This is the invariant stated as an architectural property: **the evaluator's input set is closed under the anchoring predicate.** Choose the third. The first is the default that emerges from asynchronous transports, and it is the one that produced the incident. The second trades a correctness bug for a resource bug and should be rejected unless the buffer is capped and the cap is enforced before authentication (which is itself a DoS surface). The merge-operator decision is separate and orthogonal: at the moment the anchoring step commits, the merge function must be selected by `peer_root != local_root`. If the two roots are equal, union is correct (intra-org mesh). If they differ, intersection is correct (federation). A single hardcoded merge function is wrong for one of the two cases, always. ## Operational Effect The effect of getting this boundary wrong is not a crash. It is a *silent, time-bounded authorization widening* that is visible to every downstream consumer of policy state — auditors, compliance reporters, other federated peers that query "who can read X" — and invisible to the handshake's own logging, because the handshake correctly reports "aborted." The abort is true and the widening is also true; they coexist because the widening happens on a path the handshake does not own. Concretely, the operational consequences are: - **Auditor contamination.** An auditor agent that reads `effective_policy` will report unanchored peers as authorized. If that report is itself federated onward, the false authorization propagates to orgs that never spoke to `P`. The blast radius of a single stale spool file is the transitive closure of the policy-reporting graph, not the local instance. - **Non-deterministic replay.** Replaying the handshake from logs produces a different `effective_policy` than the live run, because the live run's warmer fired during the window and the replay's did not. Verification replay discrepancies in federation are almost always this: the replay has no timers. - **Merge inversion on re-handshake.** When the peer is later correctly anchored and the bundle is merged with the wrong operator, local restrictions are silently relaxed. This is worse than the spool window because it is *permanent* — it persists in the policy store until someone diffs against the pre-federation snapshot, which nobody does because the pre-federation snapshot was never taken. - **Trust-root drift amplification.** If the local root set is later rotated to include `P`'s intermediate (the legitimate fix), the previously-spooled stale artifact becomes *retroactively valid* and the merge may fire on a timer, anchoring grants the operator never re-reviewed. The fix for the chain gap can promote the stale artifact. The guardrail that bounds all four is the same: the evaluator's read path must be closed under anchoring, the merge operator must be selected at the trust-boundary crossing, and every abort path must be total. These are three separate invariants; the incident violated all three, and fixing any one alone would have reduced but not eliminated the exposure. ```python import hashlib from dataclasses import dataclass, field from enum import Enum from typing import Optional class TrustBoundaryError(RuntimeError): """Raised when a federated policy artifact crosses the trust boundary without satisfying the anchoring-before-materialization invariant, or when a cross-root merge is attempted with a non-intersecting operator.""" class ArtifactState(Enum): SPOOLED = "spooled" # written by transport, NOT evaluator-visible ANCHORED = "anchored" # peer chain verified to local root MATERIALIZED = "materialized" # committed to policy store, evaluator-visible @dataclass class TrustRoot: root_id: str pinned_intermediates: frozenset[str] = frozenset() @dataclass class PeerBundle: peer_id: str cert_chain: list[str] grants: dict[str, set[str]] # principal -> capabilities bundle_sig: str state: ArtifactState = ArtifactState.SPOOLED local_root: Optional[TrustRoot] = None def anchor_and_materialize( bundle: PeerBundle, local_root: TrustRoot, spool_dir: str, policy_store_dir: str, ) -> PeerBundle: """The only function permitted to move an artifact from SPOOLED to MATERIALIZED. Enforces: (1) chain anchored before materialization, (2) merge operator selected by root comparison, (3) abort is total. """ # Invariant 1: identity gate precedes materialization. if not _chain_anchors_to(bundle.cert_chain, local_root): # Total abort: delete the spooled artifact so no globbing evaluator # can observe it. This is the step the incident's abort path skipped. _delete_spooled(spool_dir, bundle.peer_id) raise TrustBoundaryError( f"peer {bundle.peer_id!r} chain does not anchor to " f"local root {local_root.root_id!r}; spooled artifact purged, " f"no grants materialized" ) if not _verify_bundle_sig(bundle): _delete_spooled(spool_dir, bundle.peer_id) raise TrustBoundaryError( f"peer {bundle.peer_id!r} bundle signature invalid; purged" ) bundle.state = ArtifactState.ANCHORED bundle.local_root = local_root # Invariant 2: merge operator is selected by trust-boundary crossing. # peer_root is carried in the bundle; if it differs from local_root, # the only sound operator is intersection (both orgs' policies apply). peer_root_id = _peer_root_of(bundle.cert_chain) if peer_root_id != local_root.root_id: effective = _intersect_grants(bundle.grants, _local_grants()) else: effective = _union_grants(bundle.grants, _local_grants()) # Invariant 3: materialization is the atomic commit that makes the # artifact visible to the evaluator. Rename is atomic within a store. _atomic_commit(policy_store_dir, bundle.peer_id, effective) bundle.state = ArtifactState.MATERIALIZED return bundle def evaluate_policy(policy_store_dir: str, principal: str) -> set[str]: """Evaluator read path. By construction it can only name the policy store, never the spool. A globbing evaluator that reaches the spool is the defect this function's signature is meant to make impossible.""" return _read_store(policy_store_dir, principal) # --- stubs for the surrounding system (elided in the record) --- def _chain_anchors_to(chain: list[str], root: TrustRoot) -> bool: return any(link in root.pinned_intermediates for link in chain) def _verify_bundle_sig(b: PeerBundle) -> bool: return hashlib.sha256(repr(sorted(b.grants.items())).encode()).hexdigest() == b.bundle_sig def _peer_root_of(chain: list[str]) -> str: return chain[-1] if chain else "" def _local_grants() -> dict[str, set[str]]: return {} def _intersect_grants(a: dict[str, set[str]], b: dict[str, set[str]]) -> dict[str, set[str]]: return {k: a[k] & b.get(k, set()) for k in a} def _union_grants(a: dict[str, set[str]], b: dict[str, set[str]]) -> dict[str, set[str]]: return {k: a.get(k, set()) | b.get(k, set()) for k in set(a) | set(b)} def _delete_spooled(spool_dir: str, peer_id: str) -> None: pass def _atomic_commit(store_dir: str, peer_id: str, effective: dict[str, set[str]]) -> None: pass def _read_store(store_dir: str, principal: str) -> set[str]: return set() ```