2022-01-25 17:38:37 +03:00
|
|
|
args@{ nixpkgs ? <nixpkgs>, ... }:
|
2021-05-10 00:22:48 +03:00
|
|
|
|
2022-01-25 17:38:37 +03:00
|
|
|
with (import "${nixpkgs}/lib");
|
2022-01-18 22:25:06 +03:00
|
|
|
|
2022-01-25 17:38:37 +03:00
|
|
|
import "${nixpkgs}/nixos/tests/make-test-python.nix"
|
2022-01-18 22:25:06 +03:00
|
|
|
(
|
|
|
|
let
|
|
|
|
sshdConf = {
|
|
|
|
enable = true;
|
|
|
|
hostKeys = [{ type = "ed25519"; path = "/etc/ssh/ssh_host_ed25519_key"; }];
|
|
|
|
};
|
|
|
|
in
|
|
|
|
rec {
|
|
|
|
name = "agenix-integration";
|
2021-05-10 00:22:48 +03:00
|
|
|
|
2022-01-18 22:25:06 +03:00
|
|
|
nodes.system1 = { config, ... }: {
|
|
|
|
imports = [
|
|
|
|
../modules/age.nix
|
|
|
|
./install_ssh_host_keys.nix
|
|
|
|
];
|
2021-05-10 00:22:48 +03:00
|
|
|
|
2022-01-18 22:25:06 +03:00
|
|
|
services.openssh = sshdConf;
|
2021-05-10 00:22:48 +03:00
|
|
|
|
2022-01-18 22:25:06 +03:00
|
|
|
age.secrets.passwordfile-user1.file = ../example/passwordfile-user1.age;
|
2022-01-18 22:22:15 +03:00
|
|
|
|
2022-01-18 22:25:06 +03:00
|
|
|
users = {
|
|
|
|
mutableUsers = false;
|
2021-05-10 00:22:48 +03:00
|
|
|
|
2022-01-18 22:25:06 +03:00
|
|
|
users = {
|
|
|
|
user1 = {
|
|
|
|
isNormalUser = true;
|
|
|
|
passwordFile = config.age.secrets.passwordfile-user1.path;
|
|
|
|
};
|
|
|
|
};
|
2021-05-10 00:22:48 +03:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2022-06-07 21:42:18 +03:00
|
|
|
nodes.system2 = { pkgs, ... }: {
|
2022-01-18 22:25:06 +03:00
|
|
|
imports = [
|
|
|
|
../modules/age.nix
|
|
|
|
./install_ssh_host_keys.nix
|
|
|
|
];
|
|
|
|
|
|
|
|
services.openssh = sshdConf;
|
|
|
|
|
|
|
|
age.secrets.ex1 = {
|
|
|
|
file = ../example/passwordfile-user1.age;
|
2022-06-07 21:42:18 +03:00
|
|
|
onChange = "touch /tmp/onChange-executed";
|
|
|
|
reloadUnits = [ "reloadTest.service" ];
|
|
|
|
restartUnits = [ "restartTest.service" ];
|
|
|
|
};
|
|
|
|
|
|
|
|
systemd.services.reloadTest = {
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
path = [ pkgs.coreutils ];
|
|
|
|
reload = "touch /tmp/reloadTest-reloaded";
|
|
|
|
preStop = "touch /tmp/reloadTest-stopped";
|
|
|
|
serviceConfig = {
|
|
|
|
Type = "oneshot";
|
|
|
|
RemainAfterExit = true;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
systemd.services.restartTest = {
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
path = [ pkgs.coreutils ];
|
|
|
|
reload = "touch /tmp/restartTest-reloaded";
|
|
|
|
preStop = "touch /tmp/restartTest-stopped";
|
|
|
|
serviceConfig = {
|
|
|
|
Type = "oneshot";
|
|
|
|
RemainAfterExit = true;
|
|
|
|
};
|
2022-01-18 22:25:06 +03:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2022-06-07 21:42:18 +03:00
|
|
|
nodes.system2After = { lib, ... }: {
|
|
|
|
imports = [ nodes.system2 ];
|
|
|
|
age.secrets.ex1.file = lib.mkForce ../example/secret1.age;
|
2022-01-18 22:25:06 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
testScript =
|
|
|
|
let
|
|
|
|
user = "user1";
|
|
|
|
password = "password1234";
|
|
|
|
in
|
|
|
|
{ nodes, ... }:
|
|
|
|
''
|
|
|
|
system1.start()
|
|
|
|
system2.start()
|
|
|
|
|
|
|
|
system1.wait_for_unit("multi-user.target")
|
|
|
|
system1.wait_until_succeeds("pgrep -f 'agetty.*tty1'")
|
|
|
|
system1.sleep(2)
|
|
|
|
system1.send_key("alt-f2")
|
|
|
|
system1.wait_until_succeeds("[ $(fgconsole) = 2 ]")
|
|
|
|
system1.wait_for_unit("getty@tty2.service")
|
|
|
|
system1.wait_until_succeeds("pgrep -f 'agetty.*tty2'")
|
|
|
|
system1.wait_until_tty_matches(2, "login: ")
|
|
|
|
system1.send_chars("${user}\n")
|
|
|
|
system1.wait_until_tty_matches(2, "login: ${user}")
|
|
|
|
system1.wait_until_succeeds("pgrep login")
|
|
|
|
system1.sleep(2)
|
|
|
|
system1.send_chars("${password}\n")
|
|
|
|
system1.send_chars("whoami > /tmp/1\n")
|
|
|
|
system1.wait_for_file("/tmp/1")
|
|
|
|
assert "${user}" in system1.succeed("cat /tmp/1")
|
|
|
|
|
2022-06-07 21:42:18 +03:00
|
|
|
# test changing secret
|
2022-01-18 22:25:06 +03:00
|
|
|
system2.wait_for_unit("multi-user.target")
|
2022-06-07 21:42:18 +03:00
|
|
|
system2.wait_for_unit("reloadTest.service")
|
|
|
|
system2.wait_for_unit("restartTest.service")
|
|
|
|
# none of the files should exist yet. start blank
|
|
|
|
system2.fail("test -f /tmp/onChange-executed")
|
|
|
|
system2.fail("test -f /tmp/reloadTest-reloaded")
|
|
|
|
system2.fail("test -f /tmp/restartTest-stopped")
|
|
|
|
system2.fail("test -f /tmp/reloadTest-stopped")
|
|
|
|
# change the secret
|
|
|
|
system2.succeed(
|
2022-01-25 17:38:37 +03:00
|
|
|
"${nodes.system2After.config.system.build.toplevel}/bin/switch-to-configuration test"
|
|
|
|
)
|
2022-06-07 21:42:18 +03:00
|
|
|
|
|
|
|
system2.wait_for_file("/tmp/onChange-executed")
|
|
|
|
system2.wait_for_file("/tmp/reloadTest-reloaded")
|
|
|
|
system2.wait_for_file("/tmp/restartTest-stopped")
|
|
|
|
system2.fail("test -f /tmp/reloadTest-stopped")
|
|
|
|
system2.fail("test -f /tmp/restartTest-reloaded")
|
2022-01-18 22:25:06 +03:00
|
|
|
'';
|
|
|
|
}
|
|
|
|
)
|
2022-01-18 22:22:15 +03:00
|
|
|
args
|