Skip to content

M4 Phase 3: notesd on lodge's app socket - #46

Merged
bketelsen merged 22 commits into
mainfrom
m4/phase3
Oct 19, 2026
Merged

bketelsen merged 22 commits into
mainfrom
m4/phase3

Conversation

@bketelsen

@bketelsen bketelsen commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

M4 plan 0006 Phase 3: notesd on lodge's app socket. Stacked on #45 (Phase 2), so its base is m4/phase2. Built overnight at your request, for review.

What changes

  • notesd -lodge serves lodge's app socket as app notes, through github.com/frostyard/lodge/kit pinned at 38f7be7 (v0.0.0-20261019030549-38f7be71e665), which the master session relayed.
    • The socket is /run/lodge/apps/notes.sock, or the one systemd passes. LODGE_ROOT and LODGE_UID move it for development.
    • The kit owns the peer check, the Lodge-* headers and one caller kind per path.
  • internal/lodgeapp (lodge-app.md) is the only package importing the kit:
    • /health answers {ok, version, protocol: 1}.
    • /api is JSON-RPC as caller session, with the identity from lodge's headers. Writes are "<Lodge-Node-Name> (web)", from Phase 2.
    • /content/blobs/<hash>.<ext> serves lodge-content.
    • /device/sync… reaches internal/hub's handler unchanged; the device token still decides. Any other /device/ path is 404.
    • /mcp is Phase 4, so it answers 404 for now.
  • Pending pairings behind lodge show the node lodge names, as phone ([email protected]). The name is for display only (hub.WithPeer).
  • internal/blobhttp is the dev gateway's blob handler, shared and given the spec's limits:
    • one range per request, else 416;
    • a 206 of at most 8 MiB (a longer or open range is cut);
    • a whole answer up to 64 MiB, else 413;
    • ?download=1.
  • -hub now refuses an address that isn't loopback. The user's hub keeps its M2 binary until Phase 7.
  • packaging/:
    • lodge/app.json, the spec's manifest, whose version is set at build;
    • systemd/frostnotes-lodge.socket (SocketUser=frostnotes, SocketGroup=lodge, 0660);
    • systemd/frostnotes.service (notesd -lodge as frostnotes, data in /var/lib/frostnotes, private socket /run/frostnotes/notesd.sock);
    • sysusers.d/frostnotes.conf (in lodge-apps, never lodge).
  • Docs: the package maps in AGENTS.md and overview.md. lodge-app.md now states the 416, how ranges are cut, and the pending-pairing name.

Tests (over a real Unix socket, with kittest)

  • kittest.CheckRules against packaging/lodge/app.json: health without a caller, missing and forged callers, one kind per path, /api's upgrade, the manifest's routes, and another uid's connection closed. mcp is masked to false until Phase 4.
  • A session reads, writes as e2e (web) (the params' author is ignored), gets note.changed, is refused vault.add, and pings. A second session without a display name works the same.
  • Blobs:
    • the headers (CSP, nosniff, immutable caching), ?download=1, and 404s for malformed names;
    • 403 as a session, 405 for PUT;
    • 64 MiB whole and 64 MiB + 1 as 413;
    • ranges of exactly 8 MiB and past it, open and suffix ranges;
    • 416 for several ranges or one past the end.
  • A device behind a loopback relay that plays lodge's /device/notes pairs (the pending pairing names the node), pulls, and pushes. Without a token it's 401 whatever node headers lodge sends.
  • checkLoopback for -hub.

Gates: make check is green locally, including a fix to a Phase 2 test that could race the loop's state. I also ran a manual smoke test of notesd -lodge under LODGE_ROOT: /health, a 0660 socket, 403 without a caller, and 401 on a device route without a token. make sync-sim is running; I'll add its result here.

Security review (overnight, an independent agent)

  • If-Range bypassed the blob limits. http.ServeContent answers whole when If-Range doesn't match, so Range: bytes=0-0 with a stale If-Range fetched a blob of any size. The handler now drops If-Range: a blob never changes under its hash. There is a test.

The master session's security review

  • L5 (content URLs): under ts.net, every tailnet page is same-site to lodge-content, so one could probe for a file it knows by its hash. Paths are now /content/blobs/<mac>/<hash>.<ext>.
    • mac is an HMAC-SHA256 of the hash under notesd's 32-byte content key (content.key in the data directory, 0600). The key stays the same across restarts, so URLs stay cacheable.
    • A wrong or missing MAC is 404, and the lodge socket never serves unkeyed paths.
    • rpc.hello gives a session the key as contentKey.
    • Checked live in lodge's e2e build: unkeyed 404, keyed 200, wrong MAC 404.
  • N6 (pairings): behind lodge, one node (Lodge-Node-ID) may have 2 pairings waiting, so one peer can't take all 8 slots. The node ID is a rate key, never an admission.
  • Kit: lodge/kit is bumped to 2017aec, whose MCP sessions sweep idle ones on a ticker.

🤖 Generated with Claude Code

bketelsen and others added 12 commits October 18, 2026 22:58
A method may list callers that narrow its domain's, and be marked
writes. Both reach the Go router and the TypeScript tables
(METHOD_CALLERS, WRITES), and the reference shows them. agent joins
the caller kinds; a method an agent may call names its vault in a
required int vaultId, which the generated handler checks against the
connection's scope (ADR-0026, plan 0006 Phase 2).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- schema: callers and writes marks as specs/lodge-app.md lists them;
  rpc.ping, rpc.hello's caller and identity, hub.setURL and
  hub.status's url, log.hub and sync.relocate.
- api: CallerAgent, Identity and Scope. Router.Dispatch refuses a
  method marked writes under a read scope, and a scoped call that
  names another vault answers notFound, as for no vault.
- rpcserver: ServeConn takes the connection's identity; rpc.hello
  reports it. The engine records a session's writes as editor,
  "<node> (web)", and an agent's as agent, its token's name,
  whatever the params say.
- hub: the recorded URL (migration 0004), log.hub, and POST
  /sync/hub's relocation proof, an HMAC keyed with the token's hash.
- syncer: a device follows log.hub at each connection, and
  sync.relocate keeps a new URL only when the hub there proves itself.
- tests: every method as each caller kind, every note method under
  another vault and a read scope, every writing method's attribution,
  and relocation against a relay, a wrong hub, a URL that differs and a
  forged proof.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
MockOptions.caller makes the mock refuse what notesd refuses a browser
inside lodge (METHOD_CALLERS), report the session's login and node from
rpc.hello, answer rpc.ping, and name a session's writes "<node> (web)",
for the web app's tests (plan 0006 Phase 2).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
sync-protocol.md gains POST /sync/hub, log.hub, sync.relocate,
hub.setURL and hub.status's url, and the rule that a device follows
log.hub at each connection; lodge-app.md says what hub.setURL accepts
and POST /sync/hub's 400 and 413; plan 0006 records the overnight
build.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Task card T-0084, implemented by the executor model and verified by taskrun.
The loop can be syncing again by the time the test reads sync.status
after its quiet point.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The development gateway's blob handler becomes internal/blobhttp, with
the limits lodge's content route needs: one range per request (416
otherwise), a range cut to MaxRange, a whole answer up to MaxWhole
(413 past it), and ?download=1's Content-Disposition.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
internal/lodgeapp builds the kit's server for notes (plan 0006 Phase 3,
docs/specs/lodge-app.md): /health with notesd's version and RPC major,
/api as caller session named by lodge's headers, /content/blobs/ with
its headers and limits, and the hub's sync routes under /device/, where
lodge's peer headers only name a pending pairing's node. lodge/kit is
pinned to 38f7be7. -hub now refuses an address that is not loopback.

