···
# This tests that systemd-ssh-proxy and systemd-ssh-generator work correctly with:
# - a local unix socket on the same system
9
-
# - a vsock socket inside a vm
9
+
# - a unix socket inside a container
inherit (import ./ssh-keys.nix pkgs)
snakeOilEd25519PrivateKey
15
-
qemu = config.nodes.virthost.virtualisation.qemu.package;
17
-
(import ../lib/eval-config.nix {
18
-
inherit (pkgs.stdenv.hostPlatform) system;
20
-
../modules/installer/cd-dvd/iso-image.nix
22
-
services.openssh = {
24
-
settings.PermitRootLogin = "prohibit-password";
26
-
isoImage.isoBaseName = lib.mkForce "nixos";
27
-
isoImage.makeBiosBootable = true;
28
-
system.stateVersion = lib.trivial.release;
31
-
}).config.system.build.isoImage;
name = "systemd-ssh-proxy";
···
49
-
systemd.services.test-vm = {
50
-
script = "${lib.getExe qemu} --nographic -smp 1 -m 512 -cdrom ${iso}/iso/nixos.iso -device vhost-vsock-pci,guest-cid=3 -smbios type=11,value=\"io.systemd.credential:ssh.authorized_keys.root=${snakeOilEd25519PublicKey}\"";
32
+
containers.guest = {
35
+
users.users.root.openssh.authorizedKeys.keys = [ snakeOilEd25519PublicKey ];
36
+
services.openssh = {
38
+
settings.PermitRootLogin = "prohibit-password";
40
+
system.stateVersion = lib.trivial.release;
56
-
virthost.systemctl("start test-vm.service")
virthost.succeed("mkdir -p ~/.ssh")
virthost.succeed("cp '${snakeOilEd25519PrivateKey}' ~/.ssh/id_ed25519")
virthost.succeed("chmod 600 ~/.ssh/id_ed25519")
62
-
with subtest("ssh into a vm with vsock"):
63
-
virthost.wait_until_succeeds("systemctl is-active test-vm.service")
64
-
virthost.wait_until_succeeds("ssh -i ~/.ssh/id_ed25519 vsock/3 echo meow | grep meow")
65
-
virthost.wait_until_succeeds("ssh -i ~/.ssh/id_ed25519 vsock/3 shutdown now")
66
-
virthost.wait_until_succeeds("! systemctl is-active test-vm.service")
51
+
with subtest("ssh into a container with AF_UNIX"):
52
+
virthost.wait_for_unit("container@guest.service")
53
+
virthost.wait_until_succeeds("ssh -i ~/.ssh/id_ed25519 unix/run/systemd/nspawn/unix-export/guest/ssh echo meow | grep meow")
with subtest("elevate permissions using local ssh socket"):
virthost.wait_for_unit("sshd-unix-local.socket")