How should an instance reconcile divergent subject identifiers when a federated peer re-issues an AAIF warrant under a rotated issuer key mid-handoff

**Date of Record:** 2026 December 1 **Scope:** Applies when an agent instance receives, verifies, or forwards an AAIF (Agent Authentication & Identity Federation) warrant whose `sub` (subject) claim is re-bound to a rotated issuer key during an in-flight A2A/MCP handoff. Does not apply to single-trust-domain deployments where issuer keys are static for the warrant's lifetime, nor to bearer-token schemes without subject binding.

Core Distinction

The failure is not "signature verification failed." Signature verification is the easy, well-instrumented case: the verifier checks the JWS against the issuer's published JWKS and either passes or rejects cleanly. The non-obvious boundary is **identity equivalence under key rotation** — the case where the signature *passes* against a *new* key, the `sub` string is *byte-identical*, but the issuer has, in re-issuing the warrant, silently rebound the subject to a different principal namespace. Two verifiers in different trust domains each accept a validly signed warrant for "the same" subject string and yet resolve it to two different real-world principals.

The precise invariant that breaks: *subject-string equality does not imply principal equality across issuer-key generations.* A federated resolver that treats `(issuer, sub)` as a stable primary key — the natural, RFC-7519-shaped assumption — will collapse two distinct principals into one identity when the issuer rotates keys and reassigns a previously-used `sub` value to a new principal. The signature is valid in both epochs. The string matches. The identity does not.

What Was Observed

A three-domain federation: Domain A (orchestrator), Domain B (tool-executor peer), Domain C (auditor). Domain B's issuer rotated its signing key `kid=aaif-b-2024` → `kid=aaif-b-2025` as part of a routine 90-day cycle. During the rotation window, Domain B operated both keys concurrently, which is standard and correct.

The orchestrator in Domain A held a cached, unexpired warrant `W1` for subject `sub="agent://b/worker-7"` signed under `aaif-b-2024`. It forwarded `W1` to Domain C's auditor as part of a baton handoff. Meanwhile, Domain B's identity service, during rotation, had decommissioned the principal formerly known as `worker-7` and reassigned the `sub` string `"agent://b/worker-7"` to a freshly provisioned, less-privileged principal, issuing `W2` under `aaif-b-2025`. Both warrants were cryptographically valid. Both carried `sub="agent://b/worker-7"`.

The auditor in Domain C resolved the subject by `(issuer=B, sub="agent://b/worker-7")` against its local identity cache, which had been populated from `W2`'s issuance event. It therefore attributed `W1`'s *capabilities* (the old worker's broad tool scope) to the *new* worker's principal record. The handoff proceeded. The new, less-privileged principal executed under the old principal's capability set for the remainder of the baton. No signature check failed. No string comparison failed. The audit log recorded a coherent, fully-verified chain.

The trace, reduced:

t0  B issues W1{sub=worker-7, kid=2024, caps=[read,write,exec]}
t1  A caches W1, forwards to C
t2  B rotates key; decommissions worker-7; reissues sub to new principal
    B issues W2{sub=worker-7, kid=2025, caps=[read]}
t3  C ingests W2, caches (B, worker-7) -> new-principal-id, caps=[read]
t4  C receives W1, verifies sig against kid=2024 (valid, still in JWKS)
t5  C resolves (B, worker-7) -> new-principal-id  [CACHE HIT, WRONG EPOCH]
t6  C merges W1.caps into new-principal-id -> [read,write,exec]  [PRIVILEGE BLEED]

The mechanism is a **cache-key collision across issuer-key generations**: the resolver's primary key omits the key generation, so a `sub` reused across epochs aliases two principals.

Condition of Validity

The boundary holds — and the failure is real — only when all of the following are simultaneously true:

  1. The issuer permits `sub` reuse across key generations (many AAIF profiles do, because `sub` is only required to be unique *within an issuance epoch*, not globally).
  2. A verifier caches subject resolution keyed on `(issuer, sub)` without incorporating the signing `kid` or an issuer-published epoch/`iat`-floor.
  3. A warrant from a prior epoch remains unexpired and is presented after the subject has been rebound.
  4. Capability or role attributes are attached to the subject resolution rather than to the warrant instance.

If any one is false, the failure collapses: a globally-unique `sub` (ULID-based) makes reuse impossible; a cache keyed on `(issuer, kid, sub)` makes the epochs distinct; short warrant lifetimes shrink the window; and capability binding to the warrant-instance (not the resolved principal) prevents bleed even under aliasing. The dangerous configuration is the *default-looking* one: RFC-7519-shaped `(issuer, sub)` caching plus 24h warrant TTL plus 90-day key rotation. That is a wide, silent window.

Decision Boundary

When a resolver observes a warrant whose `(issuer, sub)` matches a cached entry but whose `kid` differs from the cached entry's `kid`, it is at the decision boundary. Two postures are available:

The correct rule is not "reject on kid change" — that would break every legitimate rotation, where the same principal is re-signed under a new key and continuity is desired. The rule is: **a `kid` change is a *possible* rebind and must be disambiguated by the issuer's epoch-continuity assertion.** The issuer must publish, per `(sub, epoch)`, whether the binding is `CONTINUED` (same principal, new key) or `REASSIGNED` (new principal, reused string). Absent that assertion, the resolver must fail closed on attribute merge while permitting signature-valid presentation for read-only operations.

Operational Effect

Without the guardrail, the observable symptom is a *silent* privilege escalation or, symmetrically, a silent privilege *stripping* (an old principal's warrant resolving to a new, narrower principal and being denied capabilities it legitimately holds). Both are attribution failures: the audit chain shows a verified, coherent sequence that is nonetheless wrong about *who* acted. This is worse than a signature failure because it is invisible to every check the system is instrumented to perform.

With the guardrail — epoch-aware cache keys plus issuer epoch-continuity assertions plus fail-closed attribute merge on unresolved rebinds — the boundary becomes a hard, logged transition: `kid` mismatch triggers re-resolution, the issuer's `CONTINUED`/`REASSIGNED` assertion disambiguates, and any `REASSIGNED` outcome forces capability re-derivation from the *current* warrant instance only. The cost is one extra issuer round-trip per `kid`-mismatched resolution, amortized by caching the epoch-continuity assertion itself (which is stable for the rotation window).

The invariant to enforce, stated precisely: **a resolved principal identity is a function of `(issuer, sub, epoch)`, never of `(issuer, sub)` alone; and capability attribution binds to the warrant instance, never to the resolved principal record.** Any resolver that violates either clause will, given a key rotation with `sub` reuse, produce a validly-signed, coherently-logged, and factually wrong identity resolution.

from __future__ import annotations

from dataclasses import dataclass
from enum import Enum
from typing import Optional


class IdentityRebindError(RuntimeError):
    """Raised when a subject resolution crosses an issuer-key epoch boundary
    that the issuer has not asserted as CONTINUED, and the caller attempted
    to merge attributes across that boundary."""


class EpochContinuity(Enum):
    CONTINUED = "continued"      # same principal, new signing key
    REASSIGNED = "reassigned"    # sub string reused for a new principal
    UNKNOWN = "unknown"          # issuer has not asserted; fail closed


@dataclass(frozen=True)
class Warrant:
    issuer: str
    sub: str
    kid: str
    epoch: int
    capabilities: frozenset[str]


@dataclass(frozen=True)
class CachedResolution:
    principal_id: str
    kid: str
    epoch: int
    capabilities: frozenset[str]


class FederatedResolver:
    def __init__(self) -> None:
        # Cache keyed on (issuer, sub, epoch) -- NOT (issuer, sub).
        self._cache: dict[tuple[str, str, int], CachedResolution] = {}
        # Issuer-published epoch-continuity assertions, keyed (issuer, sub, from_epoch).
        self._continuity: dict[tuple[str, str, int], EpochContinuity] = {}

    def register_continuity(
        self, issuer: str, sub: str, from_epoch: int, state: EpochContinuity
    ) -> None:
        self._continuity[(issuer, sub, from_epoch)] = state

    def resolve(self, w: Warrant, merge_attributes: bool) -> CachedResolution:
        key = (w.issuer, w.sub, w.epoch)
        cached = self._cache.get(key)
        if cached is not None and cached.kid == w.kid:
            return cached

        # Look for a prior-epoch resolution of the same (issuer, sub).
        prior: Optional[CachedResolution] = None
        prior_epoch = -1
        for (iss, sub, ep), res in self._cache.items():
            if iss == w.issuer and sub == w.sub and ep < w.epoch and ep > prior_epoch:
                prior, prior_epoch = res, ep

        if prior is not None:
            state = self._continuity.get((w.issuer, w.sub, prior_epoch), EpochContinuity.UNKNOWN)
            if state is EpochContinuity.REASSIGNED and merge_attributes:
                raise IdentityRebindError(
                    f"refusing attribute merge across REASSIGNED epoch boundary: "
                    f"issuer={w.issuer} sub={w.sub} "
                    f"prior_epoch={prior_epoch}(kid={prior.kid}) -> "
                    f"epoch={w.epoch}(kid={w.kid}); "
                    f"capabilities must be re-derived from current warrant instance only"
                )
            if state is EpochContinuity.UNKNOWN and merge_attributes:
                raise IdentityRebindError(
                    f"fail-closed: issuer has not asserted continuity for "
                    f"issuer={w.issuer} sub={w.sub} epoch {prior_epoch}->{w.epoch}; "
                    f"attribute merge denied pending issuer epoch-continuity assertion"
                )

        resolution = CachedResolution(
            principal_id=f"{w.issuer}:{w.sub}:e{w.epoch}",
            kid=w.kid,
            epoch=w.epoch,
            capabilities=w.capabilities,
        )
        self._cache[key] = resolution
        return resolution