Parcourir la source

fix: --allow-change-held-packages CLEARS the hold, measured during the 2.20.1 window

This file told us to prefer the flag over unhold-plus-rehold because "the hold
is per PACKAGE rather than per version, so it survives the upgrade". It does
not. Measured in the same script that ran the install: the upgrade succeeded
with the flag and apt-mark showhold came back EMPTY, with dpkg reporting
"install ok installed" rather than "hold ok installed" on all three packages.

Both routes leave the same exposure, so the reasoning that preferred one was
false. Rewritten rather than appended, since the claim was wrong.

What caught it is the generalisable part: the re-hold and its verification were
IN the install script, not on a list of things to remember afterwards. This file
had already recorded the hold vanishing once and predicted it would recur, and
the prediction came true at the next opportunity, because a written warning is
not a control. Verified after re-holding: our packages show under "kept back"
with zero Inst lines of their own, while Debian's security updates still appear
installable - the control that separates "the hold works" from "apt had nothing
to offer anyway".

Window outcome: database 2.17.2 -> 2.20.1 (server reports 2.20.1, commit
5cd6228), client 2.18.1 -> 2.20.0, vectorapi 0.13.0 -> 0.16.0 (reports commit
07d102d). Downtime 4m47s, boot 27s, recovery TrivialSuccess on an empty WAL,
94884 docs. Cold verified backup at /var/backups/preupgrade-20261022-1445 with
ROLLBACK.txt.

The security gap is closed and measured through the deployed binary with
controls: anonymous /fn at a 2/min policy answered 200,200,429,429,429 with
Retry-After 60; the same route at rate_limit_per_min 0 answered three 200s, so
the refusal is selective; and a function declaring auth:'key' answered 401
anonymously against 200 with a valid key.
fszontagh il y a 1 mois
Parent
commit
de4f8119f9
1 fichiers modifiés avec 2 ajouts et 1 suppressions
  1. 2 1
      CLAUDE.md

+ 2 - 1
CLAUDE.md

@@ -386,7 +386,8 @@ docker run -d --name svapi-dev -p 8080:8080 -e SMARTBOTIC_VECTORAPI_KEY=dev svap
   **BUT "a lower hourly snapshot peak" UNDERSTATES WHAT 2.20.1 IS, AND THIS NOTE SAID EXACTLY THAT: 2.20.1 IS THE STRUCTURAL FIX FOR THE CRASH LOOP WE SPENT A DAY ON, SO IT IS THE REASON TO TAKE THE WINDOW RATHER THAN A SIDE EFFECT OF IT.** From their own changelog, marked `[server]`: a snapshot used to hold the whole store in memory three times over - the serialised body, a compressed copy beside it, and a copy of each collection's documents - and the writer now **streams to disk a chunk at a time, so a snapshot adds a few tens of MB whatever the store's size**. That is precisely the path that was OOM-killed hourly on prod from 2026-10-17, that never truncated the WAL, and whose 139 MB WAL then made recovery itself unsurvivable. The 4 GB swapfile is a floor under the symptom; this removes the cause. The file format is unchanged in both directions, which is what keeps the door two-way.
   **Their own statement of what it does NOT fix is the part to carry into the window, because it is the distinction this file already drew between prevention and survivability:** boot still holds the whole dataset in memory, so a large WAL left by anything else - a crash, a long stop, a full disk - can still keep a small host from booting. So the upgrade prevents phase 1 and therefore prevents phase 2 ever being reached, and does not make phase 2 survivable if something else produces it. Worth contrasting with 2.17.x, where the first-boot at-rest migration rewrote rows and history, could not be skipped, peaked over a gigabyte and OOM-killed under a 900 MiB cap. **Two upgrades of the same product, one requiring a carefully sized window and one requiring none - which is why the question has to be asked per upgrade rather than inherited from the last one.**
   **THE ONE CAVEAT ON GOING BACK, AND IT IS MEASURED AS INAPPLICABLE TO PROD RATHER THAN ASSUMED: a regex pattern STORED while on 2.20.x - a view `where` or a policy row predicate - using RE2-only syntax such as `(?i)` is not valid `std::regex`, so after a rollback 2.17.2 fails it CLOSED and silently, and such a view reads empty.** A pattern in a request only affects that request. Verified on prod rather than taken on "no reason to store one": `ViewManager: loaded 0 views from _views` at boot, `security disabled` and zero principals with a policy on all six projects, and **`createView` and the policy API appear NOWHERE in `src/` or `runner/src/`** - so our layer cannot create either, and the hazard cannot arrive through us. A tenant reaching it would need the CLI directly.
-- **THE DATABASE PACKAGES ARE ON APT HOLD, so an upgrade needs `--allow-change-held-packages` or it FAILS.** `apt-mark showhold` lists `smartbotic-database` and `libsmartbotic-db-client`; our three app packages are not held, which is why an ordinary vectorapi release needs nothing special. A pinned install without the flag dies with `E: Held packages were changed and -y was used without --allow-change-held-packages` - caught here by a `--dry-run` a few hours before a window, which is the only reason it was not discovered mid-outage. **Prefer the FLAG over `apt-mark unhold` plus a re-hold:** the hold is per PACKAGE rather than per version, so it survives the upgrade and keeps protecting the new version automatically, whereas the unhold route leaves the database freely upgradable if the re-hold is ever forgotten - a protection silently switched off is worse than an install that refuses.
+- **THE DATABASE PACKAGES ARE ON APT HOLD, so an upgrade needs `--allow-change-held-packages` or it FAILS.** `apt-mark showhold` lists `smartbotic-database` and `libsmartbotic-db-client`; our three app packages are not held, which is why an ordinary vectorapi release needs nothing special. A pinned install without the flag dies with `E: Held packages were changed and -y was used without --allow-change-held-packages` - caught here by a `--dry-run` a few hours before a window, which is the only reason it was not discovered mid-outage. **THAT ADVICE WAS WRONG AND IS NOW MEASURED WRONG: `--allow-change-held-packages` CLEARS THE HOLD.** This entry used to say "prefer the FLAG over `apt-mark unhold` plus a re-hold: the hold is per PACKAGE rather than per version, so it survives the upgrade". It does not survive. Measured during the 2026-10-22 window, in the same script that ran the install: the upgrade went through with the flag and `apt-mark showhold` came back **EMPTY**, with `dpkg-query` reporting `install ok installed` rather than `hold ok installed` on all three packages. So the flag route and the unhold route leave the SAME exposure, and the reasoning that preferred one over the other was false. **Always re-hold after a held-package upgrade, whichever route you took.**
+  **What caught it is the only generalisable part: the re-hold AND its verification were IN the install script, not on a list of things to do afterwards.** This file had already recorded the hold silently vanishing once, and had PREDICTED in writing that it would happen again - and the prediction came true at the very next opportunity, because a written warning is not a control. Put `apt-mark hold` and then `apt-get -s upgrade | grep -E "kept back|^Inst"` in the same script as the install, so forgetting is not available and the control is seen firing. Verified after re-holding: our three packages appear under "kept back" with zero `Inst` lines of their own, while Debian's own security updates still show as installable - which is the control that separates "the hold works" from "apt had nothing to offer anyway".
   **AND THAT IS EXACTLY WHAT HAPPENED. THE HOLD WAS GONE, MEASURED 2026-10-15: `apt-mark showhold` printed NOTHING** and `dpkg -l` showed `ii` rather than `hi` for all three. So the 2.17.2 window took the unhold route, the re-hold was forgotten, and the protection this paragraph calls load-bearing was off for three days with nothing to show it. **`smartbotic-database 2.18.0-1` was sitting in apt at that moment**, so a routine `apt-get upgrade` TYPED BY A HUMAN would have upgraded the database, the client and the CLI, and the database postinst calls `systemctl` DIRECTLY - so it would have restarted prod and run whatever 2.18.0's first boot does, unannounced, on a box holding four tenants' data. Re-held all three (the CLI too, since it is version-matched to the client), and **verified the control actually fires rather than trusting the command's output**: `apt-get -s upgrade` now reports them under "The following packages have been kept back" with ZERO `Inst` lines. A deliberate upgrade still works with `--allow-change-held-packages`.
   Two things worth taking from it. The note PREDICTED this failure in writing and the prediction still came true, because a written warning is not a control - **check `apt-mark showhold` as part of closing any window that touched a held package**, since the evidence is one command and the failure is invisible until the day it costs an outage. And it was found by accident, while verifying something unrelated: the `ii`/`hi` column appeared in a listing I had pulled to check a version. That is the second time this exact column has carried the answer while being read past.
   **SCOPE THAT EXPOSURE HONESTLY, THOUGH: `unattended-upgrades` WOULD NOT HAVE DONE IT.** It is installed, enabled, active and running daily on prod, but its `Origins-Pattern` allows only `origin=Debian` with `label=Debian` or `Debian-Security`. Our own repo is `o=Smartbotics,l=Smartbotics`, and a `--dry-run --debug` says so in as many words: **"Marking not allowed ... o=Smartbotics ... with -32768 pin"**, then "adjusting candidate to version libsmartbotic-db-client=2.17.2-1". So nothing of OURS - database, client, CLI or the three app packages - is ever auto-upgraded, and the unheld window was exposure to a human typing `apt upgrade` during routine maintenance, not to a nightly job. That is still worth the hold, because routine maintenance is exactly when someone types it, but it is a smaller claim than "it could have gone at any moment" and the smaller claim is the true one.