1 # This test verifies that systemd-timesyncd can resolve the NTP server hostname when DNSSEC validation
2 # fails even though it is enforced in the systemd-resolved settings. It is required in order to solve
3 # the chicken-and-egg problem when DNSSEC validation needs the correct time to work, but to set the
4 # correct time, we need to connect to an NTP server, which usually requires resolving its hostname.
6 # This test does the following:
7 # - Sets up a DNS server (tinydns) listening on the eth1 ip addess, serving .ntp and fake.ntp records.
8 # - Configures that DNS server as a resolver and enables DNSSEC in systemd-resolved settings.
9 # - Configures systemd-timesyncd to use fake.ntp hostname as an NTP server.
10 # - Performs a regular DNS lookup, to ensure it fails due to broken DNSSEC.
11 # - Waits until systemd-timesyncd resolves fake.ntp by checking its debug output.
12 # Here, we don't expect systemd-timesyncd to connect and synchronize time because there is no NTP
13 # server running. For this test to succeed, we only need to ensure that systemd-timesyncd
14 # resolves the IP address of the fake.ntp host.
16 import ./make-test-python.nix ({ pkgs, ... }:
19 ntpHostname = "fake.ntp";
23 name = "systemd-timesyncd";
24 nodes.machine = { pkgs, lib, config, ... }:
26 eth1IP = (lib.head config.networking.interfaces.eth1.ipv4.addresses).address;
29 # Setup a local DNS server for the NTP domain on the eth1 IP address
35 +.${ntpHostname}:${ntpIP}
39 # Enable systemd-resolved with DNSSEC and use the local DNS as a name server
40 services.resolved.enable = true;
41 services.resolved.dnssec = "true";
42 networking.nameservers = [ eth1IP ];
44 # Configure systemd-timesyncd to use our NTP hostname
45 services.timesyncd.enable = lib.mkForce true;
46 services.timesyncd.servers = [ ntpHostname ];
47 services.timesyncd.extraConfig = ''
48 FallbackNTP=${ntpHostname}
51 # The debug output is necessary to determine whether systemd-timesyncd successfully resolves our NTP hostname or not
52 systemd.services.systemd-timesyncd.environment.SYSTEMD_LOG_LEVEL = "debug";
56 machine.wait_for_unit("tinydns.service")
57 machine.wait_for_unit("systemd-timesyncd.service")
58 machine.fail("resolvectl query ${ntpHostname}")
59 machine.wait_until_succeeds("journalctl -u systemd-timesyncd.service --grep='Resolved address ${ntpIP}:123 for ${ntpHostname}'")