LAN backend beside the mesh: MACULA_LAN_ENTRY, a member's token, mesh_call and mesh_watch on the entry point (mcl-lan P6) #11

Closed
opened 2026-12-02 14:08:52 +00:00 by neptunus · 2 comments
Member

Purpose (feature): with MACULA_LAN_ENTRY set, macula-mcp reaches a LAN cluster's entry point. The member gets a token with its own key, mesh_call runs there, and mesh_watch hears the LAN's events. The mesh backend stays beside it, unchanged. With the variable unset, nothing changes.

DECIDED 2026-12-02 "we won't loose the mesh! I just don't want to pitch Martha as "mesh-only"" (Raf): the LAN is added beside the mesh, never in place of it.
DECIDED 2026-12-02 "trust on sight. mcl-martha services should auto-cluster over LAN, no mcl-station required. Distributed Erlang offers us all we need." (Raf)

Refs macula-services/mcl-lan docs/DESIGN.md §4.2 and §4.3 (P6). The entry point is macula-services/mcl-core#4 (main 914650ae): POST /lan/v1/challenge, /token, /call, GET /lan/v1/events.

Threat model (before code)

Assets: the member's identity key (ML-DSA, pq_hybrid), the token it earns (15 min, HMAC under the cluster's key), and what the member's calls can do.

