Skip to content

fix(backend): dial credential-less machines through the user's own ssh - #100

Merged
flymysql merged 2 commits into
flymysql:mainfrom
davidlin2k:fix/openssh-default-for-credentialless-machines
Nov 9, 2026
Merged

flymysql merged 2 commits into
flymysql:mainfrom
davidlin2k:fix/openssh-default-for-credentialless-machines

Conversation

@davidlin2k

Copy link
Copy Markdown

Why

A ~/.ssh/config alias whose Host block carries only HostName/User has nothing the
native (ssh2) backend can authenticate with: ssh2 implements no default-identity
discovery (id_rsa/id_ed25519, the agent, AddKeysToAgent/UseKeychain). from-ssh-config
persisted such a machine as backend: "native", so Connect / 测试连接 returned
「缺少凭据」 for a host ssh <alias> reaches fine. Refs #99.

Scope

lib/index.js gains nativeUsableCredential(m) and backendFor(m, cfg): native stays
for a password, a privateKeyPath, useAgent, keyboard-interactive or a stored keychain
secret, or an explicit openssh; otherwise openssh (the user's own ssh). Applied at the
machine-pool builder, rw_connect's ephemeral target, /dsh-remote/connect,
upsertMachineRecord, from-ssh-config (new records default openssh; a pre-fix
credential-less native record is upgraded in place) and the /test-connect probe.
lib/errors.js names the openssh option in the 缺少凭据 hint.
Out of scope: no new route, no client/UI change, no change to ~/.ssh/config writes.

Tradeoffs

  • A machine that explicitly chose native but carries no credential is still moved to
    openssh: native provably cannot connect, so honouring it reproduces the dead end.
  • The /connect route ignores the exec exit code, so an openssh dial that fails still
    answers ok:true; existing route behaviour, unchanged.

Blast radius

Only the transport default. Credentialed machines keep native; explicit openssh choices
are unchanged. No secrets, argv or config-file paths change.

Verification

  • node --check over lib/*.js → clean; node check.mjs → 35 routes, no violations.
  • New tests: 7/12 fail on the test-only commit, 12/12 pass with the fix; the superseded saved-credentials.test.js control fails test-only and passes fixed.
  • npm test → exit 0, 0 failures (twice; the serial coverage-style run also passed).
  • npm run test:coverage → 79.1% weighted. The CI-equivalent gate intermittently breaches per-file floors here, and the pristine upstream worktree breaches them too — pre-existing coverage instability, not this diff.
    Verbatim commands and output: upstream-pr/verification.md.

A ~/.ssh/config alias whose Host block carries only HostName/User has no
credential ssh2 can authenticate with, so dialing it on the native backend
reports 「缺少凭据」 for a host `ssh <alias>` reaches fine. The new suite pins
the resolution rule: credential-less machines dial through the user's own ssh,
and every machine that carries a password/privateKeyPath/agent/
keyboard-interactive (or a stored keychain secret), or that explicitly chose
openssh, keeps its backend. All of these fail on the unfixed code (7 of 12).

saved-credentials.test.js's negative control is superseded by that rule — a
credential-less machine is now handed to the local ssh instead of being
refused as missing credentials — so it asserts the new contract; the 缺少凭据
classification stays covered at the pure level in errors.test.js.
Native (ssh2) authenticates only through a password, a privateKeyPath, an
agent or keyboard-interactive. A ~/.ssh/config alias whose Host block carries
just HostName/User relies on OpenSSH's own default-identity discovery and the
agent/keychain, which ssh2 does not implement, so dialing it on native
reported 「缺少凭据」 for a host `ssh <alias>` reaches fine.

backendFor(m, cfg) now picks the transport from the credentials a machine
actually carries: native stays when a password/privateKeyPath/useAgent/
keyboard-interactive or a stored keychain secret exists, or when the machine
explicitly chose openssh; otherwise the system-OpenSSH backend hands the alias
to the user's own ssh. Applied at every effective-backend site (machine-pool
builder, rw_connect ephemeral target, /connect, upsertMachineRecord,
from-ssh-config adoption and its upgrade of a pre-fix native record, and the
test-connect probe). The missing-credential hint now names the openssh option
for a ~/.ssh/config machine whose ssh already works.
@flymysql
flymysql merged commit a776de7 into flymysql:main Nov 9, 2026
@flymysql

flymysql commented Nov 9, 2026

Copy link
Copy Markdown
Owner

Merged. Thorough work — every dial site is covered (pool builder, /connect, upsert, probe, rw_connect, plus the in-place upgrade for pre-fix records), the test matrix isolates each credential shape, and the tradeoff note is honest about the one deliberate behaviour change.

Suite green on our side as well (1061 pass / 0 fail, check.mjs clean). Ships in the next release. This also resolves the scenario reported in #99. Thanks!

flymysql added a commit that referenced this pull request Nov 9, 2026
…less machines + resilient rw_sync + TUI mirror-folder key (PR #102/#100/#105/#103)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants