feat: direct TCP URI with SSL toggle and optional password auth (#635)
* feat: direct TCP URI with SSL toggle and optional password auth Replaces the heuristic-driven direct-connection model with a user-controlled one. The Add Host dialog now exposes structured Host, Port, "Use SSL", and masked Password fields that compose the canonical `tcp://host:port?ssl=true&password=xxx` URI used as the storage form. The daemon gains optional shared-secret auth: `Authorization: Bearer <pw>` on HTTP and `Sec-WebSocket-Protocol: paseo.bearer.<pw>` on the WS upgrade (browser WebSocket can't set custom headers). Configured via config.json `auth.password` or `PASEO_PASSWORD` env. Off by default — old clients keep working unchanged. The `port === 443` heuristic for ws/wss is gone; the explicit `useTls` flag drives scheme selection at every call site. * fix: stabilize direct tcp auth ci checks * fix: restore fetch stub in bootstrap smoke test * fix(app): collapse Advanced section in add-host modal * feat(server): hash daemon password in config * fix: update lockfile signatures and Nix hash * Improve direct TCP auth failures * Fix workspace cwd updates after rebase --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
This commit is contained in:
co-authored by
github-actions[bot] <github-actions[bot]@users.noreply.github.com>
parent
30f7842e8f
commit
088a6c14c0
@@ -1,10 +1,14 @@
|
||||
import { existsSync, readFileSync } from "node:fs";
|
||||
import {
|
||||
loadConfig,
|
||||
resolvePaseoHome,
|
||||
DaemonClient,
|
||||
buildDaemonWebSocketUrl,
|
||||
buildRelayWebSocketUrl,
|
||||
loadConfig,
|
||||
normalizeHostPort,
|
||||
parseConnectionUri,
|
||||
parseConnectionOfferFromUrl,
|
||||
DaemonClient,
|
||||
resolvePaseoHome,
|
||||
shouldUseTlsForDefaultHostedRelay,
|
||||
type ConnectionOffer,
|
||||
type WebSocketLike,
|
||||
} from "@getpaseo/server";
|
||||
@@ -46,6 +50,27 @@ export function normalizeDaemonHost(raw: string): string | null {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (trimmed.startsWith("tcp://")) {
|
||||
try {
|
||||
const parsed = parseConnectionUri(trimmed);
|
||||
const endpoint = normalizeHostPort(
|
||||
parsed.isIpv6 ? `[${parsed.host}]:${parsed.port}` : `${parsed.host}:${parsed.port}`,
|
||||
);
|
||||
const query = new URLSearchParams();
|
||||
if (parsed.useTls) {
|
||||
query.set("ssl", "true");
|
||||
}
|
||||
if (parsed.password) {
|
||||
query.set("password", parsed.password);
|
||||
}
|
||||
const queryString = query.toString();
|
||||
const suffix = queryString ? `?${queryString}` : "";
|
||||
return `tcp://${endpoint}${suffix}`;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
trimmed.startsWith("unix://") ||
|
||||
trimmed.startsWith("pipe://") ||
|
||||
@@ -174,21 +199,37 @@ export function resolveDaemonTarget(host: string): DaemonTarget {
|
||||
};
|
||||
}
|
||||
|
||||
if (trimmed.startsWith("tcp://")) {
|
||||
const parsed = parseConnectionUri(trimmed);
|
||||
const endpoint = normalizeHostPort(
|
||||
parsed.isIpv6 ? `[${parsed.host}]:${parsed.port}` : `${parsed.host}:${parsed.port}`,
|
||||
);
|
||||
return {
|
||||
type: "tcp",
|
||||
url: buildDaemonWebSocketUrl(endpoint, { useTls: parsed.useTls }),
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
type: "tcp",
|
||||
url: `ws://${trimmed}/ws`,
|
||||
};
|
||||
}
|
||||
|
||||
export function resolveDaemonPassword(host: string): string | undefined {
|
||||
const trimmed = host.trim();
|
||||
return trimmed.startsWith("tcp://") ? parseConnectionUri(trimmed).password : undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a WebSocket factory that works in Node.js
|
||||
*/
|
||||
function createNodeWebSocketFactory() {
|
||||
return (
|
||||
url: string,
|
||||
options?: { headers?: Record<string, string>; socketPath?: string },
|
||||
options?: { headers?: Record<string, string>; protocols?: string[]; socketPath?: string },
|
||||
): WebSocketLike => {
|
||||
return new WebSocket(url, {
|
||||
return new WebSocket(url, options?.protocols, {
|
||||
headers: options?.headers,
|
||||
...(options?.socketPath ? { socketPath: options.socketPath } : {}),
|
||||
}) as unknown as WebSocketLike;
|
||||
@@ -201,6 +242,7 @@ function createNodeWebSocketFactory() {
|
||||
*/
|
||||
async function tryConnectHost(
|
||||
host: string,
|
||||
password: string | undefined,
|
||||
clientId: string,
|
||||
timeout: number,
|
||||
nodeWebSocketFactory: ReturnType<typeof createNodeWebSocketFactory>,
|
||||
@@ -211,10 +253,15 @@ async function tryConnectHost(
|
||||
clientId,
|
||||
clientType: "cli",
|
||||
appVersion: resolveCliVersion(),
|
||||
password,
|
||||
connectTimeoutMs: timeout,
|
||||
webSocketFactory: (url: string, config?: { headers?: Record<string, string> }) =>
|
||||
webSocketFactory: (
|
||||
url: string,
|
||||
config?: { headers?: Record<string, string>; protocols?: string[] },
|
||||
) =>
|
||||
nodeWebSocketFactory(url, {
|
||||
headers: config?.headers,
|
||||
protocols: config?.protocols,
|
||||
...(target.type === "ipc" ? { socketPath: target.socketPath } : {}),
|
||||
}),
|
||||
reconnect: { enabled: false },
|
||||
@@ -239,6 +286,7 @@ async function connectViaRelayOffer(
|
||||
endpoint: offer.relay.endpoint,
|
||||
serverId: offer.serverId,
|
||||
role: "client",
|
||||
useTls: shouldUseTlsForDefaultHostedRelay(offer.relay.endpoint),
|
||||
});
|
||||
|
||||
const client = new DaemonClient({
|
||||
@@ -247,8 +295,10 @@ async function connectViaRelayOffer(
|
||||
clientType: "cli",
|
||||
appVersion: resolveCliVersion(),
|
||||
connectTimeoutMs: timeout,
|
||||
webSocketFactory: (target: string, config?: { headers?: Record<string, string> }) =>
|
||||
nodeWebSocketFactory(target, { headers: config?.headers }),
|
||||
webSocketFactory: (
|
||||
target: string,
|
||||
config?: { headers?: Record<string, string>; protocols?: string[] },
|
||||
) => nodeWebSocketFactory(target, { headers: config?.headers, protocols: config?.protocols }),
|
||||
e2ee: { enabled: true, daemonPublicKeyB64: offer.daemonPublicKeyB64 },
|
||||
reconnect: { enabled: false },
|
||||
});
|
||||
@@ -293,8 +343,11 @@ export async function connectToDaemon(options?: ConnectOptions): Promise<DaemonC
|
||||
throw new Error(`Unable to connect to Paseo daemon via ${hosts.join(", ")}`);
|
||||
}
|
||||
const host = hosts[index] as string;
|
||||
const result = await tryConnectHost(host, clientId, timeout, nodeWebSocketFactory);
|
||||
if ("client" in result) return result.client;
|
||||
const password = resolveDaemonPassword(host);
|
||||
const result = await tryConnectHost(host, password, clientId, timeout, nodeWebSocketFactory);
|
||||
if ("client" in result) {
|
||||
return result.client;
|
||||
}
|
||||
return tryNext(index + 1, result.error);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ import type { Command } from "commander";
|
||||
|
||||
const JSON_OPTION_DESCRIPTION = "Output in JSON format";
|
||||
const DAEMON_HOST_OPTION_DESCRIPTION =
|
||||
"Daemon host target (default: local socket/pipe, then localhost:6767)";
|
||||
"Daemon host target: host:port or tcp://host:port?ssl=true&password=secret (default: local socket/pipe, then localhost:6767)";
|
||||
|
||||
export function collectMultiple(value: string, previous: string[]): string[] {
|
||||
return previous.concat([value]);
|
||||
|
||||
Reference in New Issue
Block a user