Tests run over a real socket with kittest: lodge's rules (the peer
check, one caller per path, forged callers), a session that reads,
writes as its node and gets events, the blob limits at and past 8 and
64 MiB, and a device that pairs, pulls and pushes through /device/.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
packaging/lodge/app.json is lodge-app.md's manifest; a socket unit gives
lodge's group /run/lodge/apps/notes.sock, the service runs notesd -lodge
as frostnotes with its data in /var/lib/frostnotes, and sysusers.d
declares frostnotes in lodge-apps. M6 packages them.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
bketelsen and others added 9 commits October 18, 2026 23:33
…first

A system service has no Secret Service session, so frostnotes.service
sets FROSTNOTES_SECRETS=file. Phase 7 stops and disables the M2 hub's
unit before enabling frostnotes.service: both use /run/frostnotes.
Found deploying the overnight build beside the trial hub.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
From the security review of the overnight build: a device moved to the
URL its hub recorded and sent its token there on the next connection, so
a mistyped notesctl hub url, or a hub database someone changed, could
collect every device's token. follow now checks the host at that URL
with the relocation proof first, as sync.relocate does (shared as
proven), and stays otherwise. Also: hub URLs keep their host in lower
case, so URLs SameURL calls the same are equal strings; POST /sync/hub
logs at debug; lodge-app.md says what the endpoint reveals and what the
proof's key allows.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…mits

From the security review: http.ServeContent answers whole when If-Range
does not match, so Range: bytes=0-0 with a stale If-Range fetched a
blob of any size in one response, past lodge-app.md's 8 and 64 MiB. A
blob never changes under its hash, so the handler drops If-Range.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ired one

From the master's security review (N5): the endpoint answered 404 for a
device ID that does not exist, so any peer reaching /device/ could count
the paired devices. An unknown or revoked device now gets the same 200
answer, with a proof under an HMAC of its ID with a random key of the
hub's, which no token makes; the device's own check refuses it. Requests
are logged at debug.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
From the master's security review (N6): any tailnet peer could fill the
hub's 8 pending-pairing slots. Behind lodge a pairing now carries its
node's ID (Lodge-Node-ID, through hub.Peer), and a node with two
pairings waiting gets 429 for a third; the ID is a rate key, never an
admission, and the global limit stays.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
From the master's security review (L5): under ts.net, a public suffix,
every page on every tailnet node is same-site to lodge-content, so one
could probe CONTENT/notes/blobs/<sha256>.<ext> with image loads and learn
whether the vault holds a file it knows. Content paths are now
/content/blobs/<mac>/<hash>.<ext>, the mac an HMAC-SHA256 of the hash
under a 32-byte key notesd keeps in its data directory (content.key,
0600; the same across restarts, so URLs stay cacheable); a path without
the right mac is 404. rpc.hello hands a session the key (contentKey) to
make its URLs; the lodge socket never serves unkeyed paths.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@bketelsen
bketelsen changed the base branch from m4/phase2 to main October 19, 2026 13:42
@bketelsen
bketelsen merged commit 58abc7a into main Oct 19, 2026
4 checks passed
bketelsen added a commit that referenced this pull request Oct 19, 2026
@frostyard-machines
frostyard-machines deleted the m4/phase3 branch October 26, 2026 00:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant