about summary refs log tree commit diff
path: root/nixos/tests/step-ca.nix
blob: a855b590232dd92d0659394bd84ccc09e0b1cd38 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import ./make-test-python.nix ({ pkgs, ... }:
  let
    test-certificates = pkgs.runCommandLocal "test-certificates" { } ''
      mkdir -p $out
      echo insecure-root-password > $out/root-password-file
      echo insecure-intermediate-password > $out/intermediate-password-file
      ${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
    '';
  in
  {
    name = "step-ca";
    nodes =
      {
        caserver =
          { config, pkgs, ... }: {
            services.step-ca = {
              enable = true;
              address = "0.0.0.0";
              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, ... }: {
            security.acme.defaults.server = "https://caserver:8443/acme/acme/directory";
            security.acme.defaults.email = "root@example.org";
            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;
                };
              };
            };
          };

        catester = { config, pkgs, ... }: {
          security.pki.certificateFiles = [ "${test-certificates}/root_ca.crt" ];
        };
      };

    testScript =
      ''
        catester.start()
        caserver.wait_for_unit("step-ca.service")
        caclient.wait_for_unit("acme-finished-caclient.target")
        catester.succeed("curl https://caclient/ | grep \"Welcome to nginx!\"")
      '';
  })