···
1
-
import ../make-test-python.nix (
4
-
inherit (import ./../ssh-keys.nix pkgs)
8
+
inherit (import ./../ssh-keys.nix hostPkgs)
9
-
# don't check host keys or known hosts, use the snakeoil ssh key
10
-
ssh-config = builtins.toFile "ssh.conf" ''
11
-
UserKnownHostsFile=/dev/null
12
-
StrictHostKeyChecking=no
13
-
IdentityFile=~/.ssh/id_snakeoil
17
-
name = "google-oslogin";
18
-
meta = with pkgs.lib.maintainers; {
13
+
# don't check host keys or known hosts, use the snakeoil ssh key
14
+
ssh-config = builtins.toFile "ssh.conf" ''
15
+
UserKnownHostsFile=/dev/null
16
+
StrictHostKeyChecking=no
17
+
IdentityFile=~/.ssh/id_snakeoil
21
+
name = "google-oslogin";
22
+
meta = with lib.maintainers; {
23
-
# the server provides both the the mocked google metadata server and the ssh server
24
-
server = (import ./server.nix pkgs);
27
+
# the server provides both the the mocked google metadata server and the ssh server
28
+
server = ./server.nix;
26
-
client = { ... }: { };
29
-
MOCKUSER = "mockuser_nixos_org"
30
-
MOCKADMIN = "mockadmin_nixos_org"
30
+
client = { ... }: { };
33
+
MOCKUSER = "mockuser_nixos_org"
34
+
MOCKADMIN = "mockadmin_nixos_org"
33
-
server.wait_for_unit("mock-google-metadata.service")
34
-
server.wait_for_open_port(80)
37
+
server.wait_for_unit("mock-google-metadata.service")
38
+
server.wait_for_open_port(80)
36
-
# mockserver should return a non-expired ssh key for both mockuser and mockadmin
38
-
f'${pkgs.google-guest-oslogin}/bin/google_authorized_keys {MOCKUSER} | grep -q "${snakeOilPublicKey}"'
41
-
f'${pkgs.google-guest-oslogin}/bin/google_authorized_keys {MOCKADMIN} | grep -q "${snakeOilPublicKey}"'
40
+
# mockserver should return a non-expired ssh key for both mockuser and mockadmin
42
+
f'${pkgs.google-guest-oslogin}/bin/google_authorized_keys {MOCKUSER} | grep -q "${snakeOilPublicKey}"'
45
+
f'${pkgs.google-guest-oslogin}/bin/google_authorized_keys {MOCKADMIN} | grep -q "${snakeOilPublicKey}"'
44
-
# install snakeoil ssh key on the client, and provision .ssh/config file
45
-
client.succeed("mkdir -p ~/.ssh")
47
-
"cat ${snakeOilPrivateKey} > ~/.ssh/id_snakeoil"
49
-
client.succeed("chmod 600 ~/.ssh/id_snakeoil")
50
-
client.succeed("cp ${ssh-config} ~/.ssh/config")
48
+
# install snakeoil ssh key on the client, and provision .ssh/config file
49
+
client.succeed("mkdir -p ~/.ssh")
51
+
"cat ${snakeOilPrivateKey} > ~/.ssh/id_snakeoil"
53
+
client.succeed("chmod 600 ~/.ssh/id_snakeoil")
54
+
client.succeed("cp ${ssh-config} ~/.ssh/config")
52
-
client.wait_for_unit("network.target")
53
-
server.wait_for_unit("sshd.service")
56
+
client.wait_for_unit("network.target")
57
+
server.wait_for_unit("sshd.service")
55
-
# we should not be able to connect as non-existing user
56
-
client.fail("ssh ghost@server 'true'")
59
+
# we should not be able to connect as non-existing user
60
+
client.fail("ssh ghost@server 'true'")
58
-
# we should be able to connect as mockuser
59
-
client.succeed(f"ssh {MOCKUSER}@server 'true'")
60
-
# but we shouldn't be able to sudo
62
-
f"ssh {MOCKUSER}@server '/run/wrappers/bin/sudo /run/current-system/sw/bin/id' | grep -q 'root'"
62
+
# we should be able to connect as mockuser
63
+
client.succeed(f"ssh {MOCKUSER}@server 'true'")
64
+
# but we shouldn't be able to sudo
66
+
f"ssh {MOCKUSER}@server '/run/wrappers/bin/sudo /run/current-system/sw/bin/id' | grep -q 'root'"
65
-
# we should also be able to log in as mockadmin
66
-
client.succeed(f"ssh {MOCKADMIN}@server 'true'")
67
-
# pam_oslogin_admin.so should now have generated a sudoers file
69
-
f"find /run/google-sudoers.d | grep -q '/run/google-sudoers.d/{MOCKADMIN}'"
69
+
# we should also be able to log in as mockadmin
70
+
client.succeed(f"ssh {MOCKADMIN}@server 'true'")
71
+
# pam_oslogin_admin.so should now have generated a sudoers file
73
+
f"find /run/google-sudoers.d | grep -q '/run/google-sudoers.d/{MOCKADMIN}'"
72
-
# and we should be able to sudo
74
-
f"ssh {MOCKADMIN}@server '/run/wrappers/bin/sudo /run/current-system/sw/bin/id' | grep -q 'root'"
76
+
# and we should be able to sudo
78
+
f"ssh {MOCKADMIN}@server '/run/wrappers/bin/sudo /run/current-system/sw/bin/id' | grep -q 'root'"