Repository navigation
feat(update): refuse a manifest-driven downgrade - #129
Merged
Merged
Conversation
`resolve_target()` returned the manifest's `latest` with no comparison against the running version, so a manifest that lags the fleet silently rolled nodes BACKWARDS. Not theoretical: the published manifest sat at 0.5.0 while nodes ran 0.9.0, so `greffer update` on a current node was a four-minor-version rollback. Nothing else caught it. `min_supported` is parsed but never enforced (and the baked min_supported_baseline is copied into the updater image and never read), and `no_rollback_from` cannot help because a stale manifest cannot list a pair it has never seen. The v2 remote path already refused downgrades (engine._is_downgrade, HLD section 11). This closes the same hole in the v1 operator CLI, which is the path proven in production. What changed: - update.version_tuple / update.is_downgrade: dotted-numeric ordering, zero-padded so 0.9 and 0.9.0 compare equal, numeric so 0.10.0 > 0.9.0. Returns None (no claim) when either side is unorderable. - run_update refuses when the target is older AND came from the manifest. An explicit `--to` still works: a deliberate rollback is legitimate, and it still passes through the no-rollback check. - Re-checks under the update lock. Everything above ran unlocked and the in-container remote updater flocks the SAME /data/.update.lock inode, so it can advance the node between our read and our acquire: read 0.5 -> remote lands 0.9 -> we take the lock -> manifest target 0.7 looks forward -> rollback. Found by Codex. The rollback-safety pair is keyed on the running version too, so it is re-evaluated on the fresh value. - --check reported direction. It printed "available: yes" for an OLDER target, which is how the downgrade looked routine. - engine._is_downgrade now delegates to update.is_downgrade rather than keeping a second copy of a security-relevant comparison. Semantics preserved (unorderable -> False there); all 18 engine tests unchanged. 16 tests added, 273 pass. The race test was verified to FAIL with the under-lock re-check removed and pass with it restored, so it tests the fix rather than the happy path. No new ruff findings (the 4 in these files are pre-existing).
The node image is built with `COPY . /app` and the updater image with `COPY cli/ /src/`, so the guard changes the bytes of BOTH greffon/greffer and greffon/greffer-updater. docker-publish tags on app/__init__.py and only asserts the value is non-empty, so merging without this bump would republish :0.9.0 pointing at different content — breaking the tag immutability the :previous rollback rests on, and leaving two different builds behind one version. Minor rather than patch: this changes `greffer update` behaviour (an auto-latest downgrade is now refused), matching the repo convention of bumping app/__init__.py + pyproject.toml in the feature PR itself.
omarsy
added a commit
that referenced
this pull request
Aug 8, 2026
* feat(update): enforce the min_supported floor in v1 The manifest has always carried min_supported and nothing read it: it was parsed into Manifest and never consulted, and the min_supported_baseline file baked into greffer-updater has no reader in cli/ at all. Per the trust model the floor exists to "block below-floor reintroduction" -- an update must never land the node on a release withdrawn as known-bad. v1 was meant to have it: hld-v2-per-container-recreate section 7 says v1 "reads the manifest over HTTPS for the downgrade floor". It never did. v2 is deliberately untouched. The :latest updater drops the floor BY CONSTRUCTION (section 11), replacing it with verify-then-pull plus a pre-run no-downgrade refusal. Adding it there would reverse a recorded architectural decision, so this is v1-only. Semantics, distinct from the downgrade guard added in #129: is_downgrade is about DIRECTION relative to what is running; below_floor is about an absolute bound. 0.9 -> 0.8 is a downgrade that may still be above the floor, and a fresh install of a below-floor version is not a downgrade at all yet is still refused. NOT overridable by --to. A downgrade is a legitimate operator choice; a below-floor release is withdrawn, so an explicit request for one is exactly what this refuses. --check reports it too. Also fixes a live crash in version_tuple, which #129 already merged. str.isdigit() is not enough to make int() safe on manifest-supplied text: it is True for non-ASCII digits ('²'.isdigit() is True, int('²') raises) and for digit runs past CPython's 4300-char int-string limit. Either turned a malformed manifest into a traceback out of `greffer update`. Now requires plain ASCII digits with a bounded length. Found by Codex. Honest scope: v1 fetches the manifest over HTTPS but does not verify its signature, and there is no /data ratchet, so a hostile or rolled-back origin can serve a LOWER floor. This is a safety guard against landing on a known-bad release, not a security control against a hostile origin. The signed-manifest + ratchet half (HLD section 11) remains unbuilt and is stated as such in the docstring. 294 tests pass (21 added). Both the floor tests and the hostile-input tests were verified to FAIL with their fix removed. * docs(update): state that the floor is tag-based, not content-based Codex flagged that below_floor() compares the requested tag, so a tag moved or mispublished to below-floor content passes. Correct, and left unimplemented on purpose. Closing it needs the pulled image's version label, which v1 has no machinery to read, and that label is forgeable (v2 trust model section 7) so it would not close the case against a hostile registry either. v1 does not cosign-verify images at all and is operator-trust by design, so tag-trust is already its baseline. Documenting rather than silently leaving the reader to assume the floor is content-based.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The bug
resolve_target()returns the manifest'slatestwith no comparison against the running version. So a manifest that lags the fleet silently rolls nodes backwards.Not theoretical. The published manifest sat at
0.5.0while nodes ran0.9.0, makinggreffer updateon a current node a four-minor-version rollback.Nothing else caught it:
min_supportedis parsed but never enforced, and the bakedmin_supported_baselineis copied into the updater image and never readno_rollback_fromcannot help — a stale manifest cannot list a pair it has never seenThe v2 remote path already refused downgrades (
engine._is_downgrade, HLD section 11). This closes the same hole in the v1 operator CLI, which is the path proven in production.What changed
update.version_tuple/update.is_downgrade— dotted-numeric ordering, zero-padded so0.9and0.9.0compare equal, numeric so0.10.0 > 0.9.0(the string-compare trap). ReturnsNonewhen either side is unorderable, andNoneis deliberately not a downgrade, so an unparseable version can never wedge updates shut.The guard refuses when the target is older and came from the manifest. An explicit
--tostill works: a deliberate rollback is legitimate, and it still passes through the no-rollback check.Re-check under the lock (found by Codex, P1). Every version decision ran unlocked, and the in-container remote updater flocks the same
/data/.update.lockinode, so it can advance the node in between:The rollback-safety pair is keyed on the running version too, so it is re-evaluated against the fresh value.
--checkreported direction. It printedavailable: yesfor an OLDER target, which is precisely how the downgrade looked like a routine update.Deduplicated the comparison.
engine._is_downgradenow delegates toupdate.is_downgradeinstead of keeping a second copy of a security-relevant comparison in a different module. Semantics preserved there (unorderable →False); all 18 engine tests pass unchanged.Verification
0.10.0 > 0.9.0,0.9vs0.9.0, and every unorderable shape.Related
This is the structural fix. The immediate symptom is landing-page#55, which republishes the manifest at 0.9.0 — still open, blocked by a failing Cloudflare Pages build unrelated to its content (that route only does
fs.readFile).🤖 Generated with Claude Code