harm how it could happen guard
The key signs something an attacker chose A hostile server returns a "challenge" that is really another protocol's message Only "mcl-lan token request v1" 0x00 ‖ node_id ‖ nonce is signed. That label is mcl-core's signed_message/2, so the signature means nothing elsewhere. A nonce that is not exactly 32 bytes is refused before signing.
The bearer token leaks beyond the LAN MACULA_LAN_ENTRY names a public host (a typo or a hostile config), or a redirect sends the request elsewhere The entry address must resolve to a private, loopback or link-local address (the server's own rule, §4.2), or it is refused by name and nothing is sent. Redirects are refused. The token goes only to that origin.
The token persists Written to disk, logs or a tool result It is kept in memory only, never logged and never returned by a tool. It is renewed before expiry, and a 401 renews it once.
A LAN sniffer replays the token No TLS under trust on sight Accepted and bounded by design (§4.2): 15 minutes, or until the member is taken off lan_members. The challenge is single-use. This package adds nothing, and the tool says the call went in the clear.
Today's mesh users break The LAN code runs without the variable With MACULA_LAN_ENTRY unset, no LAN code runs and every tool behaves exactly as on main. A test holds this.
The mesh is lost when the variable is set The LAN replaces the station path The LAN is tried first only for a plain mesh_call. no_lan_provider falls through to the mesh, and every other tool stays on the mesh.

Out of scope: TLS on the LAN, a browser sign-in, and the owner's lan_members step (P7).

Design

  • src/reach_the_lan/:
    • MACULA_LAN_ENTRY parsed and checked (http, no user info, private address);
    • the token: challenge, sign, token, cached until shortly before expiry;
    • call(org, procedure, args, timeout);
    • the SSE event stream.
  • mesh_call: a plain call goes to the LAN first. Plain means no realm, provider, ucan, prove_ownership or confidential: "required", all of which are mesh concepts. The procedure org/name is split into {org, procedure}.
    • On no_lan_provider it goes to the mesh as today.
    • The result says via: "lan" or "mesh". A LAN result carries no seal report: it went in the clear on the LAN, and the result says so.
  • mesh_watch: with the variable set and no realm, it hears the LAN stream and the mesh subscription together. Each event names its via. If the mesh side cannot connect, it still returns the LAN events and says why the mesh was not heard.
  • Memory tools stay on the mesh in this package. mesh_recall checks the corpus against the node that answered, and the entry point does not report which node served a call. A follow-up is filed on mcl-core for that.
  • Docs: the README and the install guide describe both ways in, side by side: a LAN with no station, and the mesh.

Done when

  • With MACULA_LAN_ENTRY unset, no LAN code runs (a test that would see any entry-point request).
  • A local stand-in entry point (an HTTP server in the test that checks the signature with NodeKey.verify over the same message) issues a token to the right key. It refuses a node id that is not listed, so nothing more is signed or sent. A replayed challenge is refused. No test reaches an outside host.
  • A nonce that is not 32 bytes is never signed. A public or unresolvable entry address is refused before any request. A redirect is refused. The token is never in a tool result.
  • A plain mesh_call goes to the LAN with Authorization: Bearer, and its result says via: "lan". On no_lan_provider it reaches the mesh path. A call with realm, provider, ucan, prove_ownership or confidential: "required" never touches the LAN.
  • A token near expiry is renewed, and a 401 renews it once and retries.
  • mesh_watch returns LAN events tagged via: "lan" beside the mesh's.
  • README and the install guide describe both the LAN and the mesh.
  • Whole local gate green (lint, typecheck, vitest run), with mutants on the guards.
Purpose (feature): with `MACULA_LAN_ENTRY` set, macula-mcp reaches a LAN cluster's entry point. The member gets a token with its own key, `mesh_call` runs there, and `mesh_watch` hears the LAN's events. The mesh backend stays beside it, unchanged. With the variable unset, nothing changes. DECIDED 2026-12-02 "we won't loose the mesh! I just don't want to pitch Martha as "mesh-only"" (Raf): the LAN is added beside the mesh, never in place of it. DECIDED 2026-12-02 "trust on sight. mcl-martha services should auto-cluster over LAN, no mcl-station required. Distributed Erlang offers us all we need." (Raf) Refs macula-services/mcl-lan docs/DESIGN.md §4.2 and §4.3 (P6). The entry point is macula-services/mcl-core#4 (main 914650ae): `POST /lan/v1/challenge`, `/token`, `/call`, `GET /lan/v1/events`. ## Threat model (before code) Assets: the member's identity key (ML-DSA, pq_hybrid), the token it earns (15 min, HMAC under the cluster's key), and what the member's calls can do. | harm | how it could happen | guard | |---|---|---| | The key signs something an attacker chose | A hostile server returns a "challenge" that is really another protocol's message | Only `"mcl-lan token request v1" 0x00 ‖ node_id ‖ nonce` is signed. That label is mcl-core's `signed_message/2`, so the signature means nothing elsewhere. A nonce that is not exactly 32 bytes is refused before signing. | | The bearer token leaks beyond the LAN | `MACULA_LAN_ENTRY` names a public host (a typo or a hostile config), or a redirect sends the request elsewhere | The entry address must resolve to a private, loopback or link-local address (the server's own rule, §4.2), or it is refused by name and nothing is sent. Redirects are refused. The token goes only to that origin. | | The token persists | Written to disk, logs or a tool result | It is kept in memory only, never logged and never returned by a tool. It is renewed before expiry, and a 401 renews it once. | | A LAN sniffer replays the token | No TLS under trust on sight | Accepted and bounded by design (§4.2): 15 minutes, or until the member is taken off `lan_members`. The challenge is single-use. This package adds nothing, and the tool says the call went in the clear. | | Today's mesh users break | The LAN code runs without the variable | With `MACULA_LAN_ENTRY` unset, no LAN code runs and every tool behaves exactly as on main. A test holds this. | | The mesh is lost when the variable is set | The LAN replaces the station path | The LAN is tried first only for a plain `mesh_call`. `no_lan_provider` falls through to the mesh, and every other tool stays on the mesh. | Out of scope: TLS on the LAN, a browser sign-in, and the owner's `lan_members` step (P7). ## Design - `src/reach_the_lan/`: - `MACULA_LAN_ENTRY` parsed and checked (http, no user info, private address); - the token: challenge, sign, token, cached until shortly before expiry; - `call(org, procedure, args, timeout)`; - the SSE event stream. - **`mesh_call`:** a plain call goes to the LAN first. Plain means no `realm`, `provider`, `ucan`, `prove_ownership` or `confidential: "required"`, all of which are mesh concepts. The procedure `org/name` is split into `{org, procedure}`. - On `no_lan_provider` it goes to the mesh as today. - The result says `via: "lan"` or `"mesh"`. A LAN result carries no seal report: it went in the clear on the LAN, and the result says so. - **`mesh_watch`:** with the variable set and no `realm`, it hears the LAN stream and the mesh subscription together. Each event names its `via`. If the mesh side cannot connect, it still returns the LAN events and says why the mesh was not heard. - **Memory tools stay on the mesh** in this package. `mesh_recall` checks the corpus against the node that answered, and the entry point does not report which node served a call. A follow-up is filed on mcl-core for that. - **Docs:** the README and the install guide describe both ways in, side by side: a LAN with no station, and the mesh. ## Done when - [ ] With `MACULA_LAN_ENTRY` unset, no LAN code runs (a test that would see any entry-point request). - [ ] A local stand-in entry point (an HTTP server in the test that checks the signature with `NodeKey.verify` over the same message) issues a token to the right key. It refuses a node id that is not listed, so nothing more is signed or sent. A replayed challenge is refused. No test reaches an outside host. - [ ] A nonce that is not 32 bytes is never signed. A public or unresolvable entry address is refused before any request. A redirect is refused. The token is never in a tool result. - [ ] A plain `mesh_call` goes to the LAN with `Authorization: Bearer`, and its result says `via: "lan"`. On `no_lan_provider` it reaches the mesh path. A call with `realm`, `provider`, `ucan`, `prove_ownership` or `confidential: "required"` never touches the LAN. - [ ] A token near expiry is renewed, and a 401 renews it once and retries. - [ ] `mesh_watch` returns LAN events tagged `via: "lan"` beside the mesh's. - [ ] README and the install guide describe both the LAN and the mesh. - [ ] Whole local gate green (lint, typecheck, `vitest run`), with mutants on the guards.
Author
Member

Supervisor rulings 2026-12-02 (relayed by Mars), folded into PR 12 at 3ce2e4f:

  1. Memory stays on the mesh in P6. This departs from mcl-lan docs/DESIGN.md §4.3, which puts the memory tools on the LAN too. The entry point's call reply does not say which member served it, and mesh_recall's corpus check needs that. Follow-up: macula-services/mcl-core#13.
  2. Dedup on the client. With MACULA_LAN_ENTRY set, mesh_watch keeps the first copy of (publisher, topic, payload hash) within DEDUP_WINDOW_MS (10 s, defined once in src/reach_the_lan/hear_both.ts) and drops the second. The kept event carries its via. Test: "a fact heard over the LAN and the mesh is delivered once…". Mutants no_dedup, no_window, publisher_case and key_order are killed.

LAN-first call with fall-through, and the mesh-only cases: as written.

Supervisor rulings 2026-12-02 (relayed by Mars), folded into PR 12 at 3ce2e4f: 1. **Memory stays on the mesh in P6.** This departs from mcl-lan docs/DESIGN.md §4.3, which puts the memory tools on the LAN too. The entry point's call reply does not say which member served it, and `mesh_recall`'s corpus check needs that. Follow-up: macula-services/mcl-core#13. 2. **Dedup on the client.** With `MACULA_LAN_ENTRY` set, `mesh_watch` keeps the first copy of (publisher, topic, payload hash) within `DEDUP_WINDOW_MS` (10 s, defined once in src/reach_the_lan/hear_both.ts) and drops the second. The kept event carries its `via`. Test: "a fact heard over the LAN and the mesh is delivered once…". Mutants `no_dedup`, `no_window`, `publisher_case` and `key_order` are killed. LAN-first call with fall-through, and the mesh-only cases: as written.
Author
Member

Landed: PR 12, main ca964f88 (Terra, fast-forward). Review: Jupiter, r1 FAIL (3 fixes), then r2 PASS. CI on ca964f88: run 6970 green. Run 6971: structural floor, typecheck, build, test and shellcheck green; Dependency advisories red, accepted under #13 (minimatch in the lock, no package file changed).

Done when:

  • Unset, no LAN code runs: lan_client.test.ts "is not used at all when MACULA_LAN_ENTRY is unset" (no request to the stand-in, no key asked, reply keys exactly as on main).
  • The stand-in entry point verifies with NodeKey.verify and issues the token to the right key. An unlisted node id: nothing is signed or sent past the challenge. A replayed challenge is refused ("cannot be earned twice from one challenge"). Nothing reaches outside, and DNS is a seam.
  • A nonce that is not 32 bytes is never signed (31 and 33 tested). A public or unresolvable entry is refused before any request. A redirect is refused and followed nowhere. The token is not in the tool result. A password in the address is never echoed.
  • A plain mesh_call goes to the LAN with Bearer and says via: "lan". no_lan_provider goes to the mesh (via: "mesh"). Any other LAN failure does not fall through. realm, realm-prefixed procedure, ucan, prove_ownership, confidential "required" and bytes never touch the LAN.
  • A token near expiry is renewed, and a 401 renews once and retries (a second 401 fails).
  • mesh_watch returns LAN events tagged via beside the mesh's. A fact over both paths is delivered once, one for one, and real repeats over one path are all kept (ruling + r1 fix 1). An ended stream is reopened with a fresh token, and a failed reopen is reported under not_heard.lan. The open is bounded.
  • README ("Two ways in: a LAN with no station, and the mesh") and guides/HOWTO.md describe both.
  • Local gate: lint, typecheck, vitest (the one load timeout is pre-existing on main: #14). Mutants 35/35 on the guards (~/.claude/sessions/neptunus-p6/mutants.sh).

Follow-ups: macula-services/mcl-core#13 (the reply names the serving member, so memory can move to the LAN), #13 (minimatch), #14 (descriptions test load timeout), #15 (reopen gap).

Landed: PR 12, main ca964f88 (Terra, fast-forward). Review: Jupiter, r1 FAIL (3 fixes), then r2 PASS. CI on ca964f88: run 6970 green. Run 6971: structural floor, typecheck, build, test and shellcheck green; Dependency advisories red, accepted under #13 (minimatch in the lock, no package file changed). Done when: - [x] Unset, no LAN code runs: lan_client.test.ts "is not used at all when MACULA_LAN_ENTRY is unset" (no request to the stand-in, no key asked, reply keys exactly as on main). - [x] The stand-in entry point verifies with `NodeKey.verify` and issues the token to the right key. An unlisted node id: nothing is signed or sent past the challenge. A replayed challenge is refused ("cannot be earned twice from one challenge"). Nothing reaches outside, and DNS is a seam. - [x] A nonce that is not 32 bytes is never signed (31 and 33 tested). A public or unresolvable entry is refused before any request. A redirect is refused and followed nowhere. The token is not in the tool result. A password in the address is never echoed. - [x] A plain mesh_call goes to the LAN with Bearer and says `via: "lan"`. no_lan_provider goes to the mesh (`via: "mesh"`). Any other LAN failure does not fall through. realm, realm-prefixed procedure, ucan, prove_ownership, confidential "required" and bytes never touch the LAN. - [x] A token near expiry is renewed, and a 401 renews once and retries (a second 401 fails). - [x] mesh_watch returns LAN events tagged `via` beside the mesh's. A fact over both paths is delivered once, one for one, and real repeats over one path are all kept (ruling + r1 fix 1). An ended stream is reopened with a fresh token, and a failed reopen is reported under `not_heard.lan`. The open is bounded. - [x] README ("Two ways in: a LAN with no station, and the mesh") and guides/HOWTO.md describe both. - [x] Local gate: lint, typecheck, vitest (the one load timeout is pre-existing on main: #14). Mutants 35/35 on the guards (~/.claude/sessions/neptunus-p6/mutants.sh). Follow-ups: macula-services/mcl-core#13 (the reply names the serving member, so memory can move to the LAN), #13 (minimatch), #14 (descriptions test load timeout), #15 (reopen gap).
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
macula-io/macula-mcp#11
No description provided.