banger/internal/daemon
Thales Maciel ae14b9499d
ssh: trust-on-first-use host key pinning everywhere
Guest host-key verification was off in all three SSH paths:

  * Go SSH (internal/guest/ssh.go) used ssh.InsecureIgnoreHostKey
  * `banger vm ssh` passed StrictHostKeyChecking=no
    + UserKnownHostsFile=/dev/null
  * `~/.ssh/config` Host *.vm shipped the same posture into the
    user's global config

Now each path verifies against a banger-owned known_hosts file at
`~/.local/state/banger/ssh/known_hosts` with TOFU semantics:

  * First dial to a VM pins the key.
  * Subsequent dials require an exact match. A mismatch fails with
    an explicit "possible MITM" error.
  * `vm delete` removes the entries so a future VM reusing the IP
    or name re-pins cleanly.
  * The user's `~/.ssh/known_hosts` is untouched.

Changes:

  internal/guest/known_hosts.go (new) — OpenSSH-compatible parser,
    TOFUHostKeyCallback, RemoveKnownHosts. Process-wide mutex
    around the file.
  internal/guest/ssh.go — Dial and WaitForSSH grew a knownHostsPath
    parameter threaded through the callback. Empty path keeps the
    insecure callback (tests + throwaway tools only; documented).
  internal/daemon/{guest_sessions,session_attach,session_lifecycle,
    session_stream}.go — call sites pass d.layout.KnownHostsPath.
  internal/daemon/ssh_client_config.go — the ~/.ssh/config Host *.vm
    block now points at banger's known_hosts and uses
    StrictHostKeyChecking=accept-new. Missing path → fail closed.
  internal/daemon/vm_lifecycle.go — deleteVMLocked drops known_hosts
    entries for the VM's IP and DNS name via removeVMKnownHosts.
  internal/cli/banger.go — sshCommandArgs swaps StrictHostKeyChecking
    no + /dev/null for banger's file + accept-new. Path resolution
    failure falls through to StrictHostKeyChecking=yes.
  internal/paths/paths.go — Layout gains SSHDir + KnownHostsPath;
    Ensure creates SSHDir at 0700.

Tests (internal/guest/known_hosts_test.go): pin on first use, accept
matching key on second dial, reject mismatch, empty path skips
checking, RemoveKnownHosts drops the entry, re-pin works after
remove. Existing daemon + cli tests updated to assert the new
posture and regression-guard against the old flags.

