Skip to content

Commit 5fef1e0

Browse files
committed
smoke: the vm key is 0600 before ssh is asked to use it
Run 7 finally booted the guest all the way to a login prompt — the console karg fix held — and still died waiting for ssh. The reason was waiting in the kept artifacts: the throwaway key on disk is 0644, and ssh refuses a world-readable private key outright. The smoke runs as root with BatchMode, so the refusal was swallowed and the stage read as 'no ssh within 1800s' while the guest sat at its prompt, reachable and willing, for half an hour. Two layers now enforce what should never have depended on whoever wrote the file first: kuma vm sets the mode on the private key whatever its age (a reused VM directory must heal, not inherit), and the boot stage chmods the key at the use site, so an artifact kept by an older binary still works.
1 parent db39922 commit 5fef1e0

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

‎scripts/smoke.sh‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3203,7 +3203,10 @@ smoke_boot() {
32033203
local ssh_opts=(-p "$port" -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null
32043204
-o ConnectTimeout=5 -o LogLevel=ERROR -o BatchMode=yes)
32053205
# `kuma vm` writes this only when the host had no key of its own.
3206-
[ -f "$dir/ssh-key" ] && ssh_opts+=(-i "$dir/ssh-key")
3206+
# A kept key may predate the 0600 rule: ssh refuses a world-readable
3207+
# private key outright ("bad permissions", which BatchMode then
3208+
# swallows), so heal the mode here rather than trust whoever wrote it.
3209+
[ -f "$dir/ssh-key" ] && chmod 600 "$dir/ssh-key" && ssh_opts+=(-i "$dir/ssh-key")
32073210
ssh_opts+=(kuma@127.0.0.1)
32083211
# shellcheck disable=SC2029 # client-side expansion is the point: every
32093212
# caller builds the command here and wants the guest to run it literally.

‎src/main.rs‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4104,6 +4104,16 @@ fn vm_ssh_key(output: &Path) -> Option<String> {
41044104
])
41054105
.ok()?;
41064106
}
4107+
// The private half is only ever meant for the caller of this
4108+
// command, whoever that is: a key that ships world-readable makes
4109+
// ssh refuse it outright — "bad permissions" — and the VM
4110+
// unopenable over its own key. Heal rather than assume, because
4111+
// the key may predate this run (a reused VM directory) and
4112+
// whatever wrote it may not have agreed on the mode.
4113+
use std::os::unix::fs::PermissionsExt;
4114+
let mut perms = std::fs::metadata(&private).ok()?.permissions();
4115+
perms.set_mode(0o600);
4116+
std::fs::set_permissions(&private, perms).ok()?;
41074117
std::fs::read_to_string(&public).ok()
41084118
}
41094119

0 commit comments

Comments
 (0)