feat(system): mimic SSH known_hosts key addition process#121
Conversation
WalkthroughModified SSH initialization to add interactive known_hosts handling. When an unknown host is encountered during TTY sessions, the system prompts for user confirmation to trust the host, then appends the host key to the known_hosts file on acceptance. Warnings are issued for modified host keys. Changes
Sequence DiagramsequenceDiagram
participant SSH as SSH Connection
participant Callback as wrappedKnownHostsCallback
participant KnownHosts as known_hosts File
participant User as User/TTY
SSH->>Callback: HostKeyCallback invoked
alt Host Known
Callback-->>SSH: Accept (success)
else Host Unknown & TTY Active
Callback->>User: Prompt: Trust this host?
alt User Confirms
User-->>Callback: Yes
Callback->>KnownHosts: Append host/key pair
Callback-->>SSH: Accept (success)
else User Rejects
User-->>Callback: No
Callback-->>SSH: Error (rejected)
end
else Host Key Changed
Callback-->>SSH: Warning (potential MITM)
else Unknown Host & No TTY
Callback-->>SSH: Error (cannot prompt)
end
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🧰 Additional context used🧬 Code graph analysis (1)internal/system/ssh.go (2)
🔇 Additional comments (4)
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 |
Description
The SSH knownhosts package does not behave like the OpenSSH client binary does currently. If a host is unknown, then an error is immediately raised and the program exits, without a chance to add the key to the known_hosts file. The only way to work around this is to add these keys to the known_hosts file beforehand.
As such, I mimic the process here using the nixos-cli logger and confirmation input, in case the key does not exist.
Summary by CodeRabbit