mirror of
https://github.com/pithings/unkernel.git
synced 2026-12-02 01:09:49 +08:00
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.
29 lines
1.4 KiB
TypeScript
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"),
|
|
};
|
|
}
|