Run infrastructure probes as Rust integration tests in the CI suite
Detail General notes
Amended by ADR-0104
Infrastructure checks are tests in the suite CI runs, reading the configuration that's actually deployed.
Decision
Write every infrastructure check as a test in the Rust workspace suite that CI already runs. A check that runs only when someone remembers it can stop being run without anything reporting it.
Each test checks one property, is named after it, and starts its own daemon on a free loopback port. It waits until that daemon answers, and it fails if the daemon exits first. A check against a service that never started reports the same green as one that passed, so the readiness wait is mandatory.
Take what a test knows about the deployed configuration from Nix evaluation of the real NixOS configuration, never from a copy. A test that retypes the settings it exercises certifies a configuration nobody deploys, and a grep of the module source finds a value whether or not anything uses it. A value shared by a deployed module and a test is one expression that both read.
Keep inspection out of the suite. A tool that reads the live cluster and prints what it finds has no pass or fail, and turning it into a test would mean inventing a threshold nobody chose.
Why
Security changes to the platform each shipped with a probe script that started the real daemon locally, drove it and checked the change worked. A task-runner recipe was the only thing that ran them, so nothing ran a probe again once its change merged. A later change could undo the property it checked, or the property could fail to hold in production, without any probe reporting it.
Rejected alternatives
- Probe scripts behind task-runner recipes. They are accurate, and they stop being run without anyone noticing.
- Folding cluster inspection into the suite. It has no pass condition anyone chose.
- NixOS VM tests (
runNixOSTest). They exercise the whole deployed unit, including systemd ordering, secrets and the firewall, which a single daemon on loopback does not. They need KVM, and neither of our Linux build hosts has it: Hetzner Cloud offers no nested virtualization, and the Linux VM on the Mac already runs under software emulation. Each test would either never be scheduled or run emulated twice over. They become the better tool if the builder moves to a host with KVM.
Consequences
The suite needs the daemons it tests wherever it runs. It builds them from the nixpkgs revision the cluster's flake pins, so the tests exercise the versions the cluster deploys, and a cold machine needs network access to fetch them. Each test adds seconds to every CI build, and tests that evaluate the NixOS configuration add more.
A converted probe is done only when each test has been seen to fail with its property broken. A test that stays green through the break is not checking the property it is named for.