From bbecdd919516dcfe0ac7bb6282e0b8c10e74ff76 Mon Sep 17 00:00:00 2001 From: kisfenyo Date: Sun, 15 Nov 2026 08:20:49 +0100 Subject: [PATCH] =?UTF-8?q?03=20=C2=A712a=20item=207:=20a=20cut=20write=20?= =?UTF-8?q?of=20the=20agent's=20config=20is=20repaired=20at=20start=20(R-1?= =?UTF-8?q?380);=20red-proofs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Claude-Session: https://claude.ai/code/session_0159rPz1ZhFKsS53msqPYxtS --- documentation/architecture/03-host-agent.md | 19 +++++- .../part0/redproof-agent-cutwrite.txt | 66 +++++++++++++++++++ 2 files changed, 82 insertions(+), 3 deletions(-) create mode 100644 documentation/audits/release-2b-3-2026-11-15/part0/redproof-agent-cutwrite.txt diff --git a/documentation/architecture/03-host-agent.md b/documentation/architecture/03-host-agent.md index f2dfaf09..5abcd238 100644 --- a/documentation/architecture/03-host-agent.md +++ b/documentation/architecture/03-host-agent.md @@ -1015,9 +1015,22 @@ the new root alone. Checked with the real openssl and a real TLS server in the w (`Ensure` is called from the start, the timer, a failed collect and a bundle install), and the root step has a 90-second deadline — it runs on the daemon's start path and inside the report loop. (c) **One lock for every writer of `agent.json`** in the process (`config.FileMu`: the trust move, the PBS seed, the backup-target move): each reads -the whole file and writes the whole file. **Left open, low:** the write is in place (not a rename), and nothing reads -the parked copy `agent.json.pre-pve-trust` back by itself — on a full disk a failed write and a failed put-back can -leave an empty config; the hand repair is to copy the parked file back. +the whole file and writes the whole file. + +**7. A cut write cannot leave a blind box (2026-11-15, before the release; R-1380).** The agent cannot rename a new +file into the config's folder (root owns it), so the write is in place: truncate, write, sync. A power cut in between +left an empty or half config, the agent did not start, and a box whose agent does not start cannot be repaired from +the hub. Now the three writers use `config.ReplaceInPlace`: (1) the OLD bytes go into a journal file in the agent's +own state folder (`/var/lib/felhom-agent/agent.json.write-in-flight`; a new file, synced, renamed, the folder synced +— the agent can do that there); (2) the config is written, synced and read back; (3) the journal is removed. **At +every daemon start, before the config is read,** `config.RecoverCutWrite`: a journal beside a config that does not +parse → the old bytes go back; a journal beside a config that parses → the file is whole (old or new), only the +journal goes. No journal folder → no write. A selftest never repairs (it can run beside a live agent that is in the +middle of a write). So after a cut the agent starts with the old file or the new file; with the old one it is a +pinned box again and the move runs again. Tested with a cut staged at each of the four steps +(`TestRecoverCutWrite_AfterACutAtEveryStepTheConfigIsWholeAndLoads`); the wiring is pinned +(`TestMainCallsTheConfigRepairBeforeItLoadsTheConfig`, `TestAgentJSONWritersUseTheJournalledWrite`). **Not proven: a +real power cut on a box.** The copy `agent.json.pre-pve-trust` stays, for a person; nothing reads it. **What changes for a pinned box when Proxmox makes a new certificate:** the first failed call names `pinned_cert_changed`, runs the order above, and the next call works — the box is blind for one report cycle at most, diff --git a/documentation/audits/release-2b-3-2026-11-15/part0/redproof-agent-cutwrite.txt b/documentation/audits/release-2b-3-2026-11-15/part0/redproof-agent-cutwrite.txt new file mode 100644 index 00000000..3aa56e03 --- /dev/null +++ b/documentation/audits/release-2b-3-2026-11-15/part0/redproof-agent-cutwrite.txt @@ -0,0 +1,66 @@ +== MUTATION: the journal is not written before the truncate + RED on the mutant, GREEN on the real file + --- FAIL: TestRecoverCutWrite_AfterACutAtEveryStepTheConfigIsWholeAndLoads (0.00s) + cutwrite_test.go:76: the repair saw no journal — a cut write would stay broken + cutwrite_test.go:76: the repair saw no journal — a cut write would stay broken + cutwrite_test.go:76: the repair saw no journal — a cut write would stay broken +== MUTATION: the start does not put the old bytes back + *** NOT A RED-PROOF *** (mutant rc=1 built=False real rc=0) + FAIL gitea.dooplex.hu/admin/felhom-agent/internal/config [build failed] + internal/config/cutwrite.go:121:2: declared and not used: perm +== MUTATION: the start puts the OLD file over a whole NEW file + RED on the mutant, GREEN on the real file + --- FAIL: TestRecoverCutWrite_AfterACutAtEveryStepTheConfigIsWholeAndLoads (0.00s) + cutwrite_test.go:79: after a cut at synced and the repair the config is "{\"proxmox\":{\"tls\":{\"fingerprint\":\"AA:BB\"}},\"keep\":\"me\"}", want "{\"proxmox\":{\"tls\":{\"ca_file\":\"/etc/felhom-agent/pve-root-ca.pem\",\"finger +== MUTATION: the journal stays after a whole write + RED on the mutant, GREEN on the real file + --- FAIL: TestReplaceInPlace_AWholeWriteLeavesTheNewFileAndNoJournal (0.00s) + cutwrite_test.go:102: the journal stayed after a whole write: +== MUTATION: a write goes on with no journal folder + *** NOT A RED-PROOF *** (mutant rc=0 built=True real rc=0) +== MUTATION: the repair writes mode 644 + *** NOT A RED-PROOF *** (mutant rc=1 built=False real rc=0) + FAIL gitea.dooplex.hu/admin/felhom-agent/internal/config [build failed] + internal/config/cutwrite.go:122:5: declared and not used: st + +6 mutations, 3 not a red-proof +== MUTATION: main does not call the repair + RED on the mutant, GREEN on the real file + --- FAIL: TestMainCallsTheConfigRepairBeforeItLoadsTheConfig (0.01s) + config_cutwrite_test.go:84: main: repair call found=false, config.Load found=true +== MUTATION: the repair seam does nothing + RED on the mutant, GREEN on the real file + --- FAIL: TestMainRecoversACutConfigWrite (0.00s) + config_cutwrite_test.go:39: note="" err= + +2 mutations, 0 not a red-proof +== MUTATION: the trust move writes the config by hand again + RED on the mutant, GREEN on the real file + --- FAIL: TestAgentJSONWritersUseTheJournalledWrite (0.00s) + config_cutwrite_test.go:131: ../../internal/pvetrust/pvetrust.go writeConfig: 0 call(s) to config.ReplaceInPlace, want 1 + +1 mutations, 0 not a red-proof + +## three mutants redone (the first two did not compile, the third was equal to the real code: the folder check failed first) +== MUTATION: the start does not put the old bytes back + RED on the mutant, GREEN on the real file + --- FAIL: TestRecoverCutWrite_AfterACutAtEveryStepTheConfigIsWholeAndLoads (0.00s) + cutwrite_test.go:79: after a cut at half-written and the repair the config is "{\"proxmox\":{\"tls\":{\"ca_file\":\"/etc/felhom-agent/", want "{\"proxmox\":{\"tls\":{\"fingerprint\":\"AA:BB\"}},\"keep\":\"me\"}" + cutwrite_test.go:79: after a cut at truncated and the repair the config is "", want "{\"proxmox\":{\"tls\":{\"fingerprint\":\"AA:BB\"}},\"keep\":\"me\"}" +== MUTATION: a write goes on when the journal cannot be made + RED on the mutant, GREEN on the real file + --- FAIL: TestReplaceInPlace_WithoutAJournalNothingIsWritten (0.00s) + cutwrite_test.go:120: the write went on with no journal +== MUTATION: the repair writes mode 644 + *** NOT A RED-PROOF *** (mutant rc=0 built=True real rc=0) + +3 mutations, 1 not a red-proof + +## the mode test was REMOVED, not kept: the repair writes into the existing file and cannot change its mode, so no mutant could make the test red. The mode argument was dead code and went with it. +== MUTATION: the start does not put the old bytes back (after the simplification) + RED on the mutant, GREEN on the real file + --- FAIL: TestRecoverCutWrite_AfterACutAtEveryStepTheConfigIsWholeAndLoads (0.00s) + cutwrite_test.go:79: after a cut at truncated and the repair the config is "", want "{\"proxmox\":{\"tls\":{\"fingerprint\":\"AA:BB\"}},\"keep\":\"me\"}" + cutwrite_test.go:79: after a cut at half-written and the repair the config is "{\"proxmox\":{\"tls\":{\"ca_file\":\"/etc/felhom-agent/", want "{\"proxmox\":{\"tls\":{\"fingerprint\":\"AA:BB\"}},\"keep\":\"me\"}" + +1 mutations, 0 not a red-proof