1 import ./make-test-python.nix ({ ... }:
5 nodes.machine = { pkgs, ... }: {
6 imports = [ ./common/user-account.nix ];
7 boot.kernelModules = [ "ecryptfs" ];
8 security.pam.enableEcryptfs = true;
9 environment.systemPackages = with pkgs; [ keyutils ];
14 machine.wait_until_tty_matches("1", "login: ")
15 machine.send_chars("alice\n")
16 machine.wait_until_tty_matches("1", "Password: ")
17 machine.send_chars("foobar\n")
18 machine.wait_until_tty_matches("1", "alice\@machine")
22 machine.send_chars("logout\n")
23 machine.wait_until_tty_matches("1", "login: ")
26 machine.wait_for_unit("default.target")
28 with subtest("Set alice up with a password and a home"):
29 machine.succeed("(echo foobar; echo foobar) | passwd alice")
30 machine.succeed("chown -R alice.users ~alice")
32 with subtest("Migrate alice's home"):
33 out = machine.succeed("echo foobar | ecryptfs-migrate-home -u alice")
34 machine.log(f"ecryptfs-migrate-home said: {out}")
36 with subtest("Log alice in (ecryptfs passwhrase is wrapped during first login)"):
38 machine.send_chars("logout\n")
39 machine.wait_until_tty_matches("1", "login: ")
41 # Why do I need to do this??
42 machine.succeed("su alice -c ecryptfs-umount-private || true")
45 with subtest("check that encrypted home is not mounted"):
46 machine.fail("mount | grep ecryptfs")
48 with subtest("Show contents of the user keyring"):
49 out = machine.succeed("su - alice -c 'keyctl list \@u'")
50 machine.log(f"keyctl unlink said: {out}")
52 with subtest("Log alice again"):
55 with subtest("Create some files in encrypted home"):
56 machine.succeed("su alice -c 'touch ~alice/a'")
57 machine.succeed("su alice -c 'echo c > ~alice/b'")
59 with subtest("Logout"):
62 # Why do I need to do this??
63 machine.succeed("su alice -c ecryptfs-umount-private || true")
66 with subtest("Check that the filesystem is not accessible"):
67 machine.fail("mount | grep ecryptfs")
68 machine.succeed("su alice -c 'test \! -f ~alice/a'")
69 machine.succeed("su alice -c 'test \! -f ~alice/b'")
71 with subtest("Log alice once more"):
74 with subtest("Check that the files are there"):
76 machine.succeed("su alice -c 'test -f ~alice/a'")
77 machine.succeed("su alice -c 'test -f ~alice/b'")
78 machine.succeed('test "$(cat ~alice/b)" = "c"')
80 with subtest("Catch https://github.com/NixOS/nixpkgs/issues/16766"):
81 machine.succeed("su alice -c 'ls -lh ~alice/'")