From 00ce81676920e2dceacaf86ed1a3a26eb9fccf07 Mon Sep 17 00:00:00 2001 From: Drewry Pope Date: Sun, 1 Nov 2026 11:07:12 -0600 Subject: [PATCH] docs(id): design #3398 residency boundaries --- doc/2026-11-01_design_id3398.md | 286 ++++++++++++++++++++++++++++++++ 1 file changed, 286 insertions(+) create mode 100644 doc/2026-11-01_design_id3398.md diff --git a/doc/2026-11-01_design_id3398.md b/doc/2026-11-01_design_id3398.md new file mode 100644 index 0000000000..94d37d984d --- /dev/null +++ b/doc/2026-11-01_design_id3398.md @@ -0,0 +1,286 @@ +# Design: residency boundaries for native bridge, federation and relays + +- Date: 2026-11-01 +- Status: **decision-ready design** for #3398; no implementation is included + in this change. +- Issue: [#3398](https://github.com/developing-today/code/issues/3398), + "id: design: residency boundaries for native bridge, federation and relays." +- Source tree: `pkgs/id` at `origin/main` `927f38307`, merged into this + branch before the design was written. + +## The decision + +Adopt **explicit, per-plane residency policy with locally trusted placement +evidence and fail-closed path checks**. A residency-scoped object may move, +persist or execute only when every applicable storage, processing, transport +and metadata boundary is permitted and supported by current evidence. A peer's +own location statement is not evidence. A missing, expired, revoked, unknown or +out-of-policy path is denied before bytes are sent, accepted, queued or applied. + +This is an enforceable policy about configured providers, services, endpoints +and application-controlled hops. It is **not** a claim that signatures, +encryption, or an endpoint's region setting prove the physical route of every +packet or every provider replica. If a deployment requires that stronger +physical guarantee, public-network routes and provider details without evidence +must remain unavailable for that residency scope. + +## 1. Context and current code + +Issue #3398 requires residency-scoped hosted worlds to fail closed across +native sync/bridge, federation, relay and hot-world spill. It explicitly +separates storage, processing, transport and metadata; requires verified +jurisdiction rather than peer assertions; calls out encrypted payload versus +metadata, discovery, telemetry and in-flight messages; and requires negative +tests. The issue also requires any disclosed export to disclaim control after +it leaves the protected world. Its intake comment warns not to present +signatures or encryption as locality guarantees. + +The code paths today provide useful identity, authorization and integrity +mechanisms, but those are not jurisdiction proofs: + +| Path | What exists at this checkout | Residency implication | +| --- | --- | --- | +| **Native sync** | `EventSyncProtocol` serves the node's shared `LocalEvents` store. Its pull gate is `Open`; it does not consult world membership or a per-world policy (`pkgs/id/src/event_sync.rs:14-25,70-100,104-123`). `serve` registers it as an Iroh protocol (`pkgs/id/src/commands/serve.rs:978-985`). | A valid sync identity or event does not establish an allowed location. Scoped sync must add a policy gate before transfer and ingest. | +| **Native world sessions** | Iroh identifies the connected node, but the join capability—not that node identity—is the world authority (`pkgs/id/src/world_net.rs:8-10,30-32,57-75`). | A join capability authorizes world access; it must not be treated as a jurisdiction attestation. | +| **Native-to-hosted bridge** | The checked-in bridge is a test PoC using a DO-shaped store and a loopback WebSocket session; the native side dials and both stores ingest the received events (`pkgs/id/tests/bridge_poc.rs:1-24,586-633`). | This is not a production hosted bridge or evidence of hosted placement controls. The earlier bridge design says the bridge is a sync peer, not a translator or trust authority (`doc/2026-10-29T11-27-00Z_investigation_bridge_semantics_hosted_native/2026-10-29T11-27-00Z_investigation_bridge_semantics_hosted_native.md:17-42,71-91`). | +| **Federation / replicated records** | `RecordsStore` publishes a world program's records as a read-only Iroh document; a holder of a join capability can replicate it (`pkgs/id/src/world_records.rs:1-14,141-151,228-255`). This is a projection, not replication of the world journal. `WorldHub` cross-world checks cover worlds managed by the same hub (`pkgs/id/src/world_hub.rs:269-314`). | Replication is still a data transfer. Signatures and read-only tickets do not make a cross-jurisdiction transfer local. General cross-host world/journal federation is not implemented by these paths; the records path is a projection only. | +| **Outbox / targeted delivery** | The durable outbox holds friend envelopes and signed artifacts; destinations are endpoint tickets or node IDs and are dialed through Iroh (`pkgs/id/src/envelope_outbox.rs:1-6,52-58,369-417`). | A node ID identifies a destination, not its location. Enqueue, retry and delivery each need a residency check. | +| **Iroh infrastructure relay** | The default relay policy uses n0 public relays; `Disabled` permits direct addresses only (`pkgs/id/src/connectivity.rs:16-46`). | `--no-relay` is not proof of a local route. A relay can be a transport hop even when payloads are encrypted; current endpoint policy exposes relay mode, not jurisdiction evidence for all network hops. | +| **Hot-world spill** | Durable worlds currently open from a local world directory and journal (`pkgs/id/src/commands/serve.rs:419-430,587-605`; `pkgs/id/src/world_store.rs:1-22,59-70`). `restore_program` starts a native module from its stored local file (`pkgs/id/src/world_store.rs:592-615`); the recorded native tier is host-local execution, not remote spill (`doc/2026-10-31T18-03-36Z_investigation_native_tier_tradeoffs/2026-10-31T18-03-36Z_investigation_native_tier_tradeoffs.md:55-60`). `WorldHub::evict_idle` closes an idle in-process world so it can reopen from that journal; it is not remote spill (`pkgs/id/src/world_hub.rs:661-690`). | Remote execution spill remains future work. The newest hot-world decision keeps a single journal under a single-writer lease and makes native spill temporary, only after cheaper shedding and partitioning (`doc/2026-10-30T19-35-00Z_investigation_hot_world_sharding/2026-10-30T19-35-00Z_investigation_hot_world_sharding.md:30-55,183-206,232-241`). The lease is still follow-up design work (`doc/2026-10-30T19-35-00Z_investigation_hot_world_sharding/2026-10-30T19-35-00Z_investigation_hot_world_sharding.md:296-305`). | + +The hosted jurisdiction investigation also distinguishes product guarantees: +pinning a store does not restrict who can access it; workers may access a +pinned object from anywhere. Storage, execution, caches, queues, logs and +metadata have separate controls, and some replication, backup and metadata +locations were unconfirmed (`doc/2026-10-29T11-43-02Z_investigation_do_jurisdiction_pinning/2026-10-29T11-43-02Z_investigation_do_jurisdiction_pinning.md:61-71,156-171,193-215,217-259`). Therefore, a provider's primary-store setting alone cannot satisfy this design. + +## 2. Model the four boundaries separately + +| Plane | Count as in scope | Evidence needed before allowing a scoped path | +| --- | --- | --- | +| **Storage** | Journal, event store, modules/blobs, replicas, caches, queues, outbox, snapshots, backups and recovery copies. | An approved placement record for every persistent or transient store that can retain the object, including copies and recovery systems. Unknown copies mean deny or mark that store unsupported. | +| **Processing** | The host executing a request, world turn, native/Wasm program, indexing task or spill worker, including managed async work. | An approved placement record bound to the actual service/resource and execution class. A storage pin alone is insufficient. | +| **Transport** | Source and destination plus application-controlled bridge, relay, proxy, queue and store-and-forward hops. | Every controlled hop must be identified and permitted. The current code has no proof of physical underlay routing; for a policy that requires that proof, deny public-network paths unless a separately managed network supplies it. | +| **Metadata** | Identities, world/topic names, pointers, discovery queries, route choices, logs, traces, billing/debug identifiers, timing, volume and traffic relationships. | A separate metadata policy and evidence for telemetry/discovery destinations. Payload encryption does not satisfy this plane. The bridge investigation explicitly notes that a relay can observe who syncs what topic, when and how much (`doc/2026-10-29T11-27-00Z_investigation_bridge_semantics_hosted_native/2026-10-29T11-27-00Z_investigation_bridge_semantics_hosted_native.md:214-228`). | + +### Scope and placement evidence + +- Existing unscoped content keeps today's behavior. A world/object becomes + residency-scoped only when an owner or deployment explicitly assigns a local + policy. Within a scoped world, all inputs, journal entries, attachments, + snapshots and derived data inherit that scope; a missing incoming label + inherits the target's stricter scope, and a peer cannot downgrade or remove + it. Export creates a separate, explicitly authorized output object. +- A policy names permitted jurisdictions and, separately, permitted operators, + storage/process classes, transport hops and metadata destinations. “EU” on a + primary database does not implicitly permit every other plane. +- Placement evidence is accepted only from trust roots configured by the local + operator. Bind each assertion to the service/resource identity, jurisdiction, + plane, evidence source and expiry; check signature, binding, scope, freshness + and revocation at use. Remote peers may present evidence, but cannot select + their own trust root or make a self-assertion authoritative. +- A signature authenticates who made an assertion and that it was not changed; + it does not establish the physical truth of the location. The operator must + decide whether the provider's control-plane record, contract, or another + verifier is trustworthy for a given plane. Where the source does not establish + a needed copy or service, that plane is unknown and denied. +- Evaluate before enqueue/send and before accept/ingest. Recheck when a queued + retry starts and when policy or evidence expires/revokes during an in-flight + session. A refusal must not persist the received payload in a disallowed store. +- Export is a separate, explicit action, never an implicit fallback. Show the + destination and affected planes before export; record the user's authorization + and the boundary crossed. After export, do not claim control over the + recipient's copies, processing, onward transfer or deletion. + +## 3. Path policy and negative tests + +| Path class | Recommended policy for residency-scoped content | Required negative test | +| --- | --- | --- | +| **Native sync** | Replace the open pull decision for scoped worlds with policy evaluation on both sides. Require compatible local scopes and current evidence for the receiving store and applicable controlled transport. Do not infer location from Iroh identity, join capability or event signature. | Unknown, expired, revoked, or out-of-policy receiver evidence refuses before event bytes are sent or ingested; a valid join capability does not override the denial. | +| **Native ↔ hosted bridge** | Preserve the sync-peer semantics: no bridge translation, re-signing or new trust authority. Verify every hosted store and execution/transport service used by the session. Keep the production bridge disabled for scoped content until those checks exist; the current test PoC is not a placement verifier. | Missing evidence for any store (including replica/backup), mismatched scope, or expired bridge evidence sends and stores zero protected events; a relay cannot turn a denial into an allow. | +| **Federation** | Make world residency partitioning the default. Replicate only the explicitly selected projection/object set. A cross-boundary shared world requires an explicit world-level policy and participant consent; it is not implied by a read ticket or join capability. This follows the prior hosted-world decision that cross-jurisdiction participation must be partitioned or explicit and disclosed (`doc/2026-10-29T11-43-02Z_investigation_do_jurisdiction_pinning/2026-10-29T11-43-02Z_investigation_do_jurisdiction_pinning.md:309-319`). | A valid capability plus a destination outside the allowed set is denied. An attempted silent cross-boundary join/write is rejected and does not create a replica. | +| **Relay** | Treat Iroh relays as transport, not as trusted residency evidence. A scoped route may use only an approved, attested relay. Direct-only mode may remove the known relay hop, but cannot certify the underlying Internet route. If transport policy requires that guarantee, deny until a managed route can prove it. | Unknown/unapproved relay, missing route evidence, or forbidden metadata destination never receives protected bytes or identifiers; changing to direct mode alone does not satisfy a strict transport requirement. | +| **Hot-world spill** | Keep the recorded escalation order: shed non-actor work, then partition where appropriate, then consider temporary native execution for indivisible load. Do not spill scoped work unless the execution host, journal location and transport satisfy policy **and** the single-writer lease/handoff is implemented. Until both gates pass, keep work local, shed it or report overload. | An unattested native host or missing/expired lease cannot receive work; tests prove the original and spill host cannot both accept writes and no journal/event copy crosses the boundary on denial. | + +For all rows, add cases for unknown jurisdiction, stale/revoked evidence, +policy mismatch, policy change mid-session, retry after evidence expiry, +metadata/discovery/telemetry egress, and an explicitly authorized export. Tests +must assert both the refusal and the absence of disallowed side effects (no +payload in logs, queues, stores or retry buffers). Encryption may be tested for +confidentiality, and signatures for integrity/authorship, but neither test may +be named or reported as proof of locality. These negative tests implement the +failure cases required by #3398. + +## 4. Options and trade-offs + +| Option | Benefits | Costs / failure mode | Decision | +| --- | --- | --- | --- | +| **A. Trust peer claims or infer location from identity, signatures or encryption** | Minimal engineering and keeps existing routes open. | Fails the issue's explicit “verified jurisdiction, not peer assertions” requirement; cryptographic integrity/confidentiality is not placement evidence. | Reject. | +| **B. Pin only the primary storage product** | Narrower than A and can use provider placement configuration. | Omits processing, replicas/backups, bridge/relay transit, discovery and metadata. The hosted investigation documents these as separate or unconfirmed boundaries (`doc/2026-10-29T11-43-02Z_investigation_do_jurisdiction_pinning/2026-10-29T11-43-02Z_investigation_do_jurisdiction_pinning.md:156-171,193-215,228-259`). | Reject as a complete residency design. May be one evidence input for the storage plane only. | +| **C. Disable every remote path for every object** | Simple, conservative boundary with no dependence on remote attestations. | Breaks ordinary sync/federation and applies residency restrictions to data that was never scoped. It does not provide a route to a verified hosted or federated deployment. | Keep as the fallback for a strict scope when evidence is unavailable, not as the product-wide default. | +| **D. Separate policy by plane; use operator-trusted evidence; deny unknown paths** | Matches the issue; preserves unscoped operation; makes hidden copies and metadata destinations visible; supports incremental rollout. | Requires policy/evidence schemas, integrations, and ongoing evidence freshness. Some hosted/provider paths will remain unavailable until their claims are verified. | **Recommend.** The availability cost is explicit and reversible; the false assurance risk of A/B is not. | + +## 5. Recommendation and invariants + +1. **Default deny for scoped content.** A path is allowed only if every plane + required by that scope is evidenced, current and permitted, and every + application-controlled hop is permitted. A missing or unknown value is not + an allow. +2. **Trust is configured locally.** Evidence issuers and accepted proof sources + come from operator-managed trust roots. An Iroh node ID, join capability, + signed event, peer-provided region, or endpoint ticket is not a location + proof (`pkgs/id/src/world_net.rs:8-10,57-75`; `pkgs/id/src/envelope_outbox.rs:72-87,403-417`). +3. **No cross-plane inference.** Storage jurisdiction does not imply processing, + transit or metadata jurisdiction. The provider investigation explicitly + states that a pinned Durable Object can be accessed from anywhere and that + metadata controls differ (`doc/2026-10-29T11-43-02Z_investigation_do_jurisdiction_pinning/2026-10-29T11-43-02Z_investigation_do_jurisdiction_pinning.md:66-71,193-215,256-259`). +4. **No cryptographic locality claim.** Signatures bind authorship/integrity; + transport encryption, where the protocol provides it, protects payload + confidentiality on that leg. Neither proves where a peer, relay, replica + or packet is located. Metadata remains a separate policy plane, as the + bridge investigation observes + (`doc/2026-10-29T11-27-00Z_investigation_bridge_semantics_hosted_native/2026-10-29T11-27-00Z_investigation_bridge_semantics_hosted_native.md:214-228`). +5. **No silent export.** A user-authorized export is visible, scoped and + auditable. The product stops claiming control after the explicit boundary. +6. **No implicit shared-world exception.** Partition by residency by default; + any cross-boundary participation must be explicit, consented and disclosed + (`doc/2026-10-29T11-43-02Z_investigation_do_jurisdiction_pinning/2026-10-29T11-43-02Z_investigation_do_jurisdiction_pinning.md:309-319`). +7. **No spill without both gates.** Residency admission and single-writer + lease/handoff are independent requirements; satisfying one does not satisfy + the other (`doc/2026-10-30T19-35-00Z_investigation_hot_world_sharding/2026-10-30T19-35-00Z_investigation_hot_world_sharding.md:183-206`). +8. **Every asynchronous path reauthorizes.** Outbox enqueue, retry, discovery, + telemetry and in-flight sessions cannot inherit an old allow after policy or + evidence changes. + +The latest recorded crate-split design places stable policy vocabulary in the +planned `id-kernel`/`id-caps` layer, with event/store, sync and world enforcement +in their respective planned crates (`doc/2026-11-01T16-53-00Z_design_id_crate_split/2026-11-01T16-53-00Z_design_id_crate_split.md:126-168`). Follow those ownership boundaries as the split lands; if implementation starts before then, keep the new module internal and preserve the existing public facade. For protocol naming, current source is authoritative: range event sync uses `/id-range-sync/1`, distinct from handshake `/id-sync/1` (`pkgs/id/src/event_sync.rs:1-5,225-233`; `pkgs/id/src/log_sync.rs:56-61`). + +## 6. Implementation acceptance criteria and launch gates + +Implementation is ready for a residency-scoped launch only when all of the +following are true: + +- A policy explicitly represents each applicable plane, allowed jurisdictions + and services, trusted evidence source, expiry/revocation, and export behavior. +- Every path in §3 evaluates that policy before send, accept, persistence, + queueing, execution and retry. An unknown, untrusted, stale or disallowed + value fails closed without a disallowed side effect. +- Placement evidence is bound to the resource actually used—not just its + account, endpoint or primary store. All replicas, backups, caches and + recovery copies are accounted for; unsupported or unconfirmed copies are + denied for that scope. The 2026-10-29 hosted investigation specifically + leaves DO WAL/follower and PITR placement unconfirmed and notes metadata + leakage, so those cannot be silently included in a claim + (`doc/2026-10-29T11-43-02Z_investigation_do_jurisdiction_pinning/2026-10-29T11-43-02Z_investigation_do_jurisdiction_pinning.md:228-259`). +- Discovery, logs, traces, metrics and billing/debug identifiers have explicit + metadata destinations and retention rules. Telemetry cannot reintroduce + identifiers that payload policy blocked. +- Negative tests cover every path row plus unknown/stale/revoked/mismatched + evidence, in-flight policy change, retry, metadata egress and export. They + prove zero forbidden writes/sends as well as the expected denial. +- Shared-world boundary behavior is disclosed and tested; export authorization + states that onward handling is outside the product's control. +- Native spill is disabled for scoped content until both residency evidence and + the journaled single-writer lease/handoff have passed their tests. +- Customer-facing language names exactly which planes and services are + covered. Neither signatures, encryption, a provider region setting, nor + `--no-relay` alone is described as a guarantee of physical locality. + +## 7. Phased implementation plan + +Each step is a separately reviewable and mergeable packet. Until a step's gates +are implemented, the affected route remains denied for residency-scoped +content; unscoped behavior is unchanged. + +1. **Policy vocabulary and evidence verification.** Define the scope, plane, + jurisdiction, trust-root, evidence-expiry/revocation and decision types; + implement a pure evaluator with allow/deny reason codes and unit tests for + unknown, stale, revoked and mismatched evidence. Follow #3195's planned + kernel/caps ownership; do not trust remote self-assertions. No network + behavior changes in this step. +2. **Storage and processing inventory/admission.** Add deployment configuration + and resource-bound evidence for journals, blobs, replicas, backups, + telemetry stores and execution hosts. Enforce at world create/open/restore + and managed work submission. Keep a resource unsupported—and deny a scoped + world—when its placement cannot be established. +3. **Native sync and hosted bridge.** Add preflight and receive-side policy + checks to native sync and the production bridge seam; cover outbox enqueue + and retry. Preserve signed-event ingest semantics and do not make the bridge + a trust authority. Keep bridge sync for scoped content disabled until every + store and hop has evidence. +4. **Federation, relays and metadata.** Apply route policy to replicated + projections/world participation, approved relay selection, discovery and + observability. Make jurisdiction partitioning the default and require + explicit consent/disclosure for a cross-boundary shared world or export. + Add tests for forbidden relay metadata, direct-route limits and telemetry. +5. **Hot-world spill and launch gate.** Integrate residency checks with the + recorded shed/partition/spill ladder. Enable scoped spill only after the + separate single-writer lease/handoff design is implemented and verified; + otherwise remain local, shed work or report overload. Run the complete + acceptance matrix and review all customer-facing claims before launch. + +## 8. Questions for Drew + +These do not block the recommended design or the initial policy/evidence work; +implementation can proceed with the defaults below and keep uncertain paths +denied. + +1. **What does transport residency promise about the network underlay?** + - **A — Application-controlled hops only:** verify endpoints, bridges, + relays and other services; explicitly state that ordinary Internet routing + is not proven. **Recommendation:** use this as the baseline definition, + while denying any scope that explicitly requires proof about every + physical transit link. + - **B — Every physical transit link stays in-jurisdiction:** allow remote + sync only over a managed network that can attest the route; public Iroh + direct and public-relay paths remain denied until then. + +2. **Which authority may establish a verified jurisdiction?** + - **A — Operator-managed trust roots over provider control-plane/contract + evidence, bound to each resource and refreshed:** **Recommendation.** + Remote peer assertions are never sufficient; unresolved provider copies + remain unsupported. + - **B — Accept provider configuration screenshots/declarations without a + trusted machine-verifiable source:** simpler, but weaker auditability and + more room for drift. + - **C — No hosted/native remote path for scoped content until an independent + verifier is available:** strongest conservatism, but may make the feature + unusable initially. + +3. **May a shared world cross residency boundaries by opt-in?** + - **A — Always partition worlds by jurisdiction for v1:** + **Recommendation.** Treat a later cross-boundary copy as an explicitly + authorized export, not as a world that still has the original residency + guarantee. + - **B — Permit a world-level cross-boundary mode with explicit consent from + every participant and disclosure of the exact planes/destinations:** + possible later product choice, but it needs a separate design for consent, + scope transition and the loss of control after export. + - **C — Never permit cross-boundary participation:** simplest product rule, + a stricter alternative to the recommended v1 partition plus explicit + export model. + +The issue's required fail-closed behavior applies whichever options Drew +chooses: until a decision and evidence exist, unknown paths are denied. + +## Sources and conflict handling + +- **Primary requirement:** #3398 body, acceptance criteria and intake review + comment (2026-11-01). +- **Current implementation:** `pkgs/id/src/event_sync.rs`, + `pkgs/id/src/log_sync.rs`, `pkgs/id/src/world_net.rs`, + `pkgs/id/src/connectivity.rs`, `pkgs/id/src/world_records.rs`, + `pkgs/id/src/envelope_outbox.rs`, `pkgs/id/src/world_hub.rs`, + `pkgs/id/src/world_store.rs`, `pkgs/id/src/commands/serve.rs` and + `pkgs/id/tests/bridge_poc.rs`, at the source tree named above. +- **Recorded decisions:** bridge semantics (2026-10-29), hosted jurisdiction + limits (2026-10-29), hot-world escalation (2026-10-30), native execution + tier (2026-10-31), and crate split (2026-11-01), linked inline above. +- The 2026-10-29 multi-hop investigation describes event range sync as + `/id-sync/1` (`doc/2026-10-29T11-05-00Z_investigation_multi_hop_relay_and_p2p_media/2026-10-29T11-05-00Z_investigation_multi_hop_relay_and_p2p_media.md:80-89`). + Current source's explicit ALPN split wins: range event sync is + `/id-range-sync/1`, and handshake sync is `/id-sync/1` + (`pkgs/id/src/event_sync.rs:1-5,225-233`; `pkgs/id/src/log_sync.rs:56-61`). +- **Scope:** this is a design record only. It does not implement residency, + certify any provider, create follow-up issues, or close #3398.