Skip to content

feat: require a per-home token on the RPC listener - #173

Closed
sanchitrk wants to merge 1 commit into
feat-oauth-clerkfrom
feat/local-door
Closed

sanchitrk wants to merge 1 commit into
feat-oauth-clerkfrom
feat/local-door

Conversation

@sanchitrk

@sanchitrk sanchitrk commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #171. It lands in canary once #171 merges.

What changes

A CodeWork server no longer accepts any local caller. It keeps a token per home and refuses a WebSocket upgrade that does not carry it.

  • Token. Created once in <home>/token (mode 0600) and copied into service.json at each start. Delete the file and restart to replace it.
  • Door. Runs before the upgrade. A missing or wrong token gets 401. A foreign Host (on a loopback bind) or Origin gets 403.
  • Transport. The client offers Sec-WebSocket-Protocol: codework, <token>. The server selects codework, so the token is never echoed.
  • CLI. Sends the token only to the server its home registered. A loopback alias with the same port and path reaches that server; any other --server URL is refused with a plain error and hint. --home now works with --server.
  • App server. Takes its own token per start, printed in its ready line and handed to the renderer over the preload bridge. Each remote server row stores a token, which is never returned to the renderer.
  • server.info reports the machine id.

Also in here

  • The OrbStack machine fixtures install from the checkout under test instead of a pinned commit.
  • A reads test assumed a reply's first chunk always arrives as a delta. It can arrive in the draft message instead. The test now accepts both; no production code changed.

Breaking

  • A remote server row saved before this change has no token and is refused until it is added again.
  • A client that connects without the token is refused, on loopback too.

Verified

Check Result
vp check, vp run typecheck, knip exports pass
packages/codework tests 151 passed, 23 skipped
apps/server tests, three runs 42 passed each
Live sync suite on four OrbStack machines, three runs 12 passed each
Live usage, recovery and daemon suites 6, 5 and 1 passed

Also driven by hand: the upgrade matrix from the Mac and between three OrbStack machines, the Electron app through setup, connect and a real prompt, and each CLI --server case.

Known gaps

  • The token travels in clear over ws:// to a non-loopback host.
  • The desktop app has no screen yet for adding a remote server with its token.
  • The live machine suites share a machine, so they run one file at a time.

🤖 Generated with Claude Code


Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

A server now keeps a token in <home>/token and refuses a WebSocket
upgrade that does not offer it, or that comes from a foreign Host or
Origin. The token is published in service.json, and the CLI, the app
server and the desktop renderer send it when they connect.

- The CLI sends the token only to the server its home registered, and
  prints a plain error for any other --server URL.
- The app server takes its own token per start and stores one on each
  remote server row.
- server.info reports the machine id.
- Machine test fixtures install from the checkout under test.
- Fix a reads test that assumed the first chunk arrives as a delta.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
sanchitrk added a commit that referenced this pull request Nov 23, 2026
…rue (#177)

Lands #173, #174, #175 and #176 with it: a per-home token on the RPC listener, plain CLI errors, a session per paired client, one Machines page and machines behind a TLS proxy.

- Every remote client pairs a key of its own: a one-time code from `codework service pair`, then short-lived tickets signed with that key.
- Relay alone decides whether a machine is in a workspace; while it can't be reached, its last status shows, or Unknown Link.
- An unlink while Relay can't be reached keeps the link, marked leaving, until a heartbeat's revoke is confirmed.
- Setup's last step is Link, and it can be skipped. User-facing copy calls the broker Relay.
- The relay listens on HOST; a new E2E test links a paired machine through a real Relay.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@sanchitrk

Copy link
Copy Markdown
Contributor Author

Landed in #177 (squash-merged into feat-oauth-clerk as 00a8ac3), whose branch carried this change. Closing as merged through it.

@sanchitrk sanchitrk closed this Nov 23, 2026
sanchitrk added a commit that referenced this pull request Nov 23, 2026
Accounts and workspaces through Clerk and the relay, and machines that connect, link and pair:

- The relay holds accounts, workspaces and machine links; machines pair with it by a code a member approves, bound to one identity key per home (#172).
- Local listeners take a per-home token; remote clients pair keys of their own and use short-lived tickets (#173, #175, #177).
- One Machines page for this machine, paired machines and the workspace's machines (#176, #177). Relay alone decides membership; an unlink while Relay can't be reached finishes once it can.
- Plain CLI errors for bad ids, flag checks and refused connections (#174).
- E2E coverage: the relay suite, and a paired machine linked through a real Relay from the app server.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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