at 25.11-pre 2.6 kB view raw
1import ./make-test-python.nix ( 2 { pkgs, lib, ... }: 3 let 4 inherit (import ./ssh-keys.nix pkgs) 5 snakeOilPrivateKey 6 snakeOilPublicKey 7 ; 8 9 setUpPrivateKey = name: '' 10 ${name}.succeed( 11 "mkdir -p /root/.ssh", 12 "chmod 700 /root/.ssh", 13 "cat '${snakeOilPrivateKey}' > /root/.ssh/id_snakeoil", 14 "chmod 600 /root/.ssh/id_snakeoil", 15 ) 16 ${name}.wait_for_file("/root/.ssh/id_snakeoil") 17 ''; 18 19 sshOpts = "-oStrictHostKeyChecking=no -oUserKnownHostsFile=/dev/null -oIdentityFile=/root/.ssh/id_snakeoil"; 20 21 in 22 { 23 name = "tmate-ssh-server"; 24 nodes = { 25 server = 26 { ... }: 27 { 28 services.tmate-ssh-server = { 29 enable = true; 30 port = 2223; 31 openFirewall = true; 32 }; 33 }; 34 client = 35 { ... }: 36 { 37 environment.systemPackages = [ pkgs.tmate ]; 38 services.openssh.enable = true; 39 users.users.root.openssh.authorizedKeys.keys = [ snakeOilPublicKey ]; 40 }; 41 client2 = 42 { ... }: 43 { 44 environment.systemPackages = [ pkgs.openssh ]; 45 }; 46 }; 47 testScript = '' 48 start_all() 49 50 server.wait_for_unit("tmate-ssh-server.service") 51 server.wait_for_open_port(2223) 52 server.wait_for_file("/etc/tmate-ssh-server-keys/ssh_host_ed25519_key.pub") 53 server.wait_for_file("/etc/tmate-ssh-server-keys/ssh_host_rsa_key.pub") 54 server.succeed("tmate-client-config > /tmp/tmate.conf") 55 server.wait_for_file("/tmp/tmate.conf") 56 57 ${setUpPrivateKey "server"} 58 client.wait_for_unit("sshd.service") 59 client.wait_for_open_port(22) 60 server.succeed("scp ${sshOpts} /tmp/tmate.conf client:/tmp/tmate.conf") 61 62 client.wait_for_file("/tmp/tmate.conf") 63 client.wait_until_tty_matches("1", "login:") 64 client.send_chars("root\n") 65 client.sleep(2) 66 client.send_chars("tmate -f /tmp/tmate.conf\n") 67 client.sleep(2) 68 client.send_chars("q") 69 client.sleep(2) 70 client.send_chars("tmate display -p '#{tmate_ssh}' > /tmp/ssh_command\n") 71 client.wait_for_file("/tmp/ssh_command") 72 ssh_cmd = client.succeed("cat /tmp/ssh_command") 73 74 client2.succeed("mkdir -p ~/.ssh; ssh-keyscan -4 -p 2223 server > ~/.ssh/known_hosts") 75 client2.wait_until_tty_matches("1", "login:") 76 client2.send_chars("root\n") 77 client2.sleep(2) 78 client2.send_chars(ssh_cmd.strip() + "\n") 79 client2.sleep(2) 80 client2.send_chars("touch /tmp/client_2\n") 81 82 client.wait_for_file("/tmp/client_2") 83 ''; 84 } 85)