Files
unkernel/js/node/tailscale-args.ts
Pooya Parsa d382f7fa9b js: add a pure-JS Tailscale network device (work in progress)
The guest joins a tailnet from Node or the page: ts2021 control over
WebSocket, DERP relays, WireGuard and the packet filter in JS, loaded as
a separate chunk only when the option is used. SDK net option, CLI
--tailscale* flags and a page panel. Relay only; exit nodes, IPv6 and
real peer traffic are not covered yet.
2026-11-28 22:06:18 +00:00

29 lines
1.4 KiB
TypeScript

// SPDX-License-Identifier: MIT
// Copyright (C) 2026 Pooya Parsa <pooya@pi0.io>
// The CLI's --tailscale* flags as a net.tailscale spec (without the saved
// state, which the CLI reads from --tailscale-state itself). Tailscale is
// on only when a --tailscale* flag asks for it: TS_AUTHKEY in the
// environment supplies the key then and never turns it on by itself (many
// machines with Tailscale tooling export one).
import type { TailscaleSpec } from "../core/devices.ts";
/** The flags that ask for Tailscale (any of them). */
export const TAILSCALE_FLAGS = ["tailscale", "tailscale-authkey", "tailscale-state", "tailscale-login-server", "tailscale-hostname", "tailscale-accept-routes", "tailscale-rewrite"];
/** The spec for these arguments, or undefined when no --tailscale* flag is there. */
export function tailscaleArgs(args: readonly string[], env: Record<string, string | undefined>): TailscaleSpec | undefined {
if (!TAILSCALE_FLAGS.some((f) => args.includes(`--${f}`))) return undefined;
const opt = (name: string) => {
const i = args.indexOf(`--${name}`);
return i >= 0 ? args[i + 1] : undefined;
};
return {
authKey: opt("tailscale-authkey") ?? (env.TS_AUTHKEY || undefined),
controlURL: opt("tailscale-login-server"),
hostname: opt("tailscale-hostname") ?? "unkernel",
acceptRoutes: args.includes("--tailscale-accept-routes"),
guestAddress: !args.includes("--tailscale-rewrite"),
};
}