nixos/test-driver: add backdoor based on systemd-ssh-proxy & AF_VSOCK

With this it's possible to trivially SSH into running machines from the
test-driver. This is especially useful when running VM tests
interactively on a remote system.

This is based on `systemd-ssh-proxy(1)`, so there's no need to configure
any additional networking on the host-side.

Suggested-by: Ryan Lahfa <masterancpp@gmail.com>
This commit is contained in:
Maximilian Bosch 2025-03-21 17:14:23 +00:00
parent cb74a2a15e
commit 1bd8073958
No known key found for this signature in database
4 changed files with 73 additions and 4 deletions

View file

@ -87,6 +87,10 @@ in
machine.switch_root() to leave stage 1 and proceed to stage 2
'';
sshBackdoor = {
enable = mkEnableOption "vsock-based ssh backdoor for the VM";
};
};
config = {
@ -100,6 +104,18 @@ in
}
];
services.openssh = mkIf config.testing.sshBackdoor.enable {
enable = true;
settings = {
PermitRootLogin = "yes";
PermitEmptyPasswords = "yes";
};
};
security.pam.services.sshd = mkIf config.testing.sshBackdoor.enable {
allowNullPassword = true;
};
systemd.services.backdoor = lib.mkMerge [
backdoorService
{
@ -175,6 +191,10 @@ in
# we avoid defining attributes if not possible.
# TODO: refactor such that test-instrumentation can import qemu-vm
package = lib.mkDefault pkgs.qemu_test;
options = mkIf config.testing.sshBackdoor.enable [
"-device vhost-vsock-pci,guest-cid=${toString (config.virtualisation.test.nodeNumber + 2)}"
];
};
};