feat: enhance known_hosts management with deletion cleanup and SSH cache handling

This commit is contained in:
2026-09-21 21:04:41 +05:30
parent 871afcf454
commit c75c7d9baf
4 changed files with 68 additions and 4 deletions
+25 -1
View File
@@ -77,6 +77,7 @@ Packet integration tests must remain inside disposable isolated namespaces.
│ ├── integrity.py # SHA-256 and integrity manifest logic
│ ├── install.py # Apt, Firecracker, kernel, rootfs installation
│ ├── images.py # Template lookup, private disks, and guest credentials
│ ├── known_hosts.py # Deletion-only cleanup of local SSH host-key caches
│ ├── network.py # IP/MAC/TAP/bridge/NAT/forward rules
│ ├── firewall.py # Owned nft bridge tables and offline conntrack cleanup
│ ├── lifecycle.py # Lifecycle, bulk operations, recovery, port intent
@@ -185,6 +186,7 @@ process:
| CommandRunner | `CommandRunner` | Logged/testable subprocess execution |
| StateStore | `StateStore` | Inventory, locks, JSON persistence |
| ImageStore | `ImageStore` | Template verification, VM disks, and offline credentials |
| KnownHostsManager | `KnownHostsManager` | Scoped local SSH cache cleanup before deleted IPs are released |
| NetworkManager | `NetworkManager` | Guest allocation and Linux networking |
| FirewallManager | Constructed by `NetworkManager` | Owned native bridge policy and scoped offline conntrack cleanup |
| FirecrackerProcessManager | `FirecrackerProcessManager` | VMM process control |
@@ -415,7 +417,7 @@ stop:
delete (destroy alias):
persist delete intent -> same runtime cleanup -> remove owned runtime directory
-> remove state record -> release name/IP
-> clean local known_hosts entries -> remove state record -> release name/IP
```
Stop signals the **VMM**, not a guest shutdown agent or ACPI-coordinated
@@ -428,6 +430,28 @@ Runtime cleanup retains reservations when process exit, TAP ownership, or
connection cleanup is uncertain. A pending spawn cannot be declared gone
merely because its PID was never persisted or its socket has not appeared.
`KnownHostsManager` is an explicit lifecycle dependency, also used by API and
bulk deletion. It runs after successful process/network/disk teardown and before
the registry entry is removed, under the same operation lock. Cleanup errors
retain `operation=delete` and the IP reservation; repeating delete retries it.
Stop, restart, and resize retain the existing guest's trusted host-key entries.
Default caches are `known_hosts` and `known_hosts2` under the effective user's
and sudo invoker's account homes (`SUDO_UID`, with a `SUDO_USER` fallback).
`UVM_KNOWN_HOSTS_FILES` overrides this discovery for service deployments using a
colon-separated list of absolute paths. Only local files are managed. Matches
are explicit guest IPs or UVM's `uvm-<VM-ID>` host-key alias, including OpenSSH's
HMAC-SHA1 hashed form. Plain bracketed ports are recognized directly; hashed
bracketed candidates use port 22 and the VM's recorded allowlist. Wildcard rules
and other aliases sharing a line are retained.
File updates use pinned directory descriptors, regular/single-link checks,
an advisory lock, and a sibling temporary file. Owner, group, mode, and extended
attributes are preserved. A changed source snapshot prevents publication over
concurrent edits. A matching-free file is not rewritten and missing files are
not created. Tests inject the dependency to avoid accessing developers' caches,
and verify hashed-entry interoperability using real OpenSSH on temporary files.
### Policy and Bulk Operations
`set_ports()` takes a frozen registry ID, not a reusable name/IP; the CLI resolves