Skip to content

DeepSeek Harness Tauri 桌面版 | Only 8mb installer, zero environment setup, preset plugins, Windows / macOS / Linux.

fix(ssh): 隧道 URL 携带 launch token——远端 web 免 401 鉴权页

Menghuan191870b802a06928
diff --git a/packages/dsh-tauri-ssh/src/host/service/bootstrap.ts b/packages/dsh-tauri-ssh/src/host/service/bootstrap.ts
index 0e0743be..42329329 100644
--- a/packages/dsh-tauri-ssh/src/host/service/bootstrap.ts
+++ b/packages/dsh-tauri-ssh/src/host/service/bootstrap.ts
@@ -508,6 +508,17 @@ export function layoutDshEntry(plan?: RemoteInstallPlan): string {
* @param plan - the resolved install plan (chooses the DSH entry).
* @returns the shell command line that starts (or restarts) the instance.
*/
+/**
+ * The launch-token lookup command: `dsh web` prints its authenticated URL
+ * (`…/?token=…`) to stdout, which the start command appends to the remote
+ * web log. The last match wins (a restarted instance appends a fresh line);
+ * prints nothing when the log has no token (callers fall back to the bare
+ * tunnel URL). Token charset is the URL-safe base the launch token uses.
+ */
+export function remoteWebTokenCommand(): string {
+ return `grep -oE 'token=[A-Za-z0-9._~-]+' "$HOME/${REMOTE_WEB_LOG}" 2>/dev/null | tail -n 1 | cut -d= -f2`
+}
+
export function startCommandFor(profile: MachineProfile, plan?: RemoteInstallPlan): string {
if (profile.startCommand !== undefined)
return `mkdir -p "$HOME/.dsh" && ( ${profile.startCommand} >>"$HOME/${REMOTE_WEB_LOG}" 2>&1 < /dev/null & ) &`
diff --git a/packages/dsh-tauri-ssh/src/host/service/manager.ts b/packages/dsh-tauri-ssh/src/host/service/manager.ts
index 293ca7c5..006d1a5f 100644
--- a/packages/dsh-tauri-ssh/src/host/service/manager.ts
+++ b/packages/dsh-tauri-ssh/src/host/service/manager.ts
@@ -17,7 +17,7 @@ import { homedir } from 'node:os'
import process from 'node:process'
import { join } from 'pathe'
import { MachineId, SshError } from '../types/index'
-import { checkMissingCommand, credentialsCopyCommand, describeExecFailure, ensureRemoteInstance, firstLineOf, missingComponentsOf, planRemoteInstall, readEnvCredentials, REMOTE_ROOT, runInstallScript, skippedVerificationSummary } from './bootstrap'
+import { checkMissingCommand, credentialsCopyCommand, describeExecFailure, ensureRemoteInstance, firstLineOf, missingComponentsOf, planRemoteInstall, readEnvCredentials, REMOTE_ROOT, remoteWebTokenCommand, runInstallScript, skippedVerificationSummary } from './bootstrap'
import { fingerprintHostKey } from './host-keys'
/** One machine's live connection state. */
@@ -263,6 +263,23 @@ export class SshManager {
return state
}
+ /**
+ * Best-effort launch-token read from the remote web log. No exec timeout:
+ * a timeout in this session implementation closes the whole connection,
+ * and a slow grep must never kill a healthy link — any failure simply
+ * degrades to the bare tunnel URL.
+ */
+ private async readRemoteWebToken(session: SshSession): Promise<string | undefined> {
+ try {
+ const result = await session.exec(remoteWebTokenCommand())
+ const token = result.stdout.trim()
+ return token === '' ? undefined : token
+ }
+ catch {
+ return undefined
+ }
+ }
+
/** TOFU gate: accept a known fingerprint, remember a first sight, reject a mismatch. */
private async checkHostKey(machineId: MachineId, hostKey: Buffer): Promise<boolean> {
const fingerprint = fingerprintHostKey(hostKey)
@@ -340,9 +357,13 @@ export class SshManager {
await tunnel.close().catch(() => undefined)
throw new AttemptCancelled()
}
+ // dsh web 的 launch token:隧道 URL 带上 ?token= 后,首次加载即 mint
+ // 该 authority 的鉴权 cookie(303 → /),壳层 iframe 与新窗口免登录;
+ // 读不到(实例非本插件拉起/日志无记录)退化为裸 URL(401 页自行呈现)。
+ const webToken = await this.readRemoteWebToken(session)
const link: SshLink = {
machineId,
- tunnelBaseUrl: `http://127.0.0.1:${tunnel.localPort}`,
+ tunnelBaseUrl: `http://127.0.0.1:${tunnel.localPort}${webToken === undefined ? '' : `/?token=${webToken}`}`,
}
state.session = session
state.tunnel = tunnel