Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
# per-greffon ``min_greffer_version`` compatibility gate can refuse deploying an
# L4 (or any version-floored) greffon onto a greffer too old to run it. Keep in
# sync with pyproject.toml. Single source for the register report.
__version__ = "0.3.6"
__version__ = "0.3.7"
26 changes: 21 additions & 5 deletions cli/greffer_cli/updater/provenance.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

from __future__ import annotations

import json

from .. import compose

# Baked into the greffer-updater image at build time (the publish CI commits
Expand All @@ -25,17 +27,31 @@


def resolve_digest(ref: str) -> str | None:
"""Resolve ``greffon/<repo>:<tag>`` to its content digest (``sha256:<64hex>``),
or None. Uses ``docker buildx imagetools inspect`` so it needs no pull."""
"""Resolve ``greffon/<repo>:<tag>`` to its image-INDEX digest
(``sha256:<64hex>``, the manifest-list digest CI cosign-signs), or None.
Uses ``docker buildx imagetools inspect`` so it needs no pull.

Parses ``--format '{{json .Manifest}}'`` and reads its ``digest`` rather than
``--format '{{.Manifest.Digest}}'``: the latter is buildx-version-fragile (on
buildx >= ~0.35 it silently falls back to the verbose listing instead of
emitting the bare digest, so the whole verify-then-pull would refuse). The
JSON form is stable across the buildx versions tested (the updater's 0.34.1
and newer)."""
res = compose._run(
["docker", "buildx", "imagetools", "inspect", ref,
"--format", "{{.Manifest.Digest}}"],
"--format", "{{json .Manifest}}"],

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Apply the robust digest lookup to the release workflow

This only updates the updater's resolver; the release workflow still resolves the updater pin and all signing targets with docker buildx imagetools inspect ... --format '{{.Manifest.Digest}}' in .github/workflows/docker-publish.yml:141 and .github/workflows/docker-publish.yml:225. In the buildx versions this patch is meant to tolerate, the 0.3.7 publish path can still fail before baking GREFFER_UPDATER_IMAGE or signing the images, so the runtime fix cannot be shipped. Docker's CLI reference documents formatting .Manifest and the JSON function with a top-level digest, so the workflow needs the same JSON parsing used here.

Useful? React with 👍 / 👎.

timeout=60,
)
if not res.ok:
return None
digest = res.stdout.strip()
if not digest.startswith("sha256:"):
try:
manifest = json.loads(res.stdout)
except (json.JSONDecodeError, ValueError):
# A buildx that ignored --format and printed the verbose listing, or any
# non-JSON: fail closed rather than misread a digest.
return None
digest = manifest.get("digest") if isinstance(manifest, dict) else None
if not isinstance(digest, str) or not digest.startswith("sha256:"):
return None
hexpart = digest[len("sha256:"):]
return digest if len(hexpart) == 64 and all(
Expand Down
37 changes: 33 additions & 4 deletions cli/tests/test_updater_provenance.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,19 @@

from __future__ import annotations

import json

from greffer_cli import compose
from greffer_cli.updater import provenance


def _manifest(digest: str) -> compose.CommandResult:
"""A `docker buildx imagetools inspect --format '{{json .Manifest}}'` body."""
return compose.CommandResult(
0, json.dumps({"mediaType": "application/vnd.oci.image.index.v1+json",
"digest": digest, "size": 1609}), "")


def _ok(out: str = "") -> compose.CommandResult:
return compose.CommandResult(0, out, "")

Expand All @@ -22,15 +31,35 @@ def _fail() -> compose.CommandResult:

# --- digest resolution -----------------------------------------------

def test_resolve_digest_ok(monkeypatch):
monkeypatch.setattr(compose, "_run", lambda a, **k: _ok("sha256:" + "a" * 64 + "\n"))
def test_resolve_digest_reads_index_digest_from_manifest_json(monkeypatch):
monkeypatch.setattr(compose, "_run", lambda a, **k: _manifest("sha256:" + "a" * 64))
assert provenance.resolve_digest("greffon/greffer:0.3.5") == "sha256:" + "a" * 64
# and it asks for the JSON manifest, not the fragile {{.Manifest.Digest}}
seen = {}
monkeypatch.setattr(compose, "_run",
lambda a, **k: (seen.update(args=a), _manifest("sha256:" + "b" * 64))[1])
provenance.resolve_digest("greffon/greffer:0.3.5")
assert "{{json .Manifest}}" in seen["args"]


def test_resolve_digest_rejects_malformed(monkeypatch):
def test_resolve_digest_rejects_malformed_digest(monkeypatch):
for bad in ("", "sha256:zz", "deadbeef", "sha256:" + "a" * 63, "sha256:" + "g" * 64):
monkeypatch.setattr(compose, "_run", lambda a, _b=bad, **k: _ok(_b))
monkeypatch.setattr(compose, "_run", lambda a, _b=bad, **k: _manifest(_b))
assert provenance.resolve_digest("greffon/greffer:0.3.5") is None


def test_resolve_digest_handles_verbose_fallback_and_errors(monkeypatch):
# REGRESSION: on a newer buildx, `--format` is ignored and the verbose
# listing is printed; the old {{.Manifest.Digest}} code read that as a digest
# and returned None. Now non-JSON fails closed cleanly.
monkeypatch.setattr(compose, "_run",
lambda a, **k: _ok("Name: docker.io/greffon/greffer:0.3.6\n"
"Digest: sha256:" + "a" * 64 + "\n"))
assert provenance.resolve_digest("greffon/greffer:0.3.5") is None
# JSON without a digest field
monkeypatch.setattr(compose, "_run", lambda a, **k: _ok('{"mediaType": "x"}'))
assert provenance.resolve_digest("greffon/greffer:0.3.5") is None
# subprocess failure
monkeypatch.setattr(compose, "_run", lambda a, **k: _fail())
assert provenance.resolve_digest("greffon/greffer:0.3.5") is None

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "greffer"
version = "0.3.6"
version = "0.3.7"
description = ""
authors = ["Greffon <admin@greffon.io>"]
license = "AGPL-3.0-only"
Expand Down
4 changes: 2 additions & 2 deletions tests/test_workers_register.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,12 @@ def test_post_register_version_defaults_to_app_version(settings: Settings) -> No
from app import __version__

# Sanity: the fixture didn't set GREFFER_VERSION, so the default applies.
assert settings.greffer_version == __version__ == "0.3.6"
assert settings.greffer_version == __version__ == "0.3.7"
with patch("app.workers.register.requests") as mock_requests:
mock_requests.post.return_value.status_code = 200
_post_register(settings, "10.0.0.1", "tok")
kwargs = mock_requests.post.call_args.kwargs
assert kwargs["json"]["version"] == "0.3.6"
assert kwargs["json"]["version"] == "0.3.7"


def test_post_register_version_overridable_via_env(
Expand Down
Loading