Repository navigation
fix(machines): tell a PC's own Ovis port and https link to the bridge token (#2191) - #2248
Conversation
… token (#2191) The connection server read GET /api/access on a PC's own Ovis with the bridge token to learn the port it answers on and its Tailscale https address. The bridge token opens only GET /api/updates and POST /api/updates/install there, so a token-gated PC always answered 401 and its card showed the registered port and no "Open that PC's Ovis" link. GET /api/updates now adds `port` and `serving_url` to its answer for the bridge token only; /api/access stays closed to it, and browser polls do not run tailscale. ownOffer takes both from the status and falls back to /api/access for an older server that does not tell them.
… be read A tailscale that cannot be started made the bridge token's GET /api/updates a 500 and refused the PC's own update (omo review, LOW). The status now stands without port and serving_url, and the connection server asks /api/access as of an older server.
Codex review: the bridge's status now always tells the port this server listens on and leaves serving_url null when tailscale cannot be read (MEDIUM), and ownOffer keeps the last status that told where it answers when a read after a check for releases fails (LOW).
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 5 minutes. View limit details
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. Comment |
|
CodeRabbit did not review this PR (review limit reached). Because the PR touches an HTTP contract and what a bridge token may read, here is the code-review agents' record in its place. omo-native-code-reviewer on 86828ec: PASS, no CRITICAL/HIGH/MEDIUM.
Codex Sol 6.1 fast xhigh on 86828ec: FAIL.
Codex Sol re-review of 86828ec..d5795b4: PASS, no findings. It confirmed that Checked by both: only the bridge token gets the two fields (the owner token's answer is unchanged, and the contract test asserts it); |
|
Merging d5795b4. An HTTP contract change next to authentication, so it got a strict review; Codex was at capacity, so an omo reviewer on gpt-6.1-sol and an independent second reviewer reviewed it; both pass with no MEDIUM or above. The new fields are gated on the same |
…PC on Try again, show the QR with a token and a readable log (#2264) (#2275) Closes #2264 ## Problem Testing the Windows app's Update for an older server (#2091, #2113) in the Windows 11 VM, with `Ovis.exe` 0.4.19 and `devswha.herdr-web-ui` 0.3.45 installed under the old id, found four problems (reproduced again on main 9a44f27 before this change): 1. **An old-id server that outlived herdr was never stopped, so Update failed and then looped.** The app and install.ps1 run the old checkout's `scripts/plugin.ts stop` outside herdr. Releases before 0.4.13 read their pid from `HERDR_PLUGIN_STATE_DIR` and, without it, from `~/.local/state/herdr-web-ui`, while herdr keeps it in `%LOCALAPPDATA%\herdr\plugins\devswha.herdr-web-ui\server.pid`. The stop said "not running", install.ps1's `herdr plugin uninstall devswha.herdr-web-ui` failed with `Os { code: 32 }`, and the half-deleted checkout kept serving 0.3.45 on 7317 under a herdr list that names only `devswha.ovis`. 2. **Try again after that ran the deleted checkout** (`error: Module not found ...devswha.herdr-web-ui-210f619d6b7b\scripts\plugin.ts`, shown as "Could not stop the Ovis server"). 3. **With a token, no QR:** `GET /api/access` was read without the token, answered 401, and the app told a PC that runs Tailscale to install it. 4. **The log showed raw CLIXML** (`#< CLIXML <Objs ...>`). ## Change - **Old-id stop** (`install.ps1`, `Model.PluginCommand`): the old id's `plugin.ts` (stop, status, phone) runs with `HERDR_PLUGIN_STATE_DIR` set to herdr's state dir for the plugin, found as `scripts/plugin-state.ts` finds it (`XDG_STATE_HOME`, else `%LOCALAPPDATA%`), and restored afterwards. A stop that finds no server there runs once more with the original environment, so a server started by hand from the old checkout (pid in its own dir) is still stopped. Every new-id release (0.4.14+) finds herdr's dir by itself and is run as before. - **Try again after a failed Update** reads the PC again: it updates again while one is due (or the plugin is gone), and for a current server it runs the update's last steps again: the login start, and the start when it is stopped. - **Phone address with a token:** the token that opened `GET /api/updates` (the PC's own, from the plugin's `env`/`.env`, as before) is sent to `GET /api/access` at the same origin. When that still answers 401 the app says the token is missing or did not work, instead of "install Tailscale". - #2248's `port` and `serving_url` in `GET /api/updates` are given only to the connection server's bridge token, which this app does not hold, so they cannot replace this; the app's own token already opens `/api/access`, which also tells Tailscale's state (needed for "Make the phone address" and "Sign in to Tailscale"). No server change. - **Log:** the installer starts with `-Command` instead of `-EncodedCommand`. In the VM, Windows PowerShell 5.1 started with `-EncodedCommand` and redirected output wrote progress, warning and error records to stderr as CLIXML whatever `-OutputFormat` and stdin were; `-Command` writes the plain lines. `Run` hands the script to cmd in an environment variable, so its `|` and quotes arrive as written. ## Tests - `scripts/windows-install.test.ps1`: the old id's stop is told herdr's state dir (with and without `XDG_STATE_HOME`), the variable is not left set, and a stop that finds no server there asks again without it. Fails on main's install.ps1 ("The old id's stop must look for its pid where herdr keeps the plugin's state"), passes with this change (VM, desktop session). - `app/windows/tests` (`Ovis.Tests.exe`): the state dir, the phone step for a token the app could not use, and a real Windows PowerShell run with the app's arguments that must print host, warning and error lines without CLIXML. 20/20 pass in the VM; the PowerShell case fails with main's `-EncodedCommand` arguments. - `bun run check fast`: green. ## Manual QA (winvm, Windows 11, herdr 0.9.3, Bun 1.4.2; `Ovis.exe` built at version 0.4.19) Setup each time: `winvm reset` (dev-ready-4), `herdr plugin install devswha/herdr-web-ui --ref v0.3.45`, a `HERDR_WEB_TOKEN` and a marker line in its `env`, `herdr server`, then herdr alone ended (`taskkill /IM herdr.exe /F`): the 0.3.45 server keeps running. | | main | this change | | --- | --- | --- | | Update | "The installer stopped with an error", CLIXML in the log; afterwards the old server (same pid) still serves 0.3.45 on 7317, the old checkout is half-deleted, herdr lists only `devswha.ovis` | Running on this PC: only `devswha.ovis` 0.4.19, `/api/updates` says `current_version 0.4.19`, no old process or checkout, env marker and token moved, Run value set | | Phone step with a token | "Install Tailscale on this PC..." with Get Tailscale | "Tailscale runs here" → Make the phone address → QR code and `https://winvm.tail1e211e.ts.net` | | Failed Update, then Try again | "Could not stop the Ovis server", `Module not found ...devswha.herdr-web-ui-...\scripts\plugin.ts` | (a file in the old checkout held open, so the old id's uninstall fails with os error 32) the log shows herdr's error and `herdr failed (exit 1)` as plain lines; Try again reads the PC again and lands on Running on this PC (`devswha.ovis` 0.4.19), no `Module not found` | <details><summary>Screenshots</summary> main:    this change:     </details> ## Reviews - omo-native-code-reviewer: PASS, four LOWs, all fixed here (a stop that finds no server through herdr's dir asks again without it; the token-needed text also covers a token that did not work; `[IO.Path]::Combine` for an empty `XDG_STATE_HOME`; the PowerShell test waits with a bound). - Codex (gpt-6.1-sol, fast, xhigh), four rounds: round 1 BLOCK with two MEDIUMs (Try again skipped a start that failed after a successful reinstall; forcing the state dir hid an old server started by hand), round 2 BLOCK with one MEDIUM (Try again skipped the login start while the server already ran), all fixed; rounds 3 and 4 (the `-Command` switch) PASS with no findings. ## Not in this PR (LOW, pre-existing) - When install.ps1 fails after installing the new id but before the old id's uninstall (as in the forced failure above), the old checkout's leftovers stay on disk; herdr no longer lists the old id and the app shows the new one running, so nothing breaks, but nothing removes them either. - `check fast` once failed `scripts/self-hosted-runner.test.ts` ("the stub never hung") under load; it passes alone on this branch and on main (30/30), and a rerun of the whole check was green.
Closes #2191
Change
The connection server learns where a PC's own Ovis really answers (its port, which differs from
the registered one for a relayed bridge, #1960, and the https address Tailscale serves it at) by
reading
GET /api/accessthrough the SSH tunnel with the bridge token. The bridge token opens onlyGET /api/updatesandPOST /api/updates/installthere (#2054), so a PC whose own Ovis asks forOVIS_TOKENalways answered 401: its card and dialog showed the registered port and no"Open that PC's Ovis" link.
/api/accessstays closed to the bridge token. Instead:server/index.ts,server/update-api.ts:GET /api/updatesaddsportandserving_urlto itsanswer for the bridge token only (the port this server listens on and
tailscale.serving_url, the same values/api/accessgives). A browser's answer is unchanged,and its polls never run
tailscale. A tailscale that cannot be read leavesserving_urlnull, and the status is answered either way.shared/update.ts: the two optional fields onUpdateStatus;shared/protocol.tsnotes them.server/machines.tsownOffer: takes both from the status, with the same checks as before(an integer port in 1..65535, an
https://URL without credentials, at most 300 characters).When the status names no
port(an Ovis older than this change) it asks/api/accessas before.docs/remote-pcs.md,changelog.d/own-ovis-port-url.md.The fix takes effect once that PC's own Ovis runs this version too; until then nothing changes.
Tests
server/machine-own-update.test.ts: a PC whose/api/accessanswers 401 and whose status tellsits port and https address. Before the fix the card showed
pc.invalid:29431and no link; nowpc.invalid:7317and the https address, and/api/accessis not asked.server/api.contract.test.ts(realcreateServer,port: 0, own token + bridge token): thebridge token's status has
port === server.portand a string-or-nullserving_url; the ownertoken's has neither; the bridge token still gets 401 from
/api/access.server/update-api.test.ts: nowhere, no fields; awherethat throws still answers 200(failed before the second commit).
server/machine-own-update.test.ts: a status that told where it answers while a check ran,then a 503: the card keeps that port and link (failed before the third commit).
bun run check fast: every step green except one unit case inscripts/self-hosted-runner.test.ts("starts the runners after --cache-wait when the first refresh hangs": its stub missed a 5 s
deadline at load ~108 on 128 cores); the file is untouched here and passes 30/30 run alone.
Review
Adversarial reviews before opening (read-only, unit tests only):
started made the bridge's status a 500 (fixed in fa1b3a2, with a unit test that failed before);
no unit test of the merge (added).
read that failed after a "checking" status dropped the address it had already told. Both fixed in
d5795b4: the status always tells the port and leaves
serving_urlnull when tailscale fails,and ownOffer keeps the last status that told where it answers (a test that failed before).
Known LOW, left as is:
/api/updatesrunstailscale statusandtailscale serve statuson that PC(in parallel, 2.5 s timeout each), also during the 2 s polls of a running own-update. Bounded and
only on the bridge path; a short cache could follow if it shows up.
port/serving_urllive onUpdateStatus, which the browser also reads; it never receives them.