2020-04-24 23:36:52 +00:00
|
|
|
# The certificate for the ACME service is exported as:
|
|
|
|
#
|
|
|
|
# config.test-support.acme.caCert
|
|
|
|
#
|
|
|
|
# This value can be used inside the configuration of other test nodes to inject
|
2020-09-25 04:45:31 +00:00
|
|
|
# the test certificate into security.pki.certificateFiles or into package
|
2020-04-24 23:36:52 +00:00
|
|
|
# overlays.
|
|
|
|
#
|
|
|
|
# Another value that's needed if you don't use a custom resolver (see below for
|
|
|
|
# notes on that) is to add the acme node as a nameserver to every node
|
|
|
|
# that needs to acquire certificates using ACME, because otherwise the API host
|
|
|
|
# for acme.test can't be resolved.
|
|
|
|
#
|
|
|
|
# A configuration example of a full node setup using this would be this:
|
|
|
|
#
|
|
|
|
# {
|
|
|
|
# acme = import ./common/acme/server;
|
|
|
|
#
|
|
|
|
# example = { nodes, ... }: {
|
|
|
|
# networking.nameservers = [
|
2022-09-30 11:47:45 +00:00
|
|
|
# nodes.acme.networking.primaryIPAddress
|
2020-04-24 23:36:52 +00:00
|
|
|
# ];
|
|
|
|
# security.pki.certificateFiles = [
|
2022-09-30 11:47:45 +00:00
|
|
|
# nodes.acme.test-support.acme.caCert
|
2020-04-24 23:36:52 +00:00
|
|
|
# ];
|
|
|
|
# };
|
|
|
|
# }
|
|
|
|
#
|
|
|
|
# By default, this module runs a local resolver, generated using resolver.nix
|
|
|
|
# from the parent directory to automatically discover all zones in the network.
|
|
|
|
#
|
|
|
|
# If you do not want this and want to use your own resolver, you can just
|
|
|
|
# override networking.nameservers like this:
|
|
|
|
#
|
|
|
|
# {
|
|
|
|
# acme = { nodes, lib, ... }: {
|
|
|
|
# imports = [ ./common/acme/server ];
|
|
|
|
# networking.nameservers = lib.mkForce [
|
2022-09-30 11:47:45 +00:00
|
|
|
# nodes.myresolver.networking.primaryIPAddress
|
2020-04-24 23:36:52 +00:00
|
|
|
# ];
|
|
|
|
# };
|
|
|
|
#
|
|
|
|
# myresolver = ...;
|
|
|
|
# }
|
|
|
|
#
|
|
|
|
# Keep in mind, that currently only _one_ resolver is supported, if you have
|
|
|
|
# more than one resolver in networking.nameservers only the first one will be
|
|
|
|
# used.
|
|
|
|
#
|
|
|
|
# Also make sure that whenever you use a resolver from a different test node
|
|
|
|
# that it has to be started _before_ the ACME service.
|
|
|
|
{ config, pkgs, lib, ... }:
|
|
|
|
let
|
2020-11-03 02:18:15 +00:00
|
|
|
testCerts = import ./snakeoil-certs.nix;
|
2020-09-25 04:45:31 +00:00
|
|
|
domain = testCerts.domain;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
resolver = let
|
|
|
|
message = "You need to define a resolver for the acme test module.";
|
|
|
|
firstNS = lib.head config.networking.nameservers;
|
|
|
|
in if config.networking.nameservers == [] then throw message else firstNS;
|
|
|
|
|
|
|
|
pebbleConf.pebble = {
|
|
|
|
listenAddress = "0.0.0.0:443";
|
|
|
|
managementListenAddress = "0.0.0.0:15000";
|
2020-09-25 04:45:31 +00:00
|
|
|
# These certs and keys are used for the Web Front End (WFE)
|
|
|
|
certificate = testCerts.${domain}.cert;
|
|
|
|
privateKey = testCerts.${domain}.key;
|
2020-04-24 23:36:52 +00:00
|
|
|
httpPort = 80;
|
|
|
|
tlsPort = 443;
|
2020-10-16 20:44:37 +00:00
|
|
|
ocspResponderURL = "http://${domain}:4002";
|
2020-04-24 23:36:52 +00:00
|
|
|
strict = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
pebbleConfFile = pkgs.writeText "pebble.conf" (builtins.toJSON pebbleConf);
|
|
|
|
|
|
|
|
in {
|
|
|
|
imports = [ ../../resolver.nix ];
|
|
|
|
|
2020-09-25 04:45:31 +00:00
|
|
|
options.test-support.acme = with lib; {
|
|
|
|
caDomain = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
readOnly = true;
|
|
|
|
default = domain;
|
2022-09-09 14:08:57 +00:00
|
|
|
description = lib.mdDoc ''
|
|
|
|
A domain name to use with the `nodes` attribute to
|
2020-09-25 04:45:31 +00:00
|
|
|
identify the CA server.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
caCert = mkOption {
|
|
|
|
type = types.path;
|
|
|
|
readOnly = true;
|
|
|
|
default = testCerts.ca.cert;
|
2022-09-09 14:08:57 +00:00
|
|
|
description = lib.mdDoc ''
|
|
|
|
A certificate file to use with the `nodes` attribute to
|
2020-09-25 04:45:31 +00:00
|
|
|
inject the test CA certificate used in the ACME server into
|
2022-09-09 14:08:57 +00:00
|
|
|
{option}`security.pki.certificateFiles`.
|
2020-09-25 04:45:31 +00:00
|
|
|
'';
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
config = {
|
|
|
|
test-support = {
|
|
|
|
resolver.enable = let
|
|
|
|
isLocalResolver = config.networking.nameservers == [ "127.0.0.1" ];
|
|
|
|
in lib.mkOverride 900 isLocalResolver;
|
|
|
|
};
|
|
|
|
|
|
|
|
# This has priority 140, because modules/testing/test-instrumentation.nix
|
|
|
|
# already overrides this with priority 150.
|
|
|
|
networking.nameservers = lib.mkOverride 140 [ "127.0.0.1" ];
|
2020-09-25 04:45:31 +00:00
|
|
|
networking.firewall.allowedTCPPorts = [ 80 443 15000 4002 ];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
networking.extraHosts = ''
|
2020-09-25 04:45:31 +00:00
|
|
|
127.0.0.1 ${domain}
|
|
|
|
${config.networking.primaryIPAddress} ${domain}
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
|
|
|
|
systemd.services = {
|
|
|
|
pebble = {
|
|
|
|
enable = true;
|
|
|
|
description = "Pebble ACME server";
|
|
|
|
wantedBy = [ "network.target" ];
|
2021-12-30 13:39:12 +00:00
|
|
|
environment = {
|
|
|
|
# We're not testing lego, we're just testing our configuration.
|
|
|
|
# No need to sleep.
|
|
|
|
PEBBLE_VA_NOSLEEP = "1";
|
|
|
|
};
|
2020-09-25 04:45:31 +00:00
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
serviceConfig = {
|
2020-09-25 04:45:31 +00:00
|
|
|
RuntimeDirectory = "pebble";
|
|
|
|
WorkingDirectory = "/run/pebble";
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
# Required to bind on privileged ports.
|
|
|
|
AmbientCapabilities = [ "CAP_NET_BIND_SERVICE" ];
|
2020-09-25 04:45:31 +00:00
|
|
|
|
|
|
|
ExecStart = "${pkgs.pebble}/bin/pebble -config ${pebbleConfFile}";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|