2022-05-05 12:09:42 +02:00
|
|
|
import ./make-test-python.nix ({ pkgs, ... }:
|
|
|
|
let
|
|
|
|
certs = import ./common/acme/server/snakeoil-certs.nix;
|
|
|
|
serverDomain = certs.domain;
|
2023-06-09 00:35:56 +02:00
|
|
|
|
|
|
|
testCredentials = {
|
|
|
|
password = "Password1_cZPEwpCWvrReripJmAZdmVIZd8HHoHcl";
|
|
|
|
};
|
2022-05-05 12:09:42 +02:00
|
|
|
in
|
|
|
|
{
|
|
|
|
name = "kanidm";
|
|
|
|
meta.maintainers = with pkgs.lib.maintainers; [ erictapen Flakebi ];
|
|
|
|
|
|
|
|
nodes.server = { config, pkgs, lib, ... }: {
|
|
|
|
services.kanidm = {
|
|
|
|
enableServer = true;
|
|
|
|
serverSettings = {
|
|
|
|
origin = "https://${serverDomain}";
|
|
|
|
domain = serverDomain;
|
2022-11-20 18:10:15 +01:00
|
|
|
bindaddress = "[::]:443";
|
2022-05-05 12:09:42 +02:00
|
|
|
ldapbindaddress = "[::1]:636";
|
2022-11-20 18:10:15 +01:00
|
|
|
tls_chain = certs."${serverDomain}".cert;
|
|
|
|
tls_key = certs."${serverDomain}".key;
|
2022-05-05 12:09:42 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
security.pki.certificateFiles = [ certs.ca.cert ];
|
|
|
|
|
|
|
|
networking.hosts."::1" = [ serverDomain ];
|
2022-11-20 18:10:15 +01:00
|
|
|
networking.firewall.allowedTCPPorts = [ 443 ];
|
2022-05-05 12:09:42 +02:00
|
|
|
|
|
|
|
users.users.kanidm.shell = pkgs.bashInteractive;
|
|
|
|
|
|
|
|
environment.systemPackages = with pkgs; [ kanidm openldap ripgrep ];
|
|
|
|
};
|
|
|
|
|
|
|
|
nodes.client = { pkgs, nodes, ... }: {
|
|
|
|
services.kanidm = {
|
|
|
|
enableClient = true;
|
|
|
|
clientSettings = {
|
|
|
|
uri = "https://${serverDomain}";
|
2022-09-06 15:11:53 +02:00
|
|
|
verify_ca = true;
|
|
|
|
verify_hostnames = true;
|
|
|
|
};
|
|
|
|
enablePam = true;
|
|
|
|
unixSettings = {
|
|
|
|
pam_allowed_login_groups = [ "shell" ];
|
2022-05-05 12:09:42 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2023-04-19 22:46:14 +02:00
|
|
|
networking.hosts."${nodes.server.networking.primaryIPAddress}" = [ serverDomain ];
|
2022-05-05 12:09:42 +02:00
|
|
|
|
|
|
|
security.pki.certificateFiles = [ certs.ca.cert ];
|
|
|
|
};
|
|
|
|
|
|
|
|
testScript = { nodes, ... }:
|
|
|
|
let
|
|
|
|
ldapBaseDN = builtins.concatStringsSep "," (map (s: "dc=" + s) (pkgs.lib.splitString "." serverDomain));
|
|
|
|
|
|
|
|
# We need access to the config file in the test script.
|
|
|
|
filteredConfig = pkgs.lib.converge
|
|
|
|
(pkgs.lib.filterAttrsRecursive (_: v: v != null))
|
2023-04-19 22:46:14 +02:00
|
|
|
nodes.server.services.kanidm.serverSettings;
|
2022-05-05 12:09:42 +02:00
|
|
|
serverConfigFile = (pkgs.formats.toml { }).generate "server.toml" filteredConfig;
|
|
|
|
|
|
|
|
in
|
|
|
|
''
|
|
|
|
start_all()
|
|
|
|
server.wait_for_unit("kanidm.service")
|
2023-10-03 09:32:37 +02:00
|
|
|
client.systemctl("start network-online.target")
|
2023-08-01 12:56:10 +02:00
|
|
|
client.wait_for_unit("network-online.target")
|
2023-05-01 12:39:28 +02:00
|
|
|
|
|
|
|
with subtest("Test HTTP interface"):
|
2023-08-01 12:56:10 +02:00
|
|
|
server.wait_until_succeeds("curl -Lsf https://${serverDomain} | grep Kanidm")
|
2023-05-01 12:39:28 +02:00
|
|
|
|
|
|
|
with subtest("Test LDAP interface"):
|
|
|
|
server.succeed("ldapsearch -H ldaps://${serverDomain}:636 -b '${ldapBaseDN}' -x '(name=test)'")
|
|
|
|
|
|
|
|
with subtest("Recover idm_admin account"):
|
2023-06-09 00:35:56 +02:00
|
|
|
idm_admin_password = server.succeed("su - kanidm -c 'kanidmd recover-account -c ${serverConfigFile} idm_admin 2>&1 | rg -o \'[A-Za-z0-9]{48}\' '").strip().removeprefix("'").removesuffix("'")
|
2023-05-01 12:39:28 +02:00
|
|
|
|
2024-05-01 14:51:11 +02:00
|
|
|
with subtest("Test CLI login"):
|
|
|
|
client.wait_until_tty_matches("1", "login: ")
|
|
|
|
client.send_chars("root\n")
|
|
|
|
client.send_chars("kanidm login -D idm_admin\n")
|
|
|
|
client.wait_until_tty_matches("1", "Enter password: ")
|
|
|
|
client.send_chars(f"{idm_admin_password}\n")
|
|
|
|
client.wait_until_tty_matches("1", "Login Success for idm_admin")
|
|
|
|
|
2023-05-01 12:39:28 +02:00
|
|
|
with subtest("Test unixd connection"):
|
|
|
|
client.wait_for_unit("kanidm-unixd.service")
|
2023-08-01 12:56:10 +02:00
|
|
|
client.wait_for_file("/run/kanidm-unixd/sock")
|
2023-05-01 12:39:28 +02:00
|
|
|
client.wait_until_succeeds("kanidm-unix status | grep working!")
|
2023-06-09 00:35:56 +02:00
|
|
|
|
|
|
|
with subtest("Test user creation"):
|
|
|
|
client.wait_for_unit("getty@tty1.service")
|
|
|
|
client.wait_until_succeeds("pgrep -f 'agetty.*tty1'")
|
|
|
|
client.succeed("kanidm person create testuser TestUser")
|
|
|
|
client.succeed("kanidm person posix set --shell \"$SHELL\" testuser")
|
|
|
|
client.send_chars("kanidm person posix set-password testuser\n")
|
|
|
|
client.wait_until_tty_matches("1", "Enter new")
|
|
|
|
client.send_chars("${testCredentials.password}\n")
|
|
|
|
client.wait_until_tty_matches("1", "Retype")
|
|
|
|
client.send_chars("${testCredentials.password}\n")
|
|
|
|
output = client.succeed("getent passwd testuser")
|
|
|
|
assert "TestUser" in output
|
|
|
|
client.succeed("kanidm group create shell")
|
|
|
|
client.succeed("kanidm group posix set shell")
|
|
|
|
client.succeed("kanidm group add-members shell testuser")
|
|
|
|
|
|
|
|
with subtest("Test user login"):
|
|
|
|
client.send_key("alt-f2")
|
|
|
|
client.wait_until_succeeds("[ $(fgconsole) = 2 ]")
|
|
|
|
client.wait_for_unit("getty@tty2.service")
|
|
|
|
client.wait_until_succeeds("pgrep -f 'agetty.*tty2'")
|
|
|
|
client.wait_until_tty_matches("2", "login: ")
|
|
|
|
client.send_chars("testuser\n")
|
|
|
|
client.wait_until_tty_matches("2", "login: testuser")
|
|
|
|
client.wait_until_succeeds("pgrep login")
|
|
|
|
client.wait_until_tty_matches("2", "Password: ")
|
|
|
|
client.send_chars("${testCredentials.password}\n")
|
|
|
|
client.wait_until_succeeds("systemctl is-active user@$(id -u testuser).service")
|
|
|
|
client.send_chars("touch done\n")
|
|
|
|
client.wait_for_file("/home/testuser@${serverDomain}/done")
|
2022-05-05 12:09:42 +02:00
|
|
|
'';
|
|
|
|
})
|