Live verified: vm run writes the pin to banger's known_hosts at 0600
inside a 0700 dir; banger vm ssh + ssh root@<vm>.vm both succeed
using the pin; vm delete clears it.
2026-04-19 16:46:03 -03:00
..
dmsnap Extract opstate and dmsnap into subpackages 2026-04-15 16:02:43 -03:00
fcproc Extract fcproc subpackage for firecracker process helpers 2026-04-15 16:11:39 -03:00
imagemgr Remove image build --from-image; doctor treats catalog images as OK 2026-04-18 15:54:29 -03:00
opstate coverage: medium batch — hostnat runner, store guest-sessions, daemon helpers 2026-04-18 18:03:37 -03:00
session coverage: medium batch — hostnat runner, store guest-sessions, daemon helpers 2026-04-18 18:03:37 -03:00
workspace Extract workspace subpackage with pure repo helpers 2026-04-15 16:37:19 -03:00
ARCHITECTURE.md remove experimental web UI 2026-04-19 14:28:08 -03:00
autopull_test.go vm create: auto-pull image and kernel from catalogs if missing 2026-04-18 15:10:26 -03:00
capabilities.go vm state: split transient kernel/process handles off the durable schema 2026-04-19 14:18:13 -03:00
capabilities_test.go Remove opencode package + vm acp command (dead code) 2026-04-18 16:54:37 -03:00
daemon.go daemon: roll back host state on any Open() failure 2026-04-19 16:36:29 -03:00
daemon_test.go remove experimental web UI 2026-04-19 14:28:08 -03:00
dns_routing.go Route .vm DNS through systemd-resolved 2026-03-22 15:07:22 -03:00
dns_routing_test.go Route .vm DNS through systemd-resolved 2026-03-22 15:07:22 -03:00
doc.go remove experimental web UI 2026-04-19 14:28:08 -03:00
doctor.go vm defaults: host-aware sizing + spec line on spawn + doctor check 2026-04-19 13:06:51 -03:00
fastpath_test.go Manage image artifacts and show VM create progress 2026-03-21 14:48:01 -03:00
guest_sessions.go ssh: trust-on-first-use host key pinning everywhere 2026-04-19 16:46:03 -03:00
guest_sessions_test.go vm state: split transient kernel/process handles off the durable schema 2026-04-19 14:18:13 -03:00
image_seed.go guest sshd: drop DEBUG3 + StrictModes no; normalise /root perms 2026-04-19 13:40:40 -03:00
images.go Remove image build --from-image; doctor treats catalog images as OK 2026-04-18 15:54:29 -03:00
images_helpers_test.go coverage: medium batch — hostnat runner, store guest-sessions, daemon helpers 2026-04-18 18:03:37 -03:00
images_pull.go vm create: auto-pull image and kernel from catalogs if missing 2026-04-18 15:10:26 -03:00
images_pull_bundle_test.go image pull: dispatch to imagecat bundle path before OCI 2026-04-17 15:43:33 -03:00
images_pull_test.go Phase B-2: pre-inject banger guest agents into pulled rootfs 2026-04-16 18:08:56 -03:00
kernels.go Phase 4: remote catalog + banger kernel pull 2026-04-16 15:05:42 -03:00
kernels_test.go Phase 4: remote catalog + banger kernel pull 2026-04-16 15:05:42 -03:00
logger.go vm state: split transient kernel/process handles off the durable schema 2026-04-19 14:18:13 -03:00
logger_test.go Remove image build --from-image; doctor treats catalog images as OK 2026-04-18 15:54:29 -03:00
nat.go vm state: split transient kernel/process handles off the durable schema 2026-04-19 14:18:13 -03:00
nat_test.go vm state: split transient kernel/process handles off the durable schema 2026-04-19 14:18:13 -03:00
open_close_test.go daemon: roll back host state on any Open() failure 2026-04-19 16:36:29 -03:00
ports.go vm state: split transient kernel/process handles off the durable schema 2026-04-19 14:18:13 -03:00
preflight.go Remove image build --from-image; doctor treats catalog images as OK 2026-04-18 15:54:29 -03:00
runtime_assets.go Remove runtime-bundle image dependencies 2026-03-21 18:34:53 -03:00
session_attach.go ssh: trust-on-first-use host key pinning everywhere 2026-04-19 16:46:03 -03:00
session_controller.go Extract session subpackage with pure guest-session helpers 2026-04-15 16:33:12 -03:00
session_lifecycle.go ssh: trust-on-first-use host key pinning everywhere 2026-04-19 16:46:03 -03:00
session_stream.go ssh: trust-on-first-use host key pinning everywhere 2026-04-19 16:46:03 -03:00
snapshot.go Extract opstate and dmsnap into subpackages 2026-04-15 16:02:43 -03:00
snapshot_test.go Harden VM stop cleanup for stale snapshots 2026-03-18 12:28:15 -03:00
ssh_client_config.go ssh: trust-on-first-use host key pinning everywhere 2026-04-19 16:46:03 -03:00
ssh_client_config_test.go ssh: trust-on-first-use host key pinning everywhere 2026-04-19 16:46:03 -03:00
sshd_config_test.go guest sshd: drop DEBUG3 + StrictModes no; normalise /root perms 2026-04-19 13:40:40 -03:00
tap_pool.go vm state: split transient kernel/process handles off the durable schema 2026-04-19 14:18:13 -03:00
vm.go vm state: split transient kernel/process handles off the durable schema 2026-04-19 14:18:13 -03:00
vm_authsync.go guest sshd: drop DEBUG3 + StrictModes no; normalise /root perms 2026-04-19 13:40:40 -03:00
vm_create.go vm create: auto-pull image and kernel from catalogs if missing 2026-04-18 15:10:26 -03:00
vm_create_ops.go Add lint targets, fix gofmt drift, broaden Makefile build inputs 2026-04-16 16:49:17 -03:00
vm_disk.go vm state: split transient kernel/process handles off the durable schema 2026-04-19 14:18:13 -03:00
vm_handles.go vm state: split transient kernel/process handles off the durable schema 2026-04-19 14:18:13 -03:00
vm_handles_test.go vm state: split transient kernel/process handles off the durable schema 2026-04-19 14:18:13 -03:00
vm_lifecycle.go ssh: trust-on-first-use host key pinning everywhere 2026-04-19 16:46:03 -03:00
vm_locks.go Move subsystem state/locks off Daemon into owning types 2026-04-15 15:58:33 -03:00
vm_set.go vm state: split transient kernel/process handles off the durable schema 2026-04-19 14:18:13 -03:00
vm_stats.go vm state: split transient kernel/process handles off the durable schema 2026-04-19 14:18:13 -03:00
vm_test.go vm state: split transient kernel/process handles off the durable schema 2026-04-19 14:18:13 -03:00
workspace.go vm state: split transient kernel/process handles off the durable schema 2026-04-19 14:18:13 -03:00
workspace_test.go vm state: split transient kernel/process handles off the durable schema 2026-04-19 14:18:13 -03:00