fix: attribute weekly CVEs to PR image diff

This commit is contained in:
notplants
2026-11-16 17:39:01 +00:00
parent 19f0329d62
commit 03561bc677
5 changed files with 72 additions and 24 deletions
+13 -8
View File
@@ -1336,7 +1336,8 @@ def _default_branch_compose(url: str) -> str | None:
return f"{host}/{owner}/{repo}/raw/branch/{br}/{path}" if br else None
def windows_from_compose(to_url: str, from_url: str | None = None) -> tuple[list, str | None]:
def windows_from_compose(to_url: str, from_url: str | None = None,
include_primary: bool = False) -> tuple:
"""Derive the scan's version windows by DIFFING two compose files.
This is the deterministic alternative to a human (or a model) deciding which `--image` args a
@@ -1366,7 +1367,8 @@ def windows_from_compose(to_url: str, from_url: str | None = None) -> tuple[list
else:
others.append((repo.split("/")[-1], prev_tag, tag))
wins = ([app] if app else []) + others
return wins, f"baseline {from_url}"
result = (wins, f"baseline {from_url}")
return (*result, bool(app)) if include_primary else result
def main() -> int:
@@ -1395,7 +1397,8 @@ def main() -> int:
a = ap.parse_args()
images = []
if a.compose_to:
wins, note = windows_from_compose(a.compose_to, a.compose_from)
wins, note, app_changed = windows_from_compose(a.compose_to, a.compose_from,
include_primary=True)
if not wins:
print(f"### Advisory scan — {a.recipe}\n\n**No image versions changed between the two "
f"compose files, so this upgrade fixes no CVEs by definition.**\n\n_{note}_")
@@ -1403,11 +1406,13 @@ def main() -> int:
print(f"_derived from compose diff ({note}):_", file=sys.stderr)
for n_, f_, t_ in wins:
print(f"_ {n_}: {f_} → {t_}_", file=sys.stderr)
# The `app` service (first entry when present) drives --from/--to; the rest are --image
# windows. Passing every window as --image too is harmless: each is matched by name against
# the advisory sources, and an unmatched name is simply ignored.
a.v_from, a.v_to = a.v_from or wins[0][1], a.v_to or wins[0][2]
images = list(wins[1:])
# Only an actual app-service change defines the primary window. A sidecar-only PR must
# not be scanned as though its first sidecar were the application image.
if app_changed:
a.v_from, a.v_to = a.v_from or wins[0][1], a.v_to or wins[0][2]
images = list(wins[1:])
else:
images = list(wins)
for spec in a.image:
name, _, rng = spec.partition('=')
vf, _, vt = rng.partition(':')