1 import ./make-test-python.nix ({ pkgs, ... }:
3 name = "systemd-journal-upload";
4 meta = with pkgs.lib.maintainers; {
5 maintainers = [ minijackson raitobezarius ];
8 nodes.server = { nodes, ... }: {
9 services.journald.remote = {
13 ServerCertificateFile = "/run/secrets/sever.cert.pem";
14 ServerKeyFile = "/run/secrets/sever.key.pem";
15 TrustedCertificateFile = "/run/secrets/ca.cert.pem";
20 networking.firewall.allowedTCPPorts = [ nodes.server.services.journald.remote.port ];
23 nodes.client = { lib, nodes, ... }: {
24 services.journald.upload = {
27 URL = "http://server:${toString nodes.server.services.journald.remote.port}";
28 ServerCertificateFile = "/run/secrets/client.cert.pem";
29 ServerKeyFile = "/run/secrets/client.key.pem";
30 TrustedCertificateFile = "/run/secrets/ca.cert.pem";
34 # Wait for the PEMs to arrive
35 systemd.services.systemd-journal-upload.wantedBy = lib.mkForce [];
36 systemd.paths.systemd-journal-upload = {
37 wantedBy = [ "default.target" ];
38 # This file must be copied last
39 pathConfig.PathExists = [ "/run/secrets/ca.cert.pem" ];
47 tmpdir_o = tempfile.TemporaryDirectory()
48 tmpdir = tmpdir_o.name
50 def generate_pems(domain: str):
53 "${pkgs.minica}/bin/minica",
54 "--ca-key=ca.key.pem",
55 "--ca-cert=ca.cert.pem",
56 f"--domains={domain}",
61 with subtest("Creating keys and certificates"):
62 generate_pems("server")
63 generate_pems("client")
65 server.wait_for_unit("multi-user.target")
66 client.wait_for_unit("multi-user.target")
68 def copy_pems(machine: Machine, domain: str):
69 machine.succeed("mkdir /run/secrets")
70 machine.copy_from_host(
71 source=f"{tmpdir}/{domain}/cert.pem",
72 target=f"/run/secrets/{domain}.cert.pem",
74 machine.copy_from_host(
75 source=f"{tmpdir}/{domain}/key.pem",
76 target=f"/run/secrets/{domain}.key.pem",
79 machine.copy_from_host(
80 source=f"{tmpdir}/ca.cert.pem",
81 target="/run/secrets/ca.cert.pem",
84 with subtest("Copying keys and certificates"):
85 copy_pems(server, "server")
86 copy_pems(client, "client")
88 client.wait_for_unit("systemd-journal-upload.service")
89 # The journal upload should have started the remote service, triggered by
91 server.wait_for_unit("systemd-journal-remote.service")
93 identifier = "nixos-test"
94 message = "Hello from NixOS test infrastructure"
96 client.succeed(f"systemd-cat --identifier={identifier} <<< '{message}'")
97 server.wait_until_succeeds(
98 f"journalctl --file /var/log/journal/remote/remote-*.journal --identifier={identifier} | grep -F '{message}'"