Repository navigation
harbor: pair a phone or browser with berth pair - #145
Merged
Merged
Conversation
berth pair prints a one-time link and its QR code. The link opens a page with a Pair this device button, so a chat app's link preview does not spend the code, and the button's same-origin POST trades it for a device cookie (HttpOnly, SameSite=Lax, a year, Secure over https). --list, --revoke and --revoke-all manage devices. berthd owns the pairing file and is its only writer; the CLI and the harbor reach it through new socket ops, so no file lock is needed. The file keeps only hashes, mode 600. Ten wrong codes in a minute stop every redeem for that minute. QR codes come from rsc.io/qr, drawn in the terminal with explicit black and white so they scan on any theme. Reading the harbor still needs no login. Pairing is the groundwork for switching and stopping engines from the harbor.
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.
Step 4 of the switchboard plan: device pairing, modelled on the operator's oh-my-pocket sign-in and cut down to one owner. Reading the harbor still needs no login. This PR adds no actions; it lets a browser prove it was paired, and step 5's switchboard builds on that.
Flow
berth pair --url https://box.tailnet.ts.netprints a link (/pair?code=XXXXXXXX) and the same link as a QR code.GET /pair?code=shows a page with a Pair this device button and a name field. The GET uses nothing up, so a chat app's link preview cannot spend the code.Sec-Fetch-Site). berthd redeems the code, and the browser getsberth_device: HttpOnly, SameSite=Lax, one year, Secure over https (direct, orX-Forwarded-Proto: httpsfromtailscale serve).GET /v1/meanswers{"paired": bool}, so the page knows whether to show actions. A bearer token works too, for scripts.berth pair --list,--revoke IDand--revoke-allmanage devices.Design
harbor-devices.json, through new socket ops (pair_code,pair_redeem,pair_check,pair_list,pair_revoke). If the CLI and the harbor both wrote the file, it would need a file lock on two OSes; one owner needs none. Access to the socket already means this machine's user, so the CLI needs no extra auth.rsc.io/qrv0.2.0 (BSD, pure Go). It draws the terminal QR with explicit black and white ANSI colors, so it scans on dark and light themes, plus an SVG for the harbor's coming "Pair a phone" view.berth pairis top-level, notberth harbor pair. A command with subcommands can't also run bare, and the installed services runberth harbor --allow-host ....berth daemon --devices FILE(default in the state dir;""turns pairing off).Proof
internal/pair(race):TestPairCLI, over a real berthd socket: the link format, a code berthd accepts, list, revoke, the human view with the QR, and a non-http--urlrefused.TestPairFlow, a harbor in front of a real berthd:/v1/metells a paired, unpaired and forged cookie apart--list, a file without the code or token at mode 600, paired and unpaired,--revoke-all, and that neither log contains a code or token. The live berthd was not touched.go test ./..., Windows build and vet, golangci-lint (0 issues).