Skip to content

feat(greffer): self-update v2 (manager-triggered remote update), greffer side - #83

Merged
omarsy merged 8 commits into
mainfrom
feat/greffer-remote-update-v2
Jun 16, 2026
Merged

omarsy merged 8 commits into
mainfrom
feat/greffer-remote-update-v2

Conversation

@omarsy

@omarsy omarsy commented Jun 16, 2026

Copy link
Copy Markdown
Member

What

Greffer-side implementation of self-update v2: a manager-triggered remote update. Builds on the v1 operator-run greffer update CLI (merged) and the v2 image-provenance + trust-model design (greffon#168). Everything is behind the default-off GREFFER_REMOTE_UPDATE_ENABLED flag, so this is dormant until an operator opts in.

Flow

  1. Opt-in flag greffer_remote_update_enabled (default off, operator-sovereign) advertised in the register payload so the manager knows whether to offer the button.
  2. POST /api/controller/update/ (token-auth, flag-gated): validates the target tag, then spawns a detached, digest-pinned, socket-mounted updater container and returns 202.
  3. Inside that container, python -m greffer_cli.updater <tag> takes the shared /work/.update.lock (mutually exclusive with a host greffer update), then runs the trust model: per-image cosign verify + --annotation repo= binding + digest-pin, a monotonic min_supported anti-replay floor (max(baked baseline, signed manifest, /data ratchet)), and version cohesion — all before any recreate. Then recreate → /readyz health-gate → rollback on failure.

Fail-closed at every step: any verification, floor, or config failure refuses before the node is recreated.

Surface

  • app/settings.py: greffer_remote_update_enabled, greffer_updater_image (must be digest-pinned), greffer_version_manifest_url.
  • app/workers/register.py: advertise remote_update_enabled.
  • app/routers/controller.py + app/models/controller.py: the /update/ route (403 disabled / 503 unconfigured or not-digest-pinned / 400 bad tag / 500 spawn-failed / 202 accepted).
  • apps/utils/docker/updater.py: spawn_updater — discovers host mount sources off the greffer's own container record (compose dir → /work, /data preserved as bind or named volume), enforces @sha256: pinning.
  • cli/greffer_cli/updater/{provenance,floor,engine,__main__}.py: cosign provenance, anti-replay floor, verify→pin→recreate orchestration, container entrypoint.

Tests

cli 202 passed, greffer app 513 passed. No real docker / cosign / network / fcntl (all injected/mocked). Fail-closed branches, refusal paths, the anti-replay floor, host-path discovery, and the route gating are all covered.

Review

Took the diff through a multi-lens independent review loop to convergence (security, correctness/fail-closed, test+contract). Round 1 fixed three real defects: a lock-path divergence that broke the host/remote mutual-exclusion guarantee, a digest-vs-tag health-gate mismatch that rolled back every successful update, and an unenforced digest-pin on the most privileged container. Round 2 came back clean (only two doc/precision nits, since closed).

Not in this PR (rest of the v2 roadmap)

Manager action=update + controller client call + flag mirror + "updating" grace; frontend Update button; CI image/manifest signing (the cosign-key ops handoff).

🤖 Generated with Claude Code

omarsy and others added 7 commits June 16, 2026 10:39
python -m greffer_cli.updater <target_tag> reads the rest of its config
from the env the greffer sets, takes the /data update lock (mutually
exclusive with a host 'greffer update'), runs the verify -> pin ->
recreate engine, and exits with its code. main() injects run/lock for
tests; missing env, bad args, or a held lock all refuse fail-closed.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Wires the v2 remote-update engine into the live service. The route is
fail-closed gated: greffer_remote_update_enabled off (default) -> 403 at
the source; greffer_updater_image unset -> 503 (no silent :latest pull of
the container that recreates the greffer). On accept it spawns the signed,
digest-pinned updater container via the docker socket and returns 202.

spawn_updater (apps/utils/docker/updater.py) discovers host mount sources
off the greffer own container record (hostname == container id), so the
compose dir -> /work and /data (bind or named volume, preserved) are
mounted into the sibling exactly as the operator mounted the greffer. The
target tag is validated by the model (Docker tag grammar, 400 on bad) and
passed to the updater as a list arg (no shell); provenance + min_supported
floor verification all run inside the spawned container before any recreate.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Independent review (security + correctness + test lenses) surfaced two
load-bearing defects and several gaps:

P1 lock divergence: the remote updater locked /data/.greffer-update.lock
while a host `greffer update` (v1) locks <compose_dir>/.update.lock. Those
are different inodes, so the documented "mutually exclusive" guarantee was
broken and two updates could corrupt the shared compose file. Lock
/work/.update.lock instead (/work is that same host compose dir bind-mount,
same filename v1 uses).

P2 spurious rollback: health_gate._version_applied looked up the local tag
greffon/greffer:<target>, but v2 pulls/pins by digest and never creates that
tag, so every successful digest update read None -> GATE_NOT_APPLIED ->
rollback. Thread the verified greffer digest through health_gate(applied_ref=)
so it verifies against the digest actually running.

P2 unenforced digest-pin: the updater image (the one socket-mounted,
root-equivalent container, itself unverified) was only checked non-empty.
Enforce @sha256: pinning in spawn_updater and at the route (503
updater_image_not_digest_pinned) so a registry-side tag move cannot swap it.

Tests: cover the previously-dead digest-unresolvable / pull-failure /
empty-compose / compose-up-failure-rollback engine branches; assert the gate
receives the verified digest; assert the route mode kwarg + tunnel mode + the
non-pinned 503; assert remove=True + socket mount type + the lock-path inode.
Doc: correct the model docstring (validation maps to 400, not 422).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Round-2 review nits (both non-blocking): is_digest_pinned now fullmatches
(repo segment + exactly one @sha256:<64hex>, no trailing junk) so a
double-digest or trailing-junk ref cannot slip past; correct the acquire_lock
docstring /data -> /work after the lock-path move. Tests cover the rejected
double-digest / trailing-junk cases.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@omarsy omarsy changed the title feat(greffer): self-update v2 (manager-triggered remote update) — greffer side feat(greffer): self-update v2 (manager-triggered remote update), greffer side Jun 16, 2026
The v2 lock moved to /work/.update.lock (P1 fix) but five references still
named the old /data path (and engine.py named the wrong filename
.greffer-update.lock). One is operator-visible: the lock-contention stderr in
__main__. No behavioral change (all paths use DEFAULT_LOCK), but stale comments
pointing at the wrong path invite a regression of the very divergence the P1
fix closed. Caught by the final convergence review. DEFAULT_RATCHET stays on
/data (the ratchet legitimately lives there).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@omarsy
omarsy merged commit eb521ab into main Jun 16, 2026
6 checks passed
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