Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

fix(tailscale): tell a Headscale tailnet apart from signed out

AdityaUmaleee4482f4e929
diff --git a/electron/phone-link-routes.node-test.mjs b/electron/phone-link-routes.node-test.mjs
index 6a258ffe7a..ffc1e5bada 100644
--- a/electron/phone-link-routes.node-test.mjs
+++ b/electron/phone-link-routes.node-test.mjs
@@ -191,6 +191,15 @@ test("one status reading tells ready, signed out, not running and not allowed ap
assert.equal(tailscaleEnvironment({ PATH: "" }).TAILSCALE_BE_CLI, "1");
});
+test("a running node outside .ts.net (Headscale) is told apart from one signed out, and one without a name needs MagicDNS", () => {
+ const running = (DNSName) => JSON.stringify({ BackendState: "Running", Self: { DNSName, TailscaleIPs: ["100.64.0.5"] } });
+ assert.deepEqual(readTailscaleStatus(running("mini.example.internal.")), { state: "custom-name" });
+ assert.deepEqual(readTailscaleStatus(running("")), { state: "magicdns" });
+ assert.deepEqual(readTailscaleStatus(running("100.64.0.5.")), { state: "magicdns" });
+ assert.equal(readTailscaleStatus(running("mac.tail1.ts.net.")).state, "ready");
+ assert.deepEqual(readTailscaleStatus(JSON.stringify({ BackendState: "NeedsLogin", Self: { DNSName: "mini.example.internal." } })), { state: "signed-out" });
+});
+
test("a computer waiting for its tailnet's approval is told apart from one signed out", () => {
assert.deepEqual(readTailscaleStatus(JSON.stringify({ BackendState: "NeedsMachineAuth", Self: { DNSName: "mac.tail1.ts.net." } })), { state: "needs-approval" });
assert.deepEqual(readTailscaleStatus(JSON.stringify({ BackendState: "NeedsLogin" })), { state: "signed-out" });
diff --git a/electron/tailnet.mjs b/electron/tailnet.mjs
index f37081ce8c..79938a7368 100644
--- a/electron/tailnet.mjs
+++ b/electron/tailnet.mjs
@@ -4,6 +4,7 @@
const TAILSCALE_V6 = /^fd7a:115c:a1e0:/i;
const LABEL = "[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?";
const TAILNET_NAME = new RegExp(`^(?=.{1,253}$)${LABEL}(?:\\.${LABEL})*\\.ts\\.net$`);
+const NODE_NAME = new RegExp(`^(?=.{1,253}$)${LABEL}(?:\\.${LABEL})+$`);
/** An address as a socket reports it, without the IPv4-mapped prefix, zone or brackets. */
export const bareAddress = (address) => String(address ?? "").trim().replace(/^\[|\]$/g, "").replace(/^::ffff:(?=\d)/i, "").replace(/%.*$/, "").toLowerCase();
@@ -29,6 +30,13 @@ export function isTailnetName(host) {
return TAILNET_NAME.test(String(host ?? "").trim().toLowerCase().replace(/\.$/, ""));
}
+/** The name Tailscale itself gives this computer: a MagicDNS name, or on a tailnet run by a control server such as
+ * Headscale, a name under that tailnet's own suffix (`mini.example.internal`). Two labels at least, never an address. */
+function isNodeName(host) {
+ const name = String(host ?? "").trim().toLowerCase().replace(/\.$/, "");
+ return NODE_NAME.test(name) && !/^[0-9.]+$/.test(name);
+}
+
/** A host only a tailnet reaches: a MagicDNS name or an address in Tailscale's ranges. */
export const isTailnetHost = (host) => isTailnetName(host) || inTailscaleRange(host);
@@ -70,7 +78,7 @@ export function readTailscaleStatusJson(stdout) {
const addresses = (Array.isArray(self.TailscaleIPs) ? self.TailscaleIPs : []).map(bareAddress).filter(inTailscaleRange);
const certDomains = Array.isArray(parsed.CertDomains) && parsed.CertDomains.some((domain) => typeof domain === "string" && domain);
const capability = self.CapMap && typeof self.CapMap === "object" && Object.hasOwn(self.CapMap, "https");
- return { state, name: isTailnetName(dns) ? dns : null, addresses: addresses.sort((a, b) => Number(a.includes(":")) - Number(b.includes(":"))), https: Boolean(certDomains || capability) };
+ return { state, name: isNodeName(dns) ? dns : null, addresses: addresses.sort((a, b) => Number(a.includes(":")) - Number(b.includes(":"))), https: Boolean(certDomains || capability) };
}
const authority = (host, port) => (host.includes(":") ? `[${host}]` : host) + (port ? `:${port}` : "");
diff --git a/electron/tailnet.test.mjs b/electron/tailnet.test.mjs
index 340357647f..e6eda97f18 100644
--- a/electron/tailnet.test.mjs
+++ b/electron/tailnet.test.mjs
@@ -32,10 +32,11 @@ describe("reading tailscale status --json", () => {
expect(readTailscaleStatusJson(status({ BackendState: "NeedsMachineAuth" }))?.state).toBe("needs-approval");
});
- it("drops a name that is not a MagicDNS name and addresses outside Tailscale's ranges", () => {
- const read = readTailscaleStatusJson(status({}, { DNSName: "macmini.example.com.", TailscaleIPs: ["192.168.1.20", "100.64.0.7"] }));
- expect(read?.name).toBeNull();
+ it("keeps a Headscale tailnet's own name, and drops a name that is no host name and addresses outside Tailscale's ranges", () => {
+ const read = readTailscaleStatusJson(status({ MagicDNSSuffix: "example.internal", CertDomains: null }, { DNSName: "macmini.example.internal.", TailscaleIPs: ["192.168.1.20", "100.64.0.7"] }));
+ expect(read?.name).toBe("macmini.example.internal");
expect(read?.addresses).toEqual(["100.64.0.7"]);
+ for (const DNSName of ["macmini.", "100.64.0.7.", "mac mini.example.internal.", "-mac.example.internal.", ""]) expect(readTailscaleStatusJson(status({}, { DNSName }))?.name).toBeNull();
});
it("is null for the GUI's startup text and for anything not an object", () => {
diff --git a/electron/tailscale-check.mjs b/electron/tailscale-check.mjs
index 729a23506b..1a715e242f 100644
--- a/electron/tailscale-check.mjs
+++ b/electron/tailscale-check.mjs
@@ -45,8 +45,9 @@ const runStatus = (cli) =>
});
/** What one `tailscale status --json` says, in the row's words: ready (with this computer's MagicDNS name, its tailnet
- * addresses and whether the tailnet hands out HTTPS certificates), signed out, not running, waiting for the tailnet's
- * admin to approve this computer, or not allowed to ask. */
+ * addresses and whether the tailnet hands out HTTPS certificates), connected but without a MagicDNS name, connected
+ * under a name outside .ts.net (a Headscale tailnet's own suffix, which phones and the tailnet share cannot use yet),
+ * signed out, not running, waiting for the tailnet's admin to approve this computer, or not allowed to ask. */
export function readTailscaleStatus(stdout, stderr = "") {
const read = readTailscaleStatusJson(stdout);
if (!read) {
@@ -55,7 +56,9 @@ export function readTailscaleStatus(stdout, stderr = "") {
return { state: "not-running" };
}
if (read.state === "not-running" || read.state === "needs-approval") return { state: read.state };
- if (read.state !== "ready" || !read.name) return { state: "signed-out" };
+ if (read.state !== "ready") return { state: "signed-out" };
+ if (!read.name) return { state: "magicdns" };
+ if (!isTailnetName(read.name)) return { state: "custom-name" };
return { state: "ready", name: read.name, addresses: read.addresses, https: read.https };
}
diff --git a/src/components/PhoneDevicesSection.test.ts b/src/components/PhoneDevicesSection.test.ts
index d4bc1e2981..d2d2c9a7fd 100644
--- a/src/components/PhoneDevicesSection.test.ts
+++ b/src/components/PhoneDevicesSection.test.ts
@@ -218,6 +218,12 @@ describe("Tailscale pairing onboarding", () => {
expect(deriveTailscalePairingStatus({ enabled: false, tailscaleProblem: "not-installed" })).toMatchObject({ kind: "not-installed", title: "Tailscale isn't installed on this computer." });
expect(deriveTailscalePairingStatus({ enabled: false, tailscaleProblem: "signed-out" })).toMatchObject({ kind: "signed-out", title: "Open Tailscale and sign in, then try again." });
expect(deriveTailscalePairingStatus({ enabled: true, routes: tailscale({ on: true, since: 1, name: null }) }).kind).toBe("magicdns");
+ expect(deriveTailscalePairingStatus({ enabled: false, tailscaleProblem: "magicdns" })).toMatchObject({ kind: "magicdns", title: "Tailscale found, but MagicDNS is still needed" });
+ expect(deriveTailscalePairingStatus({ enabled: true, tailscaleProblem: "custom-name" })).toMatchObject({
+ kind: "magicdns",
+ title: "Tailscale is connected, but phone pairing and sharing with your other computers need a Tailscale name ending in .ts.net.",
+ detail: "Your tailnet gives its own names (Headscale, say). Pair the device over Same Wi-Fi instead.",
+ });
expect(deriveTailscalePairingStatus({ enabled: false, routes: tailscale({ on: true, since: 1, name: "mac.tail1234.ts.net" }) })).toMatchObject({
kind: "waiting",
title: "Ready on mac.tail1234.ts.net",
diff --git a/src/components/PhoneDevicesSection.tsx b/src/components/PhoneDevicesSection.tsx
index 267558d8e3..f8962dbdff 100644
--- a/src/components/PhoneDevicesSection.tsx
+++ b/src/components/PhoneDevicesSection.tsx
@@ -53,6 +53,8 @@ export function deriveTailscalePairingStatus(
if (state.tailscaleProblem === "needs-permission") return { kind: "signed-out", title: t("remote.tailscale.needsPermission", { app: productName() }), detail: "" };
if (state.tailscaleProblem === "needs-approval") return { kind: "signed-out", title: t("remote.tailscale.needsApproval"), detail: "" };
if (state.tailscaleProblem === "signed-out") return { kind: "signed-out", title: t("remote.tailscale.signIn"), detail: "" };
+ if (state.tailscaleProblem === "custom-name") return { kind: "magicdns", title: t("remote.tailscale.customName"), detail: t("remote.tailscale.customNameDetail") };
+ if (state.tailscaleProblem === "magicdns") return { kind: "magicdns", title: t("remote.tailscale.magicDns"), detail: t("remote.tailscale.magicDnsDetail") };
if (state.error) return { kind: "error", title: t("remote.status.attention"), detail: state.error };
const route = state.routes?.tailscale;
if (!route?.on) return { kind: "off", title: t("remote.status.off"), detail: "" };
diff --git a/src/components/devices/device-words.ts b/src/components/devices/device-words.ts
index 07a64e5fa6..41553a44d1 100644
--- a/src/components/devices/device-words.ts
+++ b/src/components/devices/device-words.ts
@@ -46,7 +46,7 @@ const DESKTOP: Record<NonNullable<Device["desktop"]>, LocaleKey> = {
const NETWORK_SHORT: Record<PrivateNetworkState, LocaleKey> = {
unknown: "devicesPage.network.short.unknown", "not-installed": "devicesPage.network.short.notInstalled", "no-cli": "devicesPage.network.short.noCli",
"signed-out": "devicesPage.network.short.signedOut", "not-running": "devicesPage.network.short.notRunning", "needs-approval": "devicesPage.network.short.needsApproval",
- "needs-permission": "devicesPage.network.short.needsPermission", magicdns: "devicesPage.network.short.magicdns", ready: "devicesPage.network.short.ready",
+ "needs-permission": "devicesPage.network.short.needsPermission", magicdns: "devicesPage.network.short.magicdns", "custom-name": "devicesPage.network.short.customName", ready: "devicesPage.network.short.ready",
};
/** Two or three words for the map. */
export const networkShort = (network: PrivateNetwork): string => (network.state === "ready" && !network.shared ? t("devicesPage.network.short.computersOff") : t(NETWORK_SHORT[network.state]));
@@ -65,6 +65,7 @@ export function networkLine(network: PrivateNetwork): string {
case "needs-approval": return t("devicesPage.network.line.needsApproval");
case "needs-permission": return t("remote.tailscale.needsPermission", { app: productName() });
case "magicdns": return t("devicesPage.network.line.magicdns");
+ case "custom-name": return `${t("remote.tailscale.customName")} ${t("remote.tailscale.customNameDetail")}`;
case "ready": return t(network.shared ? "devicesPage.network.line.readyShort" : "devicesPage.network.line.onFor", { name: shortName(network.name) });
}
}
diff --git a/src/lib/companion-types.ts b/src/lib/companion-types.ts
index 30a88f523d..4079a1ba95 100644
--- a/src/lib/companion-types.ts
+++ b/src/lib/companion-types.ts
@@ -45,7 +45,7 @@ export interface CompanionState {
/** Routes the update kept on that the person has not been told about yet. */
notices?: CompanionRoute[];
/** Why Tailscale could not be turned on or checked just now. */
- tailscaleProblem?: "not-installed" | "no-cli" | "not-running" | "needs-permission" | "needs-approval" | "signed-out";
+ tailscaleProblem?: "not-installed" | "no-cli" | "not-running" | "needs-permission" | "needs-approval" | "signed-out" | "magicdns" | "custom-name";
/** This computer's own server on the tailnet, for the person's other computers. Absent on older builds. */
tailnetShare?: TailnetShareState;
lan?: string | null;
diff --git a/src/lib/devices.test.ts b/src/lib/devices.test.ts
index 642da6b4d1..04687df93f 100644
--- a/src/lib/devices.test.ts
+++ b/src/lib/devices.test.ts
@@ -5,6 +5,7 @@ import { vpsServerId, type BotComputerRow } from "../../shared/bot-computers";
import { withBots } from "./device-bots";
import { buildDevices, groupByKind, kindFromLabel, nameKey, privateNetwork, type DeviceSources } from "./devices";
import { setLocale } from "./i18n";
+import { networkLine, networkShort } from "../components/devices/device-words";
import type { PublicPhone } from "./phones";
const NOW = 1_800_000_000_000;
@@ -221,4 +222,11 @@ describe("the private network", () => {
expect(privateNetwork({ routes: routes({ on: true, computers: true }) }, null)).toEqual({ state: "magicdns", name: null, shared: true });
expect(privateNetwork({ routes: routes({ on: true, name: "ada.tail1.ts.net", computers: true }) }, null)).toEqual({ state: "ready", name: "ada.tail1.ts.net", shared: true });
});
+ it("says a tailnet with its own names (Headscale) needs a .ts.net name, and to pair over Same Wi-Fi", () => {
+ setLocale("en");
+ const network = privateNetwork({ routes: routes({}) }, "custom-name")!;
+ expect(network.state).toBe("custom-name");
+ expect(networkShort(network)).toBe("Needs a .ts.net name");
+ expect(networkLine(network)).toContain("Pair the device over Same Wi-Fi instead.");
+ });
});
diff --git a/src/lib/devices.ts b/src/lib/devices.ts
index e077938906..41b71c3b4e 100644
--- a/src/lib/devices.ts
+++ b/src/lib/devices.ts
@@ -311,7 +311,7 @@ export function buildDevices(sources: DeviceSources): Device[] {
}
/** The private network as the map draws it. `unknown`: not asked yet, since the app asks Tailscale only when told to. */
-export type PrivateNetworkState = "unknown" | "not-installed" | "no-cli" | "signed-out" | "not-running" | "needs-approval" | "needs-permission" | "magicdns" | "ready";
+export type PrivateNetworkState = "unknown" | "not-installed" | "no-cli" | "signed-out" | "not-running" | "needs-approval" | "needs-permission" | "magicdns" | "custom-name" | "ready";
export interface PrivateNetwork {
state: PrivateNetworkState;
diff --git a/src/locales/de.json b/src/locales/de.json
index 043ee7a9ef..24113af0d8 100644
--- a/src/locales/de.json
+++ b/src/locales/de.json
@@ -1598,6 +1598,8 @@
"remote.tailscale.readyDetail": "Halte Tailscale auf dem Host und dem zu koppelnden Gerät verbunden.",
"remote.tailscale.magicDns": "Tailscale gefunden — MagicDNS fehlt noch",
"remote.tailscale.magicDnsDetail": "Aktiviere MagicDNS in Tailscale und prüf erneut, damit das Gerät einen sicheren Tailnet-Namen bekommt.",
+ "remote.tailscale.customName": "Tailscale ist verbunden, aber das Koppeln von Telefonen und das Teilen mit deinen anderen Computern brauchen einen Tailscale-Namen, der auf .ts.net endet.",
+ "remote.tailscale.customNameDetail": "Dein Tailnet vergibt eigene Namen (zum Beispiel Headscale). Kopple das Gerät stattdessen über „Gleiches WLAN“.",
"remote.title": "Fernzugriff",
"remote.checking": "Gerätezugriff wird geprüft…",
"remote.tailscaleSwitch.detail": "Aus, bis Sie es einschalten: {app} startet Tailscale nie von selbst und öffnet die Tailscale-App nie und meldet sie nie an. Eingeschaltet erreichen Geräte in Ihrem Tailnet diesen Rechner über seinen Tailnet-Namen.",
@@ -3762,6 +3764,7 @@
"devicesPage.network.short.needsApproval": "Wartet auf Freigabe",
"devicesPage.network.short.needsPermission": "Braucht eine Berechtigung",
"devicesPage.network.short.magicdns": "Braucht MagicDNS",
+ "devicesPage.network.short.customName": "Braucht einen .ts.net-Namen",
"devicesPage.network.short.ready": "An",
"devicesPage.network.line.unknown": "Tailscale verbindet deine Computer privat, egal wo sie sind. Richte es hier einmal ein.",
"devicesPage.network.line.notInstalled": "Installiere Tailscale auf diesem Computer und melde dich an. Diese Seite prüft erneut, wenn du zurückkommst.",
diff --git a/src/locales/en.json b/src/locales/en.json
index d2677fdf26..6d88852b6a 100644
--- a/src/locales/en.json
+++ b/src/locales/en.json
@@ -4935,6 +4935,8 @@
"remote.tailscale.readyDetail": "Keep Tailscale connected on the host and the device being paired.",
"remote.tailscale.magicDns": "Tailscale found, but MagicDNS is still needed",
"remote.tailscale.magicDnsDetail": "Turn on MagicDNS in Tailscale, then check again so the device gets a secure tailnet name.",
+ "remote.tailscale.customName": "Tailscale is connected, but phone pairing and sharing with your other computers need a Tailscale name ending in .ts.net.",
+ "remote.tailscale.customNameDetail": "Your tailnet gives its own names (Headscale, say). Pair the device over Same Wi-Fi instead.",
"remote.title": "Remote access",
"remote.checking": "Checking device access…",
"remote.tailscaleSwitch.detail": "Off until you turn it on: {app} never runs Tailscale by itself, and never opens or signs in the Tailscale app. On, devices on your tailnet reach this computer by its tailnet name.",
@@ -11131,6 +11133,7 @@
"devicesPage.network.short.needsApproval": "Waiting for approval",
"devicesPage.network.short.needsPermission": "Needs permission",
"devicesPage.network.short.magicdns": "Needs MagicDNS",
+ "devicesPage.network.short.customName": "Needs a .ts.net name",
"devicesPage.network.short.ready": "On",
"devicesPage.network.line.unknown": "Tailscale connects your computers privately, wherever they are. Set it up once here.",
"devicesPage.network.line.notInstalled": "Install Tailscale on this computer and sign in. This page checks again when you come back to it.",
diff --git a/src/locales/pt-br.json b/src/locales/pt-br.json
index 2de8f01381..d2f5f9b396 100644
--- a/src/locales/pt-br.json
+++ b/src/locales/pt-br.json
@@ -4617,6 +4617,8 @@
"remote.tailscale.readyDetail": "Mantenha o Tailscale conectado neste computador e no dispositivo que será pareado.",
"remote.tailscale.magicDns": "Tailscale encontrado, mas ainda falta o MagicDNS",
"remote.tailscale.magicDnsDetail": "Ligue o MagicDNS no Tailscale e verifique novamente, para o dispositivo receber um nome seguro na tailnet.",
+ "remote.tailscale.customName": "O Tailscale está conectado, mas parear o celular e compartilhar com seus outros computadores precisam de um nome do Tailscale terminado em .ts.net.",
+ "remote.tailscale.customNameDetail": "Sua tailnet dá nomes próprios (o Headscale, por exemplo). Pareie o dispositivo por “Mesmo Wi-Fi”.",
"remote.title": "Acesso remoto",
"remote.checking": "Verificando o acesso do dispositivo…",
"remote.tailscaleSwitch.detail": "Desligado até você ligar: o {app} nunca executa o Tailscale sozinho, nem abre ou faz login no app do Tailscale. Ligado, os dispositivos da sua tailnet chegam a este computador pelo nome dele na tailnet.",
@@ -11058,6 +11060,7 @@
"devicesPage.network.short.needsApproval": "Aguardando aprovação",
"devicesPage.network.short.needsPermission": "Precisa de permissão",
"devicesPage.network.short.magicdns": "Precisa do MagicDNS",
+ "devicesPage.network.short.customName": "Precisa de um nome .ts.net",
"devicesPage.network.short.ready": "Ligado",
"devicesPage.network.line.unknown": "O Tailscale conecta seus computadores de forma privada, onde quer que estejam. Configure uma vez aqui.",
"devicesPage.network.line.notInstalled": "Instale o Tailscale neste computador e entre. Esta página verifica de novo quando você voltar.",
diff --git a/src/locales/source-hashes.json b/src/locales/source-hashes.json
index 5f07311b76..d54f36bc9a 100644
--- a/src/locales/source-hashes.json
+++ b/src/locales/source-hashes.json
@@ -1014,6 +1014,9 @@
"remote.tailscale.readyDetail": "b116e483ecfafa10f5c3f7579c2f8aaec926c15006682785970a7e4269e92ff2",
"remote.tailscale.magicDns": "2b098b1a5fdaa324edada3e8d79477a3b8766ec10e7fb308d9aac7bf8f05a0c4",
"remote.tailscale.magicDnsDetail": "8cabd29657f283b8323f334c42af9e9fdf2524f717c6410058e46f697b00ad68",
+ "remote.tailscale.customName": "fc2e906e4f80d4e2e4bb62cdbb2d491131653bae049d3090dc86a8355e83dbbd",
+ "remote.tailscale.customNameDetail": "bc6f5ba67e7eeb0819a030124c319a3b1190cdf5b07e89f651c9d93251cba5a5",
+ "devicesPage.network.short.customName": "a0fe7fc32771f2cb9be1c4b56b4fd983150b9db874b8953a54f011e6a721b692",
"remote.title": "66354a1d3225edbf01146504d06aaea1242dcf50424054c3001fc6fa2ddece0f",
"remote.checking": "48a0c93645f8bb8c995e1aa1471cdd2a92a0426ce5b7264b0aa046eb71827594",
"remote.checkAgain": "fb7099ad8e818d42eceefe0d97c824fd54ddb0eeef54c263ec72c77d39198ac9",
@@ -31012,6 +31015,9 @@
"remote.tailscale.readyDetail": "b116e483ecfafa10f5c3f7579c2f8aaec926c15006682785970a7e4269e92ff2",
"remote.tailscale.magicDns": "2b098b1a5fdaa324edada3e8d79477a3b8766ec10e7fb308d9aac7bf8f05a0c4",
"remote.tailscale.magicDnsDetail": "8cabd29657f283b8323f334c42af9e9fdf2524f717c6410058e46f697b00ad68",
+ "remote.tailscale.customName": "fc2e906e4f80d4e2e4bb62cdbb2d491131653bae049d3090dc86a8355e83dbbd",
+ "remote.tailscale.customNameDetail": "bc6f5ba67e7eeb0819a030124c319a3b1190cdf5b07e89f651c9d93251cba5a5",
+ "devicesPage.network.short.customName": "a0fe7fc32771f2cb9be1c4b56b4fd983150b9db874b8953a54f011e6a721b692",
"remote.title": "66354a1d3225edbf01146504d06aaea1242dcf50424054c3001fc6fa2ddece0f",
"remote.checking": "48a0c93645f8bb8c995e1aa1471cdd2a92a0426ce5b7264b0aa046eb71827594",
"remote.checkAgain": "fb7099ad8e818d42eceefe0d97c824fd54ddb0eeef54c263ec72c77d39198ac9",