The LAN entry point: members call and follow topics over HTTP with a token (#4) #9

Closed
neptunus wants to merge 0 commits from neptunus/4-lan-entry-point into main
Member

Refs #4

P4, the LAN entry point (docs/DESIGN.md §4.2). Clients that are not BEAM nodes (Martha, lazymartha, macula-mcp) call the cluster's capabilities and follow its topics as a named member, with no station. It is off unless the lan map names entry => #{address, port}. The wire is in guides/lan_transport.md, "The entry point".

Stacked on P3 (#7, PR 8), which supplies mcl_core_lan:call_as/6. The base is uranus/7-bridge, so the diff shows P4 alone. It is retargeted to main once PR 8 lands. File overlap with P3: none in src beyond the one export P4 uses. P4 touches mcl_core_lan_sup.erl and mcl_core_health.erl, which P3 does not.

Threat model, written before the code: #4 comment 8392 (T1-T11).

Done-when, each tested in test/mcl_core_lan_entry_SUITE.erl, a real peer node with this test node as the HTTP client:

  • A key that is not on lan_members gets no challenge: a_key_not_on_the_list_gets_no_challenge, with its control.
  • A challenge is redeemed only once: a_challenge_is_redeemed_only_once.
  • A public key whose node id is not the one claimed is refused: a_key_that_is_not_the_node_id_is_refused. The refusal spends nothing, and a bad signature is refused too. The node id is macula_node_keys:node_id(Pub, Profile), a labelled hash of profile and key, not a bare SHA-256; this is how the advisory is met.
  • A removed member is refused at its next call: a_removed_member_is_refused_at_its_next_call. Its event stream ends at the next event too: a_removed_members_stream_ends_at_its_next_event.
  • A public address starts no listener, and /health names why: a_public_address_starts_no_listener, with a loopback control.

Also tested:

  • A call needs a token even for an open capability.
  • The caller written is the token's node id, and a "caller" the client sends is dropped.
  • nodes_only gives caller_refused, and a capability nobody serves gives 404 no_lan_provider.
  • Events stream over SSE.
  • Unit tests (mcl_core_lan_entry_tests): the HKDF RFC 5869 case 3 vector; every altered token byte refused; expiry, version and role checks; the member-list parsing and its others-may-write refusal; the per-node challenge cap; the private ranges; the JSON form of replies.

Mutants on the guards, 11/11 killed:

  • unlisted_challenged
  • challenge_reused
  • any_key
  • removed_still_calls
  • public_listens
  • forged_mac
  • never_expires
  • others_may_write
  • caller_kept
  • no_token_needed
  • stream_keeps_removed

Local gate (OTP 28, rebar 3.28.0): check-sealing_test, lint, xref, eunit 567/567 and dialyzer are ok, and the docs snippet check gives 0 failures. ct: every suite passes, including this one at 8/8, except mcl_service_template_SUITE. That suite refuses in init_per_suite on this box: ~/.config/rebar3/templates links to an old mcl-om clone. That is the box's setup, not this change; CI runs that suite.

Not in this PR (as built, docs/DESIGN.md §9):

  • Distribution's own address is not checked; vm.args starts it before mcl_core.
  • A call no LAN member serves is not relayed to the bridge, where it would carry the bridge's identity.
  • Loopback is accepted beside the private ranges.

🤖 Generated with Claude Code

Refs #4 P4, the LAN entry point (docs/DESIGN.md §4.2). Clients that are not BEAM nodes (Martha, lazymartha, macula-mcp) call the cluster's capabilities and follow its topics as a named member, with no station. It is off unless the `lan` map names `entry => #{address, port}`. The wire is in guides/lan_transport.md, "The entry point". **Stacked on P3 (#7, PR 8)**, which supplies `mcl_core_lan:call_as/6`. The base is `uranus/7-bridge`, so the diff shows P4 alone. It is retargeted to main once PR 8 lands. File overlap with P3: none in src beyond the one export P4 uses. P4 touches `mcl_core_lan_sup.erl` and `mcl_core_health.erl`, which P3 does not. Threat model, written before the code: #4 comment 8392 (T1-T11). Done-when, each tested in `test/mcl_core_lan_entry_SUITE.erl`, a real peer node with this test node as the HTTP client: - A key that is not on `lan_members` gets no challenge: `a_key_not_on_the_list_gets_no_challenge`, with its control. - A challenge is redeemed only once: `a_challenge_is_redeemed_only_once`. - A public key whose node id is not the one claimed is refused: `a_key_that_is_not_the_node_id_is_refused`. The refusal spends nothing, and a bad signature is refused too. The node id is `macula_node_keys:node_id(Pub, Profile)`, a labelled hash of profile and key, not a bare SHA-256; this is how the advisory is met. - A removed member is refused at its next call: `a_removed_member_is_refused_at_its_next_call`. Its event stream ends at the next event too: `a_removed_members_stream_ends_at_its_next_event`. - A public address starts no listener, and /health names why: `a_public_address_starts_no_listener`, with a loopback control. Also tested: - A call needs a token even for an `open` capability. - The caller written is the token's node id, and a `"caller"` the client sends is dropped. - `nodes_only` gives `caller_refused`, and a capability nobody serves gives 404 `no_lan_provider`. - Events stream over SSE. - Unit tests (`mcl_core_lan_entry_tests`): the HKDF RFC 5869 case 3 vector; every altered token byte refused; expiry, version and role checks; the member-list parsing and its others-may-write refusal; the per-node challenge cap; the private ranges; the JSON form of replies. Mutants on the guards, 11/11 killed: - unlisted_challenged - challenge_reused - any_key - removed_still_calls - public_listens - forged_mac - never_expires - others_may_write - caller_kept - no_token_needed - stream_keeps_removed Local gate (OTP 28, rebar 3.28.0): check-sealing_test, lint, xref, eunit 567/567 and dialyzer are ok, and the docs snippet check gives 0 failures. ct: every suite passes, including this one at 8/8, except `mcl_service_template_SUITE`. That suite refuses in init_per_suite on this box: `~/.config/rebar3/templates` links to an old mcl-om clone. That is the box's setup, not this change; CI runs that suite. Not in this PR (as built, docs/DESIGN.md §9): - Distribution's own address is not checked; vm.args starts it before mcl_core. - A call no LAN member serves is not relayed to the bridge, where it would carry the bridge's identity. - Loopback is accepted beside the private ranges. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
The LAN entry point: members call and follow topics over HTTP with a token (Refs #4)
Some checks failed
advisories / erlang in . (pull_request) Has been skipped
docs / doc snippets (erlang) (push) Has been cancelled
advisories / Dependency advisories (pull_request) Has been cancelled
advisories / erlang in . (container) (pull_request) Has been cancelled
docs / doc snippets (erlang) (pull_request) Has been cancelled
lint-and-test / lint + eunit + ct (OTP 28.4.3) (pull_request) Has been cancelled
template-lint-image / scaffold lint toolchain runs in its pinned image (pull_request) Has been cancelled
b7358f1a29
Clients that are not BEAM nodes (Martha, lazymartha, macula-mcp) reach a LAN
cluster's capabilities and topics as a named member, with no station
(docs/DESIGN.md §4.2, P4). Off unless the `lan' map names
`entry => #{address, port}'.

- The address must be private or loopback; any other starts no listener and
  /health names `{lan_entry, {not_private, Address}}'.
- `lan_members' in data_dir lists who may take a token; read on every
  request, fails closed, and names nobody when others may write it.
- POST /lan/v1/challenge, /token: a single-use 60 s challenge, a token
  request carrying the key whose node id (macula_node_keys:node_id/2) is the
  one claimed, signed over a labelled message. The token is HMAC-SHA256 under
  HKDF(gossip secret, "mcl-lan token v1"), 15 minutes, verified on any node.
- POST /lan/v1/call: mcl_core_lan:call_as/6 as the token's node id; a
  client-sent "caller" is dropped. GET /lan/v1/events: server-sent events
  until the token expires or the member leaves the list.

Threat model: mcl-core#4 comment 8392. Stacked on P3 (78ee6b0) for call_as/6.
lan entry: a send resets cowboy's idle timeout, so an event stream outlives 60 s (review r1, Refs #4)
Some checks failed
advisories / erlang in . (pull_request) Has been skipped
advisories / erlang in . (container) (pull_request) Successful in 10s
advisories / Dependency advisories (pull_request) Successful in 0s
template-lint-image / scaffold lint toolchain runs in its pinned image (pull_request) Failing after 6s
docs / doc snippets (erlang) (pull_request) Successful in 2m13s
lint-and-test / lint + eunit + ct (OTP 28.4.3) (pull_request) Successful in 7m34s
advisories / erlang in . (push) Has been skipped
template-lint-image / scaffold lint toolchain runs in its pinned image (push) Failing after 2s
advisories / erlang in . (container) (push) Successful in 17s
advisories / Dependency advisories (push) Successful in 0s
docs / doc snippets (erlang) (push) Successful in 2m35s
lint-and-test / lint + eunit + ct (OTP 28.4.3) (push) Successful in 7m23s
Publish to hex / erlang in . (push) Has been skipped
Publish to hex / erlang in . (container) (push) Successful in 14s
Publish to hex / Dependency advisories (push) Successful in 0s
Publish to hex / guard (push) Successful in 3s
Publish to hex / The release guard (push) Successful in 0s
Publish to hex / Guard and build the package (push) Successful in 2m58s
Publish to hex / doc snippets (erlang) (push) Successful in 2m33s
Publish to hex / Check the docs' code blocks (push) Successful in 0s
Publish to hex / lint + eunit + ct (OTP 28.4.3) (push) Successful in 7m54s
Publish to hex / Test the release commit (push) Successful in 0s
Publish to hex / Publish to hex.pm (push) Failing after 4m34s
914650aed7
terra changed target branch from uranus/7-bridge to main 2026-12-02 12:48:29 +00:00
Member

Landed by fast-forward: main is 914650aed7 (from e728bd59). This repository does not allow the manually-merged style, so the PR is closed by hand.

Landed by fast-forward: main is 914650aed7fd85c2d32b2de3c35713c8310102c7 (from e728bd59). This repository does not allow the manually-merged style, so the PR is closed by hand.
terra closed this pull request 2026-12-02 12:53:07 +00:00
Some checks failed
advisories / erlang in . (pull_request) Has been skipped
advisories / erlang in . (container) (pull_request) Successful in 10s
advisories / Dependency advisories (pull_request) Successful in 0s
template-lint-image / scaffold lint toolchain runs in its pinned image (pull_request) Failing after 6s
docs / doc snippets (erlang) (pull_request) Successful in 2m13s
lint-and-test / lint + eunit + ct (OTP 28.4.3) (pull_request) Successful in 7m34s
advisories / erlang in . (push) Has been skipped
template-lint-image / scaffold lint toolchain runs in its pinned image (push) Failing after 2s
advisories / erlang in . (container) (push) Successful in 17s
advisories / Dependency advisories (push) Successful in 0s
docs / doc snippets (erlang) (push) Successful in 2m35s
lint-and-test / lint + eunit + ct (OTP 28.4.3) (push) Successful in 7m23s
Publish to hex / erlang in . (push) Has been skipped
Publish to hex / erlang in . (container) (push) Successful in 14s
Publish to hex / Dependency advisories (push) Successful in 0s
Publish to hex / guard (push) Successful in 3s
Publish to hex / The release guard (push) Successful in 0s
Publish to hex / Guard and build the package (push) Successful in 2m58s
Publish to hex / doc snippets (erlang) (push) Successful in 2m33s
Publish to hex / Check the docs' code blocks (push) Successful in 0s
Publish to hex / lint + eunit + ct (OTP 28.4.3) (push) Successful in 7m54s
Publish to hex / Test the release commit (push) Successful in 0s
Publish to hex / Publish to hex.pm (push) Failing after 4m34s

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
3 participants
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-services/mcl-core!9
No description provided.