2022-08-03 12:36:11 +02:00
|
|
|
import ./make-test-python.nix ({ lib, ... }: {
|
|
|
|
name = "systemd-initrd-network-ssh";
|
|
|
|
meta.maintainers = [ lib.maintainers.elvishjerricco ];
|
|
|
|
|
2023-07-29 03:27:18 +02:00
|
|
|
nodes = {
|
2022-08-03 12:36:11 +02:00
|
|
|
server = { config, pkgs, ... }: {
|
2023-09-21 00:19:22 +02:00
|
|
|
testing.initrdBackdoor = true;
|
|
|
|
boot.initrd.systemd.enable = true;
|
|
|
|
boot.initrd.systemd.contents."/etc/msg".text = "foo";
|
|
|
|
boot.initrd.network = {
|
|
|
|
enable = true;
|
|
|
|
ssh = {
|
2022-08-03 12:36:11 +02:00
|
|
|
enable = true;
|
2023-09-21 00:19:22 +02:00
|
|
|
authorizedKeys = [ (lib.readFile ./initrd-network-ssh/id_ed25519.pub) ];
|
|
|
|
port = 22;
|
|
|
|
hostKeys = [ ./initrd-network-ssh/ssh_host_ed25519_key ];
|
2022-08-03 12:36:11 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
client = { config, ... }: {
|
|
|
|
environment.etc = {
|
|
|
|
knownHosts = {
|
2023-07-29 03:27:18 +02:00
|
|
|
text = lib.concatStrings [
|
2022-08-03 12:36:11 +02:00
|
|
|
"server,"
|
|
|
|
"${
|
2023-07-29 03:27:18 +02:00
|
|
|
toString (lib.head (lib.splitString " " (toString
|
|
|
|
(lib.elemAt (lib.splitString "\n" config.networking.extraHosts) 2))))
|
2022-08-03 12:36:11 +02:00
|
|
|
} "
|
2023-07-29 03:27:18 +02:00
|
|
|
"${lib.readFile ./initrd-network-ssh/ssh_host_ed25519_key.pub}"
|
2022-08-03 12:36:11 +02:00
|
|
|
];
|
|
|
|
};
|
|
|
|
sshKey = {
|
|
|
|
source = ./initrd-network-ssh/id_ed25519;
|
|
|
|
mode = "0600";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
testScript = ''
|
|
|
|
start_all()
|
|
|
|
|
|
|
|
def ssh_is_up(_) -> bool:
|
|
|
|
status, _ = client.execute("nc -z server 22")
|
|
|
|
return status == 0
|
|
|
|
|
|
|
|
client.wait_for_unit("network.target")
|
|
|
|
with client.nested("waiting for SSH server to come up"):
|
|
|
|
retry(ssh_is_up)
|
|
|
|
|
2023-09-21 00:19:22 +02:00
|
|
|
msg = client.succeed(
|
|
|
|
"ssh -i /etc/sshKey -o UserKnownHostsFile=/etc/knownHosts server 'cat /etc/msg'"
|
2022-08-03 12:36:11 +02:00
|
|
|
)
|
2023-09-21 00:19:22 +02:00
|
|
|
assert "foo" in msg
|
2022-08-03 12:36:11 +02:00
|
|
|
|
2023-09-21 00:19:22 +02:00
|
|
|
server.switch_root()
|
2022-08-03 12:36:11 +02:00
|
|
|
server.wait_for_unit("multi-user.target")
|
|
|
|
'';
|
|
|
|
})
|