…er the fleet preview (#3965)
## Change
Lets the plugin (`scripts/plugin.ts`) reach a machine profile, the
preview server from #3938, through its owner's unix
socket. It builds on #3955, which made `ovis add` read the fleet preview
from the plugin's settings. No release sets
the preview.
A machine profile answers only liveness on its TCP port, which the
plugin's health check does not take as a running
server. It takes its local owner on the unix socket that it records in
its state folder once it listens
(`serve.lock/http.json`, `{ port, hostname, socket, door: 1 }`).
When the plugin runs for a profile, that is `OVIS_PROFILE=machine` under
`OVIS_PREVIEW=fleet`:
- Both variables are read from the plugin's settings: its environment,
then its `env` and `.env` files, the values the
server it starts gets. The preview is read by `server/preview.ts`, as
for the rest of the plugin.
- The plugin takes the socket only when all of these hold:
- the state folder passes the profile's own check, the one the profile
makes before it serves from a folder
(`stateDirRefusal` in `server/machine-profile.ts`, which the profile's
start now calls too: one rule in one place);
- the record is a regular file of at most 4 KiB, opened without
following a link and without waiting, and names
`door: 1` and `serve.sock` in the folder's real path;
- `serve.sock` is a socket, not a link, owned by this account, and not
writable by group or other.
- The plugin sends no token on that socket, and addresses it as
`http://localhost`, the Host and the Origin the
profile takes there. These go to it:
- its health check (which `status`, `start`, `pair --approve` and `add`
make);
- the requests of `add` (also `link` and `login`) and `pair --approve`.
- The server counts as running only when it answers on that socket. With
no socket the plugin takes, it is not
running and the plugin sends it nothing; the TCP port is not asked
instead.
- `start` does not start a machine profile (the managed launcher cannot
bring one up). With none answering on
the socket it spawns nothing, writes nothing, says how a profile is
started (`OVIS_PROFILE=machine`,
`OVIS_PREVIEW=fleet` and a state folder of its own for `ovis-server
serve`) and exits 1. One that answers is
reported as running.
- `pair` (without `--approve`), `phone` and `phone-setup` show no
address, start no pairing and do not ask or
change Tailscale: a profile's port serves no app, and a code started
there can be entered at no address. Each
says that a phone reaches the profile through the Ovis relay only, and
names `add` and `link --code`.
- A command keeps the door its health check passed on for all its
requests. `start` decides anew at each of its
health checks until one passes, since the record is written once the
server listens.
- A refusal on the socket is the answer.
- A profile whose herdr does not answer counts as running (its health
carries `machine_profile.runtime_down`), and
`status` adds a line `engine: down` with the profile's reason.
- The output names the TCP address, as before; nothing printed names the
socket's path or the token.
Without the preview, or without `OVIS_PROFILE=machine`, the record is
not read, and every command behaves as before.
`scripts/plugin.ts` now imports `server/machine-profile.ts`. `status`
and `stop` still run with an empty
`node_modules` (checked by run, with the preview unset and with both
variables).
A changelog fragment is included
(`changelog.d/plugin-machine-profile-owner-socket.md`).
## Validation
On this head (`main` 678d87f merged in):
- `bun run typecheck`: passed.
- One run of `bun test scripts/plugin.test.ts
scripts/plugin-link.test.ts server/machine-profile.contract.test.ts`:
318 pass, 1 skip, 0 fail.
- `bun run check fast`: passed (workflow syntax, generated types and
themes, typecheck, build; unit tests 17,738
pass, 0 fail, 54 skip).
- macOS arm64 (27.0.1), Bun 1.4.2, in a fresh clone of this pull
request's head (b62a841): the two plugin test
files, 234 pass, 2 skip, 0 fail.
- `main` 678d87f and this head, side by side with the real
`scripts/plugin.ts`, with the preview unset:
- Setup: stdout a pipe, `OVIS_TOKEN` set, a fake server on TCP, and a
stand-in on the profile's socket that logs
its calls.
- Commands: `status`, `stop`, `add`, `add --print`, `link --code`,
`pair`, `pair --approve`, `phone` (with a
recording stand-in for `tailscale`), `phone-setup` and `help`. `start`
is left out: it spawns the real launcher.
- Five setups: nothing set, `OVIS_PROFILE=machine`, a record in the
state folder, both, and `OVIS_PROFILE=machine`
in the settings file with a record.
- Result: the output, the exit codes and every request were the same,
and the socket was not asked.
- Tests in `scripts/plugin.test.ts` (`a machine profile, under the fleet
preview`), with the plugin run as a process:
- A real machine profile from `createServer` in the test process, with
its record as `serve()` writes it and a
stand-in herdr: `status` says it runs, and `add --print` reads the
account's status on the socket and then
refuses without a terminal. With its herdr stopped, `status` says
`running` and `engine: down` with the reason.
With no door in its record, `status` says `down`.
- A stand-in profile that logs every call on each door:
- `status`, `add` and `pair --approve` on the socket as `localhost`,
with no token;
- on a running profile `pair` and `phone-setup` send nothing and print
no address, code or Tailscale command;
`phone` never calls `tailscale`; `start` with no profile answering
spawns nothing and exits 1;
- the two variables in the settings file, the file after the
environment;
- a 401 on the socket is not retried on TCP;
- the door a command's health check passed on is kept when the record
goes away afterwards;
- with both variables, nothing is sent anywhere when the record is
missing, not JSON, names no door, another
door or no socket, is larger than 4 KiB, or is a FIFO (`status` answers
at once);
- with both variables, nothing is sent anywhere when the folder does not
pass the profile's check, or
`serve.sock` is a link, in four folder set-ups; in a folder that passes,
its own socket is taken;
- with both variables, an app answering full health on the TCP port is
not taken: `status` says `down`, `add`
stops, and `start` does not report it as running;
- with the preview off or `OVIS_PROFILE` not `machine`, the TCP port is
used and the socket is never asked.
- Each run checks that the output names neither the socket's path nor
the token.
- Each of these tests failed before the code it covers, except the
controls: the preview-off cases, the own-socket
case, and one that names the state folder through a link and `..`, which
passes before and after (the runtime
resolves both spellings to the same folder).
Not run: Windows (these tests are skipped there; a profile does not
start on Windows), `add` or `link --code`
against a real relay on a profile, `stop` on a profile (it acts on the
plugin's own records, so for a profile
started by hand it says nothing runs and stops nothing), the socket
owned by
another account (one account cannot make one; the type and mode parts
are run), a real terminal, a real account,
relay or phone.
Left for a follow-up, #3968: three sentences the plugin prints for a
profile (`start` names `ovis-server serve`, which
is not on `PATH` for an installed copy; `phone-setup` at a terminal
still mentions a fresh pairing code; `stop` says
nothing runs for a profile started by hand), and `pair --approve`
waiting without a limit when a server answers
health and then stops answering (`main` does the same over TCP).
Change
Changes what
ovis add(alsoovis linkandovis login) does under the fleet preview,OVIS_PREVIEW=fleet(
server/preview.ts, from #3938, which this pull request builds on). No release sets that variable. The pluginreads it from its environment or its
settings file (
env,.env), the merged settings the server it starts gets. With it unset,ovis adddoes whatmaindoes.Under
OVIS_PREVIEW=fleet,ovis addwithout--approve, in the order a person meets it:--print, it does not start the sign-in. Itprints one line saying that adding this PC needs a terminal and exits 1. It lists nothing and shows no code.
With the preview unset,
--printbehaves as before.Signed in as Ovis account <id> (signed in with GitHub). Press Enter to show the QR code for this account's phone, or press Ctrl+C if that is not your account:. Until Enter is pressed, this PC is not listed in that account and no code is made.This PC is listed in that account as <name>.). It then shows the QR code as before, on a screen of its own, or with--printas lines that stay.The QR code was not shown, and this PC was not listed in that account.with what to run again, and exits 1.This is the same rule the existing questions of
ovis adduse.OVIS_RELAY_APP_URL; its offers carry it) replacesapp.ovis.shin the codelines of
ovis addandovis link --codeand in the--approveline.OVIS_CLI_NAME, for a wrapper that runs the plugin under another name, replacesovisin the commandsovis addsays to run.ovis add --approvegets neither the terminal check nor the Enter step. Under the preview, only the app it nameschanges.
With
OVIS_PREVIEWunset (or set to a list without the wordfleet), nothing changes, whateverOVIS_RELAY_APP_URLandOVIS_CLI_NAMEsay. The one change inscripts/plugin.tspassesOVIS_RELAY_APP_URLonto
link, which reads it only under the preview.A changelog fragment is included (
changelog.d/add-confirm-under-fleet-preview.md).Five follow-ups rated low in review are in #3957.
Validation
On this head, which holds
main9d17bcd:mainwas merged in after #3953 changed the same files (two conflicts,both in import lines:
linkSettingsnow comes withlink's deferred import ofscripts/plugin-link.ts):bun run typecheck: passed.bun test scripts/plugin-link.test.ts scripts/plugin.test.ts: 213 pass, 0 fail (withmain's new testsof a checkout whose packages are not installed).
bun run check fast: passed (workflow syntax, generated types and themes, typecheck, build; unit tests 17,705pass, 0 fail, 54 skip).
files, 211 pass, 2 skip, 0 fail.
maine5c6a8e and this branch two revisions before this head (before the settings-file change and beforemain9d17bcd was merged in), side by sidewith
OVIS_PREVIEWunset, by a reviewer that did not write it, through the realscripts/plugin.ts:add,add --print,add --approve,link --code,status,helpand an unknown command; piped and at a pty; the twovariables unset and set;
OVIS_PREVIEWunset, empty,fleetsandno-fleet: 112 runs a side understrace,against a local stand-in for the PC and an account service that refuses connections. Output (the pty's bytes
too), exit codes, the calls to the PC and the
connectandexecvecalls were the same. These runs reach therefusal, the sign-in failing,
link --codeand usage; the QR, Enter and approve paths are compared in thein-process runs below.
scripts/plugin-link.test.ts:--print, and a list that namesfleetbeside another word); the account named before anything is listed, with Enter, other lines (
no,y,x)and Ctrl+D; the line that comes too soon and the first line where the input could not be emptied; both
variables taking effect; the preview set only in the plugin's settings file (the refusal through the real
command, the Enter step in-process through the plugin's own merge of its settings);
"",fleets,no-fleet), run once with nothing set and once withboth variables set. It expects
main's lines:--printto a pipe writes the code, no Enter step,app.ovis.shand
ovisin what is printed;scripts/plugin.ts addwith its output piped: the refusal under the preview,main'ssentence without it.
the first version of this branch).
code).
main9d17bcd and this head, withOVIS_PREVIEWunset, compared side by side by the author (the realscripts/plugin.tsalso forstatus,stopandhelp):linkwas driven in-process, with the test file's fake PC, fake account service and a fixed clock, through 14runs: plain add,
--printat a terminal,--printwith the output and with both output and input not aterminal, output only or input only not a terminal, the account service off (with and without
--print),already in an account, nobody scanning for 30 minutes, Ctrl+C while the code shows, a device kept out by
Enter,
link --code, and--approve.scripts/plugin.ts addandadd --printwere run with stdout a pipe, with the account serviceunreachable and off.
OVIS_RELAY_APP_URLset,OVIS_CLI_NAMEset; the real command alsowith the two names set only in the settings file. The output, exit codes, calls to the PC and calls to the
account service were the same.
Not run: the Enter step with a person at a real terminal, or through the real command with the preview only in
the settings file; under the preview, the QR and approve paths through the
real command (in-process only); a real account service, relay or phone; Windows.