Skip to content

Fix SSH host key verification: hostname format, tempfile dep, TempDir leak#8

Merged
persimmon16 merged 2 commits intofeat/apple-containerfrom
security/fix-ssh-host-key-verification
Apr 1, 2026
Merged

Fix SSH host key verification: hostname format, tempfile dep, TempDir leak#8
persimmon16 merged 2 commits intofeat/apple-containerfrom
security/fix-ssh-host-key-verification

Conversation

@persimmon16
Copy link
Copy Markdown
Owner

Summary

Follow-up to PR #4 (Enable SSH host key verification). Fixes three bugs found during post-merge code review:

  • known_hosts hostname mismatch (security): Entries were written as [sandbox]:2222 but SSH connects to hostname sandbox at default port 22. The entry never matched, causing StrictHostKeyChecking=yes to reject every connection when a fingerprint was provided — silently defeating the host key verification feature. Fixed to use bare sandbox format.

  • Missing production dependency (build blocker): tempfile was only in [dev-dependencies] for openshell-cli, so release builds fail. Moved to [dependencies].

  • TempDir resource leak: TempDir::into_path() disables automatic cleanup, leaking temp directories on each SSH connection. Changed ssh_base_command (CLI) and apply_host_key_args (TUI) to return the TempDir guard; callers hold it until SSH exits, then drop triggers cleanup.

Also fixes a borrow-checker error in grpc.rs from PR #5's auth bypass fix (.ok_or_else() borrows request while into_inner() moves it).

Test plan

  • cargo build passes (no more missing tempfile in release)
  • cargo test — all tests pass
  • cargo clippy — no new warnings (pre-existing pedantic lints only)
  • Manual: verify SSH connects with StrictHostKeyChecking=yes when fingerprint is provided
  • Manual: verify temp directories are cleaned up after SSH session ends

… leak

Three bugs from the initial SSH host-key PR (#4):

1. known_hosts wrote [sandbox]:2222 but SSH connects to "sandbox" at
   default port 22 — entry never matched, defeating StrictHostKeyChecking.
   Fixed to use bare "sandbox" hostname.

2. tempfile crate was only in [dev-dependencies] for openshell-cli,
   breaking release builds. Moved to [dependencies].

3. TempDir::into_path() disabled automatic cleanup, leaking temp
   directories. Changed to return the TempDir guard so callers keep it
   alive until SSH exits, then cleanup runs on drop.

Also fixes borrow-checker error in grpc.rs auth check (PR #5) where
.ok_or_else() borrowed request while into_inner() tried to move it.
The macos-15 runner doesn't ship with Apple Container pre-installed.
Download the signed .pkg installer from the GitHub release and install
it before running container system info.
@persimmon16 persimmon16 merged commit f0af033 into feat/apple-container Apr 1, 2026
4 of 9 checks passed
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.

1 participant