Repository navigation
feat(link): add, remove and reorder a Remote Link's routes with ocx link routes - #8603
Merged
Merged
Conversation
…a confirmed-termination ssh run A link record may list several SSH routes to the same machine. The alias stays the pinned host-key name and is required in the list; a one-route link keeps the exact record an older Home reads. Tunnel and exec argv can connect to a route while HostKeyAlias stays the alias, and buildRouteProbeArgv checks a route strictly against the pinned key. SshRunner.run gains an opt-in AbortSignal with one termination path for timeout and abort.
…rrelated readiness proof A link with several routes is connected by selection rounds: each eligible route is probed against the pinned host key, the -R tunnel starts on the first that answers, OpenSSH must confirm the granted remote listener, and the Child must fetch its own catalog with a fresh proof id that this Home admits under the tunnel generation. Failed routes cool per class at today's per-alias rates; the link reports the most recoverable outcome over all routes. One-route links keep the existing path.
…ssion A key-admitted catalog request on the hub-link listener reports the proof id it carried; the optional listener set owns the proof registry and checks it against the tunnel generation the supervisor reports.
GET /api/link/status?routes=1 adds routes, route (name, index, since) and routeBlocked to links with several routes; the default document is unchanged. ocx link status asks for it and validates the fields strictly. An unsupported ssh client reads as a failed multi-route link.
…enSSH ssh -G shows the pinned alias, strict checking and the link known_hosts win over a hostile per-destination config. An opt-in fixture (OCX_OPENSSH_ROUTE_FIXTURE=1) runs a private sshd -i through ProxyCommand: the pinned probe passes, another key is refused without touching known_hosts, a granted -R carries bytes, and a second session or a server without forwarding is refused with OpenSSH's failure line.
… client re-checks for multi-route links
…, and take the proof header off the request A tunnel is owned and watched before its pidfile is written, and a failed write stops it before the next route. An orphan whose identity cannot be read keeps the link blocked and is never signalled; a link whose orphan is gone starts its first round. New probes and tunnels wait while lifecycle work runs, and changed links lose their round before the first stop is awaited. A proof that settles after its candidate exited cannot promote it. The hub-link catalog admission deletes the proof header before dispatch.
…thout a deadline, and recheck proof deadlines A multi-route link blocked by an earlier tunnel keeps a non-signalling watch and starts its first round once the process is gone or its pid names another process. A probe that settles while lifecycle work runs moves to a deferred phase no deadline applies to. A readiness proof promotes only before both its attempt and candidate deadlines.
…te probe results An orphan watch belongs to one multi-route record instance and pidfile; removal, replacement or a change to one route retires it before any further signal, and a pidfile is removed only when it is still exactly the watched one. A route probe that settles after its deadline counts as a timeout even before the tick runs.
…te probe answer as a timeout An orphan watch signals, lifts the block or starts a round only while the pidfile is still exactly the one it watches; a replacement is only watched and keeps the link blocked. A route probe that answers after its deadline is a transient timeout whatever its exit code or stderr says.
…laced An orphan watch keeps every process its pidfile has named; after a replacement nothing is signalled, and the link stays blocked until all of them are gone.
… management API
GET and POST /api/link/{id}/routes. A new route is stored only after it proved the pinned key over itself, probed against a private snapshot of the one known_hosts line that matches the alias (case-insensitive, whole-file shape checked, fingerprint equal to the record). Edits hold the per-alias set and the link job reservation that removal uses; the commit re-checks identity, route list and pin under the mutation lock and edits the fresh store. confirm-host refuses another key for an alias a Home-initiated link owns (link_pin_conflict), checked atomically with the write, and replaces case variants of the alias.
… routes
The command reads and edits /api/link/{id}/routes on the Home, validates the {linkId, pin, routes} document strictly, and names a refusal by its code and fixed cause. Capability entries and the generated skill surface are updated.
…d against real OpenSSH
…ases where it writes the link
…ame the probe class as cause
…e alias is the confirmed key, and never stores a link it refused
…ocked checks, and names a hand-edited known_hosts file
…checks still pass
…the Child may still be connected
Contributor
|
Caution Review failedThe pull request is closed.
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
… for its alias instead of blocking adds
…lp names exit 4 and the reload-failure read-back
# Conflicts: # tests/fixtures/test-layout-expected.json
# Conflicts: # src/cli/link.ts # src/link/status-projection.ts # src/server/management/link-routes.ts # tests/cli/cli-link-check.test.ts # tests/cli/cli-link.test.ts # tests/server/local-control-socket.test.ts
… blocks decodes with all three
# Conflicts: # skills/ocx/references/01_management_surface.md # skills/ocx/references/01_surface_access-remote.md # src/cli/capabilities-access-remote.ts # src/cli/link.ts # tests/cli/cli-link.test.ts
…ve earlier tunnel
…so a slow route keeps its full time to prove
…s the route in use
…to the link listener
…irst rested route
…it codes on the commands that return them
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
3 tasks done
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Follows the multi-route Remote Link PR #8602, merged to
devas44c3d7c95; this branch records that squash as an ancestor through a merge that changes no file. #8602 lets a Home-initiated link carry an ordered route list, direct routes first and the relay alias last, but nothing in the product could write the list. This PR adds the management API and theocx link routescommands, and closes two host-key gaps in enrollment that the route checks exposed.API.
GET /api/link/{id}/routesandPOST /api/link/{id}/routes(src/server/management/link-route-edit.ts) need the admin token on loopback or a dashboard session, the same as reconnect. Every success answers{linkId, pin, routes}.{op: "add", route, position?}inserts a route just before the alias unless a position is given.{op: "remove", route}removes a route. The alias is the pin and cannot be removed (route_is_pin).{op: "order", routes}must name exactly the current routes (route_order_mismatch).route_limit). An edit back to[alias]stores the old one-route record byte for byte.A route is stored only after it proves the pinned key. Before an add,
checkRouteTrust(src/link/route-trust.ts) requires the private link known_hosts file to hold only plain one-alias lines or well-formed hashed lines. Every line that matches the alias, as OpenSSH matches it, must carry the same key type and key, and that key must have the record'shostKeyFingerprint; otherwisepin_mismatchortrust_file_unexpected. The first such line is copied to a private temporary file, and the route probe runs against it withStrictHostKeyChecking=yes.Hashed lines from older releases. Releases before 2.89 probed without
HashKnownHosts=no, so on a Home whose ssh_config hashes known_hosts (the Debian and Ubuntu default) the link known_hosts file holds|1|salt|hashlines. A plain line matches the alias without case. A hashed line matches when it is HMAC-SHA1 of the lowercased alias: real OpenSSH 9.6p1 lowercasesHostKeyAliasbefore hashing (a line hashed frompin-aliasis accepted forHostKeyAlias=PIN-ALIAS, one hashed fromPIN-ALIASis not). Any other well-formed hashed line belongs to another host; a malformed one still fails the file. Those releases also appended a hashed line on every confirmation, and a later release adds a plain one beside it, so several lines for the alias count as one pin when they all carry the same key type and key, which is what OpenSSH accepts; the first is copied to the probe snapshot, and a second, different key for the alias is still refused. A new confirmation replaces every line for the alias.409 route_unprovenand a fixed class word inerror.cause(hostkey,auth,forward,transient). No route name or ssh text appears in the error.link_changed,pin_changed) and replaces only that record's routes.500 routes_stored_reload_failedwith the stored document; a Home restart applies it.CLI.
ocx link routes --link-id <id>,ocx link routes add --link-id <id> --route <alias> [--position <n>],remove --link-id <id> --route <alias>andorder --link-id <id> --routes a,b,..., each with--json. Route names are checked as SSH aliases before anything is sent, so a name starting with-is a usage error. Responses are validated strictly. Errors show the fixed code and, for an unproven route, a known class word only; exit codes are 4 for an unknown link, or an unknown route onremove(404), 5 for a refusal (409), and 1 when the routes were stored but the running proxy did not apply them (the message namesocx link routes --link-id <id>to read what was stored). The commands are in the capability registry and the generatedskills/ocxsurface. Like the Child-operation verbs, they are not served by the local control socket, so on a Home without a trusted loopback ingress they exit 1.Enrollment fixes the route checks exposed.
confirm-hostrefuses to replace the key of an alias that a Home-initiated link already pins, ignoring case (409 link_pin_conflict). The check and the write share one locked section, andputKnownHostnow replaces every line OpenSSH would use for the alias, case variants and hashed lines included. Before this, a later confirmation could swap the key that every route of an existing link trusts.link_exists). The trust file must pass the same whole-file check, with the confirmed key on every line for the alias (host_key_changed, ortrust_file_unexpectedfor a wildcard, host-list, marker or malformed line). OpenCodex never writes those shapes, so a one-route apply now refuses a hand-edited file too, with a message that says to remove the line. Hashed lines from older releases pass as above.500 key_cleanup_failedwhen it cannot). After a store write that threw, cleanup stores the record again only if the same checks still pass in that same locked section. When even that transaction fails, the answer is500 link_cleanup_uncertain.ocx link addprints its own fixed guidance for both codes and says when the Child may still be connected.Docs: the Remote Link guide has a "Several routes" section, which says a link picks its route when it connects and does not move back to an earlier route by itself;
structure/remote-link.mddescribes the endpoints, the checks and every error above.The branch merges the updated
feat/link-routes(withdevat7e3cefd16). The only manual resolutions: the test-layout fixture keeps both sides' entries, andsrc/cli/link.ts, the capability list and the link CLI test keep bothocx link routesanddev'socx link activity clear(22 link commands); theskills/ocxreferences were regenerated.Follow-ups from the review of #8602, which belong here because they touch route selection and its docs:
readinessDeadlineinsrc/link/route-rounds.ts). A slow route that spends most of its first 30 s on the ssh handshake keeps the full time for its readiness execs; one candidate takes at most 60 s. No real slow route (for example a relay to a Windows Child) was measured.src/link/supervisor.ts). Before, it stayed blocked with nothing watching it.structure/remote-link.mdsay what status shows for such a block (failed, "stale tunnel may hold the port") and the way out: stop that ssh, or, when its pid now names an unrelated program, check that no ssh for the link runs, delete<config dir>/link/<link id>.pidand restart OpenCodex on the Home. The guide states that a link never returns to an earlier route by itself and whatocx link reconnectdoes, and no longer says the route kind is not reported.StartServerDeps.observeAuthenticatedCatalogseam sees what the served admission reports to the link listener.Not in this PR: the dashboard maps the five new enrollment error codes (
link_pin_conflict,host_key_changed,trust_file_unexpected,key_cleanup_failed,link_cleanup_uncertain) to its generic error; a follow-up adds them with their translations. The API and CLI carry the guidance.Unchanged by default: a link without
routes, the status document, and enrollment on a link known_hosts file that only OpenCodex wrote.Verification
New tests failed first because the modules and endpoints did not exist on the base:
tests/server/link-route-edit.test.ts(26 cases: add, remove and order; proof against the private snapshot; refusals; races during probe and commit; reload failure; the reservation shared with removal; the endpoints absent from the Child relay and the local control socket),tests/clients/link-route-trust.test.ts,tests/cli/cli-link-routes.test.tsandtests/server/link-confirm-pin.test.ts. Each review fix added a case that failed on the previous commit and passes now. These cover: several same-key lines for the alias (two hashed, hashed plus plain, a case variant) and a different key still refused; a late grant that still proves within the new budget, and a stop exactly 30 s after the grant; a one-route orphan flag watched when the link gains routes; the served admission reporting the proof id and nothing without the header; a link that stays on a later route untilocx link reconnectmoves it back to the first rested route; hashed lines (a hashed pin proves a route over the hashed snapshot line, another link's hashed line lets apply pass, a hashed second key for the alias is refused, a hash of another spelling is ignored,putKnownHostdrops a hashed line for the alias); two case-variant confirmations before apply; a wildcard, host-list or hashed line beside the confirmed key; a refused or thrown apply whose key will not revoke; a failed store write followed by a pin or alias change while cleanup waits; a failed cleanup transaction; the CLI cleanup guidance.Commands, with exit codes, on
17b068d8f; the headd63921fa2only mergesa95715e5ea(which records the #8602 squash) and has the same tree, andgit merge-treeagainstdevat44c3d7c95is clean:bun run typecheck: 0bun run privacy:scan: 0bun run structure:check: 0bun run skill:surface:check: 0TMPDIR=/tmp bun scripts/test.ts --parallel=2over everytests/clients/link-*,tests/server/link-*andtests/cli/*link*file, every test file changed ondevby feat(link): measure the bytes each Remote Link carries and record request body size on log rows #8584, Fix nested model selectors in Pi exports #8287, test(sync): expect Pi's server-owned refresh after #8287 #8606, feat(link): compress Child request bodies with zstd for a Home that accepts it #8594 and feat(link): the Home accepts the Responses WebSocket over a Remote Link, behind a closed release gate #8593,local-control-socket, the CLI contract, capability and help tests,skill-ocx,skill-ocx-generated,management-route-registry,readyz-features,cli-dispatch,sync-client-integrations, the two test-layout tests,structure-ssot,ci-structure-gate,file-size-ratchet,repo-hygiene,core-link-boundaryandcore-lab-boundary(133 files): 2359 pass, 31 skip, 3 fail (exit 1). The 3 failures are the Rust ocx-child tests, which stop atcargo buildbecause the build machine has no rustup toolchain.TMPDIR=/tmp OCX_OPENSSH_ROUTE_FIXTURE=1 bun test tests/clients/link-routes-openssh.test.ts: 7 pass (exit 0), OpenSSH 9.6p1. Real OpenSSH accepts a second key stored under a case variant of the alias, and also from a wildcard, host-list or hashed line beside the confirmed one; the trust checks refuse every one of those files. The file now sets one 60 s ceiling withsetDefaultTimeoutinstead of one per test. It also shows that OpenSSH lowercasesHostKeyAliasbefore matching a hashed line.NOT RUN: the full
bun run testsuite (the build machine allows focused files only; CI covers the rest); the Rust ocx-child tests (no toolchain there); Windows and macOS, which use the same argv builders; the real-OpenSSH fixture in CI (opt-in). No real slow route was timed for the readiness budget.The design and code were reviewed by an independent reviewer: 5 plan rounds, then 8 code rounds, ending with no open P0–P2. Fresh final reviews:
5d998e9fcfound the hashed-line P2, fixed in V2c-3;6b0f45ffeapproved with three P3s (several same-key lines for one alias, the per-test fixture timeouts, the exit codes on the wrong command), all fixed here, together with the four P3s and one nit that the final review of #8602 assigned to this PR. The author's own review rounds (morph/morph-dsv41flash-1017): the round on V2c-3 found the several-lines P2, fixed here (8cb3ab8b6); the round on these V2c-4 commits (6b0f45ffe..17b068d8f) approved them, with two P3s answered without change: the never-granted half of the readiness bound is already pinned by an existing supervisor test, and lifting a one-route orphan flag when its pidfile is gone can only be reached with a hand-removed pidfile and then fails as a forward refusal that rests 60 s.Checklist
structure/remote-link.mdand the generatedskills/ocxsurface are updated.Implemented by Claude Opus 5.5 (anthropic/claude-opus-5-5) in GOAT through the Codex harness. Received as a git bundle from the VM that built it and pushed by the coordinator.