Skip to content

fix(ssh): key the add-host duplicate check on the endpoint, not the alias - #51067

Merged
nwparker merged 1 commit into
mainfrom
bugbash/issue-51036
Nov 27, 2026
Merged

nwparker merged 1 commit into
mainfrom
bugbash/issue-51036

Conversation

@nwparker

@nwparker nwparker commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

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.

Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​77 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​77
Prod 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​65 $\color{#cf222e}{\Huge{\mathbf{−}}}$​37 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​28

What Changed

Before: Adding 127.0.0.1:22101 and then 127.0.0.1:22102 failed 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]:2222 for IPv6), so the two hosts can be told apart in the list.

Mechanism:

  • isDuplicateSshTargetAlias became isDuplicateSshTarget in ssh-target-duplicate.ts. Manual adds default configHost to host, so the old check compared alias against alias and every host on one address matched. Now:
    • A candidate with a real alias (configHost !== host) is still checked on the alias, as before.
    • Otherwise it is checked on the endpoint. It is a duplicate when host and user match and the port matches. A blank user on either side matches any user, so leaving it out does not get around the check. A saved port 22 matches any port, because ssh -G can supply the real Port at connect time.
    • Imported ~/.ssh/config Hosts (including legacy imports with no source, matched by the same rule config sync uses) still own their name on any port and for any user.
    • A host whose name matches another target's alias or label is still refused.
  • New getDefaultSshTargetLabel in ssh-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, then 127.0.0.1:22102. Before, the second was refused. ssh-target-duplicate.test.ts now 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 on main because isDuplicateSshTarget does 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 listTargets IPC, 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 source go 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

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Ensure no issues in: Security, Cross-platform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • I stated the risk: what could break, for whom, and how to back it out
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

…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]>
@coderabbitai

coderabbitai Bot commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The changes add a shared fallback-label generator that uses connection details, including a non-default port when applicable. SSH host admission now checks duplicates using target identity fields, including host, port, username, and SSH-config alias rules. Tests cover duplicate and non-duplicate cases for ports, usernames, imported config hosts, labels, and aliases.

Severity of issue fixed: Medium

Merge Risk: Minimal · up to 01ff0

This change lets SSH hosts that share an address but differ by port or username be added, and still rejects exact repeats. Saved data is unchanged, so rollback is straightforward. No concrete merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: the add-host duplicate check now keys on the endpoint (host, port, user) instead of the alias. The changeset matches this. isDuplicateSshTarget replaces the alias-base…
Description check Passed The description follows the repository template closely. It has ELI5, What Changed (before and after with mechanism), Why, Linked Issue (Fixes #51036), Visual Proof (N/A with reason), Testing with a c…
Linked Issues check Passed Directly linked issue #51036 asks that duplicate detection use host, port, and username, with a blank username matching any user, and that aliases stay for display and config matching. At the reviewed…
Out of Scope Changes check Passed The changes match the duplicate-check rule and the default label rule described for #51036. ssh-target-duplicate.ts and its tests implement the endpoint rule. ssh-target-draft.ts adds getDefaultSshTar…
Full details: Title check

Explanation

The title names the main change: the add-host duplicate check now keys on the endpoint (host, port, user) instead of the alias. The changeset matches this. isDuplicateSshTarget replaces the alias-based check, and the default label change is part of the same fix. The title uses the conventional 'fix(ssh):' prefix and is 73 characters, within a reasonable length.

Full details: Description check

Explanation

The description follows the repository template closely. It has ELI5, What Changed (before and after with mechanism), Why, Linked Issue (Fixes #51036), Visual Proof (N/A with reason), Testing with a checklist, Performance (a specific line with measurements), Risk with level and back-out plan, Agent skill boundary, Notes, and Checklist. Minor gaps: the AI Disclosure section is left blank, which is allowed for internal contributors but unclear for an outside author, and the lint/typecheck/test/build checklist item is unchecked. The Testing section reports platform as macOS at unit level only, and manual testing is unchecked, which the template asks for.

Full details: Linked Issues check

Explanation

Directly linked issue #51036 asks that duplicate detection use host, port, and username, with a blank username matching any user, and that aliases stay for display and config matching. At the reviewed head, isDuplicateSshTarget in ssh-target-duplicate.ts does this for candidates without a distinct alias: it compares normalized host, port, and username, and isSameSshUser treats a blank user on either side as a match. Aliases still reserve names through getOccupiedAliases. The issue repro (127.0.0.1:22101 then 127.0.0.1:22102) is covered by the new tests in ssh-target-duplicate.test.ts. The add-host dialog and Settings share getDefaultSshTargetLabel. Two rules go beyond the issue proposal: a saved port 22 matches any port, and imported config Hosts reserve their name across ports and users. These are stated PR rules and do not block the issue repro. The issue also proposes a guard in the ssh.addTarget handler for CLI registration. The reviewed diff summary does not show a handler change, and I did not inspect the handler, so CLI bypass behavior is not verified.

Full details: Out of Scope Changes check

Explanation

The changes match the duplicate-check rule and the default label rule described for #51036. ssh-target-duplicate.ts and its tests implement the endpoint rule. ssh-target-draft.ts adds getDefaultSshTargetLabel, which includes a non-22 port and brackets IPv6 hosts. add-remote-host-ssh-actions.ts and ssh-target-save-payload.ts use this helper so the dialog and Settings produce the same label. The type change to SshTargetIdentity supports the new check. The changes are needed for the new behavior and add no unrelated changes.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 90726b2f-ce1b-4dd1-9add-f4545d460de0
Commits

Reviewing files that changed from the base of the PR and between 13defff and 01ff0c2.

Files selected for processing: 5

  • src/renderer/src/components/settings/ssh/targets/ssh-target-save-payload.ts
  • src/renderer/src/components/sidebar/host-admission/ssh/add-remote-host-ssh-actions.ts
  • src/renderer/src/components/sidebar/host-admission/ssh/ssh-target-duplicate.test.ts
  • src/renderer/src/components/sidebar/host-admission/ssh/ssh-target-duplicate.ts
  • src/renderer/src/components/ssh-host-form/ssh-target-draft.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.

@nwparker
nwparker merged commit 44810e2 into main Nov 27, 2026
54 checks passed
@nwparker
nwparker deleted the bugbash/issue-51036 branch November 27, 2026 18:26
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.

Duplicate-target check keys on alias, so several hosts on one gateway look identical

1 participant