From d76ad966eaa2f0b6f2dc55a281892894c8a07387 Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Fri, 13 Nov 2026 21:44:59 +0000 Subject: [PATCH] fix(ci): hand the vulnerability databases to the deploy jobs as run artifacts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Deploy jobs restored the day-keyed vulnerability-db caches with fail-on-cache-miss, but the repository cache was at 11.37 GB against the 10 GB limit: every PR run saves its own trivy, grype and OSV entries (about 2.9 GB a day), so GitHub evicted the least recently used vulnerability-db-osv-2026-11-12 of main while run 43288523728 still ran. Its last OSV hit was at 05:28, and 11 jobs (Matrix#1, NFS Server#0, Nextcloud#13 and 8 more) failed between 12:26 and 18:26 on the missing key, while grype, which every job restores, stayed. The vulnerability-db job now uploads each engine database as the run artifact vulnerability-db-- (retention 3 days, overwrite for a full re-run) and the deploy jobs download it, so no job of a run depends on the evictable cache; the job keeps the day cache only to avoid a second download on the same day. The OSV cache key also carries the hash of roles/sys-ctl-hlth-runtime/meta/services.yml, so a change of the ecosystem list misses the stale database, and provided_databases checks every file of a pinned engine (each OSV ecosystem zip) instead of a non-empty directory. Tests: TestDatabaseHandover in tests/lint/repository/test_deploy_vulnerability_databases.py (13 passed) and test_an_osv_database_without_one_ecosystem_fails in test_deploy.py (7 passed); negative control on main: 4 lint tests and the ecosystem test fail. ruff check and format clean. Residuals: not yet exercised in a CI run; each chunk uploads about 2.9 GB of artifacts. 🎯 Fix: 90 % 💥 Break: 4 % 💸 Cost: – ⏱️ Time: – 🛡️ Security: 100 % 🏆 Score: 86 🚦 Gate: ✅ 90/5, cost and time <= 100, security 100 % Co-Authored-By: Claude Opus 5.5 --- .github/workflows/call-test-deploy.yml | 44 ++++++++++++---- .../test_deploy_vulnerability_databases.py | 51 +++++++++++++++++++ .../unit/python/utils/security/test_deploy.py | 25 +++++++-- utils/security/deploy.py | 21 +++++--- 4 files changed, 119 insertions(+), 22 deletions(-) diff --git a/.github/workflows/call-test-deploy.yml b/.github/workflows/call-test-deploy.yml index 2d8ff9a3fa..30f05ece8f 100644 --- a/.github/workflows/call-test-deploy.yml +++ b/.github/workflows/call-test-deploy.yml @@ -265,8 +265,6 @@ jobs: name: 🔬 Vulnerability databases runs-on: ubuntu-26.04 timeout-minutes: 60 - outputs: - day: ${{ steps.day.outputs.day }} steps: - uses: actions/checkout@v7.0.0 @@ -298,7 +296,7 @@ jobs: uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 with: path: build/vulnerability-db/osv - key: vulnerability-db-osv-${{ steps.day.outputs.day }} + key: vulnerability-db-osv-${{ steps.day.outputs.day }}-${{ hashFiles('roles/sys-ctl-hlth-runtime/meta/services.yml') }} - name: 🔧 Set up Python if: ${{ !env.ACT && (steps.trivy.outputs.cache-hit != 'true' || steps.grype.outputs.cache-hit != 'true' || steps.osv.outputs.cache-hit != 'true') }} @@ -322,6 +320,36 @@ jobs: # shellcheck disable=SC2086 python -m cli.contributing.security.database --dir build/vulnerability-db --engines ${MISSING} + - name: 📤 Hand the Trivy database to this run's deploy jobs + if: ${{ !env.ACT }} + uses: actions/upload-artifact@v7.0.1 + with: + name: vulnerability-db-${{ inputs.index }}-trivy + path: build/vulnerability-db/trivy + if-no-files-found: error + retention-days: 3 + overwrite: true + + - name: 📤 Hand the Grype database to this run's deploy jobs + if: ${{ !env.ACT }} + uses: actions/upload-artifact@v7.0.1 + with: + name: vulnerability-db-${{ inputs.index }}-grype + path: build/vulnerability-db/grype + if-no-files-found: error + retention-days: 3 + overwrite: true + + - name: 📤 Hand the OSV database to this run's deploy jobs + if: ${{ !env.ACT }} + uses: actions/upload-artifact@v7.0.1 + with: + name: vulnerability-db-${{ inputs.index }}-osv + path: build/vulnerability-db/osv + if-no-files-found: error + retention-days: 3 + overwrite: true + deploy: name: "${{ matrix.label }}" if: needs.discover.outputs.apps != '' && needs.discover.outputs.apps != '[]' @@ -386,19 +414,17 @@ jobs: - name: "🍇 Restore the Grype database" if: ${{ !env.ACT && matrix.engine != '' }} - uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 + uses: actions/download-artifact@v8 with: + name: vulnerability-db-${{ inputs.index }}-grype path: build/vulnerability-db/grype - key: vulnerability-db-grype-${{ needs.vulnerability-db.outputs.day }} - fail-on-cache-miss: true - name: "🔬 Restore the ${{ matrix.engine }} database" if: ${{ !env.ACT && matrix.engine != '' && matrix.engine != 'grype' }} - uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 + uses: actions/download-artifact@v8 with: + name: vulnerability-db-${{ inputs.index }}-${{ matrix.engine }} path: build/vulnerability-db/${{ matrix.engine }} - key: vulnerability-db-${{ matrix.engine }}-${{ needs.vulnerability-db.outputs.day }} - fail-on-cache-miss: true - name: "🔬 Pin the deploy to the restored databases" if: ${{ !env.ACT }} diff --git a/tests/lint/repository/test_deploy_vulnerability_databases.py b/tests/lint/repository/test_deploy_vulnerability_databases.py index 49b9900199..115b8eb26b 100644 --- a/tests/lint/repository/test_deploy_vulnerability_databases.py +++ b/tests/lint/repository/test_deploy_vulnerability_databases.py @@ -9,11 +9,14 @@ from pathlib import Path from tests.utils import PROJECT_ROOT from utils.cache.files import read_text from utils.cache.yaml import load_yaml_any +from utils.security.engine import ROLE, SCANNERS WORKFLOWS = PROJECT_ROOT / ".github" / "workflows" ENGINE = "INFINITO_VULNERABILITY_ENGINE" DB_HOST_PATH = "INFINITO_VULNERABILITY_DB_HOST_PATH" GITHUB_ONLY = "${{ !env.ACT }}" +DB_PATH = "build/vulnerability-db" +HANDOVER = "vulnerability-db-${{ inputs.index }}-" def steps(workflow: str, job: str) -> list[dict]: @@ -79,6 +82,54 @@ class TestDeployJob(unittest.TestCase): ) +class TestDatabaseHandover(unittest.TestCase): + def setUp(self) -> None: + self.jobs = load_yaml_any(str(WORKFLOWS / "call-test-deploy.yml"))["jobs"] + + def _with(self, job: str, action: str) -> list[dict]: + return [ + step.get("with", {}) + for step in self.jobs[job]["steps"] + if step.get("uses", "").startswith(f"actions/{action}") + ] + + def test_no_deploy_job_reads_a_database_from_the_evictable_cache(self) -> None: + self.assertEqual( + [ + args["path"] + for args in self._with("deploy", "cache") + if args.get("path", "").startswith(DB_PATH) + ], + [], + ) + + def test_every_engine_is_handed_over_per_chunk(self) -> None: + self.assertEqual( + sorted(args["name"] for args in self._with("vulnerability-db", "upload")), + sorted(f"{HANDOVER}{engine}" for engine in SCANNERS), + ) + + def test_a_deploy_downloads_what_the_run_handed_over(self) -> None: + self.assertEqual( + sorted( + args["name"] + for args in self._with("deploy", "download") + if args.get("name", "").startswith(HANDOVER) + ), + [f"{HANDOVER}${{{{ matrix.engine }}}}", f"{HANDOVER}grype"], + ) + + def test_the_osv_cache_key_follows_the_ecosystem_list(self) -> None: + osv = next( + step + for step in self.jobs["vulnerability-db"]["steps"] + if step.get("id") == "osv" + ) + self.assertIn( + f"hashFiles('roles/{ROLE}/meta/services.yml')", osv["with"]["key"] + ) + + class TestWorkspaceJob(unittest.TestCase): def setUp(self) -> None: script = next( diff --git a/tests/unit/python/utils/security/test_deploy.py b/tests/unit/python/utils/security/test_deploy.py index eedbec8074..1a819e68e5 100644 --- a/tests/unit/python/utils/security/test_deploy.py +++ b/tests/unit/python/utils/security/test_deploy.py @@ -3,12 +3,15 @@ from __future__ import annotations import contextlib import io import random +import re import tempfile from pathlib import Path from unittest import TestCase, main, mock from utils.security import deploy +from utils.security.database import database_files from utils.security.engine import ENGINE_ENV, ROLE, databases_for +from utils.security.pipeline import pipeline class TestInventoryOverrides(TestCase): @@ -66,19 +69,31 @@ class TestInventoryOverrides(TestCase): with self.assertRaisesRegex(SystemExit, "no network"): self._overrides("", errors=["grype database: no network"]) + def _provide(self, name, skip=0): + files = database_files(pipeline(), self.root, name) + for path in files[: len(files) - skip]: + path.parent.mkdir(parents=True, exist_ok=True) + path.write_text("x", encoding="utf-8") + return files + def test_a_pinned_engine_never_downloads(self): for name in ("trivy", "grype"): - (self.root / name).mkdir() - (self.root / name / "db").write_text("x", encoding="utf-8") + self._provide(name) self.assertEqual( self._runtime(self._overrides("trivy"))["engines"], ["syft", "trivy"] ) self.assertEqual(self.refreshed, []) def test_a_pinned_engine_without_its_databases_fails(self): - (self.root / "grype").mkdir() - (self.root / "grype" / "db").write_text("x", encoding="utf-8") - with self.assertRaisesRegex(SystemExit, "no osv database"): + self._provide("grype") + first = database_files(pipeline(), self.root, "osv")[0] + with self.assertRaisesRegex(SystemExit, re.escape(str(first))): + self._overrides("osv") + + def test_an_osv_database_without_one_ecosystem_fails(self): + self._provide("grype") + missing = self._provide("osv", skip=1)[-1] + with self.assertRaisesRegex(SystemExit, re.escape(str(missing))): self._overrides("osv") diff --git a/utils/security/deploy.py b/utils/security/deploy.py index fc72b4f1fc..6130fc46e6 100644 --- a/utils/security/deploy.py +++ b/utils/security/deploy.py @@ -7,7 +7,7 @@ import random from pathlib import Path from typing import TYPE_CHECKING -from utils.security.database import fetch_url, refresh +from utils.security.database import database_files, fetch_url, refresh from utils.security.engine import ( ENGINE_ENV, databases_for, @@ -30,13 +30,18 @@ def provided_databases(root: Path, engine: str) -> None: Raises: SystemExit: a database was not provided. """ - for name in databases_for(engine): - path = root / name - if not path.is_dir() or not any(path.iterdir()): - raise SystemExit( - f"{ENGINE_ENV}={engine} but no {name} database at {path}; " - "provide it before the deploy" - ) + p = pipeline() + missing = [ + str(path) + for name in databases_for(engine) + for path in database_files(p, root, name) + if not path.is_file() + ] + if missing: + raise SystemExit( + f"{ENGINE_ENV}={engine} but {', '.join(missing)} is missing; " + "provide it before the deploy" + ) def inventory_overrides(