|
| 1 | +# SBOM Service |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +TypeScript/Node.js service that ingests SBOMs (CycloneDX + SPDX), scans for vulnerabilities via a local OSV.dev mirror, tracks dependency freshness and release cadence, and serves a GOV.UK-styled dashboard. Part of the View of Digital Government (VODG) project. |
| 6 | + |
| 7 | +## Architecture |
| 8 | + |
| 9 | +- Express server + pg-boss worker (single process) |
| 10 | +- Ingest: `POST /api/modules/sbom/services/:service_id` (X-API-Key auth, SHA-256 hashed) |
| 11 | +- Normalisation: parses CycloneDX/SPDX, extracts components into PostgreSQL |
| 12 | +- Scanner: queries local OSV mirror for vulnerability matches |
| 13 | +- OSV Sync: downloads ecosystem ZIPs from GCS every 6h |
| 14 | +- Freshness: evaluates dependency age against endoflife.date, npm registry, and Maven Central. Watchlist-driven (`src/freshness/watchlist.yaml`). Daily sync at 3 AM via pg-boss cron. States: green/amber/red based on majors behind + EOL status. |
| 15 | +- Cadence: monitors SBOM submission frequency |
| 16 | +- Dashboard: GOV.UK Frontend v6, Nunjucks templates, OIDC SSO auth |
| 17 | + |
| 18 | +## Running locally |
| 19 | + |
| 20 | +```bash |
| 21 | +docker compose up postgres localstack oidc-mock -d |
| 22 | +AWS_ACCESS_KEY_ID=test AWS_SECRET_ACCESS_KEY=test aws --endpoint-url=http://localhost:4566 s3 mb s3://vodg-sbom-local --region eu-west-2 |
| 23 | +cp .env.example .env |
| 24 | +pnpm install |
| 25 | +pnpm run db:migrate |
| 26 | +pnpm dev:watch |
| 27 | +``` |
| 28 | + |
| 29 | +## Package manager |
| 30 | + |
| 31 | +pnpm (v10.33.0). Node 20+ required (see `.nvmrc`). |
| 32 | + |
| 33 | +## Key files |
| 34 | + |
| 35 | +- `src/main.ts` — entrypoint (Express + pg-boss) |
| 36 | +- `src/config.ts` — environment configuration loader |
| 37 | +- `src/ingest/router.ts` — SBOM ingest endpoint |
| 38 | +- `src/normalise/` — CycloneDX + SPDX parsers |
| 39 | +- `src/scanner/` — vulnerability matching against local OSV mirror |
| 40 | +- `src/sync/` — OSV.dev data sync (downloads ecosystem ZIPs from GCS) |
| 41 | +- `src/freshness/` — dependency freshness analysis |
| 42 | +- `src/cadence/` — release cadence tracking |
| 43 | +- `src/server/routes/` — Express routes (admin, dashboard, services) |
| 44 | +- `src/db/migrations/` — PostgreSQL schema migrations |
| 45 | + |
| 46 | +## Scripts |
| 47 | + |
| 48 | +| Script | Description | |
| 49 | +|--------|-------------| |
| 50 | +| `pnpm run build` | Compile TypeScript to /dist | |
| 51 | +| `pnpm run dev` | Start development server | |
| 52 | +| `pnpm run dev:watch` | Start with file watching | |
| 53 | +| `pnpm run lint` | ESLint + Prettier | |
| 54 | +| `pnpm run test` | Jest unit tests | |
| 55 | +| `pnpm run test:e2e` | Playwright E2E tests | |
| 56 | +| `pnpm run db:migrate` | Run database migrations | |
| 57 | +| `pnpm run generate-key` | Generate API key for a service | |
| 58 | + |
| 59 | +## Docker |
| 60 | + |
| 61 | +Multi-stage Dockerfile: build stage (pnpm install + tsc), release stage (prod deps only). Base: `node:20-slim`. |
| 62 | + |
| 63 | +## TypeScript conventions |
| 64 | + |
| 65 | +- `strict: true` — no implicit any |
| 66 | +- ESM-style imports compiled to CommonJS |
| 67 | +- Collocated tests (`*.test.ts` alongside source) |
| 68 | +- Jest with `ts-jest` and `--experimental-vm-modules` |
| 69 | + |
| 70 | +## OSV Sync |
| 71 | + |
| 72 | +Ecosystems: npm, PyPI, Go, Maven, NuGet, crates.io, Packagist |
| 73 | +Schedule: every 6 hours (pg-boss cron) |
| 74 | +Data source: `https://osv-vulnerabilities.storage.googleapis.com/{ecosystem}/all.zip` (public, no auth) |
0 commit comments