2021-11-12 21:37:11 +01:00
|
|
|
import ./make-test-python.nix ({ pkgs, ... }:
|
|
|
|
let
|
2022-12-26 19:05:35 +01:00
|
|
|
test-certificates = pkgs.runCommandLocal "test-certificates" { } ''
|
2021-11-12 21:37:11 +01:00
|
|
|
mkdir -p $out
|
|
|
|
echo insecure-root-password > $out/root-password-file
|
|
|
|
echo insecure-intermediate-password > $out/intermediate-password-file
|
2022-12-26 19:05:35 +01:00
|
|
|
${pkgs.step-cli}/bin/step certificate create "Example Root CA" $out/root_ca.crt $out/root_ca.key --password-file=$out/root-password-file --profile root-ca
|
|
|
|
${pkgs.step-cli}/bin/step certificate create "Example Intermediate CA 1" $out/intermediate_ca.crt $out/intermediate_ca.key --password-file=$out/intermediate-password-file --ca-password-file=$out/root-password-file --profile intermediate-ca --ca $out/root_ca.crt --ca-key $out/root_ca.key
|
2021-11-12 21:37:11 +01:00
|
|
|
'';
|
|
|
|
in
|
|
|
|
{
|
2022-02-16 19:43:38 +01:00
|
|
|
name = "step-ca";
|
2021-11-12 21:37:11 +01:00
|
|
|
nodes =
|
|
|
|
{
|
|
|
|
caserver =
|
|
|
|
{ config, pkgs, ... }: {
|
|
|
|
services.step-ca = {
|
|
|
|
enable = true;
|
2024-06-12 13:24:42 +02:00
|
|
|
address = "[::]";
|
2021-11-12 21:37:11 +01:00
|
|
|
port = 8443;
|
|
|
|
openFirewall = true;
|
|
|
|
intermediatePasswordFile = "${test-certificates}/intermediate-password-file";
|
|
|
|
settings = {
|
|
|
|
dnsNames = [ "caserver" ];
|
|
|
|
root = "${test-certificates}/root_ca.crt";
|
|
|
|
crt = "${test-certificates}/intermediate_ca.crt";
|
|
|
|
key = "${test-certificates}/intermediate_ca.key";
|
|
|
|
db = {
|
|
|
|
type = "badger";
|
|
|
|
dataSource = "/var/lib/step-ca/db";
|
|
|
|
};
|
|
|
|
authority = {
|
|
|
|
provisioners = [
|
|
|
|
{
|
|
|
|
type = "ACME";
|
|
|
|
name = "acme";
|
|
|
|
}
|
|
|
|
];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
caclient =
|
|
|
|
{ config, pkgs, ... }: {
|
2022-02-16 19:43:38 +01:00
|
|
|
security.acme.defaults.server = "https://caserver:8443/acme/acme/directory";
|
|
|
|
security.acme.defaults.email = "root@example.org";
|
2021-11-12 21:37:11 +01:00
|
|
|
security.acme.acceptTerms = true;
|
|
|
|
|
|
|
|
security.pki.certificateFiles = [ "${test-certificates}/root_ca.crt" ];
|
|
|
|
|
|
|
|
networking.firewall.allowedTCPPorts = [ 80 443 ];
|
|
|
|
|
|
|
|
services.nginx = {
|
|
|
|
enable = true;
|
|
|
|
virtualHosts = {
|
|
|
|
"caclient" = {
|
|
|
|
forceSSL = true;
|
|
|
|
enableACME = true;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-05-18 11:35:20 +02:00
|
|
|
caclientcaddy =
|
|
|
|
{ config, pkgs, ... }: {
|
|
|
|
security.pki.certificateFiles = [ "${test-certificates}/root_ca.crt" ];
|
|
|
|
|
|
|
|
networking.firewall.allowedTCPPorts = [ 80 443 ];
|
|
|
|
|
|
|
|
services.caddy = {
|
|
|
|
enable = true;
|
|
|
|
virtualHosts."caclientcaddy".extraConfig = ''
|
|
|
|
respond "Welcome to Caddy!"
|
|
|
|
|
|
|
|
tls caddy@example.org {
|
|
|
|
ca https://caserver:8443/acme/acme/directory
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2021-11-12 21:37:11 +01:00
|
|
|
catester = { config, pkgs, ... }: {
|
|
|
|
security.pki.certificateFiles = [ "${test-certificates}/root_ca.crt" ];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
testScript =
|
|
|
|
''
|
|
|
|
catester.start()
|
|
|
|
caserver.wait_for_unit("step-ca.service")
|
2024-05-21 14:21:26 +02:00
|
|
|
caserver.wait_until_succeeds("journalctl -o cat -u step-ca.service | grep '${pkgs.step-ca.version}'")
|
2024-05-18 23:16:31 +02:00
|
|
|
|
2021-11-12 21:37:11 +01:00
|
|
|
caclient.wait_for_unit("acme-finished-caclient.target")
|
|
|
|
catester.succeed("curl https://caclient/ | grep \"Welcome to nginx!\"")
|
2024-05-18 11:35:20 +02:00
|
|
|
|
|
|
|
caclientcaddy.wait_for_unit("caddy.service")
|
|
|
|
catester.succeed("curl https://caclientcaddy/ | grep \"Welcome to Caddy!\"")
|
2021-11-12 21:37:11 +01:00
|
|
|
'';
|
|
|
|
})
|