Repository navigation
fix(link): serve ocx link status over the local control socket on Windows (#8998) #9022
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
1a63961
fix(link): serve ocx link status over the local control socket on Win…
lidge-jun 03afe39
docs(devlog): record the #8998 branch base after #9018
lidge-jun 134974c
Merge remote-tracking branch 'origin/dev' into lanew/9022
lidge-jun c49e183
fix(link): keep a lease that could not be deleted for the next stop o…
lidge-jun 2ea021d
test(link): pass the held lease path to the PowerShell holder as a li…
lidge-jun 539b059
fix(link): refuse a Windows run directory that already existed withou…
lidge-jun 7ef3b99
test(link): start predecessor fixtures from a private run directory
lidge-jun 5077530
test(link): cover run-directory creation under the config home and a …
lidge-jun 90b621b
Merge remote-tracking branch 'origin/dev' into lanew/9022
lidge-jun 6af15fd
Merge remote-tracking branch 'origin/dev' into lanew/9022
lidge-jun 41aee30
Merge remote-tracking branch 'origin/dev' into lanew/9022
lidge-jun 7ad3d86
Merge remote-tracking branch 'origin/dev' into lanew/9022
lidge-jun File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
devlog/_plan/261121_fb2100_remote_link_auth/040_windows_control_socket.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| # 040 #8998: `ocx link status` on a Windows hub with a non-loopback listener | ||
|
|
||
| Branch `codex/fb2100-win-link-socket` from `origin/dev` a8f689f2c (after #9018 merged), second PR (roadmap unit 040). | ||
|
|
||
| Problem: #8370 serves `GET /api/link/status` over a private AF_UNIX socket so the CLI's admin token has trusted | ||
| ingress on a hub whose public listener is not loopback. `localControlSocketSupported()` is false on win32, so a | ||
| Windows hub answers the CLI with `403` on every TCP listener. | ||
|
|
||
| Measured on this Windows 11 host, Bun 1.3.14: | ||
|
|
||
| | Behaviour | Result | | ||
| |---|---| | ||
| | `Bun.serve({ unix })` and `fetch(..., { unix })` with a path under 103 bytes | work (200) | | ||
| | `lstat` of the socket file and of a hard link to it | `EACCES` (a plain file in the same directory stats fine) | | ||
| | `existsSync` on the socket | `false`; `readdirSync` lists it | | ||
| | `linkSync` to the socket, then fetch through the link | works | | ||
| | unlink of either name while the server listens; rebind after unlink | works | | ||
| | `server.stop()` | unlinks its bound name once the stop completes; a killed process leaves it behind | | ||
| | `hardenSecretDir` + `verifyWindowsEntriesAcl(private-runtime-directory)` on the run directory | 410 ms + 273 ms once; a repeat harden is memoized (0 ms) | | ||
|
|
||
| Design: keep #8370's protocol (private `.c<port>.<token8>`, public hard link `control-<port>.sock`, per-port lease under | ||
| the claim mutex) and replace only the parts that read POSIX identity: | ||
|
|
||
| - `src/lib/local-control-socket.ts`: supported on win32. `isPrivateSocketDir` on win32 = a real directory (no | ||
| symlink or junction) whose DACL passes the `private-runtime-directory` policy. A socket entry on win32 = listed by | ||
| `readdir` and `lstat` refused with `EACCES` (an AF_UNIX reparse point); a readable regular file is not ours. | ||
| `isLocalControlPrivateSocketName(port, name)` matches exactly `.c<port>.<8 hex>`, so the lease and claim files are | ||
| never cleanup candidates. | ||
| - `src/server/index/local-control-listener.ts`: `preparePrivateDir` on win32 creates the directory, refuses a | ||
| symlink/junction or non-directory, hardens it with `hardenSecretDir` (as `src/client/lifecycle-lock.ts` does for its | ||
| runtime directory) and refuses it unless the ACL check then passes. No chmod of the socket on win32. Publication and | ||
| orphan sweep use the win32 socket test. Ownership at release on win32 is "the lease still names this token" checked | ||
| inside the claim mutex (a successor can publish only after it holds the lease), instead of inode identity; | ||
| `abort()` keeps Bun's own unlink, as on POSIX. | ||
| - `src/cli/link-local-control.ts`: unchanged flow; `usableLocalControlSocket` now answers on win32 after the same | ||
| directory ACL check, so the token goes to the socket only in a private directory. | ||
| - Trusted path (audit round 1, blocker 1): one check, `windowsTrustedRunDir(dir)`, used by the server before it binds | ||
| and by the CLI before it sends the token. The canonical path (`realpathSync.native`) must spell the same path, so no | ||
| junction, symlink or other reparse point sits anywhere on it; then one ACL batch must pass: every ancestor of the | ||
| config home under `trusted-ancestry` (owned by the user or a kernel-equivalent principal, nobody else holding write, | ||
| delete or DACL rights), the config home under `write-private`, and the run directory under | ||
| `private-runtime-directory`. Once no other principal can write anywhere on the path, the path verified before | ||
| connecting cannot be swapped before the connect. Same-user processes and administrators are inside the trust | ||
| boundary, as for every other file in the config home. Any failure (unexpected error, timeout, unverifiable path) | ||
| answers "not trusted": the server serves no socket and the CLI keeps its TCP request. | ||
| - Failed publication (audit round 1, blocker 2): `acquireLease` takes a rollback that runs inside the claim mutex | ||
| before the lease is removed. On win32 it stops the bound listener and unlinks the private name this attempt bound; | ||
| the public link is the last, atomic step of publication, so a failed attempt never published it and never touches it. | ||
| - A win32 cleanup candidate must be listed, match the exact private-name format and refuse `lstat` with `EACCES`; | ||
| any other error leaves the entry alone, and an unlink error leaves it too. | ||
| - The start stays synchronous: the one-time cost (about 0.7 s) applies only to a Windows hub whose public listener is | ||
| not loopback, and an async start would add a new in-flight state to stop and abort. | ||
|
|
||
| Tests: `tests/server/local-control-socket-windows.test.ts` (win32 only: TCP 403 vs socket 200, other routes 404, | ||
| `ocx link status` over the socket, files and lease removed on stop, a crashed predecessor's socket names replaced while a | ||
| decoy and the lease format survive, a loosened directory refused by the client, a loose pre-existing directory refused and left loose, | ||
| a config home under a parent other users can write refused by server and client while the token stays protected, a | ||
| failed publication that leaves no private name and no lease) and platform-neutral name-matcher cases. Registered in the | ||
| test layout. | ||
|
|
||
| Verification: that file and `tests/server/local-control-socket.test.ts` on Windows, `bun run typecheck`, | ||
| `bun run test:changed`, `bun run structure:check`, and a real `ocx start` with `hostname: 0.0.0.0` plus | ||
| `ocx link status --json` on this host. Security review by gpt-6.1-terra. | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not send the admin token to a Windows socket without proving its provenance.
On Windows,
usableLocalControlSocketreturns the public socket path when the run directory is private and a socket entry exists (src/lib/local-control-socket.ts:254). It does not check who created the listener. The POSIX branch checksstat.uidat line 259.The listener hardens the run directory before it takes the lease (
src/server/index/local-control-listener.ts:453). When the lease record is unreadable,acquireLeasereturnsunsafebeforepublish()runs (:297). The cleanup inpublish()therefore does not run, and a socket already at the public name is left in place. If another account could write to the run directory before hardening, that account's listener can remain at the public name. After hardening, the CLI can select it and send the admin token.The CLI must send the admin token only to an endpoint whose publication this runtime can establish. The mechanism for establishing that is not settled by the current code. The fix must cover the Windows admission path and the unsafe-lease path. Add a fix only after the mechanism is chosen.