@fish-under-sea/dsh-ssh-fish 1.0.2 → 1.1.0
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/NOTICE +1 -1
- package/README.en.md +5 -5
- package/README.md +5 -5
- package/README.zh.md +5 -5
- package/lib/client.js +783 -170
- package/lib/client.js.map +1 -1
- package/lib/index.js +128 -14
- package/lib/types/client/api.d.ts +21 -0
- package/lib/types/client/locales.d.ts +13 -2
- package/lib/types/client/panel/TerminalTab.d.ts +12 -7
- package/lib/types/client/panel/controller.d.ts +185 -21
- package/lib/types/engine/connection-pool.d.ts +52 -1
- package/lib/types/engine.d.ts +7 -0
- package/lib/types/index.d.ts +10 -0
- package/lib/types/loopback.d.ts +41 -1
- package/lib/types/protocol.d.ts +18 -1
- package/lib/types/store.d.ts +7 -0
- package/lib/types/tool-surface.d.ts +1 -0
- package/lib/types/tools.d.ts +1 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +24 -21
- package/src/client/api.ts +70 -0
- package/src/client/index.ts +1 -2
- package/src/client/locales.ts +26 -4
- package/src/client/panel/HostFormDialog.tsx +16 -2
- package/src/client/panel/HostsTab.tsx +3 -0
- package/src/client/panel/SshPanel.tsx +7 -15
- package/src/client/panel/TerminalTab.tsx +371 -151
- package/src/client/panel/controller.ts +370 -30
- package/src/client/panel/panel.module.css +108 -0
- package/src/client/settings-binding.ts +0 -1
- package/src/engine/connection-pool.ts +96 -4
- package/src/engine.ts +10 -0
- package/src/index.ts +16 -1
- package/src/loopback.ts +57 -1
- package/src/protocol.ts +18 -1
- package/src/routes.ts +4 -1
- package/src/store.ts +26 -0
- package/src/tool-surface.ts +1 -0
- package/src/tools.ts +9 -4
|
@@ -14,7 +14,10 @@ import { startProxyCommand, type ProxyTarget } from './proxy-command.ts'
|
|
|
14
14
|
export interface EngineOptions {
|
|
15
15
|
/** Connections idle longer than this are closed (ms). */
|
|
16
16
|
idleTimeoutMs?: number
|
|
17
|
-
/**
|
|
17
|
+
/**
|
|
18
|
+
* Ceiling for the whole pre-ready sequence (ms): TCP connect, SSH key
|
|
19
|
+
* exchange and user authentication. Passed to ssh2's `readyTimeout`.
|
|
20
|
+
*/
|
|
18
21
|
connectTimeoutMs?: number
|
|
19
22
|
/** Keepalive ping interval (ms). */
|
|
20
23
|
keepaliveIntervalMs?: number
|
|
@@ -28,10 +31,17 @@ export interface EngineOptions {
|
|
|
28
31
|
sftpConcurrency?: number
|
|
29
32
|
}
|
|
30
33
|
|
|
34
|
+
/**
|
|
35
|
+
* Default ceiling for TCP connect, SSH key exchange and user authentication
|
|
36
|
+
* together (ms). Password authentication behind PAM / LDAP can outlast the
|
|
37
|
+
* previous 15 s ceiling while the server still eventually accepts it.
|
|
38
|
+
*/
|
|
39
|
+
export const DEFAULT_CONNECT_TIMEOUT_MS = 30_000
|
|
40
|
+
|
|
31
41
|
/** Default engine knobs (applied when an option is omitted). */
|
|
32
42
|
export const DEFAULTS: Required<EngineOptions> = {
|
|
33
43
|
idleTimeoutMs: 30 * 60_000,
|
|
34
|
-
connectTimeoutMs:
|
|
44
|
+
connectTimeoutMs: DEFAULT_CONNECT_TIMEOUT_MS,
|
|
35
45
|
keepaliveIntervalMs: 15_000,
|
|
36
46
|
maxOutputBytes: 2 * 1024 * 1024,
|
|
37
47
|
defaultExecTimeoutMs: 60_000,
|
|
@@ -93,19 +103,62 @@ export function buildConnectConfig(entry: SshHostEntry, sock: ConnectConfig['soc
|
|
|
93
103
|
config.passphrase = entry.auth.passphrase
|
|
94
104
|
}
|
|
95
105
|
}
|
|
106
|
+
// Agent forwarding is additive: it never changes how the host
|
|
107
|
+
// authenticates, it only lets this connection broker signatures from the
|
|
108
|
+
// local agent for the remote side (OpenSSH ForwardAgent / ssh -A).
|
|
109
|
+
if (entry.forwardAgent === true) {
|
|
110
|
+
// Agent auth already resolved an endpoint, and reusing it keeps the
|
|
111
|
+
// forwarded agent identical to the one that authenticated.
|
|
112
|
+
const agentPath = typeof config.agent === 'string'
|
|
113
|
+
? config.agent
|
|
114
|
+
: resolveForwardAgentPath(entry.auth.agentPath)
|
|
115
|
+
if (agentPath === undefined) {
|
|
116
|
+
// ssh2's own message for this case ("You must set a valid agent path to
|
|
117
|
+
// allow agent forwarding") names neither the host nor a way out, so the
|
|
118
|
+
// engine refuses first with an actionable one.
|
|
119
|
+
throw new Error('agent forwarding is enabled for this host but no ssh-agent endpoint is available: '
|
|
120
|
+
+ 'set SSH_AUTH_SOCK, start Pageant on Windows, or configure an agent path')
|
|
121
|
+
}
|
|
122
|
+
config.agent = agentPath
|
|
123
|
+
config.agentForward = true
|
|
124
|
+
}
|
|
96
125
|
return config
|
|
97
126
|
}
|
|
98
127
|
|
|
128
|
+
/**
|
|
129
|
+
* The default ssh-agent endpoint on Windows: the named pipe the native
|
|
130
|
+
* OpenSSH ssh-agent service listens on. ssh2 connects to a named pipe for any
|
|
131
|
+
* path matching its Windows pipe form, so the default is a real endpoint
|
|
132
|
+
* rather than a protocol name (#1910). PuTTY Pageant is still reachable — it
|
|
133
|
+
* is what the literal `pageant` agent path selects — but it is no longer the
|
|
134
|
+
* assumption.
|
|
135
|
+
*/
|
|
136
|
+
export const WINDOWS_AGENT_PIPE = '\\\\.\\pipe\\openssh-ssh-agent'
|
|
137
|
+
|
|
99
138
|
/** Resolve the ssh2 agent path for 'agent' auth. */
|
|
100
139
|
export function resolveAgentPath(agentPath?: string): string | undefined {
|
|
101
140
|
const explicit = normalizeAgentPath(agentPath)
|
|
102
141
|
if (explicit !== undefined) return explicit
|
|
103
142
|
const sock = process.env.SSH_AUTH_SOCK
|
|
104
143
|
if (sock !== undefined && sock !== '') return sock
|
|
105
|
-
if (process.platform === 'win32') return
|
|
144
|
+
if (process.platform === 'win32') return WINDOWS_AGENT_PIPE
|
|
106
145
|
return undefined
|
|
107
146
|
}
|
|
108
147
|
|
|
148
|
+
/**
|
|
149
|
+
* Resolve the ssh-agent endpoint that forwarding brokers signatures through:
|
|
150
|
+
* an explicitly configured agent path wins, then SSH_AUTH_SOCK, then the
|
|
151
|
+
* native OpenSSH named pipe on Windows. Undefined means no endpoint exists on
|
|
152
|
+
* this machine.
|
|
153
|
+
*
|
|
154
|
+
* Forwarding shares the auth resolution on purpose — the endpoint a host
|
|
155
|
+
* signs through is the same one it authenticates with — but it is a separate
|
|
156
|
+
* name so the forwarding path can evolve without touching auth.
|
|
157
|
+
*/
|
|
158
|
+
export function resolveForwardAgentPath(agentPath?: string): string | undefined {
|
|
159
|
+
return resolveAgentPath(agentPath)
|
|
160
|
+
}
|
|
161
|
+
|
|
109
162
|
/** Keyboard-interactive handler callback for 2FA / dynamic prompt flow. */
|
|
110
163
|
export type KeyboardInteractiveHandler = (
|
|
111
164
|
name: string,
|
|
@@ -115,11 +168,40 @@ export type KeyboardInteractiveHandler = (
|
|
|
115
168
|
finish: (responses: string[]) => void,
|
|
116
169
|
) => void
|
|
117
170
|
|
|
171
|
+
/**
|
|
172
|
+
* Name the phase that actually stalled. ssh2 reports every pre-ready timeout
|
|
173
|
+
* as "Timed out while waiting for handshake", including one that expires
|
|
174
|
+
* during user authentication after a completed key exchange.
|
|
175
|
+
*
|
|
176
|
+
* @param timeoutMs - the configured `readyTimeout` (0 disables it).
|
|
177
|
+
* @param handshakeComplete - whether ssh2 completed the key exchange.
|
|
178
|
+
* @returns the operator-facing timeout message.
|
|
179
|
+
*/
|
|
180
|
+
export function readyTimeoutMessage(timeoutMs: number | undefined, handshakeComplete: boolean): string {
|
|
181
|
+
const budget = typeof timeoutMs === 'number' && timeoutMs > 0 ? ' after ' + timeoutMs + ' ms' : ''
|
|
182
|
+
const hint = ' - raise the dsh-ssh connectTimeoutMs setting if this host is slow'
|
|
183
|
+
return handshakeComplete
|
|
184
|
+
? 'SSH authentication timed out' + budget + ': TCP connect and key exchange completed, but the server did not finish authenticating the user' + hint
|
|
185
|
+
: 'SSH connection timed out' + budget + ' before key exchange completed: TCP connect or the SSH key exchange did not finish' + hint
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Whether ssh2 ended the attempt with its pre-ready timeout. The level is the
|
|
190
|
+
* stable discriminator; the message is reused for connect, key exchange and
|
|
191
|
+
* authentication alike.
|
|
192
|
+
*/
|
|
193
|
+
export function isReadyTimeout(error: Error): boolean {
|
|
194
|
+
return (error as Error & { level?: unknown }).level === 'client-timeout'
|
|
195
|
+
}
|
|
196
|
+
|
|
118
197
|
/** Connect one ssh2 client (resolve on ready, reject on error/close). */
|
|
119
198
|
export function connectClient(config: ConnectConfig, onKeyboardInteractive?: KeyboardInteractiveHandler): Promise<Client> {
|
|
120
199
|
return new Promise((resolve, reject) => {
|
|
121
200
|
const client = new Client()
|
|
122
201
|
let settled = false
|
|
202
|
+
// Key exchange completion is the only public phase boundary ssh2 exposes
|
|
203
|
+
// between "TCP connect / SSH handshake" and "user authentication".
|
|
204
|
+
let handshakeComplete = false
|
|
123
205
|
const fail = (error: unknown): void => {
|
|
124
206
|
if (settled) return
|
|
125
207
|
settled = true
|
|
@@ -131,8 +213,12 @@ export function connectClient(config: ConnectConfig, onKeyboardInteractive?: Key
|
|
|
131
213
|
try { (sock as { destroy: () => void }).destroy() } catch { /* already closed */ }
|
|
132
214
|
}
|
|
133
215
|
try { client.destroy() } catch { /* already closed */ }
|
|
134
|
-
|
|
216
|
+
const cause = error instanceof Error ? error : new Error(String(error))
|
|
217
|
+
reject(isReadyTimeout(cause) ? new Error(readyTimeoutMessage(config.readyTimeout, handshakeComplete)) : cause)
|
|
135
218
|
}
|
|
219
|
+
client.once('handshake', () => {
|
|
220
|
+
handshakeComplete = true
|
|
221
|
+
})
|
|
136
222
|
client.once('ready', () => {
|
|
137
223
|
if (settled) return
|
|
138
224
|
settled = true
|
|
@@ -228,6 +314,12 @@ export function parseJumpSpec(spec: string): { host: string; port?: number; user
|
|
|
228
314
|
* Resolve one ProxyJump spec: an alias configured in this plugin wins, and any
|
|
229
315
|
* other value is read as an OpenSSH address whose credentials come from the
|
|
230
316
|
* target entry (an ad-hoc hop has no stored auth of its own).
|
|
317
|
+
*
|
|
318
|
+
* An address hop deliberately carries no forwardAgent flag: OpenSSH's
|
|
319
|
+
* ForwardAgent is a per-Host setting and an ad-hoc address was never
|
|
320
|
+
* configured, so it must never inherit the target's opt-in. A hop written as
|
|
321
|
+
* an alias uses that alias's own entry, which is how a user forwards on a
|
|
322
|
+
* bastion on purpose.
|
|
231
323
|
*/
|
|
232
324
|
export function resolveHop(engine: PoolEngine, entry: SshHostEntry, spec: string): SshHostEntry {
|
|
233
325
|
const configured = engine.store.find(spec)
|
package/src/engine.ts
CHANGED
|
@@ -51,6 +51,16 @@ export class SshEngine {
|
|
|
51
51
|
this.sweepTimer.unref?.()
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
+
/**
|
|
55
|
+
* Change the pre-ready ceiling (TCP connect + key exchange + user
|
|
56
|
+
* authentication) for connections opened from now on. A pooled connection
|
|
57
|
+
* keeps serving until it reconnects, because the ceiling governs the
|
|
58
|
+
* connect path only.
|
|
59
|
+
*/
|
|
60
|
+
setConnectTimeout(timeoutMs: number): void {
|
|
61
|
+
this.opts.connectTimeoutMs = timeoutMs
|
|
62
|
+
}
|
|
63
|
+
|
|
54
64
|
// ---------------------------------------------------------------- config
|
|
55
65
|
|
|
56
66
|
/** Secret-free host list (filtered by the optional query). */
|
package/src/index.ts
CHANGED
|
@@ -14,6 +14,7 @@ import type {} from '@deepseek-ai/dsh-host-webserver'
|
|
|
14
14
|
import type {} from '@deepseek-ai/dsh-system-prompt'
|
|
15
15
|
import type {} from '@deepseek-ai/dsh-tools'
|
|
16
16
|
import { SshEngine } from './engine.ts'
|
|
17
|
+
import { DEFAULT_CONNECT_TIMEOUT_MS } from './engine/connection-pool.ts'
|
|
17
18
|
import { makeRoutes } from './routes.ts'
|
|
18
19
|
import { HostStore } from './store.ts'
|
|
19
20
|
import { sshClusterTool, sshDownloadTool, sshExecTool, sshListTool, sshTunnelTool, sshUploadTool } from './tools.ts'
|
|
@@ -54,6 +55,13 @@ export interface Config {
|
|
|
54
55
|
* Nerd Font stack here to render powerline/Nerd glyphs.
|
|
55
56
|
*/
|
|
56
57
|
terminalFontFamily?: string
|
|
58
|
+
/**
|
|
59
|
+
* Ceiling for the whole pre-ready SSH sequence in milliseconds: TCP
|
|
60
|
+
* connect, key exchange and user authentication (default 30000). Raise it
|
|
61
|
+
* for hosts whose password authentication is slow (for example PAM / LDAP
|
|
62
|
+
* behind a distant directory service).
|
|
63
|
+
*/
|
|
64
|
+
connectTimeoutMs?: number
|
|
57
65
|
}
|
|
58
66
|
|
|
59
67
|
/** The stable reference a `volatile()` config field resolves to; its owner updates it in place. */
|
|
@@ -70,6 +78,7 @@ export interface ResolvedConfig {
|
|
|
70
78
|
announceToAgent?: ConfigField<boolean>
|
|
71
79
|
enabled?: ConfigField<boolean>
|
|
72
80
|
terminalFontFamily?: ConfigField<string>
|
|
81
|
+
connectTimeoutMs?: ConfigField<number>
|
|
73
82
|
}
|
|
74
83
|
|
|
75
84
|
/**
|
|
@@ -84,6 +93,8 @@ export const Config = z.object({
|
|
|
84
93
|
announceToAgent: z.boolean().default(false).volatile(),
|
|
85
94
|
enabled: z.boolean().default(true).volatile(),
|
|
86
95
|
terminalFontFamily: z.string().default('').volatile(),
|
|
96
|
+
connectTimeoutMs: z.number().step(1).min(1_000).max(600_000).default(DEFAULT_CONNECT_TIMEOUT_MS).volatile()
|
|
97
|
+
.description('TCP connect, SSH key exchange and user authentication timeout in milliseconds; raise it for hosts whose authentication is slow.'),
|
|
87
98
|
})
|
|
88
99
|
|
|
89
100
|
/** Schema defaults, re-read for hand-built test contexts (the loader applies them normally). */
|
|
@@ -136,7 +147,7 @@ export const apply = mountOnce('@fish-under-sea/dsh-ssh-fish', applyImpl)
|
|
|
136
147
|
|
|
137
148
|
function applyImpl(ctx: Context, config?: ResolvedConfig): void {
|
|
138
149
|
const store = new HostStore()
|
|
139
|
-
const engine = new SshEngine(store)
|
|
150
|
+
const engine = new SshEngine(store, { connectTimeoutMs: readConfigField(config?.connectTimeoutMs, DEFAULT_CONNECT_TIMEOUT_MS) })
|
|
140
151
|
ctx.effect(() => () => { engine.dispose() }, 'dsh-ssh: engine')
|
|
141
152
|
|
|
142
153
|
const resolve = (): { announceToAgent: boolean; enabled: boolean } => {
|
|
@@ -176,6 +187,10 @@ function applyImpl(ctx: Context, config?: ResolvedConfig): void {
|
|
|
176
187
|
// is kept under one disposer: re-registering first tears the old one down
|
|
177
188
|
// so duplicate-name registrations never throw.
|
|
178
189
|
const sync = (): void => {
|
|
190
|
+
// A settings edit reaches this instance without a remount; apply the
|
|
191
|
+
// connection ceiling before re-deriving the surfaces so connections opened
|
|
192
|
+
// by the request that follows use the new value.
|
|
193
|
+
engine.setConnectTimeout(readConfigField(config?.connectTimeoutMs, DEFAULT_CONNECT_TIMEOUT_MS))
|
|
179
194
|
const value = resolve()
|
|
180
195
|
if (disposeSection !== undefined) {
|
|
181
196
|
disposeSection()
|
package/src/loopback.ts
CHANGED
|
@@ -8,6 +8,19 @@
|
|
|
8
8
|
* Semantics: RFC 5735 IPv4 127/8, ::1, IPv4-mapped ::ffff:127/8 (matching the
|
|
9
9
|
* remote-web-ui gate), localhost hostnames, plus the browser same-origin
|
|
10
10
|
* markers (sec-fetch-site and Origin) for the request-level fence.
|
|
11
|
+
*
|
|
12
|
+
* A reverse proxy in front of the host rewrites the Host header to its own
|
|
13
|
+
* upstream literal (a Cloudflare tunnel, frp and an nginx reverse proxy all
|
|
14
|
+
* dial 127.0.0.1:<port>), and the socket the origin sees is the proxy's, which
|
|
15
|
+
* is loopback by construction. Both halves of the fence then hold for a public
|
|
16
|
+
* request. Forwarding headers are the signal that a hop stands in between: a
|
|
17
|
+
* request that carries CF-Connecting-IP or X-Forwarded-For is answered through
|
|
18
|
+
* a proxy and is never treated as a local one (issue #1906).
|
|
19
|
+
*
|
|
20
|
+
* An operator who runs that proxy or tunnel themselves can opt into the
|
|
21
|
+
* narrower case: isForwardedLoopbackRequest describes a forwarded request that
|
|
22
|
+
* still landed on this machine's loopback upstream, and a route family admits
|
|
23
|
+
* it only behind its own default-off switch (issue #1918).
|
|
11
24
|
* @module dsh-web-shared/host/loopback
|
|
12
25
|
*/
|
|
13
26
|
|
|
@@ -36,13 +49,29 @@ export function isLoopbackHostname(hostname: string): boolean {
|
|
|
36
49
|
return isIPv4Loopback(hostname)
|
|
37
50
|
}
|
|
38
51
|
|
|
52
|
+
/**
|
|
53
|
+
* Whether a reverse proxy stood between the client and this host: the request
|
|
54
|
+
* carries CF-Connecting-IP or X-Forwarded-For. Either header is stamped by a
|
|
55
|
+
* hop that forwards traffic, so the request did not originate on this machine.
|
|
56
|
+
* @param request - node HTTP request.
|
|
57
|
+
* @returns true when a forwarding header is present.
|
|
58
|
+
*/
|
|
59
|
+
export function isProxiedRequest(request: IncomingMessage): boolean {
|
|
60
|
+
return request.headers['cf-connecting-ip'] !== undefined
|
|
61
|
+
|| request.headers['x-forwarded-for'] !== undefined
|
|
62
|
+
}
|
|
63
|
+
|
|
39
64
|
/**
|
|
40
65
|
* Request-level trust fence: a loopback socket address AND a loopback Host
|
|
41
66
|
* header, plus browser same-origin markers. The socket address is
|
|
42
|
-
* authoritative;
|
|
67
|
+
* authoritative for a direct connection; a request that carries a forwarding
|
|
68
|
+
* header is refused outright, because a proxy in front of the host makes both
|
|
69
|
+
* the socket address and the Host header describe the proxy rather than the
|
|
70
|
+
* client. X-Forwarded-For is therefore never evidence *for* loopback.
|
|
43
71
|
*/
|
|
44
72
|
export function isLoopbackRequest(request: IncomingMessage): boolean {
|
|
45
73
|
if (!isLoopbackAddress(request.socket.remoteAddress)) return false
|
|
74
|
+
if (isProxiedRequest(request)) return false
|
|
46
75
|
const host = request.headers.host
|
|
47
76
|
if (typeof host !== 'string') return false
|
|
48
77
|
let hostUrl: URL
|
|
@@ -61,3 +90,30 @@ export function isLoopbackRequest(request: IncomingMessage): boolean {
|
|
|
61
90
|
return false
|
|
62
91
|
}
|
|
63
92
|
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Whether a forwarded request landed on this machine's loopback upstream: a
|
|
96
|
+
* forwarding header (the proxy's own stamp), a loopback socket address (the
|
|
97
|
+
* proxy dials 127.0.0.1:<port>), and a loopback Host header (the proxy rewrote
|
|
98
|
+
* the authority to its upstream literal).
|
|
99
|
+
*
|
|
100
|
+
* This is a fact about the route, not a trust decision. A public request to a
|
|
101
|
+
* tunnel satisfies all three by construction, because the proxy is the client
|
|
102
|
+
* of this process: only a caller that operates the proxy can decide it stands
|
|
103
|
+
* for the browser, which is why every consumer keeps this behind an explicit
|
|
104
|
+
* default-off switch and its own browser markers. isLoopbackRequest is
|
|
105
|
+
* unchanged and still refuses a forwarded request (issue #1906).
|
|
106
|
+
* @param request - node HTTP request.
|
|
107
|
+
* @returns true when a forwarding header, a loopback socket, and a loopback Host all hold.
|
|
108
|
+
*/
|
|
109
|
+
export function isForwardedLoopbackRequest(request: IncomingMessage): boolean {
|
|
110
|
+
if (!isProxiedRequest(request)) return false
|
|
111
|
+
if (!isLoopbackAddress(request.socket.remoteAddress)) return false
|
|
112
|
+
const host = request.headers.host
|
|
113
|
+
if (typeof host !== 'string') return false
|
|
114
|
+
try {
|
|
115
|
+
return isLoopbackHostname(new URL('http://' + host).hostname)
|
|
116
|
+
} catch {
|
|
117
|
+
return false
|
|
118
|
+
}
|
|
119
|
+
}
|
package/src/protocol.ts
CHANGED
|
@@ -29,7 +29,7 @@ export interface SshHostEntry {
|
|
|
29
29
|
/**
|
|
30
30
|
* ssh-agent endpoint for 'agent' auth. A socket path, the special value
|
|
31
31
|
* 'pageant' (PuTTY Pageant on Windows), or undefined for auto-detect
|
|
32
|
-
* (SSH_AUTH_SOCK, then
|
|
32
|
+
* (SSH_AUTH_SOCK, then the native OpenSSH named pipe on Windows).
|
|
33
33
|
*/
|
|
34
34
|
agentPath?: string
|
|
35
35
|
}
|
|
@@ -50,6 +50,12 @@ export interface SshHostEntry {
|
|
|
50
50
|
tags: string[]
|
|
51
51
|
/** Physical location note. */
|
|
52
52
|
location?: string
|
|
53
|
+
/**
|
|
54
|
+
* Opt-in ssh-agent forwarding (OpenSSH ForwardAgent / ssh -A): the host's
|
|
55
|
+
* sessions request agent forwarding so the remote can sign with this
|
|
56
|
+
* machine's agent. Default off; stored only when enabled.
|
|
57
|
+
*/
|
|
58
|
+
forwardAgent?: boolean
|
|
53
59
|
createdAt: number
|
|
54
60
|
updatedAt: number
|
|
55
61
|
}
|
|
@@ -70,6 +76,12 @@ export interface SshHostSummary {
|
|
|
70
76
|
environment?: string
|
|
71
77
|
tags: string[]
|
|
72
78
|
location?: string
|
|
79
|
+
/**
|
|
80
|
+
* Whether agent forwarding is enabled. Always projected as a definite
|
|
81
|
+
* boolean: the browser and the tool bridge need a value even for entries
|
|
82
|
+
* stored before the feature existed.
|
|
83
|
+
*/
|
|
84
|
+
forwardAgent: boolean
|
|
73
85
|
createdAt: number
|
|
74
86
|
updatedAt: number
|
|
75
87
|
}
|
|
@@ -160,6 +172,11 @@ export interface HostPayload {
|
|
|
160
172
|
environment?: string
|
|
161
173
|
tags?: string[]
|
|
162
174
|
location?: string
|
|
175
|
+
/**
|
|
176
|
+
* Agent forwarding for this host. Omitted on update keeps the stored value;
|
|
177
|
+
* false clears it (PATCH semantics).
|
|
178
|
+
*/
|
|
179
|
+
forwardAgent?: boolean
|
|
163
180
|
}
|
|
164
181
|
|
|
165
182
|
/** Why one ssh_config Host block was not imported. */
|
package/src/routes.ts
CHANGED
|
@@ -130,8 +130,11 @@ const maxUploadBytes = deps.maxUploadBytes ?? MAX_UPLOAD_BYTES
|
|
|
130
130
|
// Connection-relevant changes invalidate the pooled connection:
|
|
131
131
|
// without this the pool would keep running commands on the old
|
|
132
132
|
// host/credentials until the idle sweep (up to 30 min later).
|
|
133
|
+
// Agent forwarding belongs here too: it is fixed per connection
|
|
134
|
+
// (ssh2 negotiates it when the channel opens), so toggling it must
|
|
135
|
+
// reconnect or the new setting silently never takes effect.
|
|
133
136
|
const patch = body as Record<string, unknown>
|
|
134
|
-
if (['host', 'port', 'user', 'auth', 'proxyJump', 'proxyCommand'].some(key => patch[key] !== undefined)) {
|
|
137
|
+
if (['host', 'port', 'user', 'auth', 'proxyJump', 'proxyCommand', 'forwardAgent'].some(key => patch[key] !== undefined)) {
|
|
135
138
|
engine.dropAlias(alias)
|
|
136
139
|
}
|
|
137
140
|
writeJson(res, 200, { host: store.summarize(entry) })
|
package/src/store.ts
CHANGED
|
@@ -72,6 +72,9 @@ export function validateHostPayload(payload: unknown): string | undefined {
|
|
|
72
72
|
if (p.tags !== undefined && (!Array.isArray(p.tags) || p.tags.some(x => typeof x !== 'string'))) {
|
|
73
73
|
return 'tags must be an array of strings'
|
|
74
74
|
}
|
|
75
|
+
if (p.forwardAgent !== undefined && typeof p.forwardAgent !== 'boolean') {
|
|
76
|
+
return 'forwardAgent must be a boolean'
|
|
77
|
+
}
|
|
75
78
|
return undefined
|
|
76
79
|
}
|
|
77
80
|
|
|
@@ -136,6 +139,9 @@ export class HostStore {
|
|
|
136
139
|
...(entry.environment !== undefined ? { environment: entry.environment } : {}),
|
|
137
140
|
tags: [...entry.tags],
|
|
138
141
|
...(entry.location !== undefined ? { location: entry.location } : {}),
|
|
142
|
+
// Always a definite boolean, unlike the conditional optional fields:
|
|
143
|
+
// the tool bridge rejects undefined-valued JSON properties.
|
|
144
|
+
forwardAgent: entry.forwardAgent === true,
|
|
139
145
|
createdAt: entry.createdAt,
|
|
140
146
|
updatedAt: entry.updatedAt,
|
|
141
147
|
}
|
|
@@ -171,6 +177,9 @@ export class HostStore {
|
|
|
171
177
|
environment: payload.environment?.trim() || undefined,
|
|
172
178
|
tags: [...(payload.tags ?? [])].map(tag => tag.trim()).filter(tag => tag !== ''),
|
|
173
179
|
location: payload.location?.trim() || undefined,
|
|
180
|
+
// Stored only when enabled, so a store file written without agent
|
|
181
|
+
// forwarding stays byte-identical to the pre-feature format.
|
|
182
|
+
forwardAgent: payload.forwardAgent === true ? true : undefined,
|
|
174
183
|
createdAt: now,
|
|
175
184
|
updatedAt: now,
|
|
176
185
|
}
|
|
@@ -201,6 +210,9 @@ export class HostStore {
|
|
|
201
210
|
if (patch.proxyCommand !== undefined && typeof patch.proxyCommand !== 'string') {
|
|
202
211
|
throw new Error('proxyCommand must be a string when provided')
|
|
203
212
|
}
|
|
213
|
+
if (patch.forwardAgent !== undefined && typeof patch.forwardAgent !== 'boolean') {
|
|
214
|
+
throw new Error('forwardAgent must be a boolean')
|
|
215
|
+
}
|
|
204
216
|
// The mutual exclusion is checked on the MERGED view: a patch that only
|
|
205
217
|
// adds one transport must not slip past a stored value of the other.
|
|
206
218
|
const mergedProxyCommand = patch.proxyCommand !== undefined
|
|
@@ -250,6 +262,8 @@ export class HostStore {
|
|
|
250
262
|
if (patch.environment !== undefined) entry.environment = patch.environment.trim() || undefined
|
|
251
263
|
if (patch.tags !== undefined) entry.tags = [...patch.tags].map(tag => tag.trim()).filter(tag => tag !== '')
|
|
252
264
|
if (patch.location !== undefined) entry.location = patch.location.trim() || undefined
|
|
265
|
+
// PATCH semantics: an omitted key keeps the stored value, false clears it.
|
|
266
|
+
if (patch.forwardAgent !== undefined) entry.forwardAgent = patch.forwardAgent === true ? true : undefined
|
|
253
267
|
entry.updatedAt = Date.now()
|
|
254
268
|
this.save(file)
|
|
255
269
|
return entry
|
|
@@ -326,6 +340,7 @@ export class HostStore {
|
|
|
326
340
|
environment: block.props.environment,
|
|
327
341
|
tags: (block.props.tags ?? '').split(',').map(tag => tag.trim()).filter(tag => tag !== ''),
|
|
328
342
|
location: block.props.location,
|
|
343
|
+
forwardAgent: parseForwardAgentValue(block.props.forwardagent),
|
|
329
344
|
}
|
|
330
345
|
try {
|
|
331
346
|
this.create(payload)
|
|
@@ -411,6 +426,17 @@ export function normalizeProxyCommand(raw: string | undefined): string | undefin
|
|
|
411
426
|
return trimmed
|
|
412
427
|
}
|
|
413
428
|
|
|
429
|
+
/**
|
|
430
|
+
* Read an ssh_config `ForwardAgent` value into the stored boolean flag. Only
|
|
431
|
+
* an explicit yes/true/on enables forwarding; an absent value, no/false/off,
|
|
432
|
+
* and anything unrecognized leave it off instead of failing the import — an
|
|
433
|
+
* unknown keyword must never cost the user the whole Host block.
|
|
434
|
+
*/
|
|
435
|
+
export function parseForwardAgentValue(raw: string | undefined): boolean {
|
|
436
|
+
const value = raw?.trim().toLowerCase()
|
|
437
|
+
return value === 'yes' || value === 'true' || value === 'on'
|
|
438
|
+
}
|
|
439
|
+
|
|
414
440
|
/** Expand a leading `~` in a filesystem path. */
|
|
415
441
|
export function expandHome(path: string): string {
|
|
416
442
|
if (path === '~') return homedir()
|
package/src/tool-surface.ts
CHANGED
package/src/tools.ts
CHANGED
|
@@ -28,6 +28,7 @@ export interface AgentHostRow {
|
|
|
28
28
|
keyReady: boolean
|
|
29
29
|
proxyJump: string[]
|
|
30
30
|
proxyCommandConfigured: boolean
|
|
31
|
+
forwardAgent: boolean
|
|
31
32
|
description?: string
|
|
32
33
|
environment?: string
|
|
33
34
|
tags: string[]
|
|
@@ -52,11 +53,14 @@ function renderHosts(hosts: AgentHostRow[]): string {
|
|
|
52
53
|
host.user,
|
|
53
54
|
host.auth,
|
|
54
55
|
host.proxyJump.length > 0 ? 'jump:' + host.proxyJump.join(',') : host.proxyCommandConfigured ? 'proxy-command' : '-',
|
|
56
|
+
// Forwarding is a security-relevant opt-in (the remote can sign with this
|
|
57
|
+
// machine's agent), so the model must see it in the table, not only in JSON.
|
|
58
|
+
host.forwardAgent ? 'yes' : '-',
|
|
55
59
|
host.environment ?? '-',
|
|
56
60
|
(host.tags.length > 0 ? host.tags.join(',') : '-'),
|
|
57
61
|
host.description ?? '',
|
|
58
62
|
].join(' | '))
|
|
59
|
-
return ['alias | host | port | user | auth | proxy | environment | tags | description', '--- | --- | --- | --- | --- | --- | --- | --- | ---', ...rows].join('\n')
|
|
63
|
+
return ['alias | host | port | user | auth | proxy | forward | environment | tags | description', '--- | --- | --- | --- | --- | --- | --- | --- | --- | ---', ...rows].join('\n')
|
|
60
64
|
}
|
|
61
65
|
|
|
62
66
|
/** Render one exec result (mirrors the bash-tool exit-code convention). */
|
|
@@ -91,7 +95,7 @@ function renderTunnel(tunnel: TunnelInfo): string {
|
|
|
91
95
|
export function sshListTool(engine: SshEngine) {
|
|
92
96
|
return defineTool({
|
|
93
97
|
name: 'ssh_list',
|
|
94
|
-
description: 'List configured SSH hosts (alias, host, user, auth, environment, tags, description). Use ssh_exec etc. with the alias.',
|
|
98
|
+
description: 'List configured SSH hosts (alias, host, user, auth, agent forwarding, environment, tags, description). Use ssh_exec etc. with the alias.',
|
|
95
99
|
parameters: {
|
|
96
100
|
query: { type: 'string', description: 'Optional fuzzy match against alias, description, host, and tags.' },
|
|
97
101
|
},
|
|
@@ -115,6 +119,7 @@ export function sshListTool(engine: SshEngine) {
|
|
|
115
119
|
keyReady: { type: 'boolean', required: true },
|
|
116
120
|
proxyJump: { type: 'array', items: { type: 'string' }, required: true },
|
|
117
121
|
proxyCommandConfigured: { type: 'boolean', required: true },
|
|
122
|
+
forwardAgent: { type: 'boolean', required: true },
|
|
118
123
|
description: { type: 'string' },
|
|
119
124
|
environment: { type: 'string' },
|
|
120
125
|
tags: { type: 'array', items: { type: 'string' }, required: true },
|
|
@@ -144,7 +149,7 @@ export function sshExecTool(engine: SshEngine) {
|
|
|
144
149
|
parameters: {
|
|
145
150
|
alias: { type: 'string', required: true, description: 'Host alias from ssh_list.' },
|
|
146
151
|
command: { type: 'string', required: true, description: 'The shell command to run remotely.' },
|
|
147
|
-
timeoutMs: { type: 'integer', description: '
|
|
152
|
+
timeoutMs: { type: 'integer', description: 'Remote command execution timeout in milliseconds (default 60000); it starts after the connection is ready. The connection and authentication ceiling is the dsh-ssh connectTimeoutMs setting, not this argument.' },
|
|
148
153
|
},
|
|
149
154
|
output: {
|
|
150
155
|
schema: {
|
|
@@ -362,7 +367,7 @@ export function sshClusterTool(engine: SshEngine) {
|
|
|
362
367
|
aliases: { type: 'array', items: { type: 'string' }, description: 'Optional alias filter; at least one of aliases, environment, or tags is required.' },
|
|
363
368
|
environment: { type: 'string', description: 'Optional environment filter; at least one selector is required.' },
|
|
364
369
|
tags: { type: 'array', items: { type: 'string' }, description: 'Optional ALL-tags filter; at least one selector is required.' },
|
|
365
|
-
timeoutMs: { type: 'integer', description: 'Per-host timeout in milliseconds.' },
|
|
370
|
+
timeoutMs: { type: 'integer', description: 'Per-host command execution timeout in milliseconds (default 60000); it does not extend the connection and authentication ceiling (the dsh-ssh connectTimeoutMs setting).' },
|
|
366
371
|
maxWorkers: { type: 'integer', description: 'Concurrency cap (default 8).' },
|
|
367
372
|
},
|
|
368
373
|
output: {
|