Repository navigation
fix(ssh): don't import a config alias for a machine already in Orca - #35792
Conversation
…another name The ssh-config picker compared names only, so a machine added by IP showed up again under its config alias. It now also compares the endpoint: hostname (case-insensitive), validated port, case-sensitive user, jump host and proxy command. Entries without HostName still match by alias only. Squashed from #15750 (3c3a3c6, a5575ce, 8daf213, a29d91e).
… in Orca Each config import now builds one snapshot: the config it read, and which new aliases resolve, through ssh -G, to a route an existing target already has. The duplicate check and the inserts both read only that snapshot. Imports and picker refreshes run one at a time through a single queue, so none can race another, and the picker reads the latest snapshot for its In Orca flags and Add all count without waiting (alias-only until one exists). A route is keyed only when ssh2's rules and system ssh's (OpenSSH run with system ssh's own destination args, including an unclaimed alias's stored endpoint) agree on host, port, user and proxy, with each transport's token rules. Anything uncertain, or a failed ssh -G, gives no key, so nothing is matched by guess. At most four ssh -G run at once. Restore brings back the hosts it lists, previouslyRemoved stays alias-only, and DNS isn't consulted. Co-authored-by: vam <[email protected]>
An import that inserts or updates a target outdates its own snapshot, which left the picker alias-only until the next refresh. It now queues a rebuild behind itself. The picker also ignores a snapshot past its reuse window, and the system-route shortcut requires a config alias. Co-authored-by: vam <[email protected]>
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 3 minutes. View limit details
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. Comment |
[Medium impact] The change affects SSH host imports and the config picker. The PR appears safe to merge, with a non-blocking performance concern in picker searches. Findings
SummaryImports now skip SSH config aliases that share a saved target's resolved route.
Acknowledged trade-off:
|
| const snapshot = this.latestRouteSnapshot | ||
| return snapshot && | ||
| Date.now() - snapshot.builtAt < ROUTE_SNAPSHOT_TTL_MS && | ||
| snapshot.fingerprint === this.routeSnapshotFingerprint(loadUserSshConfigWithText().text) |
There was a problem hiding this comment.
Once a snapshot exists, currentSshRouteSnapshot() reloads the SSH config on every picker search. Each debounced search expands Include files, parses every host, and hashes the result synchronously in the main process. This bypasses the picker's existing parse cache and repeats disk work for large generated configs.
Check for changes on picker refresh or through a cached file-change check instead.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
ELI5
If you added a machine to Orca by its IP address and also had it in
~/.ssh/configunder a name, Orca added it a second time from the config. You then had two hosts that were really one machine, sharing one set of sessions. Now Orca asks OpenSSH where each config entry actually connects, and doesn't add a second copy of a machine that's already there.What Changed
Before: the config import (on launch, from the hosts menu, from Settings, and from Add all) de-duplicated by alias name only. So
Host aimp/HostName 172.16.203.131was imported next to a saved172.16.203.131target.After:
ssh -G. It skips an alias whose route (host, port, user, and jump host or proxy command) an existing target already has.ssh -G; until a snapshot exists, its flags are by name only, as today.ssh) resolve it to the same host, port, user and proxy. The system side is asked of OpenSSH itself, with the exact arguments system ssh passes, including the saved endpoint it restores when an alias'sHostblock is gone. Each path's token rules are applied (%h %p %r %n %%).ssh -Gfails or times out (5s), the route is unknown and nothing is matched.ssh -Grun at once, and a snapshot is reused while nothing it was built from changed (up to 5 minutes).HostNameconnects to its own name, so it matches an IP target only ifHostNameis set to that IP; that covers the reporter's config onceHostNameis set.This builds on @kaluli123123's work in #15750. Their commit is kept with their authorship, and the follow-up commits credit them as co-author. They found that the duplicate came from comparing names, and they added the route fields (jump host, proxy command) to the identity. This PR supersedes #15750. Thank you @kaluli123123 for the careful investigation and the iterations.
Why
The identity has to match where Orca actually connects, so it comes from OpenSSH's own answer, not a partial parse of the config. Running imports one at a time against one snapshot keeps the decision simple: the picker and the import can't disagree.
Known trade-offs:
/etc/hostsor DNS aren't matched.Linked Issue
Fixes #15478
Visual Proof
N/A: no visual change. The In Orca badge and Add all count already exist; they now reflect route matches. Reproducing it needs real SSH config and hosts, so the tests drive the import and picker with a fake
ssh -G.Testing
I manually tested these changes locally
Automated tests added/updated, or explained why not below
New tests fail without their fix and pass with it:
ssh-target-identity.test.ts);Checked that OpenSSH's
ssh -Greports the route system ssh takes (-J,-o ProxyCommand,-o Hostname/-p/-l) using throwaway-Fconfigs. No connections are made.All SSH, IPC, persistence and managed-server tests that import changed modules pass.
pnpm tc:node, oxlint, the changed-code quality gate, React Doctor and the ratchets pass.Local static job: passes except the Node 18 process-host smoke (no local Node 18; process-host is untouched). The orcad terminal smoke runs on this machine only under heavy load, so CI covers it.
No manual test against real SSH hosts.
Review
Codex and an independent reviewer reviewed this design once each. The reviewer found nothing at P0–P2. Codex's two findings: one is fixed here (the picker's flags after an import changes targets); the other is the first trade-off above.
Agent skill upstream boundary
Notes
ssh -G.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)