mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-27 21:38:01 +00:00
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>
86 lines
2.6 KiB
Python
86 lines
2.6 KiB
Python
"""Pin the vulnerability scan of a development or CI deploy to one engine."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
import random
|
|
from pathlib import Path
|
|
from typing import TYPE_CHECKING
|
|
|
|
from utils.security.database import database_files, fetch_url, refresh
|
|
from utils.security.engine import (
|
|
ENGINE_ENV,
|
|
databases_for,
|
|
deploy_overrides,
|
|
draw_engine,
|
|
pinned_engine,
|
|
)
|
|
from utils.security.pipeline import pipeline
|
|
|
|
if TYPE_CHECKING:
|
|
from collections.abc import Callable
|
|
|
|
HOST_PATH_ENV = "INFINITO_VULNERABILITY_DB_HOST_PATH"
|
|
TARGET_DIR_ENV = "INFINITO_VULNERABILITY_DB_DIR"
|
|
|
|
|
|
def provided_databases(root: Path, engine: str) -> None:
|
|
"""Fail unless every database a pinned *engine* reads is in *root*.
|
|
|
|
Raises:
|
|
SystemExit: a database was not provided.
|
|
"""
|
|
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(
|
|
rng: random.Random,
|
|
refresher: Callable[[Path, list[str]], list[str]],
|
|
) -> dict:
|
|
"""Return the inventory override of one development or CI deploy.
|
|
|
|
A pinned engine reads databases that were provided and never downloads
|
|
one. Without a pin the deploy draws an engine and refreshes the shared
|
|
host databases it reads first.
|
|
|
|
Args:
|
|
rng: draws the engine of an unpinned deploy.
|
|
refresher: ``(root, engines) -> error lines``, see
|
|
:func:`utils.security.database.refresh`.
|
|
|
|
Raises:
|
|
SystemExit: a provided database is missing or a refresh failed.
|
|
"""
|
|
root = Path(os.environ[HOST_PATH_ENV])
|
|
engine = pinned_engine()
|
|
if engine:
|
|
provided_databases(root, engine)
|
|
else:
|
|
engine = draw_engine(rng)
|
|
print(f">>> vulnerability engine of this deploy: {engine}")
|
|
errors = refresher(root, databases_for(engine))
|
|
if errors:
|
|
raise SystemExit("\n".join(errors))
|
|
return deploy_overrides(engine, os.environ[TARGET_DIR_ENV])
|
|
|
|
|
|
def refresh_shared(root: Path, engines: list[str]) -> list[str]:
|
|
""":func:`utils.security.database.refresh` with the real engines and downloads."""
|
|
return refresh(root, engines, pipeline().default_runner, fetch_url)
|
|
|
|
|
|
def deploy_inventory_overrides() -> dict:
|
|
""":func:`inventory_overrides` for a real deploy."""
|
|
return inventory_overrides(random.SystemRandom(), refresh_shared)
|