diff options
author | Silvan Mosberger <infinisil@icloud.com> | 2018-08-03 16:39:12 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-08-03 16:39:12 +0200 |
commit | d31f89df44666fcd0c854a1cc8da434929e73832 (patch) | |
tree | 6a6ef00c91a6493f3bfd2915e1f5aaf034f9ac2c /nixos/tests | |
parent | 70e7235510930aa5d98b1cf0b8b4599ddb9c6b42 (diff) | |
parent | 7d7c36f8be6b064aa14d1004d6418f2b3e005e86 (diff) | |
download | nixlib-d31f89df44666fcd0c854a1cc8da434929e73832.tar nixlib-d31f89df44666fcd0c854a1cc8da434929e73832.tar.gz nixlib-d31f89df44666fcd0c854a1cc8da434929e73832.tar.bz2 nixlib-d31f89df44666fcd0c854a1cc8da434929e73832.tar.lz nixlib-d31f89df44666fcd0c854a1cc8da434929e73832.tar.xz nixlib-d31f89df44666fcd0c854a1cc8da434929e73832.tar.zst nixlib-d31f89df44666fcd0c854a1cc8da434929e73832.zip |
Merge pull request #44127 from johanot/nixos-cfssl
nixos/cfssl: Add new module for cfssl
Diffstat (limited to 'nixos/tests')
-rw-r--r-- | nixos/tests/cfssl.nix | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/nixos/tests/cfssl.nix b/nixos/tests/cfssl.nix new file mode 100644 index 000000000000..513ed8c45741 --- /dev/null +++ b/nixos/tests/cfssl.nix @@ -0,0 +1,67 @@ +import ./make-test.nix ({ pkgs, ...} : { + name = "cfssl"; + + machine = { config, lib, pkgs, ... }: + { + networking.firewall.allowedTCPPorts = [ config.services.cfssl.port ]; + + services.cfssl.enable = true; + systemd.services.cfssl.after = [ "cfssl-init.service" ]; + + systemd.services.cfssl-init = { + description = "Initialize the cfssl CA"; + wantedBy = [ "multi-user.target" ]; + serviceConfig = { + User = "cfssl"; + Type = "oneshot"; + WorkingDirectory = config.services.cfssl.dataDir; + }; + script = with pkgs; '' + ${cfssl}/bin/cfssl genkey -initca ${pkgs.writeText "ca.json" (builtins.toJSON { + hosts = [ "ca.example.com" ]; + key = { + algo = "rsa"; size = 4096; }; + names = [ + { + C = "US"; + L = "San Francisco"; + O = "Internet Widgets, LLC"; + OU = "Certificate Authority"; + ST = "California"; + } + ]; + })} | ${cfssl}/bin/cfssljson -bare ca + ''; + }; + }; + + testScript = + let + cfsslrequest = with pkgs; writeScript "cfsslrequest" '' + curl -X POST -H "Content-Type: application/json" -d @${csr} \ + http://localhost:8888/api/v1/cfssl/newkey | ${cfssl}/bin/cfssljson /tmp/certificate + ''; + csr = pkgs.writeText "csr.json" (builtins.toJSON { + CN = "www.example.com"; + hosts = [ "example.com" "www.example.com" ]; + key = { + algo = "rsa"; + size = 2048; + }; + names = [ + { + C = "US"; + L = "San Francisco"; + O = "Example Company, LLC"; + OU = "Operations"; + ST = "California"; + } + ]; + }); + in + '' + $machine->waitForUnit('cfssl.service'); + $machine->waitUntilSucceeds('${cfsslrequest}'); + $machine->succeed('ls /tmp/certificate-key.pem'); + ''; +}) |