1 import ./make-test-python.nix ({ pkgs, ... }:
3 let inherit (import ./ssh-keys.nix pkgs)
4 snakeOilPrivateKey snakeOilPublicKey;
7 meta = with pkgs.lib.maintainers; {
8 maintainers = [ aszlig eelco ];
17 services.openssh.enable = true;
18 security.pam.services.sshd.limits =
19 [ { domain = "*"; item = "memlock"; type = "-"; value = 1024; } ];
20 users.users.root.openssh.authorizedKeys.keys = [
29 services.openssh = { enable = true; startWhenNeeded = true; };
30 security.pam.services.sshd.limits =
31 [ { domain = "*"; item = "memlock"; type = "-"; value = 1024; } ];
32 users.users.root.openssh.authorizedKeys.keys = [
37 server_localhost_only =
42 enable = true; listenAddresses = [ { addr = "127.0.0.1"; port = 22; } ];
46 server_localhost_only_lazy =
51 enable = true; startWhenNeeded = true; listenAddresses = [ { addr = "127.0.0.1"; port = 22; } ];
63 server.wait_for_unit("sshd")
65 with subtest("manual-authkey"):
66 client.succeed("mkdir -m 700 /root/.ssh")
68 '${pkgs.openssh}/bin/ssh-keygen -t ed25519 -f /root/.ssh/id_ed25519 -N ""'
70 public_key = client.succeed(
71 "${pkgs.openssh}/bin/ssh-keygen -y -f /root/.ssh/id_ed25519"
73 public_key = public_key.strip()
74 client.succeed("chmod 600 /root/.ssh/id_ed25519")
76 server.succeed("mkdir -m 700 /root/.ssh")
77 server.succeed("echo '{}' > /root/.ssh/authorized_keys".format(public_key))
78 server_lazy.succeed("mkdir -m 700 /root/.ssh")
79 server_lazy.succeed("echo '{}' > /root/.ssh/authorized_keys".format(public_key))
81 client.wait_for_unit("network.target")
83 "ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no server 'echo hello world' >&2",
87 "ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no server 'ulimit -l' | grep 1024",
92 "ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no server_lazy 'echo hello world' >&2",
96 "ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no server_lazy 'ulimit -l' | grep 1024",
100 with subtest("configured-authkey"):
102 "cat ${snakeOilPrivateKey} > privkey.snakeoil"
104 client.succeed("chmod 600 privkey.snakeoil")
106 "ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i privkey.snakeoil server true",
110 "ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i privkey.snakeoil server_lazy true",
114 with subtest("localhost-only"):
115 server_localhost_only.succeed("ss -nlt | grep '127.0.0.1:22'")
116 server_localhost_only_lazy.succeed("ss -nlt | grep '127.0.0.1:22'")