dsh-remote 0.8.80 → 0.8.81
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +1 -1
- package/README.md +1 -1
- package/lib/client.js +1 -38
- package/lib/http-transport.js +6 -1
- package/lib/index.js +84 -2
- package/lib/remote-shell-child.cjs +58 -2
- package/lib/remote-shell.js +118 -1
- package/package.json +1 -1
package/README.en.md
CHANGED
|
@@ -333,7 +333,7 @@ Deploying to a product profile is a separate, explicit action (`./sync.sh`) for
|
|
|
333
333
|
| `webAttachDshHome` | string | `''` | `DSH_HOME` exported on the remote when attaching; empty reuses the remote user's own harness home |
|
|
334
334
|
| `webAttachWaitSeconds` | int | `45` | how long to wait for a freshly started remote `dsh web` to print its launch token |
|
|
335
335
|
| `localTools` | string | `bootstrap` | which `rw_*` tools a LOCAL session (cwd outside every remote mirror) sees (issue #63): `bootstrap` keeps only the configuration loop `rw_machines`/`rw_connect`/`rw_pick_workspace` (the other 19 refuse a local session with "this session is LOCAL", so exposing them just wastes schema budget); `none` hides all `rw_*` (remote setup happens via the settings page only); `all` restores the legacy full surface. REMOTE sessions (cwd inside a mirror) always see everything; an invalid value degrades to `bootstrap` |
|
|
336
|
-
| `telemetry` | bool | `true` | anonymous install heartbeat (daily-active statistics, at most once a day; the payload is a plugin-specific HMAC pseudonym + version, no machine info). `false` disables it
|
|
336
|
+
| `telemetry` | bool | `true` | anonymous install heartbeat (daily-active statistics, at most once a day; the payload is a plugin-specific HMAC pseudonym + version, no machine info). `false` disables it (the admin path); the 0.8.78 settings checkbox was removed in 0.8.81 — a previously persisted user opt-out is still honored |
|
|
337
337
|
| `remoteTerminalDefault` | bool | `true` | make the shell menu's "remote ssh" launcher the terminal's DEFAULT shell when neither the host (`config.shell`) nor the user (a remembered menu choice) has picked one: a session rooted in a remote mirror opens a terminal already sshed into the remote workspace, any other session transparently falls back to a local shell (issue #55); `false` keeps it menu-only |
|
|
338
338
|
| `tui` | bool | `true` | master switch for the TUI (dsh-tui) layer; `false` registers no `/dsh-remote` page, workspace provider or status field |
|
|
339
339
|
| `tuiProviderListRecent` | bool | `true` | list each machine's recent remote projects in the TUI workspace picker |
|
package/README.md
CHANGED
|
@@ -308,7 +308,7 @@ scripts/dev-run.sh --status # 是否在运行
|
|
|
308
308
|
| `webAttachDshHome` | string | `''` | 远端启动时导出的 `DSH_HOME`;留空则复用远端用户自己的 harness home |
|
|
309
309
|
| `webAttachWaitSeconds` | int | `45` | 等待远端 `dsh web` 打印启动令牌的秒数 |
|
|
310
310
|
| `localTools` | string | `bootstrap` | 本地 session(cwd 不在远程镜像里)暴露哪些 `rw_*` 工具(issue #63):`bootstrap`=只暴露配置闭环 `rw_machines`/`rw_connect`/`rw_pick_workspace`(其余 19 个在本地 session 必然报 "this session is LOCAL",暴露只是白占 schema);`none`=完全不暴露 `rw_*`(远程配置只能走设置页);`all`=旧的 full 暴露。远程 session(cwd 在镜像里)不受影响,始终全量;非法值按 `bootstrap` 处理 |
|
|
311
|
-
| `telemetry` | bool | `true` | 匿名安装心跳(日活统计,每天至多一次;内容为插件专属 HMAC 伪名+版本号,不含机器信息)。`false`
|
|
311
|
+
| `telemetry` | bool | `true` | 匿名安装心跳(日活统计,每天至多一次;内容为插件专属 HMAC 伪名+版本号,不含机器信息)。`false` 关闭(管理员路径);0.8.78 曾有的设置页复选框已于 0.8.81 移除——已存在的用户关闭选择仍被尊重 |
|
|
312
312
|
| `remoteTerminalDefault` | bool | `true` | 让 shell 菜单里的「remote ssh」启动器成为终端**默认 shell**(宿主未配置、用户未手动选择时):远程会话开终端即落到远端工作目录,本地会话自动回落本地 shell(issue #55);`false` 则只保留菜单项 |
|
|
313
313
|
| `tui` | bool | `true` | TUI 适配层(dsh-tui)总开关;`false` 时不注册 `/dsh-remote` 页面、工作区 provider 与状态行字段 |
|
|
314
314
|
| `tuiProviderListRecent` | bool | `true` | TUI 工作区选择器里是否列出每台机器最近的远程项目 |
|
package/lib/client.js
CHANGED
|
@@ -251,8 +251,6 @@ window.__ModuleLoader__.load({
|
|
|
251
251
|
'settings.updateNow': '立即更新',
|
|
252
252
|
'settings.updateMode': '更新模式:',
|
|
253
253
|
'settings.explorerAutoOpen': '打开远程工作区时,自动在侧边栏展开「远程文件」(需安装 better-sidebar)',
|
|
254
|
-
'settings.telemetry': '匿名使用统计(每日一次的安装心跳;不含任何机器信息,可随时关闭)',
|
|
255
|
-
'settings.telemetryHint': '上报内容只有插件专属的 HMAC 伪名与版本号;关闭后立即不再发送',
|
|
256
254
|
'settings.updateManual': '手动',
|
|
257
255
|
'settings.updateAuto': '自动',
|
|
258
256
|
'settings.updateOff': '关闭',
|
|
@@ -559,8 +557,7 @@ window.__ModuleLoader__.load({
|
|
|
559
557
|
'settings.updateNow': 'Update now',
|
|
560
558
|
'settings.updateMode': 'Update mode:',
|
|
561
559
|
'settings.explorerAutoOpen': 'Auto-open the Remote Files sidebar tab for remote workspaces (via better-sidebar)',
|
|
562
|
-
|
|
563
|
-
'settings.telemetryHint': 'Only a plugin-specific HMAC pseudonym and the version number are sent; takes effect immediately',
|
|
560
|
+
|
|
564
561
|
'settings.updateManual': 'Manual',
|
|
565
562
|
'settings.updateAuto': 'Auto',
|
|
566
563
|
'settings.updateOff': 'Off',
|
|
@@ -1266,12 +1263,6 @@ window.__ModuleLoader__.load({
|
|
|
1266
1263
|
// Issue #78: initial value comes from localStorage, so a user's choice
|
|
1267
1264
|
// survives restarts (the bug was: the panel popped again every restart).
|
|
1268
1265
|
const [explorerAuto, setExplorerAuto] = React.useState(() => explorerAutoOpenEnabled())
|
|
1269
|
-
// Anonymous-heartbeat toggle: null = not loaded yet (checkbox disabled).
|
|
1270
|
-
// Effective value is host-side (user override > profile config).
|
|
1271
|
-
const [telemetryOn, setTelemetryOn] = React.useState(null)
|
|
1272
|
-
React.useEffect(() => {
|
|
1273
|
-
api('GET', '/dsh-remote/telemetry').then((r) => setTelemetryOn(!(r && r.enabled === false))).catch(() => {})
|
|
1274
|
-
}, [])
|
|
1275
1266
|
// One applier per toggle, shared by the native-checkbox fallback (event
|
|
1276
1267
|
// semantics) and the host Switch (bare-boolean callback), so both paths
|
|
1277
1268
|
// behave identically.
|
|
@@ -1279,12 +1270,6 @@ window.__ModuleLoader__.load({
|
|
|
1279
1270
|
setExplorerAuto(on)
|
|
1280
1271
|
try { window.localStorage.setItem(EXPLORER_AUTO_OPEN_KEY, on ? '1' : '0') } catch { /* private mode: choice lasts this session only */ }
|
|
1281
1272
|
}
|
|
1282
|
-
const applyTelemetryEnabled = (on) => {
|
|
1283
|
-
setTelemetryOn(on) // optimistic; the host answer re-syncs below
|
|
1284
|
-
api('POST', '/dsh-remote/telemetry', { enabled: on })
|
|
1285
|
-
.then((r) => setTelemetryOn(!(r && r.enabled === false)))
|
|
1286
|
-
.catch(() => setTelemetryOn(null))
|
|
1287
|
-
}
|
|
1288
1273
|
const checkUpdate = (quiet) => {
|
|
1289
1274
|
if (updBusy) return
|
|
1290
1275
|
setUpdBusy(true); setUpdMsg('')
|
|
@@ -2022,28 +2007,6 @@ window.__ModuleLoader__.load({
|
|
|
2022
2007
|
}),
|
|
2023
2008
|
tr('settings.explorerAutoOpen'),
|
|
2024
2009
|
),
|
|
2025
|
-
HostSwitch
|
|
2026
|
-
? React.createElement('span', { style: { display: 'inline-flex', gap: 6, alignItems: 'center', opacity: 0.85 }, title: tr('settings.telemetryHint') },
|
|
2027
|
-
React.createElement('span', { 'data-testid': 'telemetry-toggle', style: { display: 'inline-flex' } },
|
|
2028
|
-
React.createElement(HostSwitch, {
|
|
2029
|
-
checked: telemetryOn === true,
|
|
2030
|
-
disabled: telemetryOn === null,
|
|
2031
|
-
label: tr('settings.telemetry'),
|
|
2032
|
-
title: tr('settings.telemetryHint'),
|
|
2033
|
-
onChange: (on) => { if (telemetryOn !== null) applyTelemetryEnabled(on === true) },
|
|
2034
|
-
})),
|
|
2035
|
-
React.createElement('span', {
|
|
2036
|
-
style: { cursor: telemetryOn === null ? 'default' : 'pointer' },
|
|
2037
|
-
onClick: () => { if (telemetryOn !== null) applyTelemetryEnabled(telemetryOn !== true) },
|
|
2038
|
-
}, tr('settings.telemetry')),
|
|
2039
|
-
)
|
|
2040
|
-
: React.createElement('label', { style: { display: 'flex', gap: 6, alignItems: 'center', cursor: telemetryOn === null ? 'default' : 'pointer', opacity: 0.85 }, title: tr('settings.telemetryHint') },
|
|
2041
|
-
React.createElement('input', {
|
|
2042
|
-
type: 'checkbox', checked: telemetryOn === true, disabled: telemetryOn === null, 'data-testid': 'telemetry-toggle',
|
|
2043
|
-
onChange: (e) => applyTelemetryEnabled(!!(e && e.target && e.target.checked)),
|
|
2044
|
-
}),
|
|
2045
|
-
tr('settings.telemetry'),
|
|
2046
|
-
),
|
|
2047
2010
|
),
|
|
2048
2011
|
upd && upd.pendingReload
|
|
2049
2012
|
? React.createElement('div', { style: { marginTop: 6, fontSize: 12, color: T.warn } },
|
package/lib/http-transport.js
CHANGED
|
@@ -142,7 +142,12 @@ export function guardRoute(route, connectionOf) {
|
|
|
142
142
|
return {
|
|
143
143
|
...route,
|
|
144
144
|
handler: async (req, res) => {
|
|
145
|
-
|
|
145
|
+
// `fence: 'bearer'` routes authenticate with their OWN credential (a
|
|
146
|
+
// per-boot token from a 0600 file) and serve non-browser local processes
|
|
147
|
+
// (the askpass helper) — the Connection fence would 401 them for lacking
|
|
148
|
+
// the browser cookie. They still get the fail-closed fallback fence, so a
|
|
149
|
+
// cross-site page (which cannot read the token file) stays locked out.
|
|
150
|
+
const connection = route.fence === 'bearer' ? undefined : connectionOf()
|
|
146
151
|
const rejection = typeof connection?.requestRejection === 'function'
|
|
147
152
|
? connection.requestRejection(req)
|
|
148
153
|
: fallbackRejection(req)
|
package/lib/index.js
CHANGED
|
@@ -21,7 +21,8 @@
|
|
|
21
21
|
import z from '@deepseek-ai/schemastery'
|
|
22
22
|
import { defineTool } from '@deepseek-ai/dsh-tools'
|
|
23
23
|
import { execFile } from 'node:child_process'
|
|
24
|
-
import { readFileSync, mkdirSync, writeFileSync, existsSync, readdirSync, statSync, renameSync, copyFileSync, appendFileSync, watch, rmSync } from 'node:fs'
|
|
24
|
+
import { readFileSync, mkdirSync, writeFileSync, existsSync, readdirSync, statSync, renameSync, copyFileSync, appendFileSync, watch, rmSync, chmodSync } from 'node:fs'
|
|
25
|
+
import { createHash, randomBytes, timingSafeEqual } from 'node:crypto'
|
|
25
26
|
import { homedir } from 'node:os'
|
|
26
27
|
import path from 'node:path'
|
|
27
28
|
import { fileURLToPath } from 'node:url'
|
|
@@ -52,7 +53,7 @@ import { ForwardManager } from './forwards.js'
|
|
|
52
53
|
import { WebAttach } from './web-attach.js'
|
|
53
54
|
import { formatAuditLine, readAuditLines } from './audit.js'
|
|
54
55
|
|
|
55
|
-
import { selfDir, diskVersion, LOADED_VERSION, gtVersion, fetchLatestVersion, applyUpdate, persistUpdateMode, readUpdateMode, reloadSelf, scheduleSelfReload, lastSelfReload, isInstalledCopy } from './update.js'
|
|
56
|
+
import { selfDir, diskVersion, LOADED_VERSION, gtVersion, fetchLatestVersion, applyUpdate, persistUpdateMode, readUpdateMode, reloadSelf, scheduleSelfReload, lastSelfReload, isInstalledCopy, writeFileAtomic } from './update.js'
|
|
56
57
|
import { sendHeartbeat, pseudonym, heartbeatUrl, hasPersistedId, installIdPath, telemetryAllowed, persistTelemetryOpt } from './telemetry.js'
|
|
57
58
|
import { loadMachines as _loadMachines, saveMachines as _saveMachines, sanitizeMachine as _sanitizeMachine, applyMachine as _applyMachine, machineId as _machineId, normalizeMachineGroup, filterMachinesByGroup, resolveProbeCredentials } from './registry.js'
|
|
58
59
|
import { registerHttpTransports } from './http-transport.js'
|
|
@@ -474,6 +475,34 @@ export async function apply(ctx, config) {
|
|
|
474
475
|
// 伪名,原始安装 id 与任何机器信息都不离开本机。
|
|
475
476
|
if (telemetryAllowed(dshBase(), config.telemetry)) void sendHeartbeat(dshBase(), LOADED_VERSION)
|
|
476
477
|
|
|
478
|
+
// ── terminal credential bridge (saved passwords for the `remote ssh` shell) ─
|
|
479
|
+
// The generated terminal launcher spawns the OS ssh, which cannot receive the
|
|
480
|
+
// plugin's saved passwords by itself. Bridge: a per-boot bearer token in
|
|
481
|
+
// $DSH_HOME/remote-terminal/term-secret.json (0600) + a POST route that
|
|
482
|
+
// resolves the machine through the SAME credential chain a real connect uses.
|
|
483
|
+
// The askpass helper (written next to the launcher) is the only reader.
|
|
484
|
+
const termSecretFile = () => path.join(remoteTerminalRoot(), 'term-secret.json')
|
|
485
|
+
const termSecretToken = randomBytes(24).toString('hex')
|
|
486
|
+
// A stale payload from a previous boot would name a dead port with a dead
|
|
487
|
+
// token — and with SSH_ASKPASS_REQUIRE=force a failing bridge means NO tty
|
|
488
|
+
// prompt at all. Always boot from absent; only a live webServer re-creates it
|
|
489
|
+
// (Desktop compositions have no HTTP listener, so the bridge stays off there
|
|
490
|
+
// and the terminal keeps its interactive prompt).
|
|
491
|
+
try { rmSync(termSecretFile(), { force: true }) } catch { /* absent is fine */ }
|
|
492
|
+
const writeTermSecretPayload = (origin) => {
|
|
493
|
+
if (!origin) return false
|
|
494
|
+
try {
|
|
495
|
+
mkdirSync(remoteTerminalRoot(), { recursive: true })
|
|
496
|
+
writeFileAtomic(termSecretFile(), JSON.stringify({ version: 1, url: String(origin).replace(/\/+$/, ''), token: termSecretToken }))
|
|
497
|
+
try { chmodSync(termSecretFile(), 0o600) } catch { /* Windows: dir is already user-private */ }
|
|
498
|
+
return true
|
|
499
|
+
} catch { return false }
|
|
500
|
+
}
|
|
501
|
+
const termSecretOk = (presented) => {
|
|
502
|
+
const dig = (s) => createHash('sha256').update(String(s)).digest()
|
|
503
|
+
return timingSafeEqual(dig(presented), dig(termSecretToken))
|
|
504
|
+
}
|
|
505
|
+
|
|
477
506
|
// The update marker means "a newer version landed on disk but is not the code
|
|
478
507
|
// running yet". Reaching apply() with a marker naming the version we just
|
|
479
508
|
// loaded means the swap already happened (or this is a plain boot into the
|
|
@@ -4723,10 +4752,63 @@ export async function apply(ctx, config) {
|
|
|
4723
4752
|
}
|
|
4724
4753
|
},
|
|
4725
4754
|
},
|
|
4755
|
+
{
|
|
4756
|
+
kind: 'exact',
|
|
4757
|
+
path: '/dsh-remote/term-secret',
|
|
4758
|
+
// Owns its bearer token (per boot, 0600 file): the caller is a local
|
|
4759
|
+
// PROCESS (the askpass helper), not a browser, so the Connection cookie
|
|
4760
|
+
// fence would 401 it. The fallback fence still locks out cross-site pages
|
|
4761
|
+
// (they cannot read the token file).
|
|
4762
|
+
fence: 'bearer',
|
|
4763
|
+
handler: async (req, res) => {
|
|
4764
|
+
if (req.method !== 'POST') return sendJson(res, 405, { ok: false, error: 'method not allowed' })
|
|
4765
|
+
// Self-heal: a caller exists but the payload was never published (the
|
|
4766
|
+
// origin arrived after the first write attempts).
|
|
4767
|
+
if (!existsSync(termSecretFile())) {
|
|
4768
|
+
try {
|
|
4769
|
+
const ws = ctx.get('webServer')
|
|
4770
|
+
if (ws && typeof ws.getOrigin === 'function') writeTermSecretPayload(ws.getOrigin())
|
|
4771
|
+
} catch { /* still no listener: the 403 below answers honestly */ }
|
|
4772
|
+
}
|
|
4773
|
+
// Malformed bodies are a 400 with a reason even before the token check
|
|
4774
|
+
// (the routes matrix pins that readability contract for every POST).
|
|
4775
|
+
let body = {}
|
|
4776
|
+
try { body = JSON.parse((await readBody(req)) || '{}') } catch { return sendJson(res, 400, { ok: false, error: 'invalid JSON body' }) }
|
|
4777
|
+
const presented = String((req.headers && req.headers.authorization) || '').replace(/^Bearer\s+/i, '')
|
|
4778
|
+
if (!presented || !termSecretOk(presented)) return sendJson(res, 403, { ok: false, error: 'forbidden' })
|
|
4779
|
+
const alias = String(body.alias || '')
|
|
4780
|
+
let m = null
|
|
4781
|
+
if (alias) m = machines.find((x) => x && x.useSshConfig && String(x.host) === alias) || null
|
|
4782
|
+
if (!m) {
|
|
4783
|
+
const host = String(body.host || '')
|
|
4784
|
+
const port = Number(body.port) || 22
|
|
4785
|
+
const user = String(body.username || '')
|
|
4786
|
+
m = machines.find((x) => x && !x.useSshConfig && String(x.host) === host && (Number(x.port) || 22) === port && String(x.username || '') === user) || null
|
|
4787
|
+
}
|
|
4788
|
+
if (!m) return sendJson(res, 404, { ok: false, error: 'unknown machine' })
|
|
4789
|
+
const password = await machinePassword(m)
|
|
4790
|
+
return sendJson(res, 200, { ok: true, password })
|
|
4791
|
+
},
|
|
4792
|
+
},
|
|
4726
4793
|
]
|
|
4727
4794
|
|
|
4728
4795
|
registerHttpTransports(ctx, routes)
|
|
4729
4796
|
|
|
4797
|
+
// Publish the credential-bridge payload as soon as the loopback origin is
|
|
4798
|
+
// known (the listener may still be binding at apply time — retry once).
|
|
4799
|
+
ctx.inject(['webServer'], (inner) => {
|
|
4800
|
+
const ws = inner.get('webServer')
|
|
4801
|
+
const publish = () => {
|
|
4802
|
+
try {
|
|
4803
|
+
return writeTermSecretPayload(typeof ws.getOrigin === 'function' ? ws.getOrigin() : '')
|
|
4804
|
+
} catch { return false } // listener not bound yet
|
|
4805
|
+
}
|
|
4806
|
+
if (!publish()) {
|
|
4807
|
+
const timer = setTimeout(publish, 2000)
|
|
4808
|
+
if (typeof timer.unref === 'function') timer.unref()
|
|
4809
|
+
}
|
|
4810
|
+
})
|
|
4811
|
+
|
|
4730
4812
|
// ── remote terminal: one extra shell in the host terminal's own list ──────
|
|
4731
4813
|
// Additive and optional: a composition without `terminalController` simply
|
|
4732
4814
|
// keeps the terminal it already had.
|
|
@@ -266,14 +266,59 @@ function stdinIsInteractive(deps = {}) {
|
|
|
266
266
|
}
|
|
267
267
|
}
|
|
268
268
|
|
|
269
|
+
/**
|
|
270
|
+
* Whether the machine's password auth needs (and can use) the credential
|
|
271
|
+
* bridge. Keys, agents and ssh-config aliases authenticate without us;
|
|
272
|
+
* keyboard-interactive (OTP) prompts are per-login and must stay on the tty;
|
|
273
|
+
* everything else with a stored credential (plaintext registry or OS keychain)
|
|
274
|
+
* goes through the bridge.
|
|
275
|
+
*
|
|
276
|
+
* @param {object|undefined} machine - the matched registry record.
|
|
277
|
+
* @returns {boolean}
|
|
278
|
+
*/
|
|
279
|
+
function needsAskpass(machine) {
|
|
280
|
+
if (!machine) return false
|
|
281
|
+
if (machine.useAgent || machine.useSshConfig || machine.keyboardInteractive) return false
|
|
282
|
+
if (String(machine.privateKeyPath || '')) return false
|
|
283
|
+
if (String(machine.password || '')) return true
|
|
284
|
+
return Boolean(machine.credentialBackend && machine.credentialBackend !== 'plain')
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* Environment additions that route ssh's password prompt to the bridge helper.
|
|
289
|
+
* Only applied when needsAskpass() held AND the payload file exists.
|
|
290
|
+
*
|
|
291
|
+
* `SSH_ASKPASS_REQUIRE=force` (OpenSSH ≥ 8.4) is what makes askpass run at all
|
|
292
|
+
* on a tty; DISPLAY feeds prehistoric ssh builds. DSH_TS_* carries the machine
|
|
293
|
+
* identity to the helper through the process environment.
|
|
294
|
+
*
|
|
295
|
+
* @param {object} machine
|
|
296
|
+
* @param {string} termDir - the launcher's directory (DSH_TERM_DIR).
|
|
297
|
+
* @param {string} [platform]
|
|
298
|
+
* @returns {object} env entries to merge over process.env
|
|
299
|
+
*/
|
|
300
|
+
function askpassEnv(machine, termDir, platform = process.platform) {
|
|
301
|
+
const wrapper = path.join(termDir, platform === 'win32' ? 'term-askpass.cmd' : 'term-askpass')
|
|
302
|
+
return {
|
|
303
|
+
SSH_ASKPASS: wrapper,
|
|
304
|
+
SSH_ASKPASS_REQUIRE: 'force',
|
|
305
|
+
DISPLAY: process.env.DISPLAY || 'dsh-remote:0',
|
|
306
|
+
DSH_TS_HOST: String(machine.host || ''),
|
|
307
|
+
DSH_TS_PORT: String(Number(machine.port) || 22),
|
|
308
|
+
DSH_TS_USERNAME: String(machine.username || ''),
|
|
309
|
+
DSH_TS_ALIAS: String(machine.alias || ''),
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
|
|
269
313
|
/**
|
|
270
314
|
* Hand the current process over to `file args…`, propagating the exit code.
|
|
271
315
|
* @param {string} file
|
|
272
316
|
* @param {string[]} args
|
|
317
|
+
* @param {object} [extraEnv] - env entries merged over process.env (askpass).
|
|
273
318
|
* @returns {import('node:child_process').ChildProcess}
|
|
274
319
|
*/
|
|
275
|
-
function handover(file, args) {
|
|
276
|
-
const child = spawn(file, args, { stdio: 'inherit' })
|
|
320
|
+
function handover(file, args, extraEnv) {
|
|
321
|
+
const child = spawn(file, args, { stdio: 'inherit', env: extraEnv ? { ...process.env, ...extraEnv } : process.env })
|
|
277
322
|
child.on('error', (error) => {
|
|
278
323
|
process.stderr.write(`[dsh-remote] cannot run ${file}: ${error && error.message}\n`)
|
|
279
324
|
process.exit(127)
|
|
@@ -322,13 +367,24 @@ function main(argv = process.argv.slice(2), deps = {}) {
|
|
|
322
367
|
process.stderr.write('[dsh-remote] the remote workspace is a Windows path; opening the remote default shell without changing directory.\n')
|
|
323
368
|
process.stderr.write('[dsh-remote] 远端工作区是 Windows 路径,已打开默认 shell(未自动切换目录)。\n')
|
|
324
369
|
}
|
|
370
|
+
// Saved-password bridge: when the machine needs password auth and the host
|
|
371
|
+
// wrote the bridge payload (Web composition only), answer ssh's password
|
|
372
|
+
// prompt through the plugin's credential chain instead of the tty.
|
|
373
|
+
const termDir = env.DSH_TERM_DIR || ''
|
|
374
|
+
if (termDir && needsAskpass(resolved.machine) && existsSync(path.join(termDir, 'term-secret.json'))) {
|
|
375
|
+
process.stderr.write('[dsh-remote] using the saved password via the local credential bridge.\n')
|
|
376
|
+
process.stderr.write('[dsh-remote] 已保存的密码将通过本机凭据桥自动应答。\n')
|
|
377
|
+
return handover(ssh, args, askpassEnv(resolved.machine, termDir, platform))
|
|
378
|
+
}
|
|
325
379
|
return handover(ssh, args)
|
|
326
380
|
}
|
|
327
381
|
|
|
328
382
|
module.exports = {
|
|
329
383
|
META_FILE,
|
|
384
|
+
askpassEnv,
|
|
330
385
|
buildSshArgs,
|
|
331
386
|
findMirror,
|
|
387
|
+
needsAskpass,
|
|
332
388
|
isWindowsRemotePath,
|
|
333
389
|
localShell,
|
|
334
390
|
main,
|
package/lib/remote-shell.js
CHANGED
|
@@ -250,6 +250,10 @@ export function launcherSource(spec) {
|
|
|
250
250
|
'setlocal',
|
|
251
251
|
`set "DSH_CHILD=${child}"`,
|
|
252
252
|
`set "DSH_MACHINES=${machines}"`,
|
|
253
|
+
// Where the askpass helper + credential-bridge payload live (this .cmd's
|
|
254
|
+
// own directory); the child reads it to decide whether password auth can
|
|
255
|
+
// be bridged (see remote-shell-child.cjs askpassEnv).
|
|
256
|
+
'set "DSH_TERM_DIR=%~dp0"',
|
|
253
257
|
`set "DSH_NODE=${node}"`,
|
|
254
258
|
'if defined DSH_NODE if exist "%DSH_NODE%" goto :run',
|
|
255
259
|
'set "DSH_NODE="',
|
|
@@ -287,6 +291,8 @@ export function launcherSource(spec) {
|
|
|
287
291
|
'# Generated by dsh-remote - do not edit; rewritten on every load.',
|
|
288
292
|
`DSH_CHILD=${shqPosix(child)}`,
|
|
289
293
|
`DSH_MACHINES=${shqPosix(machines)}`,
|
|
294
|
+
// Physical directory of this script: the askpass helper + payload live here.
|
|
295
|
+
'DSH_TERM_DIR=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)',
|
|
290
296
|
node ? `DSH_NODE=${shqPosix(node)}` : 'DSH_NODE=',
|
|
291
297
|
'if [ -n "$DSH_NODE" ] && [ -x "$DSH_NODE" ]; then exec "$DSH_NODE" "$DSH_CHILD" --machines "$DSH_MACHINES"; fi',
|
|
292
298
|
'if command -v node >/dev/null 2>&1; then exec node "$DSH_CHILD" --machines "$DSH_MACHINES"; fi',
|
|
@@ -301,6 +307,114 @@ export function shqPosix(value) {
|
|
|
301
307
|
return "'" + String(value).replace(/'/g, "'\\''") + "'"
|
|
302
308
|
}
|
|
303
309
|
|
|
310
|
+
// ── the credential bridge helper (saved-password terminal auth) ─────────────
|
|
311
|
+
//
|
|
312
|
+
// The `remote ssh` terminal spawns the OS ssh, which knows keys and agents but
|
|
313
|
+
// has no way to receive the password the plugin saved (plaintext registry or OS
|
|
314
|
+
// keychain). The bridge: ssh (with SSH_ASKPASS_REQUIRE=force) calls this
|
|
315
|
+
// helper, the helper POSTs the machine identity to the RUNNING plugin's
|
|
316
|
+
// loopback route `/dsh-remote/term-secret` with a per-boot bearer token, and
|
|
317
|
+
// the host answers through the same credential chain a real connect uses.
|
|
318
|
+
// The token + URL live in `term-secret.json` next to the launcher (0600); the
|
|
319
|
+
// helper itself carries no secret.
|
|
320
|
+
|
|
321
|
+
/** Absolute path of the askpass wrapper for the platform. */
|
|
322
|
+
export function askpassWrapperPath(dir, platform = process.platform) {
|
|
323
|
+
return path.join(dir, platform === 'win32' ? 'term-askpass.cmd' : 'term-askpass')
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/** Body of term-askpass.cjs — plain CJS, no dependencies, no secrets. */
|
|
327
|
+
export function askpassHelperSource() {
|
|
328
|
+
return [
|
|
329
|
+
'#!/usr/bin/env node',
|
|
330
|
+
'// Generated by dsh-remote - do not edit; rewritten on every load.',
|
|
331
|
+
'// ssh askpass helper: fetch the saved password for DSH_TS_* (host/port/',
|
|
332
|
+
'// username) from the running dsh-remote host, print it on stdout.',
|
|
333
|
+
'// Exit nonzero without output when the bridge cannot answer - ssh then',
|
|
334
|
+
'// fails authentication (SSH_ASKPASS_REQUIRE=force trades the tty prompt',
|
|
335
|
+
'// for the bridge; the child only enables it when a credential exists).',
|
|
336
|
+
"'use strict'",
|
|
337
|
+
'const { readFileSync } = require("node:fs")',
|
|
338
|
+
'const { join } = require("node:path")',
|
|
339
|
+
'const http = require("node:http")',
|
|
340
|
+
'function main() {',
|
|
341
|
+
' let cfg',
|
|
342
|
+
' try { cfg = JSON.parse(readFileSync(join(__dirname, "term-secret.json"), "utf8")) } catch { process.exit(2) }',
|
|
343
|
+
' const body = JSON.stringify({',
|
|
344
|
+
' host: process.env.DSH_TS_HOST || "",',
|
|
345
|
+
' port: Number(process.env.DSH_TS_PORT) || 22,',
|
|
346
|
+
' username: process.env.DSH_TS_USERNAME || "",',
|
|
347
|
+
' alias: process.env.DSH_TS_ALIAS || "",',
|
|
348
|
+
' })',
|
|
349
|
+
' const base = String(cfg.url || "").replace(/\\/+$/, "")',
|
|
350
|
+
' if (!cfg.token || !base) process.exit(2)',
|
|
351
|
+
' const url = new URL(base + "/dsh-remote/term-secret")',
|
|
352
|
+
' const req = http.request({',
|
|
353
|
+
' method: "POST", host: url.hostname, port: url.port, path: url.pathname,',
|
|
354
|
+
' headers: {',
|
|
355
|
+
' "content-type": "application/json",',
|
|
356
|
+
' authorization: "Bearer " + cfg.token,',
|
|
357
|
+
' "content-length": Buffer.byteLength(body),',
|
|
358
|
+
' },',
|
|
359
|
+
' timeout: 5000,',
|
|
360
|
+
' }, (res) => {',
|
|
361
|
+
' let buf = ""',
|
|
362
|
+
' res.on("data", (chunk) => { buf += chunk })',
|
|
363
|
+
' res.on("end", () => {',
|
|
364
|
+
' try {',
|
|
365
|
+
' const parsed = JSON.parse(buf)',
|
|
366
|
+
' if (res.statusCode === 200 && parsed && parsed.ok && typeof parsed.password === "string" && parsed.password.length > 0) {',
|
|
367
|
+
' process.stdout.write(parsed.password + "\\n")',
|
|
368
|
+
' return',
|
|
369
|
+
' }',
|
|
370
|
+
' } catch { /* malformed answer */ }',
|
|
371
|
+
' process.exit(3)',
|
|
372
|
+
' })',
|
|
373
|
+
' })',
|
|
374
|
+
' req.on("timeout", () => { req.destroy(); process.exit(4) })',
|
|
375
|
+
' req.on("error", () => process.exit(5))',
|
|
376
|
+
' req.end(body)',
|
|
377
|
+
'}',
|
|
378
|
+
'main()',
|
|
379
|
+
'',
|
|
380
|
+
].join('\n')
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
/**
|
|
384
|
+
* Write the askpass helper + its platform wrapper next to the launcher.
|
|
385
|
+
* Called from writeLauncher so an upgrade rewrites both in one place.
|
|
386
|
+
* Carries NO secret: URL + per-boot token land in term-secret.json, written by
|
|
387
|
+
* the host half once the webserver origin is known (and deleted on boot when
|
|
388
|
+
* the composition has no webserver, so a stale bridge can never hijack the
|
|
389
|
+
* prompt on Desktop).
|
|
390
|
+
*
|
|
391
|
+
* @param {{ dir: string, platform?: string, nodePath?: string, fs?: object }} spec
|
|
392
|
+
*/
|
|
393
|
+
export function writeTermSecretHelpers(spec) {
|
|
394
|
+
const platform = spec.platform || process.platform
|
|
395
|
+
const fs = spec.fs || { writeFileSync, chmodSync }
|
|
396
|
+
const node = spec.nodePath || 'node'
|
|
397
|
+
fs.writeFileSync(path.join(spec.dir, 'term-askpass.cjs'), askpassHelperSource(), 'utf8')
|
|
398
|
+
const wrapper = askpassWrapperPath(spec.dir, platform)
|
|
399
|
+
if (platform === 'win32') {
|
|
400
|
+
fs.writeFileSync(wrapper, [
|
|
401
|
+
'@echo off',
|
|
402
|
+
'rem Generated by dsh-remote - do not edit; rewritten on every load.',
|
|
403
|
+
`"${node}" "%~dp0term-askpass.cjs" %*`,
|
|
404
|
+
'',
|
|
405
|
+
].join('\r\n'), 'utf8')
|
|
406
|
+
} else {
|
|
407
|
+
fs.writeFileSync(wrapper, [
|
|
408
|
+
'#!/bin/sh',
|
|
409
|
+
'# Generated by dsh-remote - do not edit; rewritten on every load.',
|
|
410
|
+
`exec ${shqPosix(node)} "$(dirname -- "$0")/term-askpass.cjs" "$@"`,
|
|
411
|
+
'',
|
|
412
|
+
].join('\n'), 'utf8')
|
|
413
|
+
try { fs.chmodSync(wrapper, 0o755) } catch { /* mode-less fs */ }
|
|
414
|
+
}
|
|
415
|
+
return { wrapper, helper: path.join(spec.dir, 'term-askpass.cjs') }
|
|
416
|
+
}
|
|
417
|
+
|
|
304
418
|
/**
|
|
305
419
|
* Remove a launcher left on disk under another spelling of the same name.
|
|
306
420
|
*
|
|
@@ -353,7 +467,10 @@ export function writeLauncher(spec) {
|
|
|
353
467
|
if (platform !== 'win32') {
|
|
354
468
|
try { fs.chmodSync(file, 0o755) } catch { /* a no-op on filesystems without modes */ }
|
|
355
469
|
}
|
|
356
|
-
|
|
470
|
+
// The credential-bridge helper travels with the launcher (same rewrite
|
|
471
|
+
// cadence, same directory the launcher exports as DSH_TERM_DIR).
|
|
472
|
+
const helpers = writeTermSecretHelpers({ dir: spec.dir, platform, nodePath: spec.nodePath || '', fs })
|
|
473
|
+
return { path: file, source, askpass: helpers.wrapper }
|
|
357
474
|
}
|
|
358
475
|
|
|
359
476
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-remote",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.81",
|
|
4
4
|
"description": "Remote-work assistant for DeepSeek Harness: connect SSH (password/key/agent/keyboard-interactive, multi-hop ProxyJump), list hosts from ~/.ssh/config, pick a remote workspace, operate on it with 21 rw_* tools, conflict-aware mirror sync, an embedded PTY terminal, remote DSH web UI attach, port forwarding, host grouping, remote sandbox fencing, audit log, keychain passwords.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "flymysql <flyphp@outlook.com>",
|