# What happens when an instance's Agent Card signing key rotates mid-federation and downstream verifiers cache the old JWKS without a `kid`-anchored invalidation path **Date of Record:** 2026 November 28 **Scope:** Applies to cross-org agent trust federation where Agent Cards are JWS-signed and verified against a foreign origin's published JWKS, and where verifiers cache those key sets locally. Does not apply to single-org deployments where the verifier and signer share a trust root, nor to ephemeral per-request mTLS without signed capability documents. ## Core Distinction The failure here is not "expired credential" or "revoked key." It is a **key-rotation race across an asymmetric cache boundary**: the signing org rotates its Agent Card key, publishes a new JWKS with a new `kid`, and begins signing new Agent Cards under that `kid`—but the verifying org holds a cached JWKS snapshot that predates the rotation and, critically, *does not re-fetch on unknown-`kid`*. The distinguishing property is that verification does not fail loudly. It fails as a **`kid`-not-found lookup miss that the verifier's JWS library collapses into a generic signature-invalid error**, which the federation layer then misclassifies as "peer credential forged" rather than "peer rotated and I am stale." This is different from revocation (the old key is still validly trusted, just no longer used) and different from clock skew (no time component is wrong). It is a **cache coherence failure specific to the `kid` namespace**, and it is non-obvious because the JWS spec does not mandate re-fetch-on-miss, most JWKS caches are TTL-based rather than `kid`-aware, and the resulting error is indistinguishable at the API surface from an actual forgery. ## What Was Observed A federated auditor agent (`auditor-a`, org `A`) verifies Agent Cards presented by peer agents from org `B`. Org `B` runs a 90-day rotation policy on its Agent Card signing key. The verifier caches `B`'s JWKS with a 24-hour TTL and, on each verification, selects the key by `kid`. At T+0, `B` rotates: new keypair, new `kid` (`b-2026-05`), JWKS republished. `B`'s Agent Cards begin carrying `kid: b-2026-05`. The old key (`b-2026-02`) is retained in JWKS for a 7-day overlap window per `B`'s policy. At T+0 through T+24h, `auditor-a` continues to hold the pre-rotation JWKS snapshot (which contains only `b-2026-02`). When `B`'s agents present Cards signed under `b-2026-05`, the verifier's lookup for `kid: b-2026-05` returns nothing. The JWS library raises `SigningKeyNotFoundError`, which the federation adapter catches and re-raises as `CredentialVerificationError("signature invalid")`. The auditor's policy engine interprets "signature invalid" as a **trust violation** and quarantines `B`'s agents for the remainder of the federation epoch. Result: for up to 24 hours after a routine, policy-compliant rotation by `B`, every one of `B`'s agents is quarantined by `A` with a security-severity alert, even though both orgs did exactly what their policies said. The failure is silent at the protocol level (the JWS is well-formed, the signature is valid, the key exists) and only manifests as a **semantic misclassification at the error-type boundary** between "unknown key" and "bad signature." The compounding factor: the auditor's quarantine action is itself a signed state change federated back to `B`, so `B` now sees its own agents rejected with a `signature invalid` reason it cannot reproduce locally (because `B`'s verifier has the current JWKS). Debugging requires correlating cache snapshots across orgs, which neither side logs by default. ## Condition of Validity This failure requires all of the following to hold simultaneously: 1. The verifier caches JWKS with a **TTL-only** invalidation policy (no re-fetch on unknown `kid`). 2. The signing org rotates keys **within** the verifier's cache TTL. 3. The signing org **retains** the old key in JWKS (overlap window), so a naive "does the JWKS contain the signing key" check does not detect staleness—the cache is stale but not empty. 4. The verifier's JWS library distinguishes `kid`-not-found from signature-mismatch at the library layer but the federation adapter **collapses both into one error class**. 5. The verifier's policy engine treats that collapsed error class as a **trust violation** rather than a **transient verification failure**. If any one is absent, the failure does not occur: a `kid`-aware cache re-fetches and recovers; a rotation outside the TTL is caught on next fetch; a JWKS without overlap would produce an empty-set signal that some caches treat as "refetch now"; a non-collapsing adapter would surface "unknown kid" and trigger a refetch; a policy engine that treats verification errors as retryable would not quarantine. The invariant that bounds it: **a verifier's cached JWKS must be treated as a hint, not an authority, for any `kid` it does not contain.** The JWKS is authoritative only for keys it lists; absence of a `kid` is a *cache miss*, not a *negative fact about the peer*. ## Decision Boundary The decision boundary is between two interpretations of an unknown `kid` at verification time: - **Interpretation A (correct):** "I do not have this key. My cache may be stale. Re-fetch the JWKS from the peer's authoritative endpoint, re-verify, and only then decide." - **Interpretation B (the failure):** "I do not have this key. Therefore the peer presented a credential I cannot validate. Treat as invalid." The boundary is crossed the moment the federation adapter maps a `kid` lookup miss onto a terminal verification failure without an intervening refetch. The correct guardrail is a **two-phase verification**: 1. Verify against cached JWKS. 2. If and only if the failure is `kid`-not-found (not signature-mismatch), invalidate the cache entry for that origin, refetch JWKS **once** (with a per-origin refetch rate limit to prevent a malicious peer from forcing unbounded fetches), and re-verify. 3. Only if the second attempt also fails with `kid`-not-found does the credential become a trust event—and even then, the error class must be `unknown_kid_after_refetch`, not `signature_invalid`. The refetch must be **`kid`-scoped and rate-limited**, because an unauthenticated peer that can present arbitrary `kid` values can otherwise drive an amplification attack against the JWKS endpoint. The refetch budget (e.g., 1 per origin per 60s, with exponential backoff on repeated misses) is the guardrail that makes interpretation A safe. ## Operational Effect Downstream of the fix, three operational properties change: - **Rotation becomes invisible to federation peers** as long as the peer's JWKS endpoint is reachable and the refetch budget is not exhausted. A 90-day rotation no longer produces a 24-hour quarantine window. - **Error taxonomy must be preserved across the adapter boundary.** `kid`-not-found, signature-mismatch, expired-`exp`, and issuer-mismatch must remain distinct error classes through the federation layer, because each maps to a different remediation (refetch, reject, reject, reject). Collapsing them is the root cause; preserving them is the fix. - **Quarantine actions must be reversible and scoped.** Because the failure mode produces false-positive quarantines, the quarantine state must carry the triggering error class and a TTL, so a `kid`-not-found quarantine auto-expires after the refetch succeeds rather than persisting for the federation epoch. The residual risk: a peer that rotates *and* whose JWKS endpoint is unreachable during the overlap window will still fail verification. That is correct behavior—the verifier cannot validate what it cannot fetch—but it must be classified as `peer_unreachable_during_rotation`, not `signature_invalid`, so the peer's operators see the real cause. ```python import time from dataclasses import dataclass, field from typing import Optional class FederationVerificationError(RuntimeError): """Base for federation-layer verification failures.""" pass class UnknownKidAfterRefetch(FederationVerificationError): """The peer's JWKS was refetched and still does not contain the presented kid.""" pass class RefetchBudgetExhausted(FederationVerificationError): """The verifier has refetched this origin's JWKS too often in the window.""" pass @dataclass class JwksCache: origin: str keys_by_kid: dict = field(default_factory=dict) fetched_at: float = 0.0 ttl_seconds: float = 86400.0 refetch_timestamps: list = field(default_factory=list) refetch_window_seconds: float = 60.0 max_refetches_per_window: int = 1 def is_fresh(self, now: float) -> bool: return (now - self.fetched_at) < self.ttl_seconds def has_kid(self, kid: str) -> bool: return kid in self.keys_by_kid def refetch_allowed(self, now: float) -> bool: recent = [t for t in self.refetch_timestamps if now - t < self.refetch_window_seconds] return len(recent) < self.max_refetches_per_window def record_refetch(self, now: float) -> None: self.refetch_timestamps.append(now) def _fetch_jwks_from_peer(origin: str) -> dict: # Placeholder: real implementation performs the HTTPS fetch and parses JWKS. raise NotImplementedError("wire to peer JWKS endpoint") def verify_agent_card( cache: JwksCache, presented_kid: str, signature_valid_under_key: bool, now: Optional[float] = None, ) -> None: """ Two-phase verification: 1. Try cached JWKS. 2. On kid-not-found, refetch once (rate-limited) and retry. 3. Only then raise a terminal federation error, with a precise class. """ if now is None: now = time.time() if cache.has_kid(presented_kid): if not signature_valid_under_key: raise FederationVerificationError( f"signature_mismatch origin={cache.origin} kid={presented_kid}" ) return # kid-not-found: this is a cache-miss signal, NOT a trust violation. if not cache.refetch_allowed(now): raise RefetchBudgetExhausted( f"refetch_budget_exhausted origin={cache.origin} kid={presented_kid}" ) cache.record_refetch(now) fresh = _fetch_jwks_from_peer(cache.origin) cache.keys_by_kid = fresh cache.fetched_at = now if not cache.has_kid(presented_kid): raise UnknownKidAfterRefetch( f"unknown_kid_after_refetch origin={cache.origin} kid={presented_kid}" ) if not signature_valid_under_key: raise FederationVerificationError( f"signature_mismatch_after_refetch origin={cache.origin} kid={presented_kid}" ) ```