Repository navigation
fix(ssh): key the add-host duplicate check on the endpoint, not the alias - #51067
Conversation
…lias Manual SSH hosts default configHost to host, so the alias-keyed duplicate check refused any second host on the same address, e.g. several containers behind one gateway on 127.0.0.1:22101 and 127.0.0.1:22102, or different users on one host. When the candidate has no distinct alias, compare host, port and user: a blank user matches any user, and a saved port 22 matches any port because ssh -G may supply the real one at connect time. Real aliases and imported ssh-config Hosts still own their name, and a host that matches another target's alias or label is still refused. The default label for an unaliased host on a non-22 port now includes the port (bracketing IPv6), so such hosts stay distinguishable in the list. Settings and the add-host dialog share one label helper. Fixes #51036 Co-authored-by: Claude <[email protected]>
|
No actionable comments were generated in the recent review. Walkthrough
Severity of issue fixed: Medium Merge Risk:
|
ELI5
If you run several machines behind one gateway (same address, different ports), Orca refused to add the second one and said "That SSH host is already in Orca." Now Orca only refuses a host that really is the same one: same address, same port, same user.
What Changed
Before: Adding
127.0.0.1:22101and then127.0.0.1:22102failed with "That SSH host is already in Orca." Different users on one host collided the same way. Both hosts would also get the same default label,127.0.0.1.After: Both hosts save. An exact repeat of an endpoint is still refused. An unnamed host on a non-22 port now gets a default label that includes the port (
127.0.0.1:22102,[::1]:2222for IPv6), so the two hosts can be told apart in the list.Mechanism:
isDuplicateSshTargetAliasbecameisDuplicateSshTargetinssh-target-duplicate.ts. Manual adds defaultconfigHosttohost, so the old check compared alias against alias and every host on one address matched. Now:configHost !== host) is still checked on the alias, as before.ssh -Gcan supply the real Port at connect time.~/.ssh/configHosts (including legacy imports with nosource, matched by the same rule config sync uses) still own their name on any port and for any user.getDefaultSshTargetLabelinssh-target-draft.ts, used by both the add-host dialog and Settings, so the two screens build the same default label.Why
The rest of the model already treats the endpoint as a target's identity. Connections are keyed on host, port and user, and label/configHost can be edited freely. Checking duplicates on the alias blocked a valid setup (one gateway, N endpoints). Keeping the alias rule for real aliases and imported config Hosts keeps the config picker's ownership behaviour, and config sync keys on those names.
Linked Issue
Fixes #51036
Reported by @youyouhe
Visual Proof
N/A. The fix is in the duplicate-check and default-label logic. The only visible change is that a toast no longer shows for a valid host, and the new default label text. Both are covered by unit tests, and no UI layout changed.
Testing
Repro (from the issue): add
127.0.0.1:22101, then127.0.0.1:22102. Before, the second was refused.ssh-target-duplicate.test.tsnow covers this case, plus: an exact repeat endpoint is refused, different explicit users are allowed, a saved port 22 matches any port, an imported config Host owns its name on any port or user, a host matching a manual target's label is refused, and an existing alias is refused.pnpm exec vitest run src/renderer/src/components/sidebar/host-admission/ssh src/renderer/src/components/ssh-host-form src/renderer/src/components/settings/ssh: 7/7 pass. The new test file fails onmainbecauseisDuplicateSshTargetdoes not exist there.oxlint, oxfmt, the anti-slop and native code-quality oxlint configs, ast-grep, and the changed-code quality gate all pass on the touched files.
Platform: macOS (unit level). The logic has no platform-specific code. IPv6 hosts get brackets in the label.
I manually tested these changes locally
Automated tests added/updated, or explained why not below
Every added test fails without this change and avoids the test anti-patterns
Performance
None that matters. The check runs once per "Add host" click, after the existing
listTargetsIPC, and does a linear scan over saved targets. Micro-benchmark, old vs new, per call: N=10 1.6us vs 3.6us; N=200 13.1us vs 14.0us; N=2000 81us vs 132us. No store, selector, polling or render-path changes, so nothing scales with mounted tabs or panes.Risk
Level: Low
Renderer-only, and no saved data format changes. The riskiest part is the endpoint rule. If it is too loose, a user could add a real duplicate (same host, user, non-22 port) under a different explicit port. If it is too strict, a valid host is still refused with the existing toast. Targets from older paired servers that have no
sourcego through the same legacy-import rule config sync uses. Existing saved labels are untouched: only new hosts with no label get the port-bearing default. To back out, revert the commit.Review
Agent skill upstream boundary
Notes
Ensure no issues in: Security, Cross-platform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)