Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 1109092def | |||
| b45c47be6c | |||
| b9b831fb90 | |||
| 39fb9cbf6c | |||
| ae69ad4512 | |||
| e803ad2b91 | |||
| 7651461be2 | |||
| a0c88e5183 | |||
| 2d5840ba11 | |||
| b310773dbf | |||
| 0da792e670 | |||
| 286a7e3ecf | |||
| 4e1621c650 |
+104
-3
@@ -1,7 +1,108 @@
|
||||
## Unreleased (2026-10-19) — three fixes for the next release (R-921, R-1070, R-1010); two texts made true after 0.160.0
|
||||
## Unreleased (2026-10-22/23 night) — the tunnel heals itself after a clock that ran ahead (D30, R-1204) — COMMITTED, NOT RELEASED
|
||||
|
||||
Not released (the night brief of 2026-10-19: agent code + tests + commit only; the release is the operator's word). No
|
||||
sudoers, wrapper or config-bundle change.
|
||||
- **D30 (operator 2026-10-22: the agent makes a new key and registers it on the existing peer path).** When the latest
|
||||
handshake stays stamped in the future for 15 minutes (the R-1204 sign: ep0 keeps the future timestamp and refuses
|
||||
every newer handshake from that key), the agent makes a new WireGuard key pair, keeps the old private key as
|
||||
`wg/private.key.prev` (0600 — the escrow may hold it), and registers the new public key through `POST /hosts/<id>/wg`.
|
||||
The hub re-keys the peer IN PLACE (same /32, generation bump) and its full-list push to ep0 drops the old key and adds
|
||||
the new one — nothing new runs on ep0. A new key is a new peer for ep0, with no stored timestamp, so the next
|
||||
handshake is accepted. At most once an hour; not while the tunnel unit is down; never while a re-register is already
|
||||
in flight. A failed registration is retried by the existing re-key-in-place path. Logs carry public keys only.
|
||||
Tests `TestD30_*` (4), red-proved. A host-loss DR that installs the escrowed (older) key registers it again, and the
|
||||
hub re-keys in place back to it — the same path.
|
||||
- **Review of the night's own code (felhom.eu `REPORT-night-2026-10-23.md`, N6, N7).** The rotation never leaves the box
|
||||
without a readable key: the new key is written and fsynced to a temp file, the current key gets its kept name by a
|
||||
hard link, then the temp file is renamed OVER `private.key` and the directory fsynced (a power cut or a kill between
|
||||
two renames used to leave no key, or an empty one). `private.key.prev` keeps the FIRST old key (the escrow may hold it);
|
||||
later ones are `private.key.prev.<unix>`, the newest three kept. The once-an-hour bound is saved in `wg/last-rekey`, so
|
||||
an agent restart does not reset it; a start or a last re-key dated AFTER now (a clock that jumped back) is dropped,
|
||||
never a block until that date (the commit's own security review). Tests `TestD30_TwoRotationsKeepTheFirstOldKey`,
|
||||
`TestD30_ALastReKeyFromTheFutureDoesNotBlock`,
|
||||
`TestD30_TheHourBoundSurvivesARestart`, red-proved. **Live (felhom.eu `audits/night-2026-10-23/P2-D30/`):** the D30
|
||||
re-key ran on a test box (before these two changes): clock corrected → 15 min → new key registered → the box switched
|
||||
at its next desired-state fetch → a handshake with the new key.
|
||||
- **D4 (operator ruling 2026-10-22, R-982) — root SSH from the LAN by key only, on `main` now (2026-10-23 day brief).** The
|
||||
config bundle carries `/etc/ssh/sshd_config.d/10-felhom-root-key-only.conf` (`PermitRootLogin prohibit-password`;
|
||||
content check: exactly that line, `sshd -t -f`). After an install that wrote it: `sshd -t` (the whole config), then
|
||||
`systemctl try-reload-or-restart ssh` (a stopped or socket-activated sshd no longer refuses the bundle), then `sshd -T`
|
||||
is read back and a drop-in that is NOT in force (no Include, an earlier drop-in, a Match block) is said loudly and
|
||||
reported as `sshd_dropin_not_in_force` — never a refusal; an undone bundle reloads sshd again. The console and the
|
||||
web page keep the root password; felhom-sshd (8822) is not touched. Tests `RootKeyOnly` (6), red-proved; the
|
||||
installer's uninstall removes the file (felhom.eu installer 1.36.0). Reviewed 2026-10-23 night (A1–A7).
|
||||
- **Known gap, unchanged (filed):** after a reboot the kernel forgets the future stamp (latest handshake 0), so neither
|
||||
this re-key nor the hub's alarm sees a box whose clock was corrected and which then restarted (R-1223).
|
||||
|
||||
## Unreleased (2026-10-22 night) — the tunnel's future-stamped handshake is reported (R-1204) — COMMITTED, NOT RELEASED (no agent release tonight); root SSH by key only (R-982, D4) is a READY PATCH, not on main
|
||||
|
||||
- **R-982 / D4 — a ready patch, NOT on main.** Built and proven the same night (felhom.eu
|
||||
`audits/night-2026-10-22/P2-D4/`): a bundle drop-in `/etc/ssh/sshd_config.d/10-felhom-root-key-only.conf`
|
||||
(`PermitRootLogin prohibit-password`), a `sshd` content check (exactly `prohibit-password`; `sshd -t -f`), and after
|
||||
an install that wrote it `sshd -t` + `systemctl reload ssh`; tests `RootKeyOnly` (3), red-proved. Live on a fresh
|
||||
nested box from ISO 1.30.0: root password over SSH refused, root key works, the console and the web page still take
|
||||
the password. It was committed (`a0c88e5`) and moved back out (`7651461`): the installer's uninstall must remove every bundle file (felhom.eu `scripts/test_hostinstall.py`), the bundle half reaches a box only with an agent release, and the installer half only with a new `installer-v…` tag (R-110 — a push to `main` alone publishes nothing) — both forbidden tonight. *(Corrected the same night: the first reason written here, „a push of `felhom-host-install.sh` publishes the installer", was wrong — the website serves `/scripts/` from the tag `installer-v1.35.0`, read live in `manifests/webpage.yaml` and the running Deployment.)* Both halves are patches: `felhom-agent-bundle-D4.patch` and `felhom.eu-installer-D4.patch` in that folder; apply them together with the agent release and the next installer tag.
|
||||
- **R-1204 — `wireguard.handshake_future_s`.** A box that ran once with its clock ahead keeps a handshake stamped in the
|
||||
future; ep0 refuses every newer one, and `last_handshake_age_s` (clamped at 0) read „just now" for ever. The heartbeat
|
||||
now carries how many seconds the handshake lies ahead (> 60 s only); the age keeps its clamp. The hub alarms on it
|
||||
(felhom.eu hub `wg_tunnel_stale`). Test `TestR1204_AFutureHandshakeIsReported`, red-proved.
|
||||
|
||||
## v0.162.0 — every guest may swap as much as its RAM (R-1192, the 8 GB freeze); the host's swap is reported and checked; no false „operator access degraded" on a fresh box (R-1194) (2026-10-22) — RELEASED on the operator's yes; the vouch is the operator's
|
||||
|
||||
Released 2026-10-22 07:40 UTC (operator yes, the morning answers) with `scripts/release-agent.sh` from a clean clone at
|
||||
`b310773`: binary sha256 `5fd7a23bfe319cb521c4bc399612d5fb3413f1e695f79bc663c386f69c757928` (the same bytes as the
|
||||
night's candidate), config bundle sha256 `ac772967fd4669045e837a70bf5acca239c58d55f7f00212e472a8facd60b5a5`, tag
|
||||
`v0.162.0`; no `configs/` change since v0.161.0. Delivered by one signed `agent_update` job per box to demo-hp, Tester 1
|
||||
and demo-felhom (07:49–07:58 UTC): each `signed op COMPLETED`, `capabilities self-check ok=76 total=76`, `update
|
||||
committed`, then `guest-swap: raised` for its 9201 (512 MB → its RAM). Evidence felhom.eu
|
||||
`documentation/audits/morning-2026-10-22/release/04-agent-delivery.txt`. **Found at once:** demo-hp (host swap 8191 MB,
|
||||
guest swap 25898 MB) and demo-felhom (8191 MB vs 12288 MB) logged the host-swap WARN and the hub mailed
|
||||
`host_swap_short` — the check compares the host's swap with the guests' whole swap allowance, which a guest larger
|
||||
than the installer's 8 GB host swap always exceeds (felhom.eu register R-1216). Soak (night of 2026-10-21, 8 GB box):
|
||||
11 h, no freeze, the host's swap peaked at 2.7 GB used.
|
||||
|
||||
|
||||
The freeze of the rehearsal's first afternoon, reproduced and measured on demo-hp (felhom.eu
|
||||
`audits/fixes-2026-10-21/P4-freeze/`): Proxmox gives an LXC a 512 MB swap cap when nothing sets `swap`, and the agent
|
||||
never set it. On the 8 GB machine (guest 4096 MB) the first uploads made Immich load its analysis models; the guest hit
|
||||
its limit with the swap full and could evict only program code — 150 000–600 000 refaults and ~1 GB of disk reads per
|
||||
10 s, memory „full" pressure 92–95 %, load 155, the dashboard dead for 6½ minutes, no app killed. Raising the swap cap
|
||||
to 4096 MB live ended it within a minute while the uploads ran on.
|
||||
|
||||
- `reconcile.buildBringUpConfig`: a new guest gets `swap` = its memory.
|
||||
- `POST /guest/memory` (RAM resize): `swap` moves with `memory` (`localapi.GuestSwapMB`).
|
||||
- At agent start (one minute in): `localapi.EnsureGuestSwap` raises every LXC in the `felhom` pool whose swap is below
|
||||
its RAM to it — a live cgroup change, no restart; never lowers a higher swap; one guest's failure is logged and the
|
||||
others are still done.
|
||||
- Tests `TestR1192_EnsureGuestSwapRaisesEveryLowSwapToItsRAM`, `TestR1192_BringUpSetsSwapToTheRAM`, the resize test's
|
||||
new swap assertion — each red-proved (the write removed → `raised 0, want 2`; `swap=""` on both other paths).
|
||||
- Privilege: `swap` is under `VM.Config.Memory`, which the RAM resize already uses; no role, sudoers or bundle change.
|
||||
|
||||
Added the night of 2026-10-21 (still unreleased, the same release):
|
||||
|
||||
- **The host's swap is reported and checked (R-1192 follow-up).** The guest fix moves a memory burst onto the HOST's
|
||||
swap; a host with none gets nothing from it. The host report carries `host.host_swap_mb` (Proxmox node status — the
|
||||
kernel's SwapTotal, the same number as `/proc/meminfo`) and `host.guest_swap_mb` (the sum of the guests' `swap`; each
|
||||
guest spec also carries `swap_bytes`). When the first is below the second the agent logs one WARN (and one INFO when
|
||||
it is covered again); the hub raises `host_swap_short`. `GET /guest/memory` carries `host_swap_mb` and
|
||||
`guest_swap_mb` for the controller's install page. The agent never creates host swap (a decision — felhom.eu
|
||||
register). Measured the same night: our installer gives an 8 GB / 256 GB machine 7.75 GB of host swap.
|
||||
- **R-1194 — no false „operator access degraded" on a fresh box.** The first host report was sent before the
|
||||
felhom-sshd loop's first pass, read a config that was never rendered („config invalid, port 0") and the hub mailed
|
||||
`oob_degraded` — reproduced on a fresh install 2026-10-21 (the report at 20:34:00, the apply 0.4 s later, the daemon
|
||||
healthy; the check runs `sshd -t` through sudo, so the non-root theory was false). The loop now reports no OOB stanza
|
||||
until its first pass has run (a failed pass counts, so a real lasting failure still reaches the hub).
|
||||
- Tests `TestR1192_HostReportCarriesSwapAndWarnsOnce`, `TestR1192_GuestMemoryCarriesHostAndGuestSwap`,
|
||||
`TestR1194_NoOOBStanzaBeforeTheFirstPass` — each red-proved.
|
||||
|
||||
## v0.161.0 — three fixes (R-921, R-1070, R-1010); two texts made true after 0.160.0 (2026-10-20) — RELEASED on the operator's yes, NOT VOUCHED
|
||||
|
||||
Released 2026-10-20 (operator yes, the morning answers) with `scripts/release-agent.sh` from a clean clone at `5152123`:
|
||||
binary sha256 `ff4e6dc52dd70234913445ecdeb88d31dea8e394d77c48704d26ff19b999d3b5`, config bundle sha256
|
||||
`485f36c957d83f772aa22cac24e5e73f44da5cf8b957b1fd513bec2bc1d12c47`, tag `v0.161.0`. Delivered by one signed
|
||||
`agent_update` job per box to demo-hp (06:38 UTC), Tester 1 (06:54) and demo-felhom (06:55): each `signed op COMPLETED`,
|
||||
`capabilities self-check ok=76 total=76`, `update committed`. **The vouch is the operator's.** Live on demo-hp: `host_busy`
|
||||
answers `{"busy": true, "what": "backup:local"}` during a „Mentés most" whole-guest backup and `{"busy": false}` before
|
||||
and after (read from inside 9201 with its own token; felhom.eu `audits/night2-2026-10-20/P1/`). R-1083 (a key for an
|
||||
existing guest) is NOT in this release: see the R-1083 row. No sudoers, wrapper or config-bundle change.
|
||||
|
||||
- **R-921 — `GET /backup/status` says when the host is busy.** New field `host_busy` (`{busy, what}`): whether the
|
||||
host-wide heavy-operation gate is held right now (another guest's backup, the restore test, a night OS step, the
|
||||
|
||||
+13
@@ -1,5 +1,18 @@
|
||||
# CONTEXT — felhom-agent working state
|
||||
|
||||
> **2026-10-22/23 night — D30 on `main` (`ae69ad4`), unreleased; the D4 patches v2 ready.** Operator ruling D30
|
||||
> (2026-10-22): a handshake stamped in the future for 15 min → a new WG key pair (`wgtunnel/rekey.go`; old key kept as
|
||||
> `wg/private.key.prev`), registered on `POST /hosts/<id>/wg` (the hub re-keys in place; its full-list push swaps the
|
||||
> key on ep0). Live on a test box (felhom.eu `audits/night-2026-10-23/P2-D30/`): with ep0 free to start a handshake the
|
||||
> tunnel heals by itself (no re-key, correct); with ep0's starts dropped it stays dead and the agent re-keyed at 15 min.
|
||||
> The interface switches at the next desired-state fetch. Gap: a reboot forgets the future stamp (R-1223). The D4 bundle
|
||||
> patch v2 (`P3-review/felhom-agent-bundle-D4-v2.patch`): `try-reload-or-restart`, an `sshd -T` read-back reported as
|
||||
> `sshd_dropin_not_in_force`, a reload in undo. Next agent release = D30 + D4 v2 + R-1204's field, the operator vouches.
|
||||
> **2026-10-20 — v0.161.0 RELEASED (operator yes), NOT VOUCHED; on demo-hp, Tester 1, demo-felhom** (signed jobs, all
|
||||
> committed, 76/76). R-921 `host_busy` (proven live on demo-hp during a press), R-1070 the tunnel `absent` state (9202's
|
||||
> real Docker 29 answer is the fixture row), R-1010 the janitor's one `force=1`. Vouch: version 0.161.0, sha256
|
||||
> `ff4e6dc5…99d3b5`, bundle `485f36c9…12c47`. R-1083 left out on purpose: an agent key for 9202 would make its
|
||||
> controller book whole-guest backups through the agent, one tier writing to ep0 — the R-1083 row says what is needed.
|
||||
> **2026-10-19 — v0.160.0 RELEASED (operator yes), NOT VOUCHED; on demo-hp, Tester 1, demo-felhom.** R-1093, R-978,
|
||||
> R-973 (below) plus R-1149 (the local tier prunes `keep-daily=N`, `BackupTier.PruneSpec`) and R-1151 (a claim with
|
||||
> `{"defer_upload": true}` keeps the package until `POST /escrow/ceremony/confirm` brings the two words at the drawn
|
||||
|
||||
@@ -1,20 +1,23 @@
|
||||
# REPORT — agent, evening/night brief 2026-10-19 (code + tests + commit only, NOT released)
|
||||
# REPORT — night 2026-10-22 → 23: D30 on `main`, the D4 patches v2, nothing released
|
||||
|
||||
Commit `56aabc7` (CHANGELOG „Unreleased"), scanner wiring `84ef581`. No sudoers, wrapper or config-bundle change.
|
||||
The release is the operator's word (STATUS morning list: „Release agent 0.161.0?"), then the vouch.
|
||||
**What:** the night brief's agent parts. No release, no vouch. Design read: `03-host-agent.md` (the tunnel, the key, the
|
||||
bundle), `06-offsite-connectivity.md` (the full-list push to ep0).
|
||||
|
||||
- **R-921 — `host_busy` on `GET /backup/status`:** whether the host-wide heavy-operation gate is held (`{busy, what}`),
|
||||
the state in which `POST /backup` answers 409. Controller 0.335.0 (the floor) reads it before any stop. Test
|
||||
`TestBackupStatus_R921_HostBusy`, red-proved (assignment removed → `free gate: host_busy = <nil>`).
|
||||
- **R-1070 — tunnel `absent`:** Docker 29 prints „error: no such object" in lower case; the case-sensitive match read
|
||||
a missing cloudflared container as `unknown`, which failed the host OS-update rule (Tester4, 2026-10-15). Now a
|
||||
missing container is `absent`, and the host rule passes it only when the reading from before the step also had no
|
||||
cloudflared container. Tests `TestHostHealthVerdict_R1070_NoTunnelSetUp`, `TestClassifyTunnel` (Docker 29's wording,
|
||||
measured on demo-hp), red-proved both ways.
|
||||
- **R-1010 — the janitor's forced snapshot delete:** on „Failed to find logical volume …_vzdump" only, one retry with
|
||||
the API's `force=1` (`DeleteSnapshotForce`; `pvesh usage … -command delete` lists `--force`). Tests
|
||||
`TestStaleLock_R1010_ForcesOnceOnlyWhenTheVolumeIsGone` (6 rows), `TestDeleteSnapshotForce_R1010`, red-proved.
|
||||
- **R-986 — the security-scan gate** (tooling): the shared `felhom.eu/scripts/security_scan_gate.py` in the fast set;
|
||||
`.security-accepted` holds 15 accepted test constants; decoys in `test_gate_decoys.py`.
|
||||
- **D30** (`ae69ad4`, hardened `39fb9cb`, `b9b831f`): a handshake stamped in the future for 15 min → a new key pair,
|
||||
registered on `POST /hosts/<id>/wg` (the hub re-keys in place; its full-list push swaps the key on ep0 — nothing new
|
||||
on ep0). The key file is replaced by an fsynced rename over it (never missing or empty); the first old key stays
|
||||
`private.key.prev`, later ones dated (3 kept); the once-an-hour bound survives a restart; a wait stamp dated after now
|
||||
is dropped. Tests `TestD30_*` (7), each red-proved.
|
||||
- **Live** (felhom.eu `audits/night-2026-10-23/P2-D30/`, test box Tester4-16fdef, fixture `ae69ad4`): with ep0 free to
|
||||
start a handshake, a 2-hour clock jump healed by itself and no re-key ran (correct); with ep0's starts dropped on the
|
||||
box, the tunnel stayed dead, the agent re-keyed at 15 min, the hub took the key (`existed=false generation=3
|
||||
sync=ok`), the box switched at its next desired-state fetch and shook hands with the new key.
|
||||
- **D4 patches v2** (felhom.eu `audits/night-2026-10-23/P3-review/`), after a fresh review (A1–A7): `try-reload-or-restart`,
|
||||
an `sshd -T` read-back reported as `sshd_dropin_not_in_force`, a reload in undo, the right citation; installer: a warning
|
||||
when the reload fails. RootKeyOnly 6/6 (two new, red-proved); installer tests 40/40 with the patch. Both apply to
|
||||
tonight's mains. Live by hand on the test box: root password SSH refused, key works, web password 200.
|
||||
- **Gap filed:** a reboot after the clock was corrected forgets the future stamp (felhom.eu R-1223).
|
||||
|
||||
Gates: `go build/vet/test ./...` green; `agent_gates.py --fast` OK; decoys 36 cases OK. CI 2103, 2110 success.
|
||||
CI by commit: `ae69ad4` 2229, `39fb9cb` 2235 green; `b9b831f` and this docs commit: see felhom.eu
|
||||
`REPORT-night-2026-10-23.md`. Fixture names on the test box: `0.163.0-night.1` (= `ae69ad4`), then `0.162.99`
|
||||
(= `b9b831f`; a plain number, because the controller cannot compare a pre-release string — the off-site unlock refused).
|
||||
|
||||
@@ -936,6 +936,22 @@ func runDaemon(cfg config.Config, logger *slog.Logger, logRing *applog.Ring) int
|
||||
// network and stays under the hub's 45-minute host_stale (its
|
||||
// alerting.stale_threshold; host_down at 90). On a box without the kernel lane (an older wrapper, a BYO host) the check is refused and logged.
|
||||
go osLeg.KernelAfterBoot(ctx, 0, osupdate.KernelJudge{Wait: osupdate.DefaultKernelJudgeWait})
|
||||
// R-1192: every guest may swap as much as its RAM — raised once at start (a live change, no restart). A minute
|
||||
// after start so the guest has settled; a failure is logged and the next start retries.
|
||||
go func() {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return
|
||||
case <-time.After(time.Minute):
|
||||
}
|
||||
sctx, cancel := context.WithTimeout(ctx, 2*time.Minute)
|
||||
defer cancel()
|
||||
if n, err := localapi.EnsureGuestSwap(sctx, px, reconcile.DefaultPool, logger); err != nil {
|
||||
logger.Warn("guest-swap: check skipped", "err", err)
|
||||
} else {
|
||||
logger.Info("guest-swap: checked", "raised", n)
|
||||
}
|
||||
}()
|
||||
|
||||
// Reconcile (slice 4) runs alongside the hub loop, sharing the per-guest queue
|
||||
// (doc 03 §10). At slice 4 the desired-state provider is empty (no hub serving
|
||||
|
||||
+41
-3
@@ -165,7 +165,8 @@ KERNEL_ACTIVE = ("staged", "oneshot", "judging", "reverting")
|
||||
# dest: (source file under configs/, mode, check, policy)
|
||||
# check: the content check BEFORE anything is written (R18): sudoers → visudo -cf; sh / bash → -n; python → compile;
|
||||
# unit → a [Unit]/[Service]/[Timer] section; unit-nort → that, and never RuntimeDirectory= (the G1 incident);
|
||||
# agent-unit → User=felhom-agent; dropin → a [Unit] section (SF-3); nft → nft -c -f; plain → none.
|
||||
# agent-unit → User=felhom-agent; dropin → a [Unit] section (SF-3); nft → nft -c -f; plain → none;
|
||||
# sshd → `sshd -t -f` on the snippet alone (R-982).
|
||||
# policy: replace → always written when it differs; if-absent → only when the box has none (a setting the operator may
|
||||
# have tuned); oob → only on a box with the OOB belt (/etc/felhom-sshd exists — the installer's --no-oob leaves none).
|
||||
# Order matters: the sudoers files come LAST, so a referenced wrapper is in place before the line that allows it.
|
||||
@@ -184,6 +185,9 @@ BUNDLE_KEEP = 3
|
||||
BUNDLE_MAX_BYTES = 4 * 1024 * 1024
|
||||
BUNDLE_RE = re.compile(r"^bundle-[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.]+)?\.json$")
|
||||
OOB_DIR = "/etc/felhom-sshd"
|
||||
# R-982: the host's own sshd drop-in (after_install reloads sshd for it; undo reloads after putting it back).
|
||||
SSHD_DROPIN = "/etc/ssh/sshd_config.d/10-felhom-root-key-only.conf"
|
||||
|
||||
BUNDLE_FILES = [
|
||||
("/usr/local/sbin/felhom-mkfs-guarded", "felhom-mkfs-guarded.sh", 0o755, "bash", "replace"),
|
||||
("/usr/local/sbin/felhom-selfupdate-guarded", "felhom-selfupdate-guarded", 0o755, "sh", "replace"),
|
||||
@@ -221,6 +225,9 @@ BUNDLE_FILES = [
|
||||
("/etc/systemd/system/felhom-sshd.service", "felhom-sshd.service", 0o644, "unit-nort", "oob"),
|
||||
("/etc/felhom-oob.nft", "felhom-oob.nft", 0o644, "nft", "oob"),
|
||||
("/etc/systemd/system/felhom-oob-nft.service", "felhom-oob-nft.service", 0o644, "unit", "oob"),
|
||||
# R-982, operator ruling D4 (2026-10-22): the host's own sshd (port 22, the LAN): root by key only. The console
|
||||
# password stays; felhom-sshd (the operator's door) reads nothing from sshd_config.d. Reloaded in after_install.
|
||||
("/etc/ssh/sshd_config.d/10-felhom-root-key-only.conf", "felhom-root-ssh-key-only.conf", 0o644, "sshd", "replace"),
|
||||
("/etc/sudoers.d/felhom-op", "felhom-op.sudoers", 0o440, "sudoers", "oob"),
|
||||
("/etc/sudoers.d/felhom-agent", "felhom-agent.sudoers", 0o440, "sudoers", "replace"),
|
||||
]
|
||||
@@ -434,7 +441,8 @@ class Runner:
|
||||
def check_content(self, kind, data):
|
||||
"""Run an external syntax check on a root-only temp copy. Returns (rc, message)."""
|
||||
import tempfile
|
||||
cmd = {"sudoers": ["visudo", "-cf"], "sh": ["sh", "-n"], "bash": ["bash", "-n"], "nft": ["nft", "-c", "-f"]}[kind]
|
||||
cmd = {"sudoers": ["visudo", "-cf"], "sh": ["sh", "-n"], "bash": ["bash", "-n"], "nft": ["nft", "-c", "-f"],
|
||||
"sshd": ["/usr/sbin/sshd", "-t", "-f"]}[kind]
|
||||
with tempfile.TemporaryDirectory(prefix="felhom-bundle-") as d:
|
||||
p = os.path.join(d, "f")
|
||||
with open(p, "wb") as f:
|
||||
@@ -1864,6 +1872,7 @@ class Bundle:
|
||||
def __init__(self, apply):
|
||||
self.a, self.r = apply, apply.r
|
||||
self.report = apply.report
|
||||
self.sshd_dropin_not_in_force = False
|
||||
|
||||
# ---------- reading and checking ----------
|
||||
def load_file(self, path):
|
||||
@@ -1932,10 +1941,17 @@ class Bundle:
|
||||
text = content.decode("utf-8")
|
||||
except UnicodeDecodeError:
|
||||
raise Refused("R18", f"{dest} is not UTF-8 text")
|
||||
if check in ("sudoers", "sh", "bash", "nft"):
|
||||
if check in ("sudoers", "sh", "bash", "nft", "sshd"):
|
||||
rc, msg = self.r.check_content(check, content)
|
||||
if rc != 0:
|
||||
raise Refused("R18", f"{dest} fails its {check} check: {msg}")
|
||||
if check == "sshd":
|
||||
# R-982: the drop-in's PermitRootLogin must be exactly `prohibit-password`. `no` would also shut the root key
|
||||
# out (Proxmox's own node-to-node SSH and the LAN key route), `yes` would undo the ruling — both refused.
|
||||
# Only that line is pinned: the file is signed like every bundle file (review A7).
|
||||
vals = re.findall(r"^\s*PermitRootLogin\s+(\S+)\s*$", text, re.M | re.I)
|
||||
if vals != ["prohibit-password"]:
|
||||
raise Refused("R18", f"{dest} must set exactly `PermitRootLogin prohibit-password` (found {vals})")
|
||||
elif check == "python":
|
||||
try:
|
||||
compile(text, dest, "exec")
|
||||
@@ -2044,6 +2060,8 @@ class Bundle:
|
||||
self.report["failed"] = {"rc": 3, "step": "bundle", "reason": reason[:300]}
|
||||
return 3
|
||||
rep["signers_created"] = False
|
||||
if self.sshd_dropin_not_in_force:
|
||||
rep["sshd_dropin_not_in_force"] = True # R-982 A2: written and reloaded, but sshd -T shows root passwords allowed
|
||||
if bootstrap and not self.r.lexists(TRUST_SIGNERS):
|
||||
self.r.put_file(TRUST_SIGNERS, pinned_signers_line().encode(), 0o644)
|
||||
rep["signers_created"] = True
|
||||
@@ -2073,6 +2091,23 @@ class Bundle:
|
||||
"enable the crash guard")
|
||||
if "/etc/systemd/system/felhom-mgmt-watchdog.timer" in dests:
|
||||
self.must(["systemctl", "enable", "--now", "felhom-mgmt-watchdog.timer"], "enable the mgmt watchdog timer")
|
||||
# R-982: the host's sshd takes the root-key-only drop-in. The WHOLE config is tested first (a failure is a
|
||||
# refusal, and the bundle undo puts the old files back); `try-reload-or-restart` keeps every open session and
|
||||
# does nothing on a box whose ssh.service is not running (a socket-activated or stopped sshd reads the file
|
||||
# at its next start) — a failure there must not freeze the bundle route (review 2026-10-22 night, A1).
|
||||
# felhom-sshd is not touched. Then the POSITIVE check: sshd's own effective view for root. A box whose
|
||||
# sshd_config has no Include of sshd_config.d, an earlier drop-in or a Match block can keep the password route
|
||||
# — that is said loudly in the log and the report, never silently recorded as done (A2).
|
||||
if SSHD_DROPIN in written:
|
||||
self.must(["/usr/sbin/sshd", "-t"], "sshd -t (the host's whole sshd config)")
|
||||
self.must(["systemctl", "try-reload-or-restart", "ssh"], "systemctl try-reload-or-restart ssh")
|
||||
rc, out, err = self.r.host(["/usr/sbin/sshd", "-T", "-C", "user=root,host=felhom-check,addr=192.0.2.1"], 60)
|
||||
eff = re.findall(r"^permitrootlogin\s+(\S+)", out, re.M | re.I)
|
||||
if rc != 0 or eff != ["without-password"]:
|
||||
self.r.log(f"os-apply: BUNDLE WARNING the root-key-only drop-in is NOT in force: sshd -T says "
|
||||
f"permitrootlogin={eff or '?'} (rc={rc}) — check sshd_config's Include, an earlier drop-in "
|
||||
f"or a Match block (R-982)")
|
||||
self.sshd_dropin_not_in_force = True
|
||||
|
||||
def must(self, argv, what):
|
||||
rc, out, err = self.r.host(argv, 120)
|
||||
@@ -2133,6 +2168,9 @@ class Bundle:
|
||||
self.r.log(f"os-apply: BUNDLE UNDO could not restore {dest}: {e}")
|
||||
if any(d.startswith("/etc/systemd/system/") for d in back):
|
||||
self.r.host(["systemctl", "daemon-reload"], 120)
|
||||
if SSHD_DROPIN in back:
|
||||
# A3: after_install may already have reloaded sshd with the drop-in; the restored state takes effect now.
|
||||
self.r.host(["systemctl", "try-reload-or-restart", "ssh"], 120)
|
||||
rc, _, _ = self.r.host(["visudo", "-c"], 60)
|
||||
self.r.log(f"os-apply: BUNDLE UNDO restored={len(back)} visudo-after={'ok' if rc == 0 else 'FAILED'}")
|
||||
return back
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
# MANAGED BY FELHOM (the agent's config bundle) — R-982, operator ruling D4 (2026-10-22).
|
||||
# The Proxmox host's OWN sshd — the listener the household network reaches on port 22: root logs in with a KEY only.
|
||||
# The root password still works on the console (the break-glass password: felhom.eu runbooks/break-glass.md). The
|
||||
# operator's door (felhom-sshd, port 8822, /etc/felhom-sshd/sshd_config) is a separate daemon whose config includes
|
||||
# nothing from here, so it is not changed. Debian's sshd_config reads this folder BEFORE its own settings, and for
|
||||
# sshd the first value wins; the bundle checks the effective value with `sshd -T` after the reload.
|
||||
PermitRootLogin prohibit-password
|
||||
@@ -429,6 +429,90 @@ class SelfCheckUndo(unittest.TestCase):
|
||||
self.assert_restored(box, before, rep)
|
||||
|
||||
|
||||
|
||||
class RootKeyOnly(unittest.TestCase):
|
||||
"""R-982, operator ruling D4 (2026-10-22): the bundle gives the host's own sshd a root-key-only drop-in, tests the
|
||||
whole config and reloads sshd — only when the file was written; a drop-in that says anything but
|
||||
`prohibit-password` is refused before anything is written.
|
||||
RED-PROOF: with the after_install block removed, test_fresh_box_takes_the_dropin_and_reloads fails (no reload);
|
||||
with the content rule removed, test_a_dropin_that_says_yes_or_no_is_refused fails — seen failing 2026-10-22."""
|
||||
DEST = "/etc/ssh/sshd_config.d/10-felhom-root-key-only.conf"
|
||||
|
||||
def test_fresh_box_takes_the_dropin_and_reloads(self):
|
||||
data, sha = real_bundle()
|
||||
box = Box(data, signed_job(sha))
|
||||
rc, rep = run(box)
|
||||
self.assertEqual(rc, 0, rep)
|
||||
self.assertIn(b"PermitRootLogin prohibit-password", box.files[self.DEST])
|
||||
self.assertEqual(box.modes[self.DEST], 0o644)
|
||||
self.assertIn(["/usr/sbin/sshd", "-t"], box.calls)
|
||||
self.assertIn(["systemctl", "try-reload-or-restart", "ssh"], box.calls)
|
||||
self.assertLess(box.calls.index(["/usr/sbin/sshd", "-t"]), box.calls.index(["systemctl", "try-reload-or-restart", "ssh"]))
|
||||
self.assertFalse(any("felhom-sshd" in " ".join(c) for c in box.calls), "the operator's door must not be touched")
|
||||
|
||||
def test_an_unchanged_dropin_is_not_reloaded(self):
|
||||
data, sha = real_bundle()
|
||||
box = Box(data, signed_job(sha))
|
||||
box.put(self.DEST, (REPO / "configs" / "felhom-root-ssh-key-only.conf").read_bytes(), 0o644)
|
||||
rc, rep = run(box)
|
||||
self.assertEqual(rc, 0, rep)
|
||||
self.assertNotIn(["systemctl", "try-reload-or-restart", "ssh"], box.calls)
|
||||
|
||||
def test_a_dropin_that_says_yes_or_no_is_refused(self):
|
||||
for bad in (b"PermitRootLogin yes\n", b"PermitRootLogin no\n", b"# nothing\n",
|
||||
b"PermitRootLogin prohibit-password\nPermitRootLogin yes\n"):
|
||||
def edit(files, bad=bad):
|
||||
for e in files:
|
||||
if e["path"] == self.DEST:
|
||||
e["content_b64"] = base64.b64encode(bad).decode()
|
||||
data, sha = edited_bundle(edit)
|
||||
box = Box(data, signed_job(sha))
|
||||
rc, rep = run(box)
|
||||
self.assertNotEqual(rc, 0, bad)
|
||||
self.assertNotIn(self.DEST, box.files, bad)
|
||||
|
||||
# Review 2026-10-22 night. A2: the effective value is read back with `sshd -T`; a drop-in that is not in force is
|
||||
# said in the log and the report (not refused — a refusal would freeze the bundle route). A3: a bundle undone
|
||||
# after the reload reloads sshd again with the old state. RED-PROOF: with the sshd -T check removed,
|
||||
# test_a_dropin_not_in_force_is_reported fails; with the undo reload removed, test_an_undone_bundle_reloads_sshd
|
||||
# fails — seen failing 2026-10-22 night.
|
||||
def _sshd_T(self, box, value):
|
||||
orig = box.host
|
||||
def host(argv, timeout=600, stdin=None):
|
||||
if argv[:2] == ["/usr/sbin/sshd", "-T"]:
|
||||
box.calls.append(argv)
|
||||
return 0, f"port 22\npermitrootlogin {value}\npasswordauthentication yes\n", ""
|
||||
return orig(argv, timeout, stdin)
|
||||
box.host = host
|
||||
|
||||
def test_the_effective_value_is_checked(self):
|
||||
data, sha = real_bundle()
|
||||
box = Box(data, signed_job(sha))
|
||||
self._sshd_T(box, "without-password")
|
||||
rc, rep = run(box)
|
||||
self.assertEqual(rc, 0, rep)
|
||||
self.assertTrue(any(c[:2] == ["/usr/sbin/sshd", "-T"] for c in box.calls))
|
||||
self.assertNotIn("sshd_dropin_not_in_force", rep["bundle"])
|
||||
|
||||
def test_a_dropin_not_in_force_is_reported(self):
|
||||
data, sha = real_bundle()
|
||||
box = Box(data, signed_job(sha))
|
||||
self._sshd_T(box, "yes") # e.g. no Include of sshd_config.d
|
||||
rc, rep = run(box)
|
||||
self.assertEqual(rc, 0, rep)
|
||||
self.assertTrue(rep["bundle"].get("sshd_dropin_not_in_force"), rep)
|
||||
self.assertTrue(any("NOT in force" in l for l in box.logs), box.logs)
|
||||
|
||||
def test_an_undone_bundle_reloads_sshd(self):
|
||||
data, sha = real_bundle()
|
||||
box = Box(data, signed_job(sha))
|
||||
box.visudo_fail = True # the self-check fails AFTER the install → undo
|
||||
rc, rep = run(box)
|
||||
self.assertEqual(rc, 3, rep)
|
||||
self.assertNotIn(self.DEST, box.files)
|
||||
reloads = [i for i, c in enumerate(box.calls) if c == ["systemctl", "try-reload-or-restart", "ssh"]]
|
||||
self.assertEqual(len(reloads), 2, box.calls) # after_install, then the undo
|
||||
|
||||
class TrustBootstrap(unittest.TestCase):
|
||||
def test_missing_signers_verifies_against_the_pinned_key_and_creates_it(self):
|
||||
data, sha = real_bundle()
|
||||
|
||||
@@ -22,6 +22,11 @@ type Loop struct {
|
||||
mu sync.Mutex
|
||||
fetched bool // a desired-state document has been delivered (false = never a teardown signal)
|
||||
block *hub.WireWireguard
|
||||
// passed (R-1194) is set once the first reconcile pass has run. Until then the instance has never been rendered,
|
||||
// so its health says nothing — and the first host report, sent before that pass, used to read „config invalid,
|
||||
// port 0" and raise a false oob_degraded on EVERY fresh box (rehearsal 2026-10-20; reproduced 2026-10-21: the
|
||||
// report at 20:34:00 read an absent config, the apply landed 0.4 s later).
|
||||
passed bool
|
||||
|
||||
nudge chan struct{}
|
||||
}
|
||||
@@ -85,6 +90,7 @@ func (l *Loop) reconcile(ctx context.Context) {
|
||||
if !fetched {
|
||||
applyBlock = nil
|
||||
}
|
||||
defer l.markPassed()
|
||||
port, err := l.mgr.Apply(ctx, applyBlock)
|
||||
if err != nil {
|
||||
return // Apply logged; a claim/exhaustion or install error — retry next tick
|
||||
@@ -106,8 +112,23 @@ func oobPeerIP(block *hub.WireWireguard) string {
|
||||
return block.OOBPeerIP
|
||||
}
|
||||
|
||||
// OOBStatus implements the hub collector's reporter seam (Part 4).
|
||||
// markPassed records that a reconcile pass has run (R-1194) — after a failed Apply too, so a real, lasting failure
|
||||
// is still reported from the next report on.
|
||||
func (l *Loop) markPassed() {
|
||||
l.mu.Lock()
|
||||
l.passed = true
|
||||
l.mu.Unlock()
|
||||
}
|
||||
|
||||
// OOBStatus implements the hub collector's reporter seam (Part 4). nil — no stanza, which the hub does not evaluate —
|
||||
// until the first reconcile pass has run (R-1194).
|
||||
func (l *Loop) OOBStatus(ctx context.Context) *hub.OOBStatus {
|
||||
l.mu.Lock()
|
||||
passed := l.passed
|
||||
l.mu.Unlock()
|
||||
if !passed {
|
||||
return nil
|
||||
}
|
||||
_, block := l.snapshot()
|
||||
return l.mgr.Status(ctx, block)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
package felhomsshd
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
// R-1194: on every fresh box the first host report — sent before the OOB loop's first pass — read „config invalid,
|
||||
// port 0" (the config was not rendered yet) and the hub mailed oob_degraded. Reproduced 2026-10-21 on a fresh box
|
||||
// (felhom.eu audits/night-2026-10-21/P5-checks/): the report at 20:34:00, the apply 0.4 s later, the daemon healthy.
|
||||
// The loop now reports NO stanza (the hub does not evaluate a missing one) until a pass has run — a failed pass
|
||||
// counts, so a real lasting failure is still reported from the next report on.
|
||||
// RED-PROOF: with OOBStatus not gated on `passed`, the first assertion fails (a stanza with config_invalid).
|
||||
func TestR1194_NoOOBStanzaBeforeTheFirstPass(t *testing.T) {
|
||||
r := newScriptRunner()
|
||||
m := NewManager(r, t.TempDir(), nil)
|
||||
m.isActive = func(context.Context) bool { return false }
|
||||
m.isFailed = func(context.Context) bool { return false }
|
||||
m.now = func() time.Time { return time.Unix(1783270000, 0) }
|
||||
l := NewLoop(m, nil, time.Minute, nil)
|
||||
if st := l.OOBStatus(context.Background()); st != nil {
|
||||
t.Fatalf("a stanza before the first pass reads a config that was never rendered: %+v", st)
|
||||
}
|
||||
l.reconcile(context.Background()) // fails or succeeds — either way a pass has run
|
||||
if st := l.OOBStatus(context.Background()); st == nil {
|
||||
t.Fatal("after the first pass the health must be reported (a real failure must reach the hub)")
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
"os"
|
||||
"strings"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"gitea.dooplex.hu/admin/felhom-agent/internal/capability"
|
||||
@@ -136,6 +137,8 @@ type Collector struct {
|
||||
selfSHA func() string // R-349: sha256 of the running binary; default runningBinarySHA256
|
||||
logger *slog.Logger
|
||||
now func() time.Time
|
||||
// swapShortWarned (R-1192): the host-swap-short WARN is logged once per state change, not every report.
|
||||
swapShortWarned atomic.Bool
|
||||
}
|
||||
|
||||
// NewCollector builds a collector. hostID echoes config.Hub.HostID; agentVersion is
|
||||
@@ -375,6 +378,8 @@ func (c *Collector) Collect(ctx context.Context) (*HostReport, error) {
|
||||
}
|
||||
|
||||
host := hostMetrics(c.px.Node(), ns)
|
||||
guests := c.collectGuests(ctx)
|
||||
c.applySwap(&host, ns, guests) // R-1192: host swap vs the guests' swap allowance
|
||||
host.CPUTempC = c.cpuTempC(ctx) // slice 9: operator freebie — temp now rides the hub report too
|
||||
host.WrapperSHA256 = pbsWrapperSHA256() // R-50b(a): make privileged-artifact drift answerable
|
||||
report := &HostReport{
|
||||
@@ -383,7 +388,7 @@ func (c *Collector) Collect(ctx context.Context) (*HostReport, error) {
|
||||
AgentVersion: c.agentVersion,
|
||||
AgentSHA256: c.agentSHA256(),
|
||||
Host: host,
|
||||
Guests: c.collectGuests(ctx),
|
||||
Guests: guests,
|
||||
// storage_targets populated this slice (slice 5) via the observer; the rest stay
|
||||
// defined-but-empty (slice 6). Non-nil so they marshal as [].
|
||||
StorageTargets: c.collectStorage(ctx),
|
||||
@@ -567,6 +572,7 @@ func (c *Collector) collectGuests(ctx context.Context) []Guest {
|
||||
Cores: cfg.Cores,
|
||||
MemoryBytes: g.MaxMem,
|
||||
DiskBytes: g.MaxDisk,
|
||||
SwapBytes: cfg.Swap * (1 << 20),
|
||||
}
|
||||
}
|
||||
guests = append(guests, entry)
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
package hub
|
||||
|
||||
import (
|
||||
"gitea.dooplex.hu/admin/felhom-agent/internal/proxmox"
|
||||
)
|
||||
|
||||
// R-1192 follow-up (night 2026-10-21): the guest swap fix (every guest may swap as much as its RAM,
|
||||
// localapi/guestswap.go) moves a memory burst onto the HOST's swap. Measured on demo-hp the same day: our installer
|
||||
// gives an 8 GB / 256 GB machine 7.75 GB of host swap, so a 4096 MB guest's 4096 MB swap fits. A host with no swap
|
||||
// (a BYO install, or swap turned off) gets nothing from the fix. So the report carries both numbers, the agent says it
|
||||
// once in its log, and the hub raises host_swap_short. The agent never creates host swap itself: changing a host its
|
||||
// owner set up is a decision (felhom.eu register).
|
||||
|
||||
// HostSwapShort reports whether the host's swap is below the guests' swap allowance. A host whose guests have no
|
||||
// swap allowance (0) is never short.
|
||||
func HostSwapShort(hostMB, guestMB int64) bool { return guestMB > 0 && hostMB < guestMB }
|
||||
|
||||
// applySwap fills the host block's swap numbers from the node status and the guests' specs, and logs the short
|
||||
// state once per change.
|
||||
func (c *Collector) applySwap(h *HostMetrics, ns proxmox.NodeStatus, guests []Guest) {
|
||||
hostMB := ns.Swap.Total / (1 << 20)
|
||||
var guestMB int64
|
||||
for _, g := range guests {
|
||||
if g.Spec != nil {
|
||||
guestMB += g.Spec.SwapBytes / (1 << 20)
|
||||
}
|
||||
}
|
||||
h.HostSwapMB, h.GuestSwapMB = &hostMB, &guestMB
|
||||
if HostSwapShort(hostMB, guestMB) {
|
||||
if c.swapShortWarned.CompareAndSwap(false, true) {
|
||||
c.logger.Warn("host-swap: the host's swap is below its guests' swap allowance — a memory burst can freeze the box (R-1192); the hub is told (host_swap_short)",
|
||||
"host_swap_mb", hostMB, "guest_swap_mb", guestMB)
|
||||
}
|
||||
return
|
||||
}
|
||||
if c.swapShortWarned.CompareAndSwap(true, false) {
|
||||
c.logger.Info("host-swap: the host's swap covers its guests' swap allowance again", "host_swap_mb", hostMB, "guest_swap_mb", guestMB)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package hub
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"log/slog"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"gitea.dooplex.hu/admin/felhom-agent/internal/proxmox"
|
||||
)
|
||||
|
||||
// R-1192 follow-up (night 2026-10-21): the host report carries the host's swap and the guests' swap allowance, and the
|
||||
// agent says ONCE in its log when the host's swap is below it (and once when it is covered again).
|
||||
// RED-PROOF: with applySwap not called the numbers are nil; with the CompareAndSwap removed the WARN repeats.
|
||||
func TestR1192_HostReportCarriesSwapAndWarnsOnce(t *testing.T) {
|
||||
var buf bytes.Buffer
|
||||
c := &Collector{logger: slog.New(slog.NewTextHandler(&buf, nil))}
|
||||
guests := []Guest{{VMID: 9201, Spec: &GuestSpec{SwapBytes: 4096 << 20}}, {VMID: 9202, Spec: nil}}
|
||||
var ns proxmox.NodeStatus // a host with no swap
|
||||
for i := 0; i < 3; i++ {
|
||||
h := HostMetrics{}
|
||||
c.applySwap(&h, ns, guests)
|
||||
if h.HostSwapMB == nil || h.GuestSwapMB == nil || *h.HostSwapMB != 0 || *h.GuestSwapMB != 4096 {
|
||||
t.Fatalf("report numbers: host %v guest %v", h.HostSwapMB, h.GuestSwapMB)
|
||||
}
|
||||
}
|
||||
if n := strings.Count(buf.String(), "host-swap: the host's swap is below"); n != 1 {
|
||||
t.Fatalf("the short WARN must be logged once, got %d:\n%s", n, buf.String())
|
||||
}
|
||||
ns.Swap.Total = 7935 << 20 // the installer's 8 GB host
|
||||
h := HostMetrics{}
|
||||
c.applySwap(&h, ns, guests)
|
||||
if *h.HostSwapMB != 7935 || HostSwapShort(*h.HostSwapMB, *h.GuestSwapMB) {
|
||||
t.Fatalf("a covered host must not be short: %v / %v", *h.HostSwapMB, *h.GuestSwapMB)
|
||||
}
|
||||
if !strings.Contains(buf.String(), "covers its guests' swap allowance again") {
|
||||
t.Fatalf("the recovery must be said once:\n%s", buf.String())
|
||||
}
|
||||
if HostSwapShort(0, 0) {
|
||||
t.Fatal("a host whose guests have no swap allowance is never short")
|
||||
}
|
||||
}
|
||||
+11
-1
@@ -292,7 +292,11 @@ type WireguardStatus struct {
|
||||
Registered bool `json:"registered"` // the registration marker exists
|
||||
Active bool `json:"active"` // wg-quick@wg-felhom is-active
|
||||
LastHandshakeAgeS *int64 `json:"last_handshake_age_s,omitempty"`
|
||||
AssignedIP string `json:"assigned_ip,omitempty"` // from the marker, e.g. "10.77.0.2/32"
|
||||
// HandshakeFutureS (R-1204): seconds the latest handshake lies in the FUTURE by this box's clock — set (> 0) only
|
||||
// then. A box that ran once with its clock ahead keeps a handshake stamped in the future; WireGuard on ep0 then
|
||||
// refuses every newer handshake, and LastHandshakeAgeS (clamped at 0) reads „just now" for ever. The hub alarms on it.
|
||||
HandshakeFutureS *int64 `json:"handshake_future_s,omitempty"`
|
||||
AssignedIP string `json:"assigned_ip,omitempty"` // from the marker, e.g. "10.77.0.2/32"
|
||||
}
|
||||
|
||||
// SystemInfo is the `system` stanza (see HostReport.System).
|
||||
@@ -338,6 +342,11 @@ type HostMetrics struct {
|
||||
//
|
||||
// Empty = unreadable/absent, which the hub treats as UNKNOWN, never as drift.
|
||||
WrapperSHA256 string `json:"wrapper_sha256,omitempty"`
|
||||
// HostSwapMB / GuestSwapMB (R-1192 follow-up, night 2026-10-21): the host's swap (Proxmox node status — the
|
||||
// kernel's SwapTotal) and the sum of its guests' swap allowance. The guest swap fix (swap = RAM) needs swap ON THE
|
||||
// HOST behind it; the hub raises host_swap_short when the first is below the second. nil = not read (older agent).
|
||||
HostSwapMB *int64 `json:"host_swap_mb,omitempty"`
|
||||
GuestSwapMB *int64 `json:"guest_swap_mb,omitempty"`
|
||||
}
|
||||
|
||||
// Guest is one LXC. The agent reports vmid; the hub derives the guest PK
|
||||
@@ -355,6 +364,7 @@ type GuestSpec struct {
|
||||
Cores int `json:"cores"`
|
||||
MemoryBytes int64 `json:"memory_bytes"`
|
||||
DiskBytes int64 `json:"disk_bytes"`
|
||||
SwapBytes int64 `json:"swap_bytes,omitempty"` // R-1192: the guest's swap allowance (PVE config `swap`, MB → bytes)
|
||||
}
|
||||
|
||||
// Cloudflared is the box's tunnel (R-841, agent v0.141.0): the cloudflared container in the customer guest.
|
||||
|
||||
@@ -57,6 +57,10 @@ type MemoryInfo struct {
|
||||
MaxMB int64 `json:"max_mb"`
|
||||
FloorMB int64 `json:"floor_mb"`
|
||||
Running bool `json:"running"`
|
||||
// HostSwapMB / GuestSwapMB (R-1192 follow-up): the host's swap and this guest's swap allowance, so the controller
|
||||
// can tell the household when the host has too little swap behind the guest (its install page). nil = not read.
|
||||
HostSwapMB *int64 `json:"host_swap_mb,omitempty"`
|
||||
GuestSwapMB *int64 `json:"guest_swap_mb,omitempty"`
|
||||
}
|
||||
|
||||
// memoryResizeRequest is the POST /guest/memory body.
|
||||
@@ -94,6 +98,8 @@ type memoryBounds struct {
|
||||
maxMB int64
|
||||
floorMB int64
|
||||
running bool
|
||||
hostSwapMB int64
|
||||
guestSwapMB int64
|
||||
}
|
||||
|
||||
func (b memoryBounds) refusal(code string) memoryRefusal {
|
||||
@@ -104,7 +110,9 @@ func (b memoryBounds) refusal(code string) memoryRefusal {
|
||||
}
|
||||
|
||||
func (b memoryBounds) info(vmid int) MemoryInfo {
|
||||
hostSwap, guestSwap := b.hostSwapMB, b.guestSwapMB
|
||||
return MemoryInfo{
|
||||
HostSwapMB: &hostSwap, GuestSwapMB: &guestSwap,
|
||||
VMID: vmid, AllocatedMB: b.allocatedMB, UsageMB: b.usageMB, HostTotalMB: b.hostTotalMB,
|
||||
MinMB: b.minMB, MaxMB: b.maxMB, FloorMB: b.floorMB, Running: b.running,
|
||||
}
|
||||
@@ -139,6 +147,8 @@ func (s *Server) readMemoryBounds(ctx context.Context, vmid int) (memoryBounds,
|
||||
hostTotalMB: node.Memory.Total / mib, // bytes → MB, floor (conservative for max)
|
||||
minMB: minGuestMemoryMB,
|
||||
running: st.Status == "running",
|
||||
hostSwapMB: node.Swap.Total / mib, // R-1192 follow-up: the kernel's SwapTotal, as Proxmox reports it
|
||||
guestSwapMB: cfg.Swap, // PVE config swap is MB
|
||||
}
|
||||
b.maxMB = b.hostTotalMB - hostReserveMB
|
||||
b.floorMB = b.usageMB + shrinkUsageMarginMB
|
||||
@@ -225,7 +235,8 @@ func (s *Server) handleGuestMemoryResize(w http.ResponseWriter, r *http.Request,
|
||||
}
|
||||
|
||||
// Apply. SetConfig may be synchronous (empty UPID) or return a task to wait on.
|
||||
upid, err := s.mem.SetConfig(r.Context(), vmid, map[string]string{"memory": fmt.Sprintf("%d", target)})
|
||||
// R-1192: the swap moves with the memory (GuestSwapMB) — a grown guest with the old swap cap thrashes the same way.
|
||||
upid, err := s.mem.SetConfig(r.Context(), vmid, map[string]string{"memory": fmt.Sprintf("%d", target), "swap": fmt.Sprintf("%d", GuestSwapMB(target))})
|
||||
if err != nil {
|
||||
s.logger.Error("local-api: guest-memory SetConfig", "vmid", vmid, "target_mb", target, "err", err)
|
||||
writeErr(w, http.StatusBadGateway, "memory resize failed: "+err.Error())
|
||||
|
||||
@@ -25,12 +25,14 @@ type fakeMemory struct {
|
||||
setUPID string
|
||||
setErr error
|
||||
applyReflect bool
|
||||
hostSwapB int64 // R-1192 follow-up: node swap total
|
||||
guestSwapMB int64
|
||||
}
|
||||
|
||||
func (f *fakeMemory) GuestConfig(_ context.Context, _ int) (proxmox.GuestConfig, error) {
|
||||
f.mu.Lock()
|
||||
defer f.mu.Unlock()
|
||||
return proxmox.GuestConfig{Memory: f.allocMB}, nil
|
||||
return proxmox.GuestConfig{Memory: f.allocMB, Swap: f.guestSwapMB}, nil
|
||||
}
|
||||
func (f *fakeMemory) GuestStatus(_ context.Context, vmid int) (proxmox.Guest, error) {
|
||||
f.mu.Lock()
|
||||
@@ -42,6 +44,7 @@ func (f *fakeMemory) NodeStatus(_ context.Context) (proxmox.NodeStatus, error) {
|
||||
defer f.mu.Unlock()
|
||||
var ns proxmox.NodeStatus
|
||||
ns.Memory.Total = f.hostTotalB
|
||||
ns.Swap.Total = f.hostSwapB
|
||||
return ns, nil
|
||||
}
|
||||
func (f *fakeMemory) SetConfig(_ context.Context, _ int, params map[string]string) (string, error) {
|
||||
@@ -151,6 +154,10 @@ func TestGuestMemory_GrowAndShrink(t *testing.T) {
|
||||
if f.lastParams["memory"] != "12288" {
|
||||
t.Errorf("SetConfig param = %q, want 12288", f.lastParams["memory"])
|
||||
}
|
||||
// R-1192: the swap moves with the memory.
|
||||
if f.lastParams["swap"] != "12288" {
|
||||
t.Errorf("SetConfig swap = %q, want 12288 (swap = RAM)", f.lastParams["swap"])
|
||||
}
|
||||
})
|
||||
t.Run("shrink above floor", func(t *testing.T) {
|
||||
f := stdFixture() // floor = max(2048, 3000+512) = 3512
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
package localapi
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
|
||||
"gitea.dooplex.hu/admin/felhom-agent/internal/proxmox"
|
||||
)
|
||||
|
||||
// ── R-1192 (2026-10-21): the guest may swap as much as its RAM ────────────────────────────────────────────────────
|
||||
//
|
||||
// MEASURED (felhom.eu audits/fixes-2026-10-21/P4-freeze/): on the minimum machine (8 GB host, guest 4096 MB) the
|
||||
// household's first uploads made Immich load its analysis models (+1.15 GB) on top of 8 apps' 1.75 GB; the guest hit
|
||||
// its 4096 MB limit with its swap capped at Proxmox's LXC default of 512 MB — and full. The kernel could then evict
|
||||
// only file pages: ~360 MB was left for the program code of ~25 containers, re-read from disk without end (150 000–
|
||||
// 600 000 refaults and ~1 GB of reads per 10 s; memory „full" pressure 92–95 %, load 155, the dashboard dead, 0 OOM
|
||||
// kills). Raising the cap to 4096 MB live ended it in under a minute (memory „full" 96 % → 1.7 %, dashboard back
|
||||
// 42 s later) while the uploads ran on. The host had 7.4 GB of swap free the whole time.
|
||||
//
|
||||
// The agent never set `swap` at all, so every guest had the 512 MB default. Now:
|
||||
// - a new guest is created with swap = its memory (reconcile.bringup);
|
||||
// - a RAM resize sets swap with the memory (handleGuestMemoryResize);
|
||||
// - at agent start, every LXC in the felhom pool whose swap is below its memory is raised to it (this file).
|
||||
// Raising swap is a live cgroup change (memory.swap.max), no restart. It never lowers a swap someone set higher.
|
||||
|
||||
// GuestSwapMB is the swap a guest of memoryMB gets: the same as its RAM.
|
||||
func GuestSwapMB(memoryMB int64) int64 { return memoryMB }
|
||||
|
||||
// SwapOps is the Proxmox surface EnsureGuestSwap needs (satisfied by *proxmox.Client).
|
||||
type SwapOps interface {
|
||||
Pool(ctx context.Context, name string) (proxmox.PoolInfo, error)
|
||||
GuestConfig(ctx context.Context, vmid int) (proxmox.GuestConfig, error)
|
||||
SetConfig(ctx context.Context, vmid int, params map[string]string) (string, error)
|
||||
WaitTask(ctx context.Context, upid string, opts proxmox.WaitOptions) (proxmox.TaskStatus, error)
|
||||
}
|
||||
|
||||
// EnsureGuestSwap raises the swap of every LXC guest in pool to GuestSwapMB(memory) when it is below. Returns how
|
||||
// many guests were raised. One guest's failure is logged and the others are still handled.
|
||||
func EnsureGuestSwap(ctx context.Context, ops SwapOps, pool string, logger *slog.Logger) (int, error) {
|
||||
p, err := ops.Pool(ctx, pool)
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("guest swap: read pool %s: %w", pool, err)
|
||||
}
|
||||
raised := 0
|
||||
for _, m := range p.Members {
|
||||
if m.Type != "lxc" || m.VMID <= 0 {
|
||||
continue
|
||||
}
|
||||
cfg, err := ops.GuestConfig(ctx, m.VMID)
|
||||
if err != nil {
|
||||
logger.Warn("guest-swap: config read failed (left as it is)", "vmid", m.VMID, "err", err)
|
||||
continue
|
||||
}
|
||||
want := GuestSwapMB(cfg.Memory)
|
||||
if cfg.Memory <= 0 || cfg.Swap >= want {
|
||||
logger.Debug("guest-swap: nothing to do", "vmid", m.VMID, "memory_mb", cfg.Memory, "swap_mb", cfg.Swap)
|
||||
continue
|
||||
}
|
||||
upid, err := ops.SetConfig(ctx, m.VMID, map[string]string{"swap": fmt.Sprintf("%d", want)})
|
||||
if err == nil && upid != "" {
|
||||
_, err = ops.WaitTask(ctx, upid, proxmox.WaitOptions{})
|
||||
}
|
||||
if err != nil {
|
||||
logger.Warn("guest-swap: raise failed (left as it is)", "vmid", m.VMID, "from_mb", cfg.Swap, "to_mb", want, "err", err)
|
||||
continue
|
||||
}
|
||||
raised++
|
||||
logger.Info("guest-swap: raised (R-1192 — a guest swap cap below its RAM turned a memory burst into a freeze)",
|
||||
"vmid", m.VMID, "from_mb", cfg.Swap, "to_mb", want)
|
||||
}
|
||||
return raised, nil
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
package localapi
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"io"
|
||||
"log/slog"
|
||||
"testing"
|
||||
|
||||
"gitea.dooplex.hu/admin/felhom-agent/internal/proxmox"
|
||||
)
|
||||
|
||||
// R-1192: the freeze measured on the minimum machine (felhom.eu audits/fixes-2026-10-21/P4-freeze/) — a guest whose
|
||||
// swap is capped below its RAM evicts program code instead of idle memory. EnsureGuestSwap raises every pool guest's
|
||||
// swap to its RAM, never lowers one, skips non-LXC members, and survives one guest's failure.
|
||||
// COMPANION RED-PROOF: return 0 before the SetConfig call → „raised 0, want 2".
|
||||
type fakeSwapOps struct {
|
||||
cfg map[int]proxmox.GuestConfig
|
||||
failSet map[int]bool
|
||||
set map[int]map[string]string
|
||||
}
|
||||
|
||||
func (f *fakeSwapOps) Pool(context.Context, string) (proxmox.PoolInfo, error) {
|
||||
return proxmox.PoolInfo{Members: []proxmox.PoolMember{{VMID: 9201, Type: "lxc"}, {VMID: 9202, Type: "lxc"}, {VMID: 300, Type: "qemu"},
|
||||
{Type: "storage"}, {VMID: 9203, Type: "lxc"}, {VMID: 9204, Type: "lxc"}}}, nil
|
||||
}
|
||||
func (f *fakeSwapOps) GuestConfig(_ context.Context, vmid int) (proxmox.GuestConfig, error) {
|
||||
c, ok := f.cfg[vmid]
|
||||
if !ok {
|
||||
return c, errors.New("no such guest")
|
||||
}
|
||||
return c, nil
|
||||
}
|
||||
func (f *fakeSwapOps) SetConfig(_ context.Context, vmid int, p map[string]string) (string, error) {
|
||||
if f.failSet[vmid] {
|
||||
return "", errors.New("pve said no")
|
||||
}
|
||||
if f.set == nil {
|
||||
f.set = map[int]map[string]string{}
|
||||
}
|
||||
f.set[vmid] = p
|
||||
return "", nil
|
||||
}
|
||||
func (f *fakeSwapOps) WaitTask(context.Context, string, proxmox.WaitOptions) (proxmox.TaskStatus, error) {
|
||||
return proxmox.TaskStatus{}, nil
|
||||
}
|
||||
|
||||
func TestR1192_EnsureGuestSwapRaisesEveryLowSwapToItsRAM(t *testing.T) {
|
||||
f := &fakeSwapOps{cfg: map[int]proxmox.GuestConfig{
|
||||
9201: {Memory: 4096, Swap: 512}, // the measured box: raised
|
||||
9202: {Memory: 2048, Swap: 4096}, // already higher: never lowered
|
||||
9203: {Memory: 6144, Swap: 0}, // none: raised
|
||||
9204: {Memory: 4096, Swap: 512}, // the write fails: logged, the others still done
|
||||
}, failSet: map[int]bool{9204: true}}
|
||||
n, err := EnsureGuestSwap(context.Background(), f, "felhom", slog.New(slog.NewTextHandler(io.Discard, nil)))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if n != 2 {
|
||||
t.Fatalf("raised %d, want 2 (9201, 9203)", n)
|
||||
}
|
||||
if f.set[9201]["swap"] != "4096" || f.set[9203]["swap"] != "6144" {
|
||||
t.Fatalf("writes = %v", f.set)
|
||||
}
|
||||
if _, touched := f.set[9202]; touched {
|
||||
t.Fatal("a swap above the RAM was lowered")
|
||||
}
|
||||
if len(f.set[9201]) != 1 {
|
||||
t.Fatalf("the swap raise wrote more than the swap: %v", f.set[9201])
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package localapi
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// R-1192 follow-up (night 2026-10-21): GET /guest/memory carries the host's swap and this guest's swap allowance, so
|
||||
// the controller's install page can say when the host has no swap behind the guest. 0 is a real answer (no swap);
|
||||
// absent means an older agent.
|
||||
// RED-PROOF: without the two MemoryInfo fields the keys are missing → fails on „host_swap_mb absent".
|
||||
func TestR1192_GuestMemoryCarriesHostAndGuestSwap(t *testing.T) {
|
||||
for _, c := range []struct {
|
||||
name string
|
||||
hostB, guestMB int64
|
||||
wantHost, wantG int64
|
||||
}{
|
||||
{"installer host (7.75 GB swap), guest swap = RAM", 7935 * mib, 8192, 7935, 8192},
|
||||
{"a host with NO swap", 0, 8192, 0, 8192},
|
||||
} {
|
||||
f := stdFixture()
|
||||
f.hostSwapB, f.guestSwapMB = c.hostB, c.guestMB
|
||||
w := do(t, memServer(t, f).Handler(), "GET", "/guest/memory", "A", "")
|
||||
var m struct {
|
||||
Data map[string]any `json:"data"`
|
||||
}
|
||||
if err := json.Unmarshal(w.Body.Bytes(), &m); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
hs, ok := m.Data["host_swap_mb"].(float64)
|
||||
if !ok {
|
||||
t.Fatalf("%s: host_swap_mb absent: %s", c.name, w.Body.String())
|
||||
}
|
||||
gs, _ := m.Data["guest_swap_mb"].(float64)
|
||||
if int64(hs) != c.wantHost || int64(gs) != c.wantG {
|
||||
t.Fatalf("%s: host %v guest %v, want %d / %d", c.name, hs, gs, c.wantHost, c.wantG)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -645,6 +645,9 @@ func buildBringUpConfig(spec BringUpSpec, cfg proxmox.GuestConfig) map[string]st
|
||||
}
|
||||
if spec.MemoryMB > 0 {
|
||||
params["memory"] = strconv.Itoa(spec.MemoryMB)
|
||||
// R-1192: swap = RAM. Left unset, Proxmox gives an LXC 512 MB, and a guest that fills its RAM can then evict
|
||||
// only program code — the measured freeze (localapi.GuestSwapMB carries the reasoning and the numbers).
|
||||
params["swap"] = strconv.Itoa(spec.MemoryMB)
|
||||
}
|
||||
for i, m := range spec.Mounts {
|
||||
// backup=1 for data-bearing mounts: extra LXC mountpoints default to backup=0 = EXCLUDED
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package reconcile
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"gitea.dooplex.hu/admin/felhom-agent/internal/proxmox"
|
||||
)
|
||||
|
||||
// R-1192: a new guest is created with swap = its RAM (left unset, Proxmox gives an LXC 512 MB — the measured freeze,
|
||||
// felhom.eu audits/fixes-2026-10-21/P4-freeze/). COMPANION RED-PROOF: drop params["swap"] in buildBringUpConfig.
|
||||
func TestR1192_BringUpSetsSwapToTheRAM(t *testing.T) {
|
||||
p := buildBringUpConfig(BringUpSpec{MemoryMB: 4096}, proxmox.GuestConfig{})
|
||||
if p["memory"] != "4096" || p["swap"] != "4096" {
|
||||
t.Fatalf("bring-up params memory=%q swap=%q, want 4096/4096", p["memory"], p["swap"])
|
||||
}
|
||||
if q := buildBringUpConfig(BringUpSpec{}, proxmox.GuestConfig{}); q["swap"] != "" {
|
||||
t.Fatalf("no memory in the spec → no swap written either, got %q", q["swap"])
|
||||
}
|
||||
}
|
||||
@@ -99,6 +99,7 @@ type Manager struct {
|
||||
resolver Resolver
|
||||
|
||||
staleAfter time.Duration // handshake-age threshold for the re-resolve watchdog (doc 06 §4.2)
|
||||
rekeyAfter time.Duration // D30: how long a future-stamped handshake stays before the re-key (rekey.go)
|
||||
|
||||
mu sync.Mutex
|
||||
nextRegAt time.Time
|
||||
@@ -111,6 +112,10 @@ type Manager struct {
|
||||
resolveFailLogged bool // DNS-failure log throttle (reset on the next success)
|
||||
staleSameIPLogged bool // "stale but IP unchanged" log throttle (endpoint-down, not re-IP)
|
||||
|
||||
// D30 (rekey.go): when the latest handshake was first seen stamped in the future, and the last re-key.
|
||||
futureSince time.Time
|
||||
lastRekey time.Time
|
||||
|
||||
// conv is the CACHED tunnel-convergence snapshot (v0.90.0, R-28 fast-tick source), refreshed at
|
||||
// the end of every Apply (the tunnel's own cadence) so the fast-tick reads it WITHOUT execing
|
||||
// `wg`/`systemctl` per tick. wgBlockDesired = a wireguard block for THIS key is desired;
|
||||
@@ -156,6 +161,7 @@ func NewManager(runner proxmox.Runner, registrar Registrar, stateDir string, log
|
||||
now: time.Now,
|
||||
resolver: netResolver{},
|
||||
staleAfter: 180 * time.Second,
|
||||
rekeyAfter: rekeyAfterDefault,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -600,6 +606,10 @@ func (m *Manager) Watchdog(ctx context.Context, fetched bool, block *hub.WireWir
|
||||
if !fetched || block == nil || !m.lastResolvedIP.IsValid() {
|
||||
return // nothing applied to watch, or no desired block
|
||||
}
|
||||
// D30: a handshake stamped in the future that stays → a new key on the existing peer path (rekey.go).
|
||||
if m.clockAheadRekeyLocked(ctx, block) {
|
||||
return
|
||||
}
|
||||
if !m.handshakeStaleLocked(ctx) {
|
||||
return // healthy → no DNS, no action (the load-bearing negative)
|
||||
}
|
||||
@@ -661,6 +671,9 @@ func (m *Manager) Status(ctx context.Context) *hub.WireguardStatus {
|
||||
if age, ok := parseHandshakeAge(string(out), m.now()); ok {
|
||||
st.LastHandshakeAgeS = &age
|
||||
}
|
||||
if fut, ok := handshakeFuture(string(out), m.now()); ok {
|
||||
st.HandshakeFutureS = &fut
|
||||
}
|
||||
}
|
||||
}
|
||||
if st.Pubkey == "" && !st.Registered && !st.Active {
|
||||
@@ -669,6 +682,28 @@ func (m *Manager) Status(ctx context.Context) *hub.WireguardStatus {
|
||||
return st
|
||||
}
|
||||
|
||||
// handshakeFuture (R-1204) reports how many seconds the latest handshake lies in the future, ok only when it does
|
||||
// (by more than a minute — clock jitter is not the case). parseHandshakeAge clamps that case to 0 („just now"), which
|
||||
// is what made a box whose clock had run ahead look healthy while ep0 refused its tunnel. Pinned by
|
||||
// TestR1204_AFutureHandshakeIsReported.
|
||||
func handshakeFuture(out string, now time.Time) (int64, bool) {
|
||||
for _, line := range strings.Split(strings.TrimSpace(out), "\n") {
|
||||
f := strings.Fields(line)
|
||||
if len(f) != 2 {
|
||||
continue
|
||||
}
|
||||
epoch, err := strconv.ParseInt(f[1], 10, 64)
|
||||
if err != nil || epoch <= 0 {
|
||||
continue
|
||||
}
|
||||
if fut := epoch - now.Unix(); fut > 60 {
|
||||
return fut, true
|
||||
}
|
||||
return 0, false
|
||||
}
|
||||
return 0, false
|
||||
}
|
||||
|
||||
// parseHandshakeAge parses `wg show <if> latest-handshakes` output ("<peer-pub>\t<epoch>").
|
||||
// epoch 0 = no handshake yet → not ok (nil in the report; nil ≠ 0).
|
||||
func parseHandshakeAge(out string, now time.Time) (int64, bool) {
|
||||
|
||||
@@ -696,3 +696,31 @@ func TestInitialResolveFailureNoTeardown(t *testing.T) {
|
||||
t.Errorf("did not recover after DNS returned: %v", rr.calls)
|
||||
}
|
||||
}
|
||||
|
||||
// R-1204: a box that ran once with its clock ahead keeps a handshake stamped in the FUTURE — ep0 then refuses every
|
||||
// newer one. The age stays clamped at 0 (unchanged contract), and the new field says how far ahead it lies; a
|
||||
// handshake in the past (or within a minute of now) never sets it.
|
||||
// RED-PROOF: with Status not setting HandshakeFutureS the first assertion fails — seen failing 2026-10-22.
|
||||
func TestR1204_AFutureHandshakeIsReported(t *testing.T) {
|
||||
fh := &fakeHub{}
|
||||
m, _, active, _ := testManager(t, fh)
|
||||
ctx := context.Background()
|
||||
m.Apply(ctx, false, nil)
|
||||
*active = true
|
||||
m.now = func() time.Time { return time.Unix(1783107115-2*24*3600, 0) } // the clock came back two days earlier
|
||||
st := m.Status(ctx)
|
||||
if st.HandshakeFutureS == nil || *st.HandshakeFutureS != 2*24*3600 {
|
||||
t.Fatalf("handshake_future_s = %v, want %d", st.HandshakeFutureS, 2*24*3600)
|
||||
}
|
||||
if st.LastHandshakeAgeS == nil || *st.LastHandshakeAgeS != 0 {
|
||||
t.Fatalf("the age stays clamped at 0: %v", st.LastHandshakeAgeS)
|
||||
}
|
||||
m.now = func() time.Time { return time.Unix(1783107115+100, 0) }
|
||||
if st = m.Status(ctx); st.HandshakeFutureS != nil {
|
||||
t.Fatalf("a past handshake must not set handshake_future_s: %v", *st.HandshakeFutureS)
|
||||
}
|
||||
m.now = func() time.Time { return time.Unix(1783107115-30, 0) } // 30 s of jitter is not the case
|
||||
if st = m.Status(ctx); st.HandshakeFutureS != nil {
|
||||
t.Fatalf("clock jitter must not set handshake_future_s")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,189 @@
|
||||
package wgtunnel
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/rand"
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"gitea.dooplex.hu/admin/felhom-agent/internal/hub"
|
||||
)
|
||||
|
||||
// D30 (operator 2026-10-22, R-1204): the tunnel heals itself after the box ran with its clock ahead.
|
||||
//
|
||||
// WireGuard refuses a handshake whose timestamp is not newer than the last one it accepted from that key (replay
|
||||
// protection). A box whose clock ran ahead handshook with a future timestamp; ep0 keeps it, and once the clock is
|
||||
// right again ep0 refuses every new handshake from that key — until the box's clock passes the stored stamp. The
|
||||
// sign on the box: its own latest handshake stays stamped in the future (R-1204's handshake_future_s).
|
||||
//
|
||||
// The repair: when that sign stays for rekeyAfter, the agent makes a NEW key pair and registers the new public key on
|
||||
// the existing path (POST /hosts/<id>/wg → the hub re-keys the peer IN PLACE: same /32, new key, generation bump,
|
||||
// and the wgsync push of the FULL peer list to ep0 drops the old key and adds the new one). A new key is a new peer
|
||||
// for ep0, with no stored timestamp — the next handshake is accepted. Nothing new runs on ep0.
|
||||
//
|
||||
// The previous private key is kept as private.key.prev (0600): the escrow ceremony may hold it (a host-loss DR that
|
||||
// installs it registers it again, and the hub re-keys in place back to it — the same path).
|
||||
// Pinned by TestD30_* (rekey_test.go).
|
||||
|
||||
const (
|
||||
// rekeyAfter: how long the latest handshake must stay in the future before the re-key. A working tunnel
|
||||
// handshakes every two minutes, which ends the sign within minutes of the clock being right.
|
||||
rekeyAfterDefault = 15 * time.Minute
|
||||
// rekeyMinGap bounds the re-key to once an hour, whatever the clock does.
|
||||
rekeyMinGap = time.Hour
|
||||
prevKeyName = "private.key.prev"
|
||||
)
|
||||
|
||||
// clockAheadRekeyLocked watches for a handshake stamped in the future and re-keys when it stays. It reports whether
|
||||
// it re-keyed (the caller then skips the rest of its tick). Caller holds m.mu.
|
||||
func (m *Manager) clockAheadRekeyLocked(ctx context.Context, block *hub.WireWireguard) bool {
|
||||
if m.keyBroken || !m.isActive(ctx) {
|
||||
m.futureSince = time.Time{}
|
||||
return false
|
||||
}
|
||||
out, _, err := m.runner.Run(ctx, "wg", "show", Iface, "latest-handshakes")
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
now := m.now()
|
||||
fut, ok := handshakeFuture(string(out), now)
|
||||
if !ok {
|
||||
if !m.futureSince.IsZero() {
|
||||
m.logger.Info("wgtunnel: the handshake is no longer stamped in the future — no re-key needed")
|
||||
}
|
||||
m.futureSince = time.Time{}
|
||||
return false
|
||||
}
|
||||
if m.futureSince.IsZero() {
|
||||
m.futureSince = now
|
||||
m.logger.Warn("wgtunnel: the latest handshake is stamped in the future — this box's clock ran ahead, and the endpoint refuses its newer handshakes; re-keying if it stays",
|
||||
"future_s", fut, "rekey_after", m.rekeyAfter.String())
|
||||
return false
|
||||
}
|
||||
// A clock that jumps backwards must not stretch either wait (commit security review 2026-10-23 night): a start or a
|
||||
// last re-key stamped AFTER now is from a wrong clock and is dropped — this whole feature exists because clocks jump.
|
||||
if now.Before(m.futureSince) {
|
||||
m.futureSince = now
|
||||
}
|
||||
if now.Sub(m.futureSince) < m.rekeyAfter {
|
||||
return false
|
||||
}
|
||||
if m.lastRekey.IsZero() {
|
||||
m.lastRekey = m.loadLastRekey()
|
||||
}
|
||||
if now.Before(m.lastRekey) {
|
||||
m.lastRekey = time.Time{}
|
||||
}
|
||||
if !m.lastRekey.IsZero() && now.Sub(m.lastRekey) < rekeyMinGap {
|
||||
return false
|
||||
}
|
||||
pub, _, err := EnsureKey(m.stateDir)
|
||||
if err != nil || block.Pubkey != pub {
|
||||
return false // a re-register is already in flight, or the key is not readable — never re-key over that
|
||||
}
|
||||
newPub, err := rotateKey(m.stateDir)
|
||||
if err != nil {
|
||||
m.logger.Error("wgtunnel: re-key after a future handshake FAILED — the old key stays", "err", err)
|
||||
m.lastRekey = now // not again before rekeyMinGap
|
||||
m.saveLastRekey(now)
|
||||
return false
|
||||
}
|
||||
m.lastRekey, m.futureSince = now, time.Time{}
|
||||
m.saveLastRekey(now)
|
||||
m.logger.Warn("wgtunnel: RE-KEYED after a handshake stamped in the future (D30) — registering the new key; the hub re-keys the peer in place and the endpoint takes the new key",
|
||||
"old_pubkey", pub, "new_pubkey", newPub, "future_s", fut)
|
||||
m.nextRegAt = time.Time{} // register now, not after an older backoff
|
||||
m.registerLocked(ctx, newPub)
|
||||
return true
|
||||
}
|
||||
|
||||
// rotateKey makes a new key pair, never leaving the box without a readable key (review 2026-10-23 night, N6): the new
|
||||
// key is written and fsynced to a temp file; the current key gets a second name by a HARD LINK (the escrow may hold
|
||||
// it — `private.key.prev` keeps the first such key, later ones `private.key.prev.<unix>`, the newest three kept, N7);
|
||||
// then the temp file is renamed OVER the current name (atomic) and the directory fsynced. At every instant
|
||||
// `private.key` is a complete key. Returns the new PUBLIC key only.
|
||||
func rotateKey(stateDir string) (string, error) {
|
||||
dir := filepath.Join(stateDir, "wg")
|
||||
cur := filepath.Join(dir, keyFileName)
|
||||
if _, err := os.Stat(cur); err != nil {
|
||||
return "", fmt.Errorf("no current key: %w", err)
|
||||
}
|
||||
priv := make([]byte, 32)
|
||||
if _, err := rand.Read(priv); err != nil {
|
||||
return "", fmt.Errorf("entropy: %w", err)
|
||||
}
|
||||
clampPrivateKey(priv)
|
||||
pub, err := derivePublic(priv)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
tmp := filepath.Join(dir, keyFileName+".new")
|
||||
f, err := os.OpenFile(tmp, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0o600)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("writing the new key: %w", err)
|
||||
}
|
||||
_, werr := f.Write([]byte(base64.StdEncoding.EncodeToString(priv) + "\n"))
|
||||
serr := f.Sync()
|
||||
cerr := f.Close()
|
||||
if werr != nil || serr != nil || cerr != nil {
|
||||
os.Remove(tmp)
|
||||
return "", fmt.Errorf("writing the new key: %v %v %v", werr, serr, cerr)
|
||||
}
|
||||
prev := filepath.Join(dir, prevKeyName)
|
||||
if _, err := os.Lstat(prev); err == nil {
|
||||
prev = filepath.Join(dir, fmt.Sprintf("%s.%d", prevKeyName, rekeyNow().Unix()))
|
||||
}
|
||||
if err := os.Link(cur, prev); err != nil {
|
||||
os.Remove(tmp)
|
||||
return "", fmt.Errorf("keeping the old key: %w", err)
|
||||
}
|
||||
if err := os.Rename(tmp, cur); err != nil {
|
||||
os.Remove(tmp)
|
||||
return "", fmt.Errorf("installing the new key: %w", err)
|
||||
}
|
||||
if d, err := os.Open(dir); err == nil {
|
||||
d.Sync()
|
||||
d.Close()
|
||||
}
|
||||
prunePrevKeys(dir, 3)
|
||||
return pub, nil
|
||||
}
|
||||
|
||||
// rekeyNow is the clock for the kept-key names (a seam).
|
||||
var rekeyNow = time.Now
|
||||
|
||||
// prunePrevKeys keeps the newest `keep` of the `private.key.prev.<unix>` files (`private.key.prev` itself always stays).
|
||||
func prunePrevKeys(dir string, keep int) {
|
||||
m, _ := filepath.Glob(filepath.Join(dir, prevKeyName+".*"))
|
||||
if len(m) <= keep {
|
||||
return
|
||||
}
|
||||
sort.Strings(m) // the same digit count until 2286: lexical = time order
|
||||
for _, p := range m[:len(m)-keep] {
|
||||
os.Remove(p)
|
||||
}
|
||||
}
|
||||
|
||||
// lastRekeyFile records the last re-key's time across agent restarts (N7: the once-an-hour bound was in memory only).
|
||||
const lastRekeyFile = "last-rekey"
|
||||
|
||||
func (m *Manager) loadLastRekey() time.Time {
|
||||
b, err := os.ReadFile(filepath.Join(m.wgDir(), lastRekeyFile))
|
||||
if err != nil {
|
||||
return time.Time{}
|
||||
}
|
||||
var u int64
|
||||
if _, err := fmt.Sscanf(strings.TrimSpace(string(b)), "%d", &u); err != nil {
|
||||
return time.Time{}
|
||||
}
|
||||
return time.Unix(u, 0)
|
||||
}
|
||||
|
||||
func (m *Manager) saveLastRekey(t time.Time) {
|
||||
_ = os.WriteFile(filepath.Join(m.wgDir(), lastRekeyFile), []byte(fmt.Sprintf("%d\n", t.Unix())), 0o600)
|
||||
}
|
||||
@@ -0,0 +1,227 @@
|
||||
package wgtunnel
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
// D30 (R-1204): a handshake stamped in the future that STAYS for rekeyAfter → a new key pair, registered on the
|
||||
// existing peer path (the hub re-keys in place; its full-list push to ep0 swaps the key). The fake `wg` reports a
|
||||
// handshake at 1783107115; a clock three hours behind that sees it three hours in the future.
|
||||
// RED-PROOF (2026-10-22 night): with the clockAheadRekeyLocked call removed from Watchdog,
|
||||
// TestD30_AFutureHandshakeThatStaysReKeys and …AFailedRegistration… fail (no new key, no registration); with the
|
||||
// rekeyAfter wait removed, …ThatStaysReKeys fails (a re-key at 10 min); with the isActive check removed,
|
||||
// TestD30_NoReKeyWhileTheTunnelIsDown fails.
|
||||
|
||||
const hs = 1783107115
|
||||
|
||||
func at(m *Manager, unix int64) { m.now = func() time.Time { return time.Unix(unix, 0) } }
|
||||
|
||||
func readKey(t *testing.T, m *Manager, name string) string {
|
||||
t.Helper()
|
||||
b, err := os.ReadFile(filepath.Join(m.stateDir, "wg", name))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return strings.TrimSpace(string(b))
|
||||
}
|
||||
|
||||
func TestD30_AFutureHandshakeThatStaysReKeys(t *testing.T) {
|
||||
fh := &fakeHub{}
|
||||
m, _, active, logs := testManager(t, fh)
|
||||
oldPub := establishWG(t, m, active)
|
||||
oldPriv := readKey(t, m, keyFileName)
|
||||
ctx := context.Background()
|
||||
calls := fh.count()
|
||||
|
||||
t0 := int64(hs - 3*3600) // the clock is right again; the last handshake (made while it ran ahead) is 3 h ahead
|
||||
at(m, t0)
|
||||
m.Watchdog(ctx, true, testBlock(oldPub))
|
||||
at(m, t0+10*60)
|
||||
m.Watchdog(ctx, true, testBlock(oldPub))
|
||||
if fh.count() != calls || localPub(t, m) != oldPub {
|
||||
t.Fatal("no re-key before the future stamp has stayed rekeyAfter")
|
||||
}
|
||||
at(m, t0+16*60)
|
||||
m.Watchdog(ctx, true, testBlock(oldPub))
|
||||
newPub := localPub(t, m)
|
||||
if newPub == oldPub {
|
||||
t.Fatal("a future stamp that stayed 16 min must give a new key")
|
||||
}
|
||||
if fh.count() != calls+1 {
|
||||
t.Fatalf("the new key must be registered on the existing peer path (RegisterWG calls %d → %d)", calls, fh.count())
|
||||
}
|
||||
if mk := m.loadMarker(); mk == nil || mk.Pubkey != newPub {
|
||||
t.Fatalf("the registration marker must carry the new key: %+v", mk)
|
||||
}
|
||||
if readKey(t, m, prevKeyName) != oldPriv {
|
||||
t.Fatal("the old private key must be kept as private.key.prev (the escrow may hold it)")
|
||||
}
|
||||
if strings.Contains(logs.String(), oldPriv) || strings.Contains(logs.String(), readKey(t, m, keyFileName)) {
|
||||
t.Fatal("a private key reached the log")
|
||||
}
|
||||
// The served block still names the OLD key until the next fetch: no second re-key over that.
|
||||
at(m, t0+17*60)
|
||||
m.Watchdog(ctx, true, testBlock(oldPub))
|
||||
if localPub(t, m) != newPub {
|
||||
t.Fatal("a second re-key ran before the hub served the new key")
|
||||
}
|
||||
// The hub serves the new key → the tunnel is applied with the NEW private key.
|
||||
m.Apply(ctx, true, testBlock(newPub))
|
||||
conf, err := os.ReadFile(m.stagedConfPath())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !strings.Contains(string(conf), readKey(t, m, keyFileName)) || strings.Contains(string(conf), oldPriv) {
|
||||
t.Fatal("the applied tunnel must use the new private key, not the old one")
|
||||
}
|
||||
}
|
||||
|
||||
func TestD30_AShortFutureSpellDoesNotReKey(t *testing.T) {
|
||||
fh := &fakeHub{}
|
||||
m, _, active, _ := testManager(t, fh)
|
||||
pub := establishWG(t, m, active)
|
||||
ctx := context.Background()
|
||||
t0 := int64(hs - 3*3600)
|
||||
at(m, t0)
|
||||
m.Watchdog(ctx, true, testBlock(pub))
|
||||
at(m, hs+100) // a handshake now lies in the past: the sign ended (a working tunnel)
|
||||
m.Watchdog(ctx, true, testBlock(pub))
|
||||
at(m, t0+20*60) // in the future again: a NEW window starts, it does not continue the old one
|
||||
m.Watchdog(ctx, true, testBlock(pub))
|
||||
if localPub(t, m) != pub {
|
||||
t.Fatal("a future stamp that did not STAY for rekeyAfter must not re-key")
|
||||
}
|
||||
}
|
||||
|
||||
func TestD30_NoReKeyWhileTheTunnelIsDown(t *testing.T) {
|
||||
fh := &fakeHub{}
|
||||
m, _, active, _ := testManager(t, fh)
|
||||
pub := establishWG(t, m, active)
|
||||
*active = false
|
||||
ctx := context.Background()
|
||||
t0 := int64(hs - 3*3600)
|
||||
for _, d := range []int64{0, 20 * 60, 40 * 60} {
|
||||
at(m, t0+d)
|
||||
m.Watchdog(ctx, true, testBlock(pub))
|
||||
}
|
||||
if localPub(t, m) != pub {
|
||||
t.Fatal("no re-key while the tunnel unit is not active")
|
||||
}
|
||||
}
|
||||
|
||||
func TestD30_AFailedRegistrationIsRetriedByTheExistingPath(t *testing.T) {
|
||||
fh := &fakeHub{}
|
||||
m, _, active, _ := testManager(t, fh)
|
||||
oldPub := establishWG(t, m, active)
|
||||
ctx := context.Background()
|
||||
t0 := int64(hs - 3*3600)
|
||||
at(m, t0)
|
||||
m.Watchdog(ctx, true, testBlock(oldPub))
|
||||
fh.mu.Lock()
|
||||
fh.err = errors.New("hub down")
|
||||
fh.mu.Unlock()
|
||||
at(m, t0+16*60)
|
||||
m.Watchdog(ctx, true, testBlock(oldPub))
|
||||
newPub := localPub(t, m)
|
||||
if newPub == oldPub {
|
||||
t.Fatal("the key rotates before the registration")
|
||||
}
|
||||
if mk := m.loadMarker(); mk == nil || mk.Pubkey != oldPub {
|
||||
t.Fatal("a failed registration leaves the marker on the old key")
|
||||
}
|
||||
fh.mu.Lock()
|
||||
fh.err = nil
|
||||
fh.mu.Unlock()
|
||||
at(m, t0+30*60) // past the backoff: Apply sees the served (old) key ≠ the local key → re-key-in-place registers
|
||||
m.Apply(ctx, true, testBlock(oldPub))
|
||||
if mk := m.loadMarker(); mk == nil || mk.Pubkey != newPub {
|
||||
t.Fatalf("the existing re-key-in-place path must register the new key: %+v", mk)
|
||||
}
|
||||
}
|
||||
|
||||
// Review 2026-10-23 night. N7: a second rotation keeps the FIRST old key as `private.key.prev` (the escrow may hold it)
|
||||
// and the later one beside it; N6: the current key is replaced by a rename OVER it, so `private.key` is never missing.
|
||||
// RED-PROOF: with the „prev exists → a dated name" branch removed, TwoRotations fails (the first key overwritten) —
|
||||
// seen failing 2026-10-23 night.
|
||||
func TestD30_TwoRotationsKeepTheFirstOldKey(t *testing.T) {
|
||||
fh := &fakeHub{}
|
||||
m, _, active, _ := testManager(t, fh)
|
||||
establishWG(t, m, active)
|
||||
first := readKey(t, m, keyFileName)
|
||||
old := rekeyNow
|
||||
defer func() { rekeyNow = old }()
|
||||
rekeyNow = func() time.Time { return time.Unix(hs, 0) }
|
||||
if _, err := rotateKey(m.stateDir); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
second := readKey(t, m, keyFileName)
|
||||
rekeyNow = func() time.Time { return time.Unix(hs+7200, 0) }
|
||||
if _, err := rotateKey(m.stateDir); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if readKey(t, m, prevKeyName) != first {
|
||||
t.Fatal("private.key.prev must keep the FIRST old key")
|
||||
}
|
||||
if readKey(t, m, fmt.Sprintf("%s.%d", prevKeyName, hs+7200)) != second {
|
||||
t.Fatal("the second old key must be kept beside it")
|
||||
}
|
||||
if cur := readKey(t, m, keyFileName); cur == first || cur == second {
|
||||
t.Fatal("the current key must be new")
|
||||
}
|
||||
}
|
||||
|
||||
// N7: the once-an-hour bound survives an agent restart (it was in memory only). RED-PROOF: with loadLastRekey removed
|
||||
// from clockAheadRekeyLocked, this fails — seen failing 2026-10-23 night.
|
||||
func TestD30_TheHourBoundSurvivesARestart(t *testing.T) {
|
||||
fh := &fakeHub{}
|
||||
m, rr, active, _ := testManager(t, fh)
|
||||
pub := establishWG(t, m, active)
|
||||
ctx := context.Background()
|
||||
t0 := int64(hs - 3*3600)
|
||||
at(m, t0)
|
||||
m.Watchdog(ctx, true, testBlock(pub))
|
||||
at(m, t0+16*60)
|
||||
m.Watchdog(ctx, true, testBlock(pub))
|
||||
newPub := localPub(t, m)
|
||||
if newPub == pub {
|
||||
t.Fatal("fixture: the first re-key must happen")
|
||||
}
|
||||
// The agent restarts: a NEW manager on the same state; the served block now names the new key; the sign is back.
|
||||
m2 := NewManager(rr, fh, m.stateDir, m.logger)
|
||||
m2.isActive, m2.wgPresent, m2.resolver = m.isActive, m.wgPresent, m.resolver
|
||||
m2.Apply(ctx, true, testBlock(newPub))
|
||||
at(m2, t0+20*60)
|
||||
m2.Watchdog(ctx, true, testBlock(newPub))
|
||||
at(m2, t0+40*60)
|
||||
m2.Watchdog(ctx, true, testBlock(newPub))
|
||||
if localPub(t, m2) != newPub {
|
||||
t.Fatal("a restart must not reset the once-an-hour bound")
|
||||
}
|
||||
_ = active
|
||||
}
|
||||
|
||||
// Commit security review 2026-10-23 night: a last re-key saved while the clock ran ahead (a later date than now) must
|
||||
// not block the next re-key until that date. RED-PROOF: with the „lastRekey after now → dropped" guard removed, this
|
||||
// fails — seen failing 2026-10-23 night.
|
||||
func TestD30_ALastReKeyFromTheFutureDoesNotBlock(t *testing.T) {
|
||||
fh := &fakeHub{}
|
||||
m, _, active, _ := testManager(t, fh)
|
||||
pub := establishWG(t, m, active)
|
||||
m.saveLastRekey(time.Unix(hs+2*365*86400, 0)) // written while the clock was two years ahead
|
||||
ctx := context.Background()
|
||||
t0 := int64(hs - 3*3600)
|
||||
at(m, t0)
|
||||
m.Watchdog(ctx, true, testBlock(pub))
|
||||
at(m, t0+16*60)
|
||||
m.Watchdog(ctx, true, testBlock(pub))
|
||||
if localPub(t, m) == pub {
|
||||
t.Fatal("a last re-key dated in the future must not block the re-key")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user