Implementation notes#
Where the implementation departs from, or settles open questions in, design.md. Each entry says why.
Platform#
- Fedora 45 bootc. The design names Fedora bootc with systemd 261+; Fedora 45 ships systemd 262, Kea 3.2.0 and keepalived 2.3.4.
- Provider images are built from Fedora packages (
image/providers/) rather than ISC's images: ISC publishes no Kea 3.2 images (a "to prove" item). So the default Kea is 3.2, not 3.0 LTS; 3.2's interface handling is what the design wanted to fall back to anyway. - Bound provider images are pinned by an immutable per-commit tag
(
ghcr.io/sparewall/kea:sha-<commit>), not by digest:bootc installcannot copy a digest-referenced logically bound image from host storage ("would require changing layer representation"). Signatures are still verified on the digest by the containers policy. - Fedora base images are used by tag, not digest. quay.io/fedora
publishes no dated tags and prunes a superseded
:45manifest within about a day, so digest pins broke CI within a day of being set. Builds record the digests they used in the CI run summary, and the SBOM lists every package. bootc-image-builder, whose digests are retained, stays pinned. - The image ships
/etc/machine-idempty, as the base image does, and the build fails otherwise (#196). A systemd update pulled in by the package step runssystemd-machine-id-setup, which wrote an ID into 0.3.2-rc1 and 0.3.2: every install from their media shared it, and the next upgrade replaced it (bootc takes the new image's copy of a file the node never changed), so systemd-creds deleted its host key.sparewall-rekey-credential-secretrewrites the key's header (the machine ID hashed for systemd-creds' application ID) for the node's new ID before anything decrypts, only when it is one of those two leaked IDs. The key itself does not depend on the machine ID. - Providers order after
sparewall-early.service, not sparewalld. sparewalld starts them during its own start-up activation, so ordering them after sparewalld deadlocked a reboot of a configured node. Early boot installs their configuration; at start-up sparewalld queues the starts (--no-block) rather than waiting on them. Restarts it still awaits, so health never sees a provider mid-restart: no unit it starts may order after it, which a unit test checks.sparewall-httpdwas ordered after sparewalld until 0.3.0, so a restart of sparewalld withmanagement.webon waited for it and timed out, over and over (#164). - The image's binaries are built by Fedora's Rust (1.99 in Fedora
45), from the image's own build stage, not the toolchain CI pins
(
rust-toolchain.toml, 1.98), which runs the unit tests and clippy. Fedora's is never older, and the VM suites test the binaries it builds.rust-versionis the pinned toolchain's: nothing older is built or tested. - The containers signature policy defaults to
reject. bootc's--enforce-container-sigpolicy, which upgrades use, refuses a policy whose default accepts anything.ghcr.io/sparewallrequires the project's signature and local transports are open. - ulogd2 is built from source in an image stage (Fedora 45 does not
package it), with libnetfilter_log 1.0.2 linked statically because
Fedora has 1.0.1. syft cannot see either, so the image SBOM gets them
from the Containerfile's
ARGs (.github/sbom-source-builds.sh); their advisories are watched by hand (releasing.md). node_exporter comes from Fedora'snode-exporterpackage; it listens on localhost only, and sparewalld appends its metrics to/metrics. - The coordinator has its own enforcing SELinux domain,
sparewalld_t(image/selinux, installed withsemodulein the image build). Its state, runtime and temporary files and its units have their own types (sparewalld_var_lib_t,sparewalld_var_run_t,sparewalld_tmp_t,sparewalld_unit_file_t), and the confined daemons that read configs from/run/sparewall(ulogd, journal-upload, conntrackd) get rules for that. tmpfiles relabels/var/lib/sparewallat boot. Two grants stay generic: runningbin_tcommands, which run insparewalld_tunder the same rules; and Quadlet's generated units, which share one type. The rules are what the VM suites saw it do, and the suites fail on any denial bysparewalld_tor on its types, with dontaudit rules off (semodule -DB), so a change that needs a new access adds its rule with the code. The suites do not exercise everything (ACME issuance on a node, names rather than addresses, real hardware); name resolution is granted by interface for that, and operations.md documents making the domain permissive on a node (atypepermissiveCIL module throughsemodule: the image has nosemanage), which the boot suite exercises.sparewall-run@runs the same binary but staysunconfined_service_t(SELinuxContext=): it runs what the coordinator's confinement forbids. bootc, executed from there, entersinstall_tas it does from an admin's shell (a transition in sparewalld.te): left inunconfined_service_t, its probe formac_adminis denied and logged on every run.systemd-run --pipe -p SELinuxContext=does not work instead: systemd may not use the helper's pipes. - The installer ISO is bootc-image-builder's
anaconda-iso, made unattended by the kickstart inimage/installer.toml: it installs the image embedded in it to the first fixed disk (removable and optical drives are skipped), with no network, but only if that disk is blank (no partitions, no whole-disk filesystem, LVM or RAID signature; an empty partition table counts as blank). Otherwise its%prestops the install with a message;sparewall.erase=DISKon the kernel command line erases the named disk regardless. Without a kickstart, Anaconda waits at its interactive screens. bootc pulls the logically bound provider images from their registry during the install unless the target's image store already has them, and bootc-image-builder does not put them in the ISO, soimage/embed-bound-images.shadds them under/bound-imagesand the kickstart's%pre-installcopies them intoostree/bootc/storageon the new disk with skopeo (podman would record the store's path in its database, and bootc's podman reaches the store through another). It builds Anaconda from the image's repositories, which it reads from/etc/yum.repos.d, so the image copies Fedora 45's dnf5 repository files there (nodes never run dnf; bootc replaces the whole image). - A seeded first configuration is applied by the node itself
(
sparewalld/src/seed.rs, #46): from/etc/sparewall/config.{json,yaml}(written bysparewall init --config, which the seed stick runs forsparewall-config.yaml) or thesparewall.configcredential, only at generation 0, through the ordinary apply path with authorseedand a 600 s confirm window. It confirms after three consecutive health checks (5 s apart) out offailed; a refused or reverted seed is a degradedseedcheck while the node stays in bootstrap mode.seed.jsonin the state directory records a hash of the last seed tried from each source, so a seed is tried once: a corrected stick is tried, but the same stick left in, or a credential delivered again at boot, is not. The seed unit runs on every insertion; it records a stick's identity only while none is recorded. Secrets and pairing are not seeded. - Physical nodes get their identity from a seed stick: a filesystem
labelled
SPAREWALLwithsparewall-identity.yaml(or.json). A udev rule startssparewall-seed@.service, which mounts it read-only and runssparewall init --from, until an identity is recorded. The unattended ISO locks root, so the console route (sparewall init) needs an admin password, which only an identity can seed (password_hash). A custom kickstart could write the identity too; the release ISO has none. - Releases are drafted, then published by a maintainer
(releasing.md). A
v*tag reruns every VM suite; the draft carries the ISO, raw and qcow2 images, the static (musl) CLI, SBOMs and signed checksums. Publishing tags the tested image with the version and, unless it is a prerelease,stable: promotion is that decision, not a separate test run. - Confined daemons read their configs from their own runtime
directories (
/run/chrony,/run/keepalived), which carry their SELinux labels; everything else is under/run/sparewall/<subsystem>. - Disks built on an SELinux-enforcing host are relabelled on first
boot (#152). bootc-image-builder run there leaves ostree's own
metadata under
/sysrootwithout labels (the repo's commit, dirtree and dirmeta objects and refs, the deploy directories,/sysroot/boot); on a host with SELinux off, as in CI, it is labelled. Either way the deployment and the repo's file objects are. The coordinator's restorecon walks the mounts and was denied searching the unlabelled directories, so a node from such a disk starteddegraded.sparewall-label-sysrootlabels only what isunlabeled_t, as the policy labels its path with/sysroottaken off (ostree's own rule);restorecon -Rwould replace the file objects' labels, which are the labels of the files they are. The VM suites fail on anything unlabelled under/sysroot. A deployment it found clean is recorded in/var/lib/sparewall/sysroot-labelled, and later boots of it skip the walk, which costs a few seconds on every boot otherwise. - SELinux stays enforcing, and confined daemons get files they may
read: networkd's WireGuard keys are copies in
/run/systemd/network(masters stay root-only under/var/lib/sparewall); conntrackd's configuration is relabelledconntrackd_conf_t; keepalived's health check and notify scripts live in/usr/libexec/keepalived(where they run unconfined), and transitions reach the coordinator through a FIFO the notify script writes, since keepalived itself may not use notify_fifo. - Each Varlink connection has a server of its own. zlink's server
answers one call at a time across all its connections, and some admin
calls wait on the peer or bootc (a sync-link change waits up to 15 s
for the push reply), so the coordinator serves every connection with
its own copy of the service (
sparewalld/src/varlink.rs). Calls that change the configuration (apply, merge, patch, confirm, rollback, sync, upgrade start) still run one at a time, under a shared lock: a sync-link change must not have another land between the peer taking it and it running here. Reads run alongside them. - keepalived's health check has a socket of its own,
/run/sparewall/org.sparewall.Health, serving the same interface. A check held up past its timeout (5 s, three in a row) would hand the gateway addresses over, so it does not share a listener with admin clients. - Commands the coordinator's sandbox forbids (podman config checks,
the keepalived netns check, bootc) run as the oneshot unit
sparewall-run@<id>.service;systemd-runfrom inside the sandbox fails. The coordinator spools an operation for it, not a command line (sparewall_core::hostop::HostOp, #279): bootc status, check, stage and apply;skopeo inspect; a reboot; keepalived's stop, start and state;sparewall-*timers that run a known job; a calendar check; one lego order (its arguments rebuilt from checked values, so no hook or other option), in the image/usrships, with only the state directory'slegomounted; the renderer's own config checks (keepalived's rebuilt from its interface names), in the provider's own image, against files under/run/sparewall/check; the admin password hash; the hostname. The unit builds the command from the operation after checking its arguments against its own directories (SPAREWALL_STATE, as the coordinator's), refuses any path through a symbolic link (openat2 withRESOLVE_NO_SYMLINKS, so the check and the open are one step). lego runs confined (container_t) on private copies, in/run/sparewall-run, which the coordinator cannot write: its environment file, and its data (regular files only, read through such descriptors), relabelled there for its container. Afterwards the data is copied back relative to directory descriptors, each file under a temporary name and renamed, so a link the coordinator plants is replaced, never written through. Anything else is refused and logged, so a compromised coordinator gets these operations as root and nothing more. What remains: podman mounts a config check's directory by path, after the check, so a coordinator that swaps it for a link in between gets that mount instead, read-only and unlabelled, for the provider's checker alone. - Bound images are reached with
--storage-opt=additionalimagestore=/usr/lib/bootc/storageper podman invocation (QuadletGlobalArgs=): a global storage setting breaksbootc install. - Admin SSH keys are written to
~admin/.ssh/authorized_keys: with SELinux enforcing, sshd cannot read keys under/var/lib. Theadminaccount has passwordless sudo; root cannot log in over SSH. That is deliberate, and stays after roles are enforced per call (#11):adminis the break-glass account, an admin key already reaches root through the API (upgrades, captures, the configuration itself), and a sudo password would only add a secret to lose at the moment the node needs repairing. - The admin password is a cluster secret holding a crypt(3) hash
(
admin-password, #89):sparewall passwdhashes on the client (SHA-512 crypt with a 16-character salt, the longest crypt(3) keeps), and--lockstores!as a new version, since a deleted secret would not reach the peer. Each node sets it withusermod -pthroughsparewall-run@, outside the coordinator's domain, after a change, on receiving it from the peer, and at start-up; an identity'spassword_hashis stored as version 1 when there is none. Without the secret the account is left as installed.management.ssh.passwordrenders/run/sparewall/ssh/sparewall.conf(its own SELinux type, which sshd may read), which the image's sshd drop-in includes ahead of itsPasswordAuthentication no; it is rendered in every generation, bootstrap included, so turning it off or reverting reloads sshd too.
Coordinator#
- Adding a field (#168): mark it with
#[schemars(extend("x-since" = N))], where N is one more than the revision of the last release, and raiseSCHEMA_VERSIONto N if it is lower.schema::tests::new_fields_name_their_revisionfails on a field that is not in revision 1 (crates/sparewall-config/schema/v1.json, 0.2.0's schema) and names no revision, and on a removed field. A local apply recordsschema::revisionof the document; a generation from the peer keeps its own, since both nodes must hash it alike. Add the revision to the table in operations.md, "Schema revisions". A value that earlier releases reject as not built yet (a provider, a mode) is marked on its field with#[schemars(extend("x-since-values" = {"value": N}))], so a document that uses it needs revision N too. - What the peer reads is remembered (#224): its hello says which
schema revisions it reads, and the coordinator keeps the latest answer
in
<state>/peer-reads, through failed hellos and restarts. Forgetting it whenever the peer was out of reach refused every change at revision 2 or newer during a sync cut,--allow-divergeincluded. A peer rolled back meanwhile is no hazard: every node validates a generation it receives, and one that needs a newer revision than it reads is refused there. - Journal entries to filter on (#188) log to the tracing target
sparewall::journal(update::JOURNAL_TARGET) with amessage_idfield. A second journald layer takes only that target and writes field names unprefixed, so the field is the journal'sMESSAGE_ID; every other event keeps tracing-journald'sF_prefix. The update check's state lives in sparewalld, not the coordinator: status and/metricsread it fromupdate::status()andupdate::metrics(). - Host operations beyond
Systemare narrow adapters insparewall_core::host:Conntrackd,BackupRepository(restic),Timers(transient systemd timers),DnsZone(RFC 2136) andUpgradeHost(bootc, reboot, keepalived), plus the daemon'sUpgradePeer. Each method is one operation with its own error, not a general command runner, and the orchestration (failover, backup, ACME challenges, the rolling upgrade) is tested against fakes (#12). Reading status (bootc status,bootc upgrade --check) still calls the host directly. - networkd is driven with
networkctl(reload,reconfigure,delete) andudevadmrather than the Varlink link methods; the behaviour is the same and the Varlink calls can replace them later. - Forwarding is set with sysctl (
net.ipv4.conf.all.forwarding), notIPv4Forwarding=in networkd.conf, so bootstrap mode can turn it off. - nft reloads use a prelude computed from the live table that flushes and deletes coordinator-owned chains and sets, except sets networkd fills, in the same transaction as the new table body. A test against the kernel shows networkd's elements survive a reload (a "to prove" item).
- Config checks that need runtime state run against a variant: Kea's test listens on all interfaces and keepalived's runs in a private netns with dummy links of the same names, because both reject interfaces that only appear once the change is applied.
- Rollback creates a generation holding the target's document, on top
of the active one, so the rolled-back generation stays in history and a
peer receives the rollback as an ordinary change. Reactivating the old
generation made the node look behind its peer, which pushed the newer
generation straight back (#4). Discarding an unconfirmed change is the
exception: it never left the node, so
rollback(and a missed confirm window) just returns to its revert target, without the peer. Whether a request is only that discard is decided under the same coordinator lock as the rollback, so a confirm window expiring or a confirmation in between cannot turn it into an ungated new generation. - Catching up pushes history, runs only the newest. A peer behind by
several generations stores the earlier ones (
Pushwithactivate: false) and runs only the last, so after a change and its rollback it never runs the rolled-back configuration. Equal content does not mean in sync when one history contains the other: the peer would otherwise miss those generations and its next change would look like divergence. Older peers ignoreactivateand run each generation. - The peer link uses Varlink over TCP on the sync-tunnel address,
spliced onto a root-only Unix socket (zlink has only Unix transports).
The peer methods trust the connection, not
Hello's node name, so the connection is what is authenticated, in three independent layers: the listener is bound toswsync(SO_BINDTODEVICE), so the kernel delivers only connections that arrived through WireGuard (the binding is to an interface index, so the listener rebinds when networkd recreatesswsync, as it does for a new sync key); it accepts only the peer's tunnel address as the source (WireGuard admits that address only from the peer's key, and the client binds its own tunnel address to match); and the first input rule drops anything for the tunnel subnet arriving on another interface, ahead of conntrack state, zone policy and raw rules, while the forward chain routes nothing into or out of the tunnel. No zone-to-self policy can open it. - NAT reflection is per forward (
forwards.<name>.hairpin: [zones], #48): a DNAT rule per hairpin zone for the forward'sdst(required: without it every connection to that port would be reflected) anddport, and the implied zone pair accepts the DNATed connections, as forfrom. A client on the server's own network leaves by the interface it came in on, which the zone map never dispatches, so the forward chain accepts that case explicitly, and postrouting SNATs it to the network's gateway address (vip, which moves with the gateway; the node's address standalone without one). Other hairpinned clients keep their address. The listed zones reach the server only through the forward, not past their own zone-pair policy. - A forward's outside address and port are the server's (#102):
input rejects traffic to a forward's
dston itsdport(TCP with a reset), ahead of every zone's->selfrules. The forward's own zones are DNATed before input and never meet the rule; any other zone would otherwise reach the node's own service on that address and port (the coordinator's HTTPS, with its self-signed certificate) and now gets a refusal. To use the forward from such a zone, add it tohairpin. - Remote access on extra ports (
vpn.<instance>.extra_ports, #50) is a prerouting NAT rule on the WAN interfaces. In a pair it isip daddr <vip> ... dnat ip to <vip>:<listen_port>, notredirect:redirectrewrites the destination to the interface's primary (the node's own) address, and the output chain drops remote-access replies that do not come from the gateway address. Standalone it isfib daddr type local ... redirect. Input sees the translated port, so the listen port's accept covers it. A forward could not express this (itstomust be in another zone), and a general NAT hook would be hard to validate. - Extra gateway addresses ride in the gateway's VRRP instance
(
networks.<name>.extra_vips, #47): morevirtual_ipaddresslines, no new VRIDs, so they move in the same step as the gateway address; standalone they are static addresses. Dynamicaddressobjects include them. Ansnattarget, or a literal forwarddst, inside a statically addressed network must be an address some node holds there (a node address, the gateway address or an extra one): otherwise it would silently go nowhere. Addresses outside every static network (a DHCP WAN's) cannot be checked. - A pair's WAN may have private node addresses (#54): when
viplies outside the nodes' subnet, the public subnet is the vip's andgatewaymust be in it. The master's default route is a keepalivedvirtual_routesentry; each node also routes via its peer at metric - The postrouting SNAT for the nodes' own traffic matches
rt ip nexthop != <peer>rather than the ISP's gateway, so the master's traffic to other hosts in the public subnet is covered too, while on the backup (whose next hop is always the peer) nothing matches. No output-chain rule is needed: postrouting sees locally generated traffic. Routesrcis left to the kernel, which already prefers the vip for a gateway in its subnet. - A hold keeps keepalived running (
cluster.hold, #51): every instance also trackssparewall-held, a script that always fails, so all sit in FAULT and announce nothing while the VRRP configuration, the sync group and conntrackd are still exercised. Health reports a degradedheldcheck rather than failed, since a failed level would block the confirmations a pair relies on. Standalone, the gateway address and its extras are not installed. Kea keeps its subnets (so HA runs) with no pools or reservations, and is not authoritative: an authoritative Kea would NAK the clients of the server it is staged beside. On a WAN with private node addresses (static or leased) the route via the peer is left out too: with no master, it would bounce traffic between the nodes. - One lease for a pair (#54) is a macvlan (
swwan) with the VRRP virtual MAC rather than keepalived'suse_vmac, which creates the vmac interface on both nodes. Both nodes render the link withActivationPolicy=manual, so the renderer stays a pure function of the document; the coordinator (lease.rs) runsnetworkctl upordownto match the VRRP role.SendRelease=nokeeps the lease for the next master. The VPN extra ports use the standaloneredirectonswwan, which only the master has up. - A static block's gateway addresses are on
swwantoo (#176), with the same virtual MAC, but the link is up on both nodes: keepalived adds the public route as it becomes master, and the kernel refuses a route on a link that is down, so the coordinator could not bring it up in time. The backup's link stays silent instead: no address, IPv6 disabled by sysctl (LinkLocalAddressing=noalone leaves the kernel free to send MLD), andarp_ignore=1, which keepalived's ownuse_vmacinterface does not guarantee.KeepConfiguration=yeskeeps keepalived's addresses through a networkd reload. The pair suite models a gateway that ignores ARP for the public addresses from the nodes' own MACs, and checks that the ISP's cached MAC is the virtual one at every handover and that the backup's link sends nothing. - A generation that never ran gives way. A local change that fails
to activate is moved aside (
generations/<id>.failed-<hash>), out of history, and its id is reused. One left by a crash beforestate.jsonnamed it, or stored as history from the peer, is replaced by the peer's generation with that id when the push extends the active generation (set aside as<id>.diverged-<hash>); otherwise every push of that id conflicted untilsync --from(#24). - A state write that fails after activation is reconciled. The store
reports whether the new record had replaced the old one before the
failure. Before the rename,
applyand a peer push re-activate the previous generation, then set the change aside or reject it. After the rename (a failed directory sync), they write the previous record back and run what is then readable. They keep the generation unless the old record was written back cleanly. Tests inject failures with a directory at the temporary path and withStore::inject_sync_faults(#28). - Generations are synced before they can be named.
Store::sync_generationfsyncs a generation's directory andgenerations/. It runs after every save, and again before running the peer's generation, so a retry over a leftover whose sync failed redoes it. Every store write fsyncs its directory after the rename (#28). - Equal-version cluster secrets made independently by both nodes (each applied the pairing document) converge on the one created first.
- Health endpoint detail and
/metricsneed an API token, except/metricswhenmetrics.modeisexternal, or over loopback when it islocal. - The local Prometheus (
metrics.mode: local, #145) scrapes/metricsover loopback, which needs no token in that mode (as node_exporter answers loopback without one), rather than with a token the coordinator would have to mint and keep for itself. Its certificate is not checked there: it names the management network, not loopback. The API's queries go through the coordinator (org.sparewall.Metrics), not a proxy insparewall-httpd, which has no network at all: only the query endpoints are reachable, with the caller's role checked like any call. They needmonitor, which can read every series on/metricsalready. Retention is in the renderedprometheus.yml(Prometheus 3 deprecated the flags), so a change is a reload. It runs asnobody; podman gives a new named volume to the container's user. Its container runs ascontainer_t, like Kea's and Unbound's. - Roles are checked per call on the restricted socket (#11),
/run/sparewall-api/org.sparewall.Api. A connection binds a token first (org.sparewall.Auth.Bind). A wrapper around the service on each connection reads the method name as the call is decoded and checks it against one table (access::needed) before the service runs; a method missing from the table is refused, and a test holds the table to the interface descriptions. The token is looked up again on every call, fromtokens.jsonwithout the coordinator's lock, so a revoked token stops working on bound connections at once. Turningmanagement.anti_lockoutoff is checked in the coordinator, since it depends on the document, for apply and rollback alike. The root-only sockets are unchanged and take no token. - Users and sessions. A user is the cluster secret
user.<name>(role and crypt hash); removing one stores a tombstone, since secret deletions do not reach the peer.adminis theadmin-passwordsecret.Auth.Loginchecks SHA-crypt hashes only ($5$,$6$), assparewall passwdandsparewall usermake them; another kind seeded with the identity works at the console but not for a login until the password is set again. Sessions are tokens in the node's token store, tied to the user and ending after 12 hours. They are not synced, so after a failover the UI asks for the password again. Failed logins are counted per user name in memory, at most five in 15 minutes, and each failure answers a second late. - Kea pings an address before offering it (its open-source
ping_checkhook, #52): one echo request, a 200 ms timeout, and no ping for an address leased in the last 60 s. An answer means a host is using it without a lease here (after a restore, or beside the server Sparewall replaced), and Kea declines it and offers another. Kea will not start if the hook cannot open its ICMP socket (the container hasNET_RAWfor it), so the hook is loaded only while some network uses it:dhcp.ping_check: falseturns it off by default,dhcp.<network>.ping_checkper network (Kea's subnetuser-context). - DHCP takeover is driven by VRRP. Kea's hot-standby standby declares
its partner down only after
max-unacked-clients(5) distinct clients go unanswered, which a small network may never produce. When a node is the VRRP master and the peer is unreachable over the sync tunnel for 15 seconds, the coordinator has its Kea serve the primary's scope (ha-scopes). A cut sync VLAN alone leaves the VRRP roles in place (adverts run on the client VLANs), so it cannot split the pool. - Backups seal secrets with the backup password (Argon2id and ChaCha20-Poly1305) rather than relying on restic's encryption alone, so a bundle on the node's disk or copied by hand is no weaker than one in the repository. The restic upload runs inside sparewalld's sandbox; the timer is a transient unit recreated at start, so no unit file follows the schedule.
-
systemd-creds setupruns before the sandbox (ExecStartPre=+): the host credential key lives under/var/lib/systemd, which the sandboxed coordinator cannot create on first use. -
Live firewall verification records the table right after each load (
nft -j, normalized: no counter values, quota use,lasttimestamps, element timeouts, handles, or networkd-filled set elements) and compares it on every health check, so drift is caught even when chain names are unchanged. It fails closed: if the table cannot be read back right after a load, the node is unverified (health failed, no applied hash) until the next load records a baseline; health never learns one from the live table, which may have drifted by then. The baseline is the kernel's own listing after a successful atomic load, not a re-parse of the rendered script, because nft canonicalizes expressions. A drifted node reports no applied hash, so readiness, VRRP health, pair sync and the upgrade gate all see it. -
Replication-only links degrade, never fail. The renderer lists the sync network's interface, and a port carrying only it, apart from the links that carry traffic. keepalived's track script fails only on failed health, so losing sync locally (a dedicated port down, the sync VLAN deleted) or upstream degrades health and stops replication without moving the gateway addresses, as a cut sync link affects both nodes equally. A shared trunk carrying service networks still fails health.
-
Sync-link changes go to the peer first, in two phases (#25).
- Staging: in a pair with the peer reachable,
apply(and a rollback) only stores a change whose cluster sync settings, sync network or per-node sync port differ (ApplyResult::staged). It refuses one made while a change is pending, or one that changes anything else. - Push and run: the daemon pushes it gated through the current
tunnel (peer protocol 3), then
activate_stagedruns it pending withpeer_gate, plusneeds_adminif a confirm window was asked for. - Reply first: running the change switches the tunnel the push's reply goes through (the pair VM test hung there). So the receiver validates a gated sync-link push, replies, and then runs it. A failure after the reply is never confirmed, so the pusher reverts. That keeps the pusher's wait short on the normal path.
- Lost push replies: a push that was sent but got no reply within 15 s runs anyway. If the peer took it, it confirms over the new link; if not, nothing confirms it and this node reverts at its deadline. Only a refusal, or a failure before sending, sets the change aside.
- Prepare: the receiver marks a gated push that changes its sync
link
link_change. Itsconfirm_receivedonly setsprepared: from then on the change is in doubt. The pusher'speer_confirmedand the admin'sconfirmtogether keep it there. - Record: every way a
decides_linkchange ends (kept byfinish_confirm; reverted at the deadline, at boot or by a rollback) writesState::link_decisionin the same state write. Hello shows the record until the peer is seen with nothing pending (peer_followed). While a sync-link change is pending, apply, merge and patch are refused on both nodes. On the decider, confirm and rollback stay available (they are how the admin keeps or drops the change). On the receiver they are refused too, andsync --fromis the explicit way out. - Durability: a kept decision whose write fails after the rename
is written back as pending. If that fails too,
decision_unsuremakes Hello report pending with no decision untiltickmanages to sync the state directory. Boot syncs it first and setsdecision_unsureif that fails, so a restart does not publish an unsynced decision. - Follow: the in-doubt receiver's sync loop calls
resolve_in_doubtfrom the record. Without one, it only keeps the change if the pusher's lineage has it, and never infers a revert from history that may be pruned. Neitherticknorbootreverts a prepared change. Without contact for 30 s,alternate_in_doubtruns the other link, and the tunnel followslive_document. - Not taken: a staged change the peer does not take, or one
overtaken by another local change, is set aside as
unsent. -
Pushed generations are gated by the pusher's confirmation (peer protocol 2:
Pushwithgated, thenConfirmon a new connection). The receiver records what already fails before it runs the generation, per resource (each required link down, each provider unit inactive, each other failed check), and confirms only if nothing else fails, so a change that breaks a link it needs is not kept, even beside an older fault of the same kind, while one landing on a node with a known fault can be. Until confirmed,applied()(status,sparewall_config_applied, the peer view) reports nothing applied, and theappliedcheck is degraded, not failed: failed would block the confirmation and lower VRRP priority. The pusher confirms right after pushing and again on each sync pass while the peer reports it waiting, so a transient tunnel blip during reconfiguration is retried until the deadline (PEER_CONFIRM_SECONDS, 120 s, in the persisted state). An older peer is pushed ungated and confirms at once, as before. -
Remote-access keys are cluster secrets installed in tmpfs: the server key (
vpn-<instance>, generated by the node that first applies the instance) and any peer's preshared key (preshared_key: secret:<name>, #49) are written to/run/systemd/networkfor networkd. networkd reads key files only when it creates the interface, so a change to either, set locally or received from the peer, recreates it. A referenced preshared key that is not set is an apply warning and a degradedvpncheck rather than an error: a generation pushed to the peer may arrive before the secret does. - Remote-access VPN failover is measured, not assumed. The pair test
connects five clients over the WAN VLAN: an active one with inner TCP
and UDP flows, an idle one with a session older than 120 s, an idle one
with a fresh session, an active one behind NAT with
PersistentKeepalive, and an idle one behind NAT sending only keepalives. Probing starts the moment the gateway moves (for the upgrade, when the CLI reports the handover, with the fresh session renewed until then), after checking each idle session's age. Each client must recover within 60 s (180 s for the keepalive-only client, which waits for its session to reach 120 s) and still have the gateway address as its endpoint; the results are in the run's step summary.tests/vm/vpn-check-test.shchecks the recovery assertions without VMs. Recovery is the client's: the shared static key lets the new master accept a handshake, but sessions are not synced. The test found that a node handing the address over replied from its own address, so an active client roamed to it and was cut off for good once it rebooted; the output chain now drops remote-access packets from anything but the gateway address. - Site-to-site peers are started by the master, from the gateway
address (#148). A peer with an
endpointgetsRouteTable=main(its networks are routed through the tunnel) and itsPersistentKeepalive. On a WAN whose node addresses share the gateway address's subnet, the kernel would pick the node's own address for a handshake the master starts, and the output chain drops it. So in a pair with site-to-site peers the WireGuard interfaces mark their packets (FirewallMark=0x5357), a rule sends marked packets to table 5357, and keepalived adds routes from the gateway address there as the node becomes master (virtual_routes ... src <vip> table 5357). On the backup the table is empty: the lookup falls through to the main table, the source is the node's own address, and the output chain drops it, so a site never roams to the backup. A pair with site peers needs exactly one WAN, static, with a gateway address and a gateway: with a leased WAN the backup's own traffic is NATed out through the master, its handshakes with it, and nothing would stop them. sparewalld watches the peers (tunnels.rs), on the node that holds them: a peer named by DNS is resolved again once it has had no handshake for 135 s (as reresolve-dns does), since networkd resolves it only once, and one with a keepalive and no handshake for 180 s degrades health. - VPN clients route by incoming interface (#149). The client's peer
has
AllowedIPs=0.0.0.0/0into a table of its own (5360 on, in name order), and each routed network gets two rules on its interface: the main table withSuppressPrefixLength=0(everything but its default route: the other networks, site-to-site routes), then the client's table. Matching the incoming interface rather than the source subnet keeps the node's own traffic, even from its address on that network, on the main table, and with it the client's own handshakes. The kill switch is a forward rule from those interfaces to the WAN's, before the state rule. In a pair the client's link isActivationPolicy=manualandlease.rs, which already keeps the WAN lease link up on the master only, does the same for it; both nodes hold the same key and address, and conntrackd's entries carry the translation to the tunnel address, so a connection survives a failover when the service keeps its own translation.
Providers#
- One table of providers (
sparewall_config::providers), per role: name, default, built or not, whether it runs in an HA pair, and the state it keeps (Kea's lease database), with where it lives and which providers can import it. Validation rejects an unknown provider, one that cannot run in a pair, and one not built yet. The renderers choose by it. Backups take the lease file from the chosen DHCP provider.applywarns when a change of provider leaves state behind. With one built provider per role, provider-specific status and state export/import are not abstracted yet. The VM conformance suite covers the built providers (Kea, Unbound). - lego runs whole ACME orders, not just the DNS records: it has no
command that only publishes a TXT record. So a lego certificate uses
lego's ACME account, one per node under
/var/lib/sparewall/lego, not the cluster's (built-in RFC 2136 orders share one account through the secret store). The coordinator decides when to order (two-thirds of the lifetime, as for RFC 2136) and passes--renew-force. lego runs in its provider image, a logically bound image, throughsparewall-run@(podman is outside the coordinator's sandbox); the credentials go in an environment file under/run/sparewall/legothat exists only while lego runs. Provider codes are checked for form only; lego rejects an unknown one when it runs.
Release gates#
The two-node suite that gates promotion to stable (design: "Testing")
runs as two CI jobs, each booting its own pair: pair-test.sh (build,
boot, publish) and pair-faults.sh (pair faults). two-nic-test.sh (two
NICs, no VLANs) runs the default layout of #177: a standalone node and a
pair with no NIC but their WAN and LAN ports, managed over the LAN. upgrade-test.sh
runs once per release to upgrade from and mode (upgrade from <release>,
single node and upgrade from <release>, pair), each installed from that release's disk image.
| Gate | Where | State |
|---|---|---|
| Kill the master: gateway, flow and lease survive | pair-test | Tested |
Cut only the sync VLAN; divergence and sync --from |
pair-test | Tested |
| Lose a replication-only link on the master | pair-test | Tested |
| Move the sync link, kept and reverted | pair-test | Tested |
| VPN clients reconnect across failover and upgrade | pair-test | Tested |
| Rolling upgrade, unsigned image refused | pair-test | Tested, to a derived image of the same build |
| Flap a bond member on the master | pair-faults | Tested |
| The master loses its whole trunk | pair-faults | Tested |
| Cut one service VLAN on one side | pair-faults | Tested: see below |
| Destroy both nodes, restore from bundles, re-pair | pair-faults | Tested |
Rolling upgrade from the previous release, signed, then bootc rollback |
upgrade-test | Tested (#166), single node and pair, from each release .github/upgrade-from.sh names |
| Schema downgrade: a generation the older release cannot read | upgrade-test | Tested (#13), single node: it runs the newest generation it reads, health says why, and sparewall rollback recovers |
| Mixed versions: a change the peer cannot read is refused | upgrade-test | Tested (#13), pair: with the standby back on the older release |
A service VLAN cut on the master's side only leaves every link up,
and keepalived's sync group keeps the backup's instances BACKUP while it
hears the master on the remaining VLANs, so neither sees it. The
coordinators do (sparewalld/src/reach.rs): every 10 s each node
re-resolves the peer's own address on every network with a gateway
address (ARP, which nft does not filter), and while the peer is silent
there, the hosts either node knows on it. Each reports what answered in
its hello. A node whose peer is silent on a network, where no host
answers it but a host that answers the peer was asked, has lost the
network: after two such rounds its reach check fails, keepalived puts
it in FAULT, and the gateway moves. A network where nothing answers
either node (empty, or cut on both sides) only degrades health. In the
suite the gateway moves within about a minute of the cut; connections
through the cut network do not survive that long a stall.
Not built yet#
- ACME
http-01. - An alternative DHCP provider: networkd's DHCP server (
dhcp.provider: networkd). Earlier versions accepted it and then rendered nothing, silently turning DHCP off; validation now rejects it as not built yet (#10). (Syslog forwarding,logging.remote.provider: syslog, was in the same state until 0.5.0 built it.) - Schema migrations. Revision 2 only added a field, which needs none (see "Adding a field" above).
- Benchmarks.
- Provider passthrough (
provider_options). The schema keeps the field, and validation rejects it with an error at its path, so a document never shows a setting that has no effect. (Scheduled upgrades were in the same state until 0.4.0, and a local Prometheus until 0.5.0.)