Files
kevinveenbirkenbachandClaude Opus 5.5 d76ad966ea fix(ci): hand the vulnerability databases to the deploy jobs as run artifacts
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-<chunk index>-<engine> (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 <noreply@anthropic.com>
2026-11-13 21:44:59 +00:00

102 lines
3.4 KiB
Python

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):
def setUp(self):
self.tmp = tempfile.TemporaryDirectory()
self.root = Path(self.tmp.name)
self.refreshed = []
def tearDown(self):
self.tmp.cleanup()
def _env(self, engine):
return mock.patch.dict(
"os.environ",
{
ENGINE_ENV: engine,
deploy.HOST_PATH_ENV: str(self.root),
deploy.TARGET_DIR_ENV: "/opt/vulnerability-db",
},
)
def _refresher(self, errors):
def refresher(root, engines):
self.refreshed.append((root, engines))
return errors
return refresher
def _overrides(self, engine, errors=()):
with self._env(engine), contextlib.redirect_stdout(io.StringIO()):
return deploy.inventory_overrides(
random.Random(4), # noqa: S311 - seeded draw, not crypto
self._refresher(list(errors)),
)
def _runtime(self, overrides):
return overrides[ROLE]["services"]["runtime"]
def test_a_local_deploy_draws_one_engine_behind_syft(self):
engines = self._runtime(self._overrides(""))["engines"]
self.assertEqual((len(engines), engines[0]), (2, "syft"))
def test_a_local_deploy_refreshes_the_shared_databases_it_reads(self):
engine = self._runtime(self._overrides(""))["engines"][1]
self.assertEqual(self.refreshed, [(self.root, databases_for(engine))])
def test_the_stack_reads_the_read_only_mount(self):
runtime = self._runtime(self._overrides(""))
self.assertEqual(
(runtime["database_dir"], runtime["db_update"]),
("/opt/vulnerability-db", False),
)
def test_a_failed_refresh_fails_the_deploy(self):
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._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._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")
if __name__ == "__main__":
main()