2018-07-20 21:56:59 +01:00
|
|
|
import ../make-test.nix ({ lib, ... }:
|
2017-09-18 13:52:07 +01:00
|
|
|
|
2017-11-27 08:14:17 +00:00
|
|
|
{
|
2017-09-18 13:52:07 +01:00
|
|
|
name = "initrd-network-ssh";
|
|
|
|
meta = with lib.maintainers; {
|
|
|
|
maintainers = [ willibutz ];
|
|
|
|
};
|
|
|
|
|
2019-08-13 22:52:01 +01:00
|
|
|
nodes = with lib; {
|
2017-09-18 13:52:07 +01:00
|
|
|
server =
|
2018-07-20 21:56:59 +01:00
|
|
|
{ config, ... }:
|
2017-09-18 13:52:07 +01:00
|
|
|
{
|
|
|
|
boot.kernelParams = [
|
2017-12-03 04:14:54 +00:00
|
|
|
"ip=${config.networking.primaryIPAddress}:::255.255.255.0::eth1:none"
|
2017-09-18 13:52:07 +01:00
|
|
|
];
|
|
|
|
boot.initrd.network = {
|
|
|
|
enable = true;
|
|
|
|
ssh = {
|
|
|
|
enable = true;
|
2017-11-27 08:14:17 +00:00
|
|
|
authorizedKeys = [ "${readFile ./openssh.pub}" ];
|
2017-09-18 13:52:07 +01:00
|
|
|
port = 22;
|
2017-11-27 08:14:17 +00:00
|
|
|
hostRSAKey = ./dropbear.priv;
|
2017-09-18 13:52:07 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
boot.initrd.preLVMCommands = ''
|
|
|
|
while true; do
|
|
|
|
if [ -f fnord ]; then
|
|
|
|
poweroff
|
|
|
|
fi
|
|
|
|
sleep 1
|
|
|
|
done
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
client =
|
2018-07-20 21:56:59 +01:00
|
|
|
{ config, ... }:
|
2017-09-18 13:52:07 +01:00
|
|
|
{
|
|
|
|
environment.etc.knownHosts = {
|
|
|
|
text = concatStrings [
|
|
|
|
"server,"
|
|
|
|
"${toString (head (splitString " " (
|
|
|
|
toString (elemAt (splitString "\n" config.networking.extraHosts) 2)
|
|
|
|
)))} "
|
2017-11-27 08:14:17 +00:00
|
|
|
"${readFile ./dropbear.pub}"
|
2017-09-18 13:52:07 +01:00
|
|
|
];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
testScript = ''
|
|
|
|
startAll;
|
|
|
|
$client->waitForUnit("network.target");
|
2017-11-27 08:14:17 +00:00
|
|
|
$client->copyFileFromHost("${./openssh.priv}","/etc/sshKey");
|
2017-09-18 13:52:07 +01:00
|
|
|
$client->succeed("chmod 0600 /etc/sshKey");
|
|
|
|
$client->waitUntilSucceeds("ping -c 1 server");
|
|
|
|
$client->succeed("ssh -i /etc/sshKey -o UserKnownHostsFile=/etc/knownHosts server 'touch /fnord'");
|
|
|
|
$client->shutdown;
|
|
|
|
'';
|
|
|
|
})
|