Skip to content

feat(update): refuse a manifest-driven downgrade - #129

Merged
omarsy merged 2 commits into
mainfrom
feat/update-downgrade-guard
Aug 8, 2026
Merged

omarsy merged 2 commits into
mainfrom
feat/update-downgrade-guard

Conversation

@omarsy

@omarsy omarsy commented Aug 8, 2026

Copy link
Copy Markdown
Member

The bug

resolve_target() returns the manifest's latest with 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.0 while nodes ran 0.9.0, making greffer update on a current node 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
  • no_rollback_from cannot help — 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 (the string-compare trap). Returns None when either side is unorderable, and None is 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 --to still works: a deliberate rollback is legitimate, and it still passes through the no-rollback check.

✗ Refusing to downgrade: 0.9.0 is NEWER than the target 0.5.0.
  The version manifest advertises 0.5.0 as latest, which means it is
  stale relative to this node. Updating would roll back features and run
  older code against on-disk state written by 0.9.0.
  → if you really intend to go back, say so explicitly: `greffer update --to 0.5.0`.

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.lock inode, so it can advance the node in between:

this run reads 0.5 → remote update lands 0.9 → we acquire the lock → manifest target 0.7 looks like a forward update → node rolls back to 0.7

The rollback-safety pair is keyed on the running version too, so it is re-evaluated against the fresh value.

--check reported direction. It printed available: yes for an OLDER target, which is precisely how the downgrade looked like a routine update.

Deduplicated the comparison. engine._is_downgrade now delegates to update.is_downgrade instead 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

  • 273 tests pass (16 added).
  • 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.
  • Ordering table covers 0.10.0 > 0.9.0, 0.9 vs 0.9.0, and every unorderable shape.
  • No new ruff findings; the 4 in these files are pre-existing on main.
  • Codex CLI: "The downgrade comparison, automatic-update refusal, lock-protected recheck, and remote updater refactor are internally consistent and covered by focused tests. No actionable correctness regressions were identified."

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

omarsy added 2 commits August 8, 2026 12:28
`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
omarsy merged commit 8a885ee into main Aug 8, 2026
7 checks passed
@omarsy
omarsy deleted the feat/update-downgrade-guard branch August 8, 2026 12:26
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant