feat(backup): stage the FV firewall config in ana-docker's nightly restic run

The FV edge firewall was not backed up anywhere. Its config now lands in
/var/lib/restic/stage/fv-gateway-config.xml via ana-docker's pre-backup hook,
so the existing 01:00 restic snapshot captures it. ana-docker is one of the
three egress addresses the firewall's WAN allowlist permits, which is why the
pull lives there rather than with the FV hardware — a site that has lost power
cannot back itself up, and FV lost power two days ago.

Non-fatal by design: an unreachable firewall must not abort the nightly
database dumps. But a bad pull must not be promoted either. The summary loop
only rejects EMPTY staged files, and this endpoint answers an auth failure
with a perfectly non-empty HTML error page — which would have been backed up
as a firewall config that is the right size and restores nothing. The block
checks the body really contains <opnsense> and writes nothing otherwise.

Three tests cover it, including the HTML-error-page case. The first draft of
those tests was worthless: _fv returned a Path out of a TemporaryDirectory
context, so the tree was deleted before the assertions ran and every
exists()-is-False check passed regardless of what the script did. Only the
positive test failed, which is the sole reason the broken negatives were
caught. They now snapshot inside the tempdir's lifetime, and the docstring
says why.

Also records two OPNsense API lessons in docs/pfi/opnsense-api-reference.md:
endpoints are actions and must never be probed for existence by POSTing at
them — that is how /api/core/system/reboot took the FV site dark for 3.5
minutes while looking for an apply call this same file already documented —
and the apply step is service/reconfigure, which auth/user notably lacks, so
an API-only key edit persists in config.xml and does nothing until the OS user
sync runs at boot.

Credentials in /etc/restic/fv-gateway.env (root:600), template committed,
values vaulted as fv-gateway/opnsense-api-{key,secret}. Pre-change config
snapshot vaulted as fv-gateway/config-backup-20260914.
This commit is contained in:
vh
2026-09-15 00:12:50 -07:00
parent 9dbd829b9d
commit 80d982d1d8
4 changed files with 145 additions and 0 deletions
+44
View File
@@ -42,6 +42,50 @@ writes config **and** applies it, which is normally the one you want after a
— note **`disabled` ≠ `stopped`**: a disabled service will not start until its
model's `enabled` field is set to `"1"`.
## ⚠ Endpoints are ACTIONS — never probe for existence by calling them
A 404 tells you an endpoint is absent; a 200 tells you it **ran**. There is no
safe "does this exist?" POST against a live firewall.
**2026-09-15:** looking for the call that applies a user change, a loop POSTed an
empty body at four guessed endpoints to see which returned 404. One of them was
`/api/core/system/reboot`. It returned 200 because it rebooted the FV edge
firewall, taking the whole site — including the BMC, which sits behind it —
dark for 3.5 minutes. The call it was actually looking for is documented
directly above, in § Service control, in this file.
- Read this reference and the upstream endpoint list first.
- If you must discover, use **GET** on a `get`/`search`/`status` command, never
POST on an unknown name.
- Take `/api/core/backup/download/this` **before** any write. That part went
right and is the only reason the change was reversible.
### The one useful thing that fell out of it
`POST /api/core/system/reboot` with `{}` is a **reliable remote reboot** for the
FV gateway — it came back cleanly on its own in ~3.5 min from an API-initiated
restart, which is a capability worth knowing deliberately rather than by
accident. `/api/core/service/restart/<id>` (e.g. `openssh`) restarts one service
without the site outage, and is almost always what you want instead.
## Applying a change — `service/reconfigure`, not a reboot
`settings/set` (and `auth/user/set`) write config.xml. They do **not** sync the
change to the running system. The apply step is the module's service endpoint:
```sh
POST /api/<module>/service/reconfigure {}
```
⚠ Some modules have no `reconfigure` and return `{"errorMessage":"Endpoint not
found"}` — `auth/user` is one. For those the OS-level sync happens on the UI's
own save path or at boot, so an API-only key edit sits in config.xml and does
nothing until then. Verified 2026-09-15: `authorizedkeys` + `shell` for
`infra-ops` persisted immediately but SSH kept refusing, and started working
after a reboot completed the user sync.
⚠ `POST` with **no body at all** returns `411 Length Required`. Send `{}`.
## Field shapes — the part upstream does not document
⚠ **A `settings/get` response is NOT a valid `settings/set` body.** They are