dsh-remote-vs 0.28.0 → 0.29.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/README.en.md +50 -5
- package/README.md +42 -5
- package/lib/client.js +217 -112
- package/lib/index.js +1468 -51
- package/lib/types/client/HostsView.d.ts +139 -2
- package/lib/types/client/api.d.ts +25 -1
- package/lib/types/client/connection.d.ts +28 -1
- package/lib/types/forward.d.ts +11 -1
- package/lib/types/pool.d.ts +95 -1
- package/lib/types/protocol.d.ts +122 -0
- package/lib/types/proxy.d.ts +136 -0
- package/lib/types/store.d.ts +81 -1
- package/lib/types/tools.d.ts +3 -0
- package/package.json +1 -1
- package/src/client/ConnectionStatus.tsx +19 -5
- package/src/client/HostsView.tsx +552 -11
- package/src/client/PortsView.tsx +16 -0
- package/src/client/SettingsHosts.tsx +132 -6
- package/src/client/api.ts +30 -0
- package/src/client/connection.ts +76 -2
- package/src/client/i18n.ts +102 -0
- package/src/client/vsc/vsc.css +105 -0
- package/src/forward.ts +38 -2
- package/src/importers.ts +125 -13
- package/src/keygen.ts +8 -1
- package/src/pool.ts +422 -27
- package/src/protocol.ts +128 -0
- package/src/proxy.ts +673 -0
- package/src/routes.ts +73 -5
- package/src/store.ts +335 -0
- package/src/tools.ts +47 -2
package/src/forward.ts
CHANGED
|
@@ -45,7 +45,18 @@ const LOOPBACK = '127.0.0.1'
|
|
|
45
45
|
* the manager never reaches into the pool beyond one call.
|
|
46
46
|
*/
|
|
47
47
|
export interface ForwardPoolLike {
|
|
48
|
-
|
|
48
|
+
/**
|
|
49
|
+
* Open one direct-tcpip channel. `opts.dedicated` asks for the host's dedicated
|
|
50
|
+
* forward connection; the answer carries which connection was actually used, so
|
|
51
|
+
* the rule can SAY "shared" after a fallback instead of pretending.
|
|
52
|
+
*/
|
|
53
|
+
forwardOut(
|
|
54
|
+
alias: string,
|
|
55
|
+
dstHost: string,
|
|
56
|
+
dstPort: number,
|
|
57
|
+
srcPort?: number,
|
|
58
|
+
opts?: { dedicated?: boolean },
|
|
59
|
+
): Promise<{ channel: ClientChannel; dedicated: boolean }>
|
|
49
60
|
}
|
|
50
61
|
|
|
51
62
|
export interface ForwardManagerDeps {
|
|
@@ -147,6 +158,14 @@ interface Forward {
|
|
|
147
158
|
bytesIn: number
|
|
148
159
|
bytesOut: number
|
|
149
160
|
lastError: string | undefined
|
|
161
|
+
/**
|
|
162
|
+
* Which SSH connection the last successful channel used.
|
|
163
|
+
*
|
|
164
|
+
* `dedicated` = the host's own forward connection (the normal case); `shared` =
|
|
165
|
+
* the server refused that extra connection and the channel rode the shared one.
|
|
166
|
+
* `undefined` until a connection has succeeded at least once (no data to show).
|
|
167
|
+
*/
|
|
168
|
+
transport: 'dedicated' | 'shared' | undefined
|
|
150
169
|
startedAt: number
|
|
151
170
|
}
|
|
152
171
|
|
|
@@ -316,6 +335,7 @@ export class ForwardManager {
|
|
|
316
335
|
bytesIn: 0,
|
|
317
336
|
bytesOut: 0,
|
|
318
337
|
lastError: undefined,
|
|
338
|
+
transport: undefined,
|
|
319
339
|
startedAt: Date.now(),
|
|
320
340
|
}
|
|
321
341
|
server.on('connection', (socket) => { this.accept(forward, socket) })
|
|
@@ -384,7 +404,22 @@ export class ForwardManager {
|
|
|
384
404
|
private async connect(forward: Forward, socket: Socket): Promise<void> {
|
|
385
405
|
let channel: ClientChannel
|
|
386
406
|
try {
|
|
387
|
-
|
|
407
|
+
/**
|
|
408
|
+
* Ask for the host's DEDICATED forward connection: forwarding traffic is
|
|
409
|
+
* long-lived and heavy, and multiplexed onto the shared connection it would
|
|
410
|
+
* queue ahead of exec/SFTP channels. The pool falls back on its own when the
|
|
411
|
+
* server refuses the extra connection, and tells us which one was used so
|
|
412
|
+
* the row can say so.
|
|
413
|
+
*/
|
|
414
|
+
const opened = await this.deps.pool.forwardOut(
|
|
415
|
+
forward.alias,
|
|
416
|
+
forward.remoteHost,
|
|
417
|
+
forward.remotePort,
|
|
418
|
+
0,
|
|
419
|
+
{ dedicated: true },
|
|
420
|
+
)
|
|
421
|
+
channel = opened.channel
|
|
422
|
+
forward.transport = opened.dedicated ? 'dedicated' : 'shared'
|
|
388
423
|
} catch (error) {
|
|
389
424
|
forward.lastError = messageOf(error)
|
|
390
425
|
this.log('warn', `forward ${forward.id} -> ${forward.remoteHost}:${forward.remotePort} failed: ${forward.lastError}`)
|
|
@@ -469,6 +504,7 @@ export class ForwardManager {
|
|
|
469
504
|
bytesIn: forward.bytesIn,
|
|
470
505
|
bytesOut: forward.bytesOut,
|
|
471
506
|
...(forward.lastError === undefined ? {} : { lastError: forward.lastError }),
|
|
507
|
+
...(forward.transport === undefined ? {} : { transport: forward.transport }),
|
|
472
508
|
startedAt: forward.startedAt,
|
|
473
509
|
}
|
|
474
510
|
}
|
package/src/importers.ts
CHANGED
|
@@ -1,15 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* One-shot importers: ~/.ssh/config and the existing dsh-ssh.json. Both only
|
|
3
3
|
* READ the source and produce payloads for our own store — no runtime coupling.
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* Hosts are direct key hosts; the egress half of a `Host` block (`ProxyJump` /
|
|
5
|
+
* `ProxyCommand`) is mapped onto the store's `proxy` field when it names
|
|
6
|
+
* something this import actually produces, and refused BY NAME when it names a
|
|
7
|
+
* form this plugin cannot dial (multi-hop, a shell command, a jump host that is
|
|
8
|
+
* not part of the config). A silent skip used to be the answer to all of them;
|
|
9
|
+
* "one hop, from this same config" is the honest boundary.
|
|
6
10
|
*/
|
|
7
11
|
import { existsSync, readFileSync } from 'node:fs'
|
|
8
12
|
import { homedir } from 'node:os'
|
|
9
13
|
import { join } from 'node:path'
|
|
10
14
|
import { dshHome } from './paths.ts'
|
|
11
15
|
import type { HostPayload } from './store.ts'
|
|
12
|
-
import type { ImportReport } from './protocol.ts'
|
|
16
|
+
import type { ImportReport, RemoteHostProxySetting } from './protocol.ts'
|
|
17
|
+
import { parseProxyCommand, parseProxyJump } from './proxy.ts'
|
|
13
18
|
|
|
14
19
|
export interface ParsedImport {
|
|
15
20
|
payloads: HostPayload[]
|
|
@@ -36,9 +41,93 @@ function validPort(value: string | number): number | undefined {
|
|
|
36
41
|
return port
|
|
37
42
|
}
|
|
38
43
|
|
|
44
|
+
/** One host block that WILL be imported once its egress decision is known. */
|
|
45
|
+
interface CandidateHost {
|
|
46
|
+
alias: string
|
|
47
|
+
hostname: string
|
|
48
|
+
port: number
|
|
49
|
+
user: string
|
|
50
|
+
identityFile: string
|
|
51
|
+
fields: Map<string, string>
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** What resolving one block's `ProxyJump`/`ProxyCommand` produced. */
|
|
55
|
+
type ProxyResolution =
|
|
56
|
+
| { ok: true; proxy?: RemoteHostProxySetting }
|
|
57
|
+
| { ok: false; reason: string }
|
|
58
|
+
|
|
59
|
+
/** `ProxyJump none` / `ProxyCommand none` is OpenSSH for "explicitly no proxy". */
|
|
60
|
+
function isNone(value: string): boolean {
|
|
61
|
+
return value.trim().toLowerCase() === 'none'
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Index every name an imported host answers to: its alias and its `HostName`.
|
|
66
|
+
*
|
|
67
|
+
* `ProxyJump bastion` may name the `Host bastion` alias or the literal hostname
|
|
68
|
+
* it resolves to, so both are accepted; a name with no host behind it in THIS
|
|
69
|
+
* config cannot become a `viaAlias` (the stored setting would dangle).
|
|
70
|
+
*/
|
|
71
|
+
function nameIndex(candidates: CandidateHost[]): Map<string, string> {
|
|
72
|
+
const index = new Map<string, string>()
|
|
73
|
+
for (const candidate of candidates) {
|
|
74
|
+
index.set(candidate.alias, candidate.alias)
|
|
75
|
+
index.set(candidate.alias.toLowerCase(), candidate.alias)
|
|
76
|
+
index.set(candidate.hostname, candidate.alias)
|
|
77
|
+
index.set(candidate.hostname.toLowerCase(), candidate.alias)
|
|
78
|
+
}
|
|
79
|
+
return index
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** Resolve one jump host name against the hosts this import creates. */
|
|
83
|
+
function resolveJump(self: string, name: string, index: Map<string, string>): ProxyResolution {
|
|
84
|
+
const viaAlias = index.get(name) ?? index.get(name.toLowerCase())
|
|
85
|
+
if (viaAlias === undefined) {
|
|
86
|
+
return {
|
|
87
|
+
ok: false,
|
|
88
|
+
reason: `jump host '${name}' is not imported by this config — a jump host must be one of its Host entries`,
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
if (viaAlias === self) return { ok: false, reason: `jump host '${name}' is this host itself` }
|
|
92
|
+
return { ok: true, proxy: { mode: 'jump', jump: { viaAlias } } }
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Turn one block's egress directive into the store's proxy decision.
|
|
97
|
+
*
|
|
98
|
+
* Precedence matches OpenSSH (a set `ProxyJump` wins over `ProxyCommand`), and
|
|
99
|
+
* everything unusable keeps the PARSER's own reason so the report says what to
|
|
100
|
+
* fix ("only one hop", "not supported program") instead of a generic skip.
|
|
101
|
+
*/
|
|
102
|
+
function resolveProxy(self: string, fields: Map<string, string>, index: Map<string, string>): ProxyResolution {
|
|
103
|
+
const jump = fields.get('proxyjump')
|
|
104
|
+
if (jump !== undefined) {
|
|
105
|
+
if (isNone(jump)) return { ok: true }
|
|
106
|
+
const parsed = parseProxyJump(jump)
|
|
107
|
+
if (!parsed.ok) return { ok: false, reason: parsed.reason }
|
|
108
|
+
return resolveJump(self, parsed.target.host, index)
|
|
109
|
+
}
|
|
110
|
+
const command = fields.get('proxycommand')
|
|
111
|
+
if (command !== undefined) {
|
|
112
|
+
if (isNone(command)) return { ok: true }
|
|
113
|
+
const plan = parseProxyCommand(command)
|
|
114
|
+
if (plan.kind === 'proxy') {
|
|
115
|
+
// The parsed plan carries no credentials on purpose: an nc/ncat command
|
|
116
|
+
// line may name a proxy but never its password, and guessing one would
|
|
117
|
+
// produce a host that fails with "the proxy rejected the credentials".
|
|
118
|
+
return {
|
|
119
|
+
ok: true,
|
|
120
|
+
proxy: { mode: 'proxy', proxy: { kind: plan.proxy.kind, host: plan.proxy.host, port: plan.proxy.port } },
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
if (plan.kind === 'jump') return resolveJump(self, plan.target.host, index)
|
|
124
|
+
return { ok: false, reason: plan.reason }
|
|
125
|
+
}
|
|
126
|
+
return { ok: true }
|
|
127
|
+
}
|
|
128
|
+
|
|
39
129
|
/** Parse OpenSSH client config text into host payloads. */
|
|
40
130
|
export function parseSshConfig(text: string): ParsedImport {
|
|
41
|
-
const payloads: HostPayload[] = []
|
|
42
131
|
const skipped: { alias: string; reason: string }[] = []
|
|
43
132
|
interface Block { patterns: string[]; fields: Map<string, string> }
|
|
44
133
|
const blocks: Block[] = []
|
|
@@ -67,6 +156,11 @@ export function parseSshConfig(text: string): ParsedImport {
|
|
|
67
156
|
current.fields.set(key, value)
|
|
68
157
|
}
|
|
69
158
|
}
|
|
159
|
+
// Pass 1: which names become hosts at all. The proxy decision is resolved in
|
|
160
|
+
// pass 2 because `ProxyJump` may name a block that appears LATER in the file —
|
|
161
|
+
// and because a jump host that is itself skipped (no IdentityFile) must not be
|
|
162
|
+
// recorded as a live alias.
|
|
163
|
+
const candidates: CandidateHost[] = []
|
|
70
164
|
for (const block of blocks) {
|
|
71
165
|
// A `Host a b` line declares TWO names with the same fields: import each
|
|
72
166
|
// concrete pattern instead of silently dropping everything after the first.
|
|
@@ -79,10 +173,6 @@ export function parseSshConfig(text: string): ParsedImport {
|
|
|
79
173
|
if (special.length === 0) skipped.push({ alias: '(empty)', reason: 'Host line has no pattern' })
|
|
80
174
|
continue
|
|
81
175
|
}
|
|
82
|
-
if (block.fields.has('proxyjump') || block.fields.has('proxycommand')) {
|
|
83
|
-
for (const alias of concrete) skipped.push({ alias, reason: 'proxyJump/proxyCommand needs P1 (direct hosts only in P0)' })
|
|
84
|
-
continue
|
|
85
|
-
}
|
|
86
176
|
const rawPort = block.fields.get('port')
|
|
87
177
|
const port = rawPort === undefined ? 22 : validPort(rawPort)
|
|
88
178
|
const identityFile = block.fields.get('identityfile')?.split(/\s+/)[0]
|
|
@@ -102,16 +192,35 @@ export function parseSshConfig(text: string): ParsedImport {
|
|
|
102
192
|
skipped.push({ alias, reason: 'no IdentityFile in ssh_config — add the key or password after import' })
|
|
103
193
|
continue
|
|
104
194
|
}
|
|
105
|
-
|
|
195
|
+
candidates.push({
|
|
106
196
|
alias,
|
|
107
|
-
|
|
197
|
+
hostname: block.fields.get('hostname') ?? alias,
|
|
108
198
|
port,
|
|
109
199
|
user,
|
|
110
|
-
|
|
111
|
-
|
|
200
|
+
identityFile,
|
|
201
|
+
fields: block.fields,
|
|
112
202
|
})
|
|
113
203
|
}
|
|
114
204
|
}
|
|
205
|
+
// Pass 2: the egress decision, against the names pass 1 will actually create.
|
|
206
|
+
const index = nameIndex(candidates)
|
|
207
|
+
const payloads: HostPayload[] = []
|
|
208
|
+
for (const candidate of candidates) {
|
|
209
|
+
const resolution = resolveProxy(candidate.alias, candidate.fields, index)
|
|
210
|
+
if (!resolution.ok) {
|
|
211
|
+
skipped.push({ alias: candidate.alias, reason: resolution.reason })
|
|
212
|
+
continue
|
|
213
|
+
}
|
|
214
|
+
payloads.push({
|
|
215
|
+
alias: candidate.alias,
|
|
216
|
+
host: candidate.hostname,
|
|
217
|
+
port: candidate.port,
|
|
218
|
+
user: candidate.user,
|
|
219
|
+
auth: { kind: 'key', keyPath: expandHome(candidate.identityFile) },
|
|
220
|
+
tags: ['imported:ssh-config'],
|
|
221
|
+
...(resolution.proxy === undefined ? {} : { proxy: resolution.proxy }),
|
|
222
|
+
})
|
|
223
|
+
}
|
|
115
224
|
return { payloads, skipped }
|
|
116
225
|
}
|
|
117
226
|
|
|
@@ -148,7 +257,10 @@ export function migrateDshSsh(home: string = dshHome()): ParsedImport {
|
|
|
148
257
|
continue
|
|
149
258
|
}
|
|
150
259
|
if (hasProxy) {
|
|
151
|
-
|
|
260
|
+
// dsh-ssh.json stores the SAME two directives in its own shape; mapping
|
|
261
|
+
// them would mean a second parser with no cfg sample to verify against, so
|
|
262
|
+
// this path keeps refusing and says where the mapping DOES exist.
|
|
263
|
+
skipped.push({ alias, reason: "proxyJump/proxyCommand in dsh-ssh.json is not mapped — import from ~/.ssh/config instead" })
|
|
152
264
|
continue
|
|
153
265
|
}
|
|
154
266
|
if (kind === 'key' && (typeof auth.keyPath !== 'string' || auth.keyPath.trim() === '')) {
|
package/src/keygen.ts
CHANGED
|
@@ -117,8 +117,15 @@ export async function bootstrap(pool: RemotePool, store: RemoteStore, alias: str
|
|
|
117
117
|
if (!result.success) {
|
|
118
118
|
throw new Error(`key install failed [exit code: ${result.exitCode}]: ${result.stderr || result.stdout || result.error || 'unknown'}`)
|
|
119
119
|
}
|
|
120
|
+
// Order matters and matches the host PATCH route: flip the entry FIRST, then
|
|
121
|
+
// drop the connection, so a dial racing this request cannot slip in a
|
|
122
|
+
// password-auth connection that nobody tears down afterwards.
|
|
120
123
|
store.update(alias, { auth: { kind: 'key', keyPath: privatePath } })
|
|
121
|
-
|
|
124
|
+
// `forget`, not `drop`: the old auth attempt's verdict ("password rejected",
|
|
125
|
+
// "key not installed yet") describes a credential this entry no longer uses,
|
|
126
|
+
// so it must not survive to colour the chip. The `test()` below records the
|
|
127
|
+
// new verdict against the key.
|
|
128
|
+
pool.forget(alias)
|
|
122
129
|
// Verify the new key actually works before declaring victory.
|
|
123
130
|
const check = await pool.test(alias)
|
|
124
131
|
if (!check.ok) {
|