-
Notifications
You must be signed in to change notification settings - Fork 62
π€ feat: SSH host-key verification with interactive dialog #2399
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ethanndickson
wants to merge
13
commits into
main
Choose a base branch
from
ethan/host-key-verif
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
f3622c3
π€ feat: SSH host-key verification with interactive dialog
ethanndickson 6dcc8f7
refactor: extract HOST_KEY_APPROVAL_TIMEOUT_MS shared constant
ethanndickson 9b0acca
Fix SSH host-key approval timeouts in connection pools
ethanndickson 52eea11
fix host key verification timeout waiter fanout
ethanndickson f019508
fix: lint errors in test file + make timeout injectable for tests
ethanndickson a0724e4
fix: gate host-key interactive prompts on responder availability
ethanndickson eb5a3f6
fix: use FIFO queue for host-key verification dialog
ethanndickson d2d6cae
fix: use runtime-aware stream timeouts in SSH integration tests
ethanndickson 45f0a70
Redesign ssh askpass to use per-request file transactions
ethanndickson f2b6a4a
fix: fail fast on non-host-key ssh askpass prompts
ethanndickson 34d3f14
test: add askpass multi-prompt and prompt classification tests
ethanndickson 103383d
fix: lint errors in askpass implementation and tests
ethanndickson 4b1b239
fix: explicitly close host-key subscription iterator on cleanup
ethanndickson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,137 @@ | ||
| import { useEffect, useState } from "react"; | ||
| import { useAPI } from "@/browser/contexts/API"; | ||
| import { | ||
| Dialog, | ||
| DialogContent, | ||
| DialogHeader, | ||
| DialogTitle, | ||
| DialogDescription, | ||
| DialogFooter, | ||
| WarningBox, | ||
| WarningTitle, | ||
| WarningText, | ||
| } from "@/browser/components/ui/dialog"; | ||
| import { Button } from "@/browser/components/ui/button"; | ||
| import type { HostKeyVerificationRequest } from "@/common/orpc/schemas/ssh"; | ||
|
|
||
| export function HostKeyVerificationDialog() { | ||
| const { api } = useAPI(); | ||
| const [pendingQueue, setPendingQueue] = useState<HostKeyVerificationRequest[]>([]); | ||
| const pending = pendingQueue[0] ?? null; | ||
| const [responding, setResponding] = useState(false); | ||
|
|
||
| useEffect(() => { | ||
| if (!api) { | ||
| return; | ||
| } | ||
|
|
||
| const controller = new AbortController(); | ||
| const { signal } = controller; | ||
|
|
||
| // Track the async iterator so we can explicitly close it on cleanup. | ||
| // Some oRPC iterators don't reliably terminate on abort alone; | ||
| // calling return() ensures the backend subscription finally block runs, | ||
| // which releases the responder lease and listener state. | ||
| let iteratorRef: AsyncIterator<HostKeyVerificationRequest> | undefined; | ||
|
|
||
| // Global subscription: backend can request host-key verification at any time. | ||
| // Queue pending requests so concurrent prompts are handled FIFO without drops. | ||
| (async () => { | ||
| try { | ||
| const iterable = await api.ssh.hostKeyVerification.subscribe(undefined, { signal }); | ||
| iteratorRef = iterable[Symbol.asyncIterator](); | ||
|
|
||
| for await (const request of iterable) { | ||
| if (signal.aborted) { | ||
| break; | ||
| } | ||
|
|
||
| setPendingQueue((prev) => | ||
| prev.some((item) => item.requestId === request.requestId) ? prev : [...prev, request] | ||
| ); | ||
| } | ||
| } catch { | ||
| // Subscription closed (cleanup/reconnect): no-op | ||
| } | ||
| })(); | ||
|
|
||
| return () => { | ||
| controller.abort(); | ||
| void iteratorRef?.return?.(undefined); | ||
| }; | ||
| }, [api]); | ||
|
|
||
| const respond = async (accept: boolean) => { | ||
| if (!api || !pending || responding) { | ||
| return; | ||
| } | ||
|
|
||
| const requestId = pending.requestId; | ||
| setResponding(true); | ||
|
|
||
| try { | ||
| await api.ssh.hostKeyVerification.respond({ requestId, accept }); | ||
| } finally { | ||
| setResponding(false); | ||
| setPendingQueue((prev) => prev.filter((item) => item.requestId !== requestId)); | ||
| } | ||
| }; | ||
|
|
||
| return ( | ||
| <Dialog | ||
| open={pending !== null} | ||
| onOpenChange={(open) => { | ||
| // Treat dismiss/escape as explicit rejection so backend unblocks promptly. | ||
| if (!open && !responding) { | ||
| void respond(false); | ||
| } | ||
| }} | ||
| > | ||
| <DialogContent maxWidth="500px" showCloseButton={false}> | ||
| <DialogHeader> | ||
| <DialogTitle>Unknown SSH Host</DialogTitle> | ||
| <DialogDescription> | ||
| {pending?.prompt ?? ( | ||
| <> | ||
| The authenticity of host{" "} | ||
| <code className="text-foreground font-semibold">{pending?.host}</code> cannot be | ||
| established. | ||
| </> | ||
| )} | ||
| </DialogDescription> | ||
| </DialogHeader> | ||
|
|
||
| <div className="bg-background-secondary border-border rounded p-3 font-mono text-sm"> | ||
| <div className="text-muted">{pending?.keyType} key fingerprint:</div> | ||
| <div className="text-foreground mt-1 break-all select-all">{pending?.fingerprint}</div> | ||
| </div> | ||
|
|
||
| <WarningBox> | ||
| <WarningTitle>Host Key Verification</WarningTitle> | ||
| <WarningText>Accepting will add the host to your known_hosts file.</WarningText> | ||
| </WarningBox> | ||
|
|
||
| <DialogFooter className="justify-center"> | ||
| <Button | ||
| variant="secondary" | ||
| disabled={responding} | ||
| onClick={() => { | ||
| void respond(false); | ||
| }} | ||
| > | ||
| Reject | ||
| </Button> | ||
| <Button | ||
| variant="default" | ||
| disabled={responding} | ||
| onClick={() => { | ||
| void respond(true); | ||
| }} | ||
| > | ||
| {responding ? "Connecting..." : "Accept & Connect"} | ||
| </Button> | ||
| </DialogFooter> | ||
| </DialogContent> | ||
| </Dialog> | ||
| ); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| /** | ||
| * Maximum time (ms) to wait for the user to accept/reject a host-key | ||
| * verification prompt in the UI dialog. Shared across: | ||
| * - HostKeyVerificationService (auto-reject timeout) | ||
| * - OpenSSH connection pool (probe deadline extension) | ||
| * - SSH2 connection pool (readyTimeout extension) | ||
| */ | ||
| export const HOST_KEY_APPROVAL_TIMEOUT_MS = 60_000; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| import { z } from "zod"; | ||
|
|
||
| export const HostKeyVerificationRequestSchema = z.object({ | ||
| requestId: z.string(), | ||
| host: z.string(), | ||
| keyType: z.string(), | ||
| fingerprint: z.string(), | ||
| prompt: z.string(), | ||
| }); | ||
|
|
||
| export type HostKeyVerificationRequest = z.infer<typeof HostKeyVerificationRequestSchema>; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The dialog always removes the current request in
finally, even ifapi.ssh.hostKeyVerification.respond()throws (for example during renderer/backend reconnects). That drops the UI prompt while the backend request can still be pending until timeout, so the user cannot retry and the SSH handshake fails despite having clicked accept/reject.Useful? React with πΒ / π.