Warda-DNSDocs Warda: from ward — to protect, guardian
v0.9.3

High availability

Business → High availability (business.ha, Warda Business, beta; internal/ha, internal/admin/ha.go): two boxes paired, a primary and a secondary, share one IPv4 address with VRRP (keepalived); the devices are given that address as their DNS server, and whichever box holds it answers them. When the box that holds it stops, or its DNS stops answering, the other takes it within seconds.

Network requirements:

  • both boxes on the same network, each with a fixed IPv4 address (a DHCP reservation or a static address);
  • a shared address free on that network: outside the ranges of every DHCP server, given to no device. From 0.7.10 it is typed alone (10.0.4.100) or with the length of its network (10.0.4.100/24); up to 0.7.9 the length was required, see The shared address;
  • a virtual router (1 to 255) the same on both boxes and different from every other VRRP router of the network (derived from the secret of the pair by default; change it when the network already has VRRP);
  • VRRP (IP protocol 112) allowed between the two boxes: Warda configures it in unicast to the address of the other box, so no multicast is needed, but a firewall between them must let it through;
  • HTTPS (443, or the port of Warda) from the secondary to the primary and back, for the pairing and the synchronisation;
  • the clocks of both boxes on time (NTP): the signed calls between them are refused beyond 5 minutes of difference;
  • the devices given the shared address as DNS server, by the DHCP server of the network (the box of the provider, the router), or by the DHCP server of Warda on the primary (it then gives the shared address as DNS server; it stays off on the secondary, which refuses to turn it on (409): two servers would give addresses on the same network; it moves with a promotion, see below).

Pairing. On the future primary, Create a pair → Make a pairing code: a code of one use WH-XXXX-XXXX-XXXX-XXXX-XXXX (five groups of four letters and digits, no 0/O nor 1/I: 100 bits), valid 15 minutes, dropped after 5 wrong tries, with the address of this box to type on the other one. On the future secondary, Join a pair: Address of the primary (its IPv4 address, with its HTTPS port when it is not 443) and Pairing code (any case; a code of another form is refused at once, 400), then Join (confirmed: "The rules, devices, household, settings and accounts of this box are replaced by those of the primary within a minute. Its administration log is kept."). Each box proves it knows the code over the fingerprints of both HTTPS certificates (HMAC-SHA256 keyed with a key derived from the code by Argon2id — 32 MiB, 2 passes, about a sixth of a second on a Raspberry Pi 4 —, salted with both fingerprints and a nonce): a machine in the middle, which cannot show the certificate of the primary, is refused, and one that records a proof cannot find the code from it within its 15 minutes. A box of 0.6.8 and a box of a later version do not pair (update both first). The primary then gives a secret shared by both boxes; every later call between them (/api/v1/ha/peer/…, HTTPS only, without an account) is signed with it (X-Warda-HA-Date, X-Warda-HA-Signature) and goes to the certificate pinned at the pairing. Making a code and joining need backups.restore: they give or replace the whole configuration. The page shows the Certificate of this box (its fingerprint) to compare.

Synchronisation. The secondary asks the primary for its configuration every minute (task ha.sync): a backup of the store without the history, applied only when it changed, by restarting Warda on the secondary (a few seconds, like a restore), after checking it. To say plainly: each time it applies a configuration of the primary, the secondary keeps the last 48 hours of its own history (ha.KeptHistory, a constant, not a setting; store.RestoreKeeping, one transaction): its query journal with its names and origins, its counts and charts (by minute, by hour and by day, by country, by origin of block, those of the data loss prevention), the time used a day by a person and on a shared device, the category alerts and the notices. They are kept for the devices and the people of the configuration received: a device is found again by its hardware address (MAC; its own, or one a merge gave it), a device without one by the address it holds, among the devices without one; what was written for a device the primary does not know is deleted, never given to another device. A person is the same when its row is (its id and when it was created); what was kept about a minor goes when the configuration received makes them an adult. What is counted by day keeps three calendar days (the day that holds the limit is kept whole, in the time zone of the box). What is older is deleted, and the sessions, the requests and the modes of the people end at each synchronisation, as before. A first synchronisation with a large journal takes a few seconds more. The chart of the activity marks each one ("the configuration of the primary was applied"). Before this change the secondary emptied its journal and its statistics each time. Everything comes from the primary, the accounts included (the same administrators on both boxes), except what belongs to each box: its administration log, its identifier, the name and certificate of its encrypted DNS, the addresses it gives for its own names, its site of Warda Business, its statement of the customer area and, from 0.8.0, its installation identifier (the secondary keeps its own: the pair is two installations, not a copy), the pair itself; the DHCP servers of Warda stay off on the secondary, which learns at each exchange those the primary runs (IPv4, IPv6). The secondary says so ("This box is the secondary: its configuration comes from the primary. Make your changes on the primary; a change made here is replaced at the next change of the primary."). From 0.8.2 the secondary also receives the settings of the protections of 0.8.0, as a backup holds them: the switch of the mining pools, the automatic blocking of the learning (the secondary never blocks trackers by itself: the rules come from the primary) and the setting of the protection outside the home; a setting the primary never changed is its default. It also receives the devices enrolled in the protection outside the home, which a backup never holds, and relays them while the primary is down (see The relay outside the home in a pair). The settings of the reputation of the domains and of the older switches of the threats, and the state of the exposure check, are those of each box; the regular checks of the exposure and of the known breaches run on the primary only. Without an exchange for 3 minutes, the other box is shown unreachable. From 0.7.5 each box also tells the other, at every exchange, its key at the online service: each names the other to the customer area, which validates the pair. From 0.8.0, during the beta only, the same naming makes the two boxes one for a Subscription: the other box of a pair is covered as its peer (both boxes linked to the account and naming each other), not as a second box. Outside the beta a pair needs Warda Business, which covers every box of the account.

keepalived. On the primary, Shared address: the address, the Virtual router, the Announcements (seconds) (1 to 10), and on each box its Interface and its Priority (1 to 254; 150 for the primary, 100 for the secondary: the box of the highest priority holds the address when both are healthy). Warda makes the configuration of keepalived from them (Configuration of keepalived, previewed before saving: GET /api/v1/business/ha/keepalived?vip=&interface=&router_id=&advert=&priority=&peer=): both boxes start as BACKUP, the primary takes the address back 30 seconds after it is healthy again (preempt_delay), a password of VRRP derived from the secret of the pair (VRRP sends it in clear: it only keeps a mistaken router out), unicast_peer the other box, and a check every 5 seconds, warda healthcheck -url http://127.0.0.1:80/healthz -dns 127.0.0.1:53 (2 failures: the box goes to FAULT and leaves the address; the DNS of Warda must answer a name it answers itself); each change of state runs warda ha-notify -data-dir /var/lib/warda, which writes the state for the page (State of VRRP: Held by this box, Held by the other box, Fault, keepalived stopped).

  • Debian package and Raspberry Pi image: the service never writes the configuration of keepalived itself; it writes its parameters in its data directory and asks warda-system.service (root), which checks each of them, installs keepalived when missing, writes /etc/keepalived/keepalived.conf from the template of Warda (only a file marked as written by Warda is ever replaced) and restarts it.
  • Docker (and an archive): Warda writes keepalived.conf in its data directory; keepalived runs in its own container on the network of the host, with NET_ADMIN, NET_BROADCAST, NET_RAW and DAC_OVERRIDE, the program of Warda for its checks and the data directory: an example is in packaging/docker-compose.yml (commented out). Restart it after a change of the shared address (docker compose restart keepalived).

Make this box primary (on the secondary; the other box must answer: it becomes the secondary and takes the configuration of this one; the DHCP servers of Warda move too: the old primary turns its own off first, then the new one turns on those the old one ran, each restarting when its DHCP servers change, so that they never run on both — confirmed: "… If the other box runs the DHCP server of Warda, it moves to this one.") and End the pair (both boxes forget each other and keepalived stops: the shared address answers no more; each box keeps its configuration). To replace a primary that is gone for good: end the pair on the secondary, then pair again (with the protection outside the home, see the advice of The relay outside the home in a pair). The administration log records ha.pairing, ha.pairing.cancel, ha.paired, ha.settings, ha.sync.failed, ha.promoted, ha.demoted, ha.unpaired.

APIs (administrators; system unless said): GET /api/v1/business/ha (role, fingerprint, port, interfaces, pairing — its code only for the accounts with backups.restore —, peer, peer_fingerprint, since, peer_seen, peer_reachable, shared, local, sync, vrrp, managed, keepalived, config, config_error, dhcp; in config, the password of VRRP is ******** for the accounts that do not change the system); POST and DELETE /api/v1/business/ha/pairing (make or drop a code); POST /api/v1/business/ha/join {"address": "192.168.1.10", "code": "WH-…"}; PUT /api/v1/business/ha/settings {"vip", "router_id", "advert", "interface", "priority"}; GET /api/v1/business/ha/keepalived (the password of VRRP hidden as in config); POST /api/v1/business/ha/promote; DELETE /api/v1/business/ha (end the pair). A pair is two boxes on one network; later phases are in the design note.

The relay outside the home in a pair#

From 0.8.2 (internal/admin/roamingha.go, internal/ha/sync.go). Each box of a pair has its own key at the online service (tls/cloud.key, never given to the other) and its own name <letters>.warda-dns.net; the addresses of the enrolled devices carry the letters of the box that gave them, and the online service knows the devices, and keeps one relay connection, by key (a new connection replaces the old one). A secondary that relayed under its own key would serve nobody. So:

  • The primary gives the secondary, at each synchronisation (every minute, over the channel of the pair: its certificate pinned, signed with the secret of the pair), the enrolled devices (table roaming_devices), the setting of the protection and, while the protection is on and the primary has its name, the identity of its relay: the seed of its key at the online service and its name. The secondary keeps that identity with the pair (meta ha: never in a backup nor a diagnostic, never logged, never given by the API; forgotten with the pair). Protection turned off on the primary, or a primary older than 0.8.2: the secondary forgets it.
  • Standby: while the primary answers, the secondary does not relay; the page Outside the home says "Standby: the primary of the pair relays the devices; this box takes over while the primary is down" (waiting standby in GET /api/v1/roaming).
  • Takeover under the primary's identity: when the primary is down — no exchange with it for 3 minutes (counted from the start of the secondary when there was none yet), or the last exchange failed while this box holds the shared address (keepalived found the primary unhealthy) — the secondary connects the relay under the key and the name of the primary, so the devices stay filtered instead of being answered without the filter. Looked at every 30 seconds: about a minute with keepalived (the shared address moved and one exchange failed), at most about 3 and a half minutes without. The answers follow the same configuration; the journal and the statistics are those of the secondary, which also counts the queries the service answered without the box, told at its connection.
  • Hand-back: when the primary is back, it connects and the service replaces the connection of the secondary; the secondary waits 10 minutes before it tries again, and then stays in standby since the primary answers it.
  • Make this box primary: the new primary keeps relaying under the identity the addresses carry (that of the old primary) and gives it to its new secondary, the old primary, whose own key it is: the addresses keep working. The relay connects again under the right key at once after a promotion, a demotion or the end of a pair.
  • End the pair: each box goes back to its own key and name; only the box whose name the addresses carry serves them (the other one may connect under its own key, which serves nobody). When the box left is not that one, give the devices new addresses there.
  • On the secondary, the addresses are given and taken back on the primary: Give an address, New address and Remove are off in standby, and the API answers 409 "this box is the secondary of a pair: give the addresses on the primary" (or "take the address back on the primary").

Split network, and a pair ended on one box only. When the two boxes cannot reach each other but both reach the online service, each believes the other down: they take the relay from each other, at most once every 10 minutes; each switch costs about a second in which the service answers the devices without the filter, and two connections, 288 a day, a tenth of the 2,880 a key may open. A secondary that still holds the identity of a pair ended on the primary only goes on taking the relay every 10 minutes the same way: end a pair on both boxes.

The secondary holds the key of the primary at the online service, its identity there (the renewals of the plan, its name, its relay); it uses it only to sign the relay connection (GET /v1/relay): its plan renews with its own key, and the relay carries no installation identifier, so the online service counts no clone nor takeover of the plan (it does update when it last saw the primary). The channel of the pair already carries secrets of the same weight (the accounts, the key of the backups, the password of the directory). Both boxes must run 0.8.2 for the takeover.

The shared address#

From 0.7.10 (internal/admin/ha.go, haVIP). The field Shared address takes an IPv4 address alone or with the length of its network:

  • with a length (10.0.4.100/24): taken as typed;
  • alone (10.0.4.100): its length is the one of the network of this box that contains the address, the interface chosen for the pair first;
  • alone, and in no network of this box: refused, since nothing tells its length — the message says to type an address of the network of this box, or to add the length, each with an example.

The example is never a fixed one: it is an address of the network of the interface of the pair (example of GET /api/v1/business/ha), free of the addresses of this box and of the other one; the help and the placeholder of the field use it too. On the secondary, where the shared address is the one chosen on the primary, the address typed alone is read the same way (it is the one of the pair whatever the length).

Refusals in the language of the user. Up to 0.7.9 a refusal reached the page as the English sentence of the service ("invalid request: shared address …"). PUT /api/v1/business/ha/settings and the preview (GET /api/v1/business/ha/keepalived) now answer 400 with problems (the codes below) and example, and the page tells each in its language:

problems Meaning
vip not an IPv4 address, alone or with a length from 8 to 32
vip_outside typed alone, in no network of this box
vip_own already an address of this box
vip_peer the address of the other box
interface no such interface on this box
router_id the virtual router: a number from 1 to 255
priority the priority: a number from 1 to 254
advert the announcements: every 1 to 10 seconds
primary_only on the secondary: the shared address, the virtual router and the announcements are chosen on the primary

The form that joins a pair (on the future secondary) works the same way: the Address of the primary shown as example in the field and in its help is an address of the network of this box, never a fixed one, the address typed with spaces around it is read, and POST /api/v1/business/ha/join answers a refusal with problems and example, told by the page in the language of the user:

problems Status Meaning
join_address 400 not the IPv4 address of the primary, with its HTTPS port when it is not 443
join_code 400 not a pairing code (WH- then five groups of four letters and digits)
join_refused 400 the primary refuses the code: wrong, or no longer valid (15 minutes, five wrong tries); make a new one on the primary
join_silent 409 no Warda answers at the address: the address, its port, or the network between the two boxes