Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ The same installer adds **OX Desktop** to your application launcher. It runs on

### Pair a headless host

On the server, run the installer with `--host`, then run `ox host pair` (if HTTPS port 8443 is already used in Tailscale Serve, pass `--port <port>`, or `--listen-port <port>` if loopback port 48162 is taken). Paste the invitation into **Settings → Hosts** on OX Desktop. To reuse configured API keys, select the server and choose **Send API keys…**. From a paired browser, open **Settings → Credentials → Copy keys to another host…** on the host that already has the keys. Choose the destination, select the provider or Brave Search keys you want, and send. The receiver can use those keys and incur charges until you remove or rotate them.
On the server, run the installer with `--host`, then run `ox host pair` (if HTTPS port 8443 is already used in Tailscale Serve, pass `--port <port>`, or `--listen-port <port>` if loopback port 48162 is taken). It prints a QR code, the invitation link, and the host address and 12-character code. Scan the QR in OX on the phone, paste the link, or enter the address and code under **Add host**. All three redeem the same five-minute invitation. To pair without carrying a code, run `ox host pair --window`, scan or enter the printed address on the device, then accept the waiting request with `ox host pending` and `ox host approve <id>`. To reuse configured API keys, select the server and choose **Send API keys…**. From a paired browser, open **Settings → Credentials → Copy keys to another host…** on the host that already has the keys. Choose the destination, select the provider or Brave Search keys you want, and send. The receiver can use those keys and incur charges until you remove or rotate them.

Managed headless hosts install updates automatically when idle. Use **Settings → Host updates** in the paired web UI, or select the server in desktop **Settings → Hosts**, to choose Automatic, Download only or Manual and the Dev or Stable channel.

Expand Down
4 changes: 3 additions & 1 deletion desktop/ox-host/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,11 @@ const USAGE: &str = "Usage: ox-host COMMAND [--socket PATH] [--state-dir PATH] [
stop stop the host now; running turns are interrupted
restart [--timeout SECS] finish running turns (default bound 600s), then start the installed host
pair [--terminal] [--port HTTPS_PORT] [--listen-port LOCAL_PORT]
print a private Serve invitation, optionally granting a terminal
print a QR code, address and code for a device invitation
pair --worker-host [--port HTTPS_PORT] [--listen-port LOCAL_PORT]
invite another OX host to launch workers here
pair --window [--for LOGIN] [--port HTTPS_PORT] [--listen-port LOCAL_PORT]
wait five minutes for any device on the tailnet to pair
update [setting] install when idle or set automatic, download, manual, stable or dev
name [NAME] show or set the name shown to clients
policy [set POLICY] show or set the starting mode for this host
Expand Down
107 changes: 91 additions & 16 deletions desktop/ox-host/src/pairing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,11 @@ pub fn pair_with_ports(
let window = reply
.window
.ok_or("The host did not open a pairing window")?;
println!(
"Waiting five minutes for a device to pair. On the other machine, choose this host under Add host, or paste {} as a worker host.",
reply.origin.as_deref().unwrap_or("its Serve address")
);
println!("Waiting five minutes for a device to pair.");
if let Some(origin) = reply.origin.as_deref() {
println!("On your phone, enter this address to ask to pair: {origin}");
}
println!("On desktop, choose this host under Add host.");
println!(
"A request waits for you here: approve it in OX Desktop or on a paired phone, or run `ox host pending` and `ox host approve <id>`."
);
Expand Down Expand Up @@ -212,24 +213,53 @@ pub fn pair_with_ports(
pairing.url
);
} else {
let qr = qrcode::QrCode::new(&pairing.url).map_err(|e| e.to_string())?;
println!(
"{}",
qr.render::<qrcode::render::unicode::Dense1x2>()
.module_dimensions(1, 1)
.build()
);
let manual = reply.origin.is_some() && pairing.short_code.is_some();
println!(
"Scan on your phone or paste this invitation into Add host on your desktop. It expires in five minutes.\n{}",
pairing.url
"Scan this invitation with OX on your phone, or {} below. It expires in five minutes.",
if manual {
"enter the address and code"
} else {
"paste the invitation link"
}
);
}
if let (Some(origin), Some(code)) = (reply.origin, pairing.short_code) {
println!("Host {origin}\nCode {code}");
println!("{}", invitation_output(&pairing, reply.origin.as_deref())?);
}
Ok(())
}

/// A QR code for terminal output. It keeps the quiet zone the QR encoder adds,
/// which is what lets a phone camera read the block characters on a screen.
fn qr(text: &str) -> Result<String, String> {
let qr = qrcode::QrCode::new(text).map_err(|e| e.to_string())?;
Ok(qr
.render::<qrcode::render::unicode::Dense1x2>()
.module_dimensions(1, 1)
.build())
}

/// One short-lived invitation in every form a headless operator can carry:
/// the QR a phone scans, the full link to paste, and the address and manual
/// code to type. All three redeem the same invitation.
fn invitation_output(pairing: &admin::Pairing, origin: Option<&str>) -> Result<String, String> {
let mut out = qr(&pairing.url)?;
out.push_str("\n\nInvitation ");
out.push_str(&pairing.url);
if let Some(origin) = origin {
out.push_str("\nAddress ");
out.push_str(origin);
if !origin.trim_start_matches("https://").contains(':') {
// A bare host entered with a manual code defaults to OX's port 8443.
// Show 443 explicitly when Tailscale Serve uses the standard HTTPS port.
out.push_str(":443");
}
}
if let Some(code) = pairing.short_code.as_deref() {
out.push_str("\nCode ");
out.push_str(code);
}
Ok(out)
}

pub fn pending(paths: &Paths) -> Result<(), String> {
let rows = access::status(paths).map_err(|e| e.to_string())?.pending;
if rows.is_empty() {
Expand Down Expand Up @@ -534,4 +564,49 @@ mod tests {
assert!(args(&["--port", "9443", "--listen-port", "9443"]).is_err());
assert!(args(&["--port"]).is_err());
}

fn invitation() -> admin::Pairing {
admin::Pairing {
short_code: Some("1A2B-3C4D-5E6F".into()),
url: "https://studio.fixture.ts.net:8443/#pair=secret".into(),
qr_svg: String::new(),
expires_at: 0,
invited_login: None,
}
}

#[test]
fn an_invitation_prints_one_qr_and_both_manual_forms() {
let pairing = invitation();
let origin = "https://studio.fixture.ts.net:8443";
let output = invitation_output(&pairing, Some(origin)).unwrap();

// The QR is the invitation itself, not the bare origin: scanning it
// carries the secret into the phone's pairing form.
assert!(output.contains(&qr(&pairing.url).unwrap()));
assert!(!output.contains(&qr(origin).unwrap()));
assert!(output.contains("\n\nInvitation https://studio.fixture.ts.net:8443/#pair=secret"));
assert!(output.contains("\nAddress https://studio.fixture.ts.net:8443"));
assert!(output.contains("\nCode 1A2B-3C4D-5E6F"));
}

#[test]
fn an_invitation_without_a_short_code_or_origin_still_prints_its_link() {
let pairing = admin::Pairing {
short_code: None,
..invitation()
};
let output = invitation_output(&pairing, None).unwrap();
assert!(output.contains(&qr(&pairing.url).unwrap()));
assert!(output.contains("\nInvitation https://studio.fixture.ts.net:8443/#pair=secret"));
assert!(!output.contains("\nAddress"));
assert!(!output.contains("\nCode"));
}

#[test]
fn the_manual_address_names_standard_https_explicitly() {
let output =
invitation_output(&invitation(), Some("https://studio.fixture.ts.net")).unwrap();
assert!(output.contains("\nAddress https://studio.fixture.ts.net:443"));
}
}
10 changes: 10 additions & 0 deletions desktop/tests/host_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import json
import os
from pathlib import Path
import re
import signal
import socket
import subprocess
Expand Down Expand Up @@ -178,7 +179,16 @@ def command(*argv, check=True):
assert conflict.returncode != 0 and "--port" in conflict.stderr, conflict
paired = command("pair", "--port", "9443", "--listen-port", "49162")
assert "https://workstation.fixture.ts.net:9443/#pair=" in paired.stdout, paired
assert "Invitation https://workstation.fixture.ts.net:9443/#pair=" in paired.stdout, paired
assert "Address https://workstation.fixture.ts.net:9443" in paired.stdout, paired
code = re.search(r"^Code (\S+)$", paired.stdout, re.MULTILINE)
assert code and re.fullmatch(r"[0-9A-Z]{4}-[0-9A-Z]{4}-[0-9A-Z]{4}", code.group(1)), paired
assert any(block in paired.stdout for block in "█▀▄"), f"no QR code in {paired.stdout!r}"
assert "https://workstation.fixture.ts.net:9443 → 127.0.0.1:49162" in command("status").stdout
# A pairing window lets the phone enter a host address and wait for approval.
window = command("pair", "--window")
assert "enter this address to ask to pair: https://workstation.fixture.ts.net:9443" in window.stdout, window
assert "No device is waiting to pair." in command("pending").stdout
# Subsequent pair without flags remembers the configured custom ports.
paired_again = command("pair")
assert "https://workstation.fixture.ts.net:9443/#pair=" in paired_again.stdout, paired_again
Expand Down
2 changes: 1 addition & 1 deletion docs/design/desktop/host-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ The carried text goes only to the target runtime and its provider, never to the

## Remote access and privacy

Enable Remote access in Desktop settings and use a private HTTPS Tailscale Serve origin. The HTTP listener binds to loopback. A Tailscale login header, by itself, grants no session access. Initial pairing starts from a same-user local administration socket. A paired operator may sign a request to create another short-lived invitation bound to their own Tailscale identity. Revoking the issuer withdraws its unredeemed invitations. The QR fragment carries a short-lived, single-use invitation. An operator may instead open a five-minute pairing window on the host; while it is open, a device that reaches the Serve origin asks to pair, and the operator accepts that request on the host in the desktop, on a paired phone or with `ox host approve`. The desktop and phone list each other's open windows, so neither side has to type a code or an address. The mobile client creates a non-exportable signing key. The registration binds the device to the Tailscale login that redeemed it, its expected HTTPS origin, secure cookie and public key. A host's own invitation is open to any login Tailscale Serve authenticated on that origin, because a tagged machine has no user of its own; `ox host pair --for LOGIN` binds one login where that matters. Opening the live connection requires signing a fresh challenge. Cross-origin requests, unpaired clients, expired challenges and revoked devices are refused. Revoking a device also disconnects its live stream. Unused pairings expire after 30 days. The PWA caches its shell assets. Transcripts, invitation secrets and approval content stay out of the offline cache.
Enable Remote access in Desktop settings and use a private HTTPS Tailscale Serve origin. The HTTP listener binds to loopback. A Tailscale login header, by itself, grants no session access. Initial pairing starts from a same-user local administration socket. A paired operator may sign a request to create another short-lived invitation bound to their own Tailscale identity. Revoking the issuer withdraws its unredeemed invitations. The QR fragment carries a short-lived, single-use invitation. On a host without a desktop session, `ox host pair` prints that same invitation as a QR code, a link, and an address and 12-character code, so a phone can scan it or the operator can type it. An operator may instead open a five-minute pairing window on the host; while it is open, a device that reaches the Serve origin asks to pair, and the operator accepts that request on the host in the desktop, on a paired phone or with `ox host pending` and `ox host approve`. `ox host pair --window` prints the window address as a QR code for a device with no code to carry. The desktop and phone list each other's open windows, so neither side has to type a code or an address. The mobile client creates a non-exportable signing key. The registration binds the device to the Tailscale login that redeemed it, its expected HTTPS origin, secure cookie and public key. A host's own invitation is open to any login Tailscale Serve authenticated on that origin, because a tagged machine has no user of its own; `ox host pair --for LOGIN` binds one login where that matters. Opening the live connection requires signing a fresh challenge. Cross-origin requests, unpaired clients, expired challenges and revoked devices are refused. Revoking a device also disconnects its live stream. Unused pairings expire after 30 days. The PWA caches its shell assets. Transcripts, invitation secrets and approval content stay out of the offline cache.

The installed iPhone web app keeps its non-exportable key in IndexedDB. WebKit gives Home Screen installations their own storage. Open the installed app and use its camera to scan a fresh same-origin invitation. QR frames are decoded on the phone with the bundled jsQR 1.4.0 decoder. No external script or camera upload is involved. [WebKit storage behavior](https://webkit.org/blog/14787/webkit-features-in-safari-17-2/)

Expand Down
65 changes: 46 additions & 19 deletions src/desktop_launch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,39 @@ fn companion(program: &str) -> Result<PathBuf, RelayError> {
})
}

const HOST_COMMANDS: &[&str] = &[
"install",
"status",
"doctor",
"pair",
"pending",
"approve",
"deny",
"devices",
"policy",
"name",
"labels",
"project",
"update",
"revoke",
"terminal",
"restart",
"stop",
"uninstall",
];

const HOST_USAGE: &str = "Usage: ox host COMMAND
install start the session host at login
status show whether the host and its login service run
pair [--terminal] [--port HTTPS_PORT] [--listen-port LOCAL_PORT]
enable private Serve access and print a device invitation
enable private Serve access and print a QR code, address and code
pair --worker-host [--port HTTPS_PORT] [--listen-port LOCAL_PORT]
invite another OX host to launch workers here
pair --window [--for LOGIN] [--port HTTPS_PORT] [--listen-port LOCAL_PORT]
wait five minutes for any device on the tailnet to pair
pending list devices waiting to pair through a window
approve <request-id> accept one of them, registering the device
deny <request-id> refuse it
update [setting] install when idle or set automatic, download, manual, stable or dev
name [NAME] show or change this host’s display name
project [list | add DIR | remove DIR] manage registered checkouts
Expand All @@ -106,25 +132,8 @@ const HOST_USAGE: &str = "Usage: ox host COMMAND
Codex and Claude Code sessions and sign-ins are never touched.";

pub(crate) fn host(args: &[OsString]) -> Result<u8, RelayError> {
const COMMANDS: &[&str] = &[
"install",
"status",
"doctor",
"pair",
"devices",
"policy",
"name",
"labels",
"project",
"update",
"revoke",
"terminal",
"restart",
"stop",
"uninstall",
];
match args.first().and_then(|a| a.to_str()) {
Some(command) if COMMANDS.contains(&command) => {
Some(command) if HOST_COMMANDS.contains(&command) => {
Err(Command::new(companion("ox-host")?).args(args).exec().into())
}
None | Some("-h" | "--help" | "help") => {
Expand All @@ -134,3 +143,21 @@ pub(crate) fn host(args: &[OsString]) -> Result<u8, RelayError> {
_ => Err(HOST_USAGE.into()),
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn the_host_wrapper_delegates_the_pairing_commands_its_output_names() {
for command in [
"pair", "pending", "approve", "deny", "devices", "terminal", "revoke",
] {
assert!(
HOST_COMMANDS.contains(&command),
"ox host {command} is not delegated to ox-host"
);
assert!(HOST_USAGE.contains(command), "ox host help omits {command}");
}
}
}
6 changes: 4 additions & 2 deletions src/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,11 +238,13 @@ Checks and next steps
ox doctor Check files, providers and saved accounts. It prints
home: and a next: line with the command to run.
ox doctor --fix Repair what ox can repair; files are backed up first.
ox host pair [--port N] Pair a desktop or phone over your tailnet (default HTTPS port 8443).
ox host pair [--port N] Pair a desktop or phone over your tailnet (default HTTPS port 8443);
prints a QR code, address and 12-character code.
ox host pair --worker-host Create an invitation for a worker host.
ox host pair --terminal Include terminal access for the device that pairs.
ox host pair --for LOGIN Only that Tailscale login may redeem the invitation.
ox host pair --window Wait five minutes for a device on the tailnet to pair, with no code.
ox host pair --window Wait five minutes for any device on the tailnet to pair, with no code.
ox host pending List devices waiting to pair through a window; approve <id> or deny <id>.
ox host name [NAME] Show or change the name shown on paired devices.
ox host policy Show the host mode policy. Use set POLICY to change it.
ox host project add DIR Keep a checkout available on a headless host. Use list or remove DIR to manage it.
Expand Down
Loading