Files
kevinveenbirkenbachandClaude Opus 5.5 f1cd68ea38 feat(ci): file the hlth-runtime findings of every main run as vulnerability-runtime issues
The maintainer decided on 2026-11-12 that CRITICAL hlth-runtime findings no longer fail a development or CI deploy but are tracked as issues. The mirror scan already files vulnerability issues for 23 of the 41 images main run 43131801262 reported; 18 images and the host CVEs had no issue path.

- The report-main-failures job of call-orchestrator.yml now runs on every main run; its failure report still runs only when a deploy failed or was cancelled. A new step runs cli.meta.ci.runtime_vulnerabilities.
- That module downloads the rescue-diagnostics artifacts every deploy uploads, reads the hlth-runtime finding lines and events from their journals and syncs them through cli.contributing.security.issues under the label vulnerability-runtime: one issue per image (titled like the mirror scan) and one per host distro.
- An issue closes only when a deploy of the run scanned its target without an engine error and reported nothing, so chunked or cancelled runs close nothing they did not scan.
- cli.contributing.security.issues gains a Tracker (label, source line, close rule); MIRROR keeps the old behaviour, and the head line now ends in per-severity CVE counts.

Tests: 49 green across the runtime, issues and report_failures modules; 6 of 6 mutants caught (shared label, closing unscanned targets, ignoring engine errors, a PR ref passing the main guard, no severity counts, no dash for a missing fix).

Residuals: not yet run on a real main run; the new head line adds one comment and a body edit to every open vulnerability issue on the next cron run; one engine per CI row can make an issue close and reopen; an image with a mirror issue gets a second issue under the other label.

🎯 Fix: 85 %
💥 Break: 6 %
💸 Cost: –
⏱️ Time: –
🛡️ Security: ~100 %
🏆 Score: 80
🚦 Gate: ⛔ fix 85 % < 90, break 6 % > 5 (operator approved)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 12:58:03 +00:00

194 lines
7.1 KiB
Python

from __future__ import annotations
import json
import subprocess
from unittest import TestCase, main
import cli.contributing.security.issues.__main__ as issues_main
MIRROR = issues_main.MIRROR
ROW = {
"engine": "grype",
"role": "web-app-roundcube",
"service": "roundcube",
"image": "docker.io/roundcube/roundcubemail:1.7.5-apache",
"mirror": "ghcr.io/o/r/mirror/docker.io/roundcube/roundcubemail",
"digest": "sha256:abc",
"id": "CVE-2026-109618",
"ids": ["CVE-2026-109618"],
"severity": "CRITICAL",
"package": "php-cli",
"installed": "8.4.26",
"fixed": "8.4.27",
"suppressed_until": None,
}
SUPPRESSED = {**ROW, "id": "CVE-2026-109619", "suppressed_until": "2026-12-03"}
TITLE = "🛡️ docker.io/roundcube/roundcubemail:1.7.5-apache"
OTHER_IMAGE = "docker.io/library/nginx:1.31.8-alpine"
def body(rows):
return issues_main.body(rows, MIRROR)
class FakeGh:
def __init__(self, open_issues, hang=()):
self.open_issues = open_issues
self.hang = [list(verb) for verb in hang]
self.calls = []
def __call__(self, args):
if list(args[:2]) in self.hang:
raise subprocess.TimeoutExpired(["gh", *args], 120)
self.calls.append(list(args))
if args[:2] == ["issue", "list"]:
return json.dumps(self.open_issues)
return ""
def verbs(self):
return [
call[:2] for call in self.calls if call[0] == "issue" and call[1] != "list"
]
class TestSync(TestCase):
def test_a_new_finding_opens_one_issue(self):
gh = FakeGh([])
issues_main.sync(
{"findings": [ROW, {**ROW, "engine": "trivy"}], "errors": []},
"o/r",
gh,
MIRROR,
)
self.assertEqual(gh.verbs(), [["issue", "create"]])
def test_a_changed_image_gets_a_comment_and_an_updated_body(self):
gh = FakeGh([{"number": 7, "title": TITLE, "body": "old table"}])
issues_main.sync({"findings": [ROW], "errors": []}, "o/r", gh, MIRROR)
self.assertEqual(gh.verbs(), [["issue", "comment"], ["issue", "edit"]])
comment = gh.calls[-2]
self.assertIn("Still unresolved:", comment[comment.index("--body") + 1])
self.assertIn(ROW["id"], comment[comment.index("--body") + 1])
def test_an_unchanged_image_leaves_its_issue_alone(self):
current = body([ROW])
gh = FakeGh([{"number": 7, "title": TITLE, "body": current + "\r\n"}])
actions = issues_main.sync({"findings": [ROW], "errors": []}, "o/r", gh, MIRROR)
self.assertEqual((gh.verbs(), actions), ([], [f"unchanged #7 {TITLE}"]))
def test_a_second_open_issue_of_one_image_closes_as_duplicate(self):
current = body([ROW])
gh = FakeGh(
[
{"number": 9, "title": TITLE, "body": current},
{"number": 7, "title": TITLE, "body": current},
]
)
actions = issues_main.sync({"findings": [ROW], "errors": []}, "o/r", gh, MIRROR)
self.assertEqual(gh.verbs(), [["issue", "close"]])
self.assertEqual(gh.calls[-1][2], "9")
self.assertIn(f"unchanged #7 {TITLE}", actions)
def test_a_fixed_finding_closes_its_issue(self):
gh = FakeGh([{"number": 7, "title": TITLE}])
actions = issues_main.sync({"findings": [], "errors": []}, "o/r", gh, MIRROR)
self.assertEqual(actions, [f"closed #7 {TITLE}"])
def test_a_suppressed_finding_keeps_its_issue_open(self):
gh = FakeGh([{"number": 7, "title": TITLE, "body": "old table"}])
actions = issues_main.sync(
{"findings": [SUPPRESSED], "errors": []}, "o/r", gh, MIRROR
)
self.assertEqual(gh.verbs(), [["issue", "comment"], ["issue", "edit"]])
self.assertNotIn(f"closed #7 {TITLE}", actions)
def test_a_scan_error_closes_nothing(self):
gh = FakeGh([{"number": 7, "title": TITLE}])
issues_main.sync(
{"findings": [], "errors": ["x: the mirror served no digest"]},
"o/r",
gh,
MIRROR,
)
self.assertEqual(gh.verbs(), [])
def test_a_failed_issue_call_is_reported_and_the_others_still_run(self):
other = {**ROW, "image": OTHER_IMAGE}
gh = FakeGh([{"number": 7, "title": TITLE}], hang=[("issue", "edit")])
actions = issues_main.sync(
{"findings": [ROW, other], "errors": []}, "o/r", gh, MIRROR
)
failed = [action for action in actions if action.startswith("failed ")]
self.assertEqual(len(failed), 1)
self.assertTrue(failed[0].startswith(f"failed updated #7 {TITLE}"))
self.assertEqual(gh.verbs(), [["issue", "create"], ["issue", "comment"]])
def test_every_cve_of_one_image_shares_one_issue(self):
gh = FakeGh([])
actions = issues_main.sync(
{
"findings": [ROW, {**ROW, "id": "CVE-2026-109619"}],
"errors": [],
},
"o/r",
gh,
MIRROR,
)
self.assertEqual(actions, [f"opened {TITLE}"])
def test_the_issue_is_labelled(self):
gh = FakeGh([])
issues_main.sync({"findings": [ROW], "errors": []}, "o/r", gh, MIRROR)
create = gh.calls[-1]
self.assertEqual(create[create.index("--label") + 1], issues_main.LABEL)
class TestBody(TestCase):
def _table(self, text):
return [line for line in text.splitlines() if line.startswith("| CVE-")]
def test_every_engine_gets_a_row(self):
text = body([ROW, {**ROW, "engine": "trivy"}])
self.assertEqual(len(self._table(text)), 2)
def test_critical_rows_come_first(self):
high = {**ROW, "id": "CVE-2026-000001", "severity": "HIGH"}
table = self._table(body([high, ROW]))
self.assertIn("| CRITICAL |", table[0])
def test_a_suppressed_cve_is_listed_after_the_failing_ones_with_its_until(self):
text = body([SUPPRESSED, ROW])
table = self._table(text)
self.assertEqual(
(table[0].endswith("| - |"), table[1].endswith("| 2026-12-03 |")),
(True, True),
)
self.assertIn(
"carries 2 CVE(s) at the scan threshold, 1 of them suppressed: CRITICAL 2.",
text,
)
def test_the_head_line_counts_each_severity_most_severe_first(self):
rows = [
{**ROW, "id": "CVE-2026-000001", "severity": "HIGH"},
{**ROW, "id": "CVE-2026-000002", "severity": "HIGH"},
{**ROW, "engine": "trivy"},
]
head = body(rows).splitlines()[0]
self.assertTrue(head.endswith(": CRITICAL 1, HIGH 2."), head)
def test_the_mirror_body_names_its_mirror_copy(self):
self.assertIn(f"Mirror: `{ROW['mirror']}@{ROW['digest']}`", body([ROW]))
def test_a_large_image_stays_under_the_body_limit(self):
rows = [{**ROW, "id": f"CVE-2026-{index:06d}"} for index in range(2000)]
text = body(rows)
self.assertLessEqual(len(text), issues_main.BODY_LIMIT)
hidden = 2000 - len(self._table(text))
self.assertGreater(hidden, 0)
self.assertIn(f"{hidden} more row(s)", text)
if __name__ == "__main__":
main()