Repository navigation
Commit be89b32
feat(greffer-cli):
* feat(cli): update-engine compose helpers (pull, image-ref rewrite, /readyz probe, digests)
First increment of the `greffer update` v1 engine (design: greffon docs/features/
greffer-self-update, merged greffon#165). Adds the compose.py primitives the engine
builds on, each unit-tested (no Docker needed):
- compose_pull: explicit pull of node images (incl. profile-gated ones) before
recreate, since `up` reuses the cached image when only the tag changed in-file.
- set_image_tag / set_image_refs: rewrite every greffon/* image line (tagged or
digest-pinned) atomically; set_image_tag returns prior refs for rollback.
- data_volume_is_named: pre-flight that /data is a named volume (so identity
survives recreate), distinguishing a named source from a bind path; no YAML dep.
- exec_in_greffer_readyz: probe /readyz inside the container with the resolved
X-GREFFON-TOKEN, returning the {id,status,reasons} body for the health gate.
- image_id / container_image_id: verify the recreate advanced to the pulled target
and capture the running image for rollback.
105 CLI tests pass. Next: update.py engine + `greffer update` command + strings.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* feat(cli): `greffer update` engine + command (resolve, pre-flight, pull, recreate, /readyz gate, rollback)
Increment 2 of the v1 update engine (design greffon#165). The 5-step host-side update:
- update.py: HTTPS-only manifest fetch + target resolution (--to > manifest latest);
no_rollback_from gate (reachable-but-silent manifest = rollback-safe; unreachable =
needs --confirm-no-rollback); pre-flight /data named-volume check; snapshot via
set_image_tag (prior refs) -> compose_pull (all node images incl the profile-gated
sidecar) -> compose_up; health gate (/healthz live -> /readyz ready + id match +
version-applied + all active services up; restart-count fail-fast); rollback restores
prior refs and recreates from local cache (exit 1 rolled-back / 2 rollback-failed).
Idempotent by running-image digest. --check is read-only.
- compose.py: service_container_id + exec_greffer_version helpers.
- main.py: `greffer update [--to] [--check] [--timeout] [--config-dir] [--confirm-no-rollback]`.
- strings.py: operator-facing update strings (marketing review pending at PR time).
- tests: 14 update tests (pure logic + engine paths via a FakeDocker harness, no Docker).
Full CLI suite: 119 passed.
Next: manager-side update_available/latest_version (Feature 1), cli-e2e, PR.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* fix(greffer-cli): harden update engine after adversarial review
Address findings from a pre-PR adversarial review of the `greffer update`
v1 engine:
- mode resolution: when env.env lacks GREFFER_MODE (hand-edited / legacy
install), detect the mode from the running node (tunnel-sidecar present
=> tunnel) instead of assuming a static default, so the health gate
waits on the right service set. Explicit GREFFER_MODE still wins.
- pre-flight: refuse the update when GREFFER_ID is missing from env.env,
since the post-recreate gate's id-match check would otherwise be a
silent no-op (updating blind).
- health gate: tolerate degraded reasons via set membership
(TOLERABLE_DEGRADED_REASONS) rather than exact-list equality, so a
registration_pending paired with any other reason still fails.
- compose: enforce the full 64-char sha256 length in the image-line
regex; simplify the old-ref extraction (drop a misleading `and`/dead
fallback); close the raw fd if os.fdopen raises in _atomic_write.
Tests: add the 5 missing health-gate failure outcomes (timeout, fatal,
wrong-id, degraded-other, crash-loop), both rollback-failure paths
(rollback compose up fails / rollback never healthy => exit 2), mode
auto-detection, and the no-GREFFER_ID pre-flight refusal. 129 passing.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* test(greffer-cli): make compose-arg assertions OS-portable
The Windows CI build failed: three update-engine tests hardcoded the
POSIX string "/tmp/c.yml" and asserted it verbatim in the docker args,
but str(Path("/tmp/c.yml")) is "\tmp\c.yml" on Windows. The product code
is correct (it passes str(compose_file), right per-OS); only the test
assertions baked in a POSIX path. Compare against str(Path(...)) instead.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* fix(greffer-cli): make /data named-volume preflight separator-agnostic
data_volume_is_named distinguished a named volume from a bind mount with
a POSIX-only test (`"/" not in src`). On Windows a relative, backslash-
separated bind source onto /data (e.g. `data\sub:/data`) contains no "/"
and so was misclassified as a named volume, letting the identity-
preservation preflight pass and `greffer update` recreate a bind-backed
/data, dropping the persisted token / TLS key / migration ledger.
Use a positive allowlist matching Docker's own volume-name grammar
([A-Za-z0-9][A-Za-z0-9_.-]*): separator-agnostic, so the classification
is identical on every host the CLI ships to. Add POSIX and Windows
relative-bind regression cases.
Found by a cross-platform portability audit of the update diff.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* fix(greffer-cli): validate update tag, disarm on interrupt, lock, pull all images
Second review round on the update engine found, and this fixes:
- SECURITY (tag injection -> RCE): the update target tag was written into
docker-compose.yml with no grammar validation, and the default source is
a network-fetched manifest. A manifest `latest` carrying a newline + YAML
(e.g. a `command:` key) injected into the compose file, then `compose up`
executed it. Add is_valid_image_tag (Docker tag grammar, fullmatch) and
enforce it at every entry: fetch_manifest coerces non-string fields to
None, resolve_target drops an invalid tag, `update --to` is validated at
the CLI boundary, and set_image_tag raises rather than write an invalid
tag. Restores the HLD's "a tampered manifest can name only a tag in the
known repo, never an arbitrary image" invariant.
- INTERRUPT SAFETY: a Ctrl-C / SIGTERM after the retag but before the gate
passed left the compose file pinned to an un-gated target with no
rollback, so a later bare `docker compose up` would recreate into it.
Wrap rewrite->pull->recreate->gate in try/finally + a SIGTERM handler
that restores the prior refs unless the gate passed.
- CONCURRENCY: serialize the mutating path on a host flock
(~/.greffer/.update.lock) so two concurrent runs can't race the rewrite /
rollback-baseline capture; a second run refuses cleanly. POSIX flock
(auto-releases on death); degrades to unlocked where fcntl is absent.
- CONTRACT: pull/validate ALL three node images (incl. the profile-gated
tunnel-sidecar in proxy mode), since set_image_tag retags all three; a
bad sidecar tag is now caught at update time, not on a later proxy->tunnel
switch. Recreate and the health gate stay mode-scoped.
Tests: +26 — tag-grammar + injection refusal, manifest coercion/malformed,
parse_readyz defensive shapes, listed-pair no-rollback gate, tunnel-profile
recreate, partial-services-up timeout->rollback, single-restart tolerated,
Ctrl-C disarm, lock-held refusal, idempotent file-untouched. 157 passing.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* fix(greffer-cli): SIGTERM-on-success exit code + manifest message; pin new paths
Third review round, addressing its findings:
- SIGTERM on a *succeeded* update exited 143: the handler raised
SystemExit(143) unconditionally, so a kill in the window after the gate
passed but before the handler is restored reported failure for a
confirmed success. The handler now exits 0 once gate_passed (a v2
wrapper keying on the exit code must not misread success).
- Diagnostics: a reachable manifest whose `latest` is missing / non-string
/ an invalid tag now prints a distinct "manifest reached but no usable
latest" message (UPDATE_BAD_MANIFEST) instead of the misleading
"manifest unreachable" text.
Tests pinning behavior the prior commit left unguarded:
- compose_pull is called with profile="tunnel" + all three services in
proxy mode (a revert to mode-scoped pull would now fail — this is the
security-motivated sidecar-validation line).
- the SIGTERM path: a bare kill mid-recreate disarms the compose file and
exits 143, and the prior handler is restored.
- the CLI --to boundary rejects an invalid tag with exit 2 before the
engine runs.
- the bad-manifest message branch.
161 passing.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* fix(greffer-cli): refuse https->http downgrade when fetching the manifest
The first-hop `url.startswith("https://")` check did not bind redirects:
the default urllib opener transparently follows a 302 to http://, so a
MITM / misconfigured CDN could downgrade the manifest channel to plaintext
and serve a forged manifest — suppressing the no_rollback_from safety
confirmation (the manifest's only "proceed without --confirm" signal) and,
in auto-latest mode, dictating the target tag.
Fetch through a dedicated opener whose redirect handler re-checks the
scheme on every hop and raises on any non-https target (a URLError
subclass, so the existing except turns it into a fail-closed None ->
treated as unreachable -> forces --confirm-no-rollback). Also bound the
read (_MAX_MANIFEST_BYTES) so a hostile endpoint can't stream an unbounded
body into the process.
Tests: the redirect handler refuses an http downgrade and allows an https
redirect; an oversized body yields None. 163 passing.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>greffer update self-update engine (v1) (#76)1 parent 5afe7f0 commit be89b32
7 files changed
Lines changed: 1880 additions & 0 deletions
File tree
- cli
- greffer_cli
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
| 13 | + | |
12 | 14 | | |
13 | 15 | | |
| 16 | + | |
14 | 17 | | |
15 | 18 | | |
16 | 19 | | |
| |||
256 | 259 | | |
257 | 260 | | |
258 | 261 | | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
259 | 552 | | |
260 | 553 | | |
261 | 554 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
| |||
203 | 204 | | |
204 | 205 | | |
205 | 206 | | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
206 | 254 | | |
207 | 255 | | |
208 | 256 | | |
| |||
0 commit comments