SbomScan result caching - models and db changes
What does this MR do and why?
Adds database layer and models for SBOM scan result caching which enables the reuse of scan results for scans when dependencies haven't changed.
Currently, SBOM scans are triggered on every pipeline run regardless of whether dependencies have changed, wasting computational resources by processing identical dependencies and generating the same results. This MR introduces an SbomScanResult model which will allow SbomScan instances to reference the same result.
References
Parent MR: Avoid triggering a re-scan when dependencies ha... (#562694) • Igor Frenkel • 18.7 • Needs attention
This MR is one of 3
- Current
👉 SbomScan result caching - models and db changes (!213584) • Igor Frenkel • 18.7 - SbomScan result caching - service and api layer (!213586) • Igor Frenkel • 18.7
- Pending: observability events for caching
Analyzer MR: Add sbom scan caching support (gitlab-org/security-products/analyzers/dependency-scanning!400) • Igor Frenkel • 18.7
Change summary
- Migrations
- New table
sbom_vulnerability_scan_resultsallows scan result re-use. - Modify
sbom_vulnerability_scansto add a foreign key to added table. - Modify
sbom_vulnerability_scansto add ansbom_digestwhich will allow clients (e.g. DS analyzer) to look for SBOMs that have already been scanned.
- New table
- Models
- Add
SbomScanResult - Add association between new model and
SbomScan - Add uploader like
SbomScanUploaderbut simpler since we don't have to handle user uploads. -
SbomScan#result_fileis changed to serve either the "old" results (stored in column) or new results (stored in association).
- Add
Database
-
Results of the migration checks are here: !213584 (comment 2916768128)
-
The biggest change (found in the 2nd MR) is a query against the
sbom_vulnerability_scanstable to fetch results bysbom_digest(invoked by theSbomScanResultCachingServicein the 2nd MR). Example:SELECT "sbom_vulnerability_scans".* FROM "sbom_vulnerability_scans" WHERE "sbom_vulnerability_scans"."project_id" = 35 AND "sbom_vulnerability_scans"."sbom_digest" = 'sha256v1-abc123def456' AND "sbom_vulnerability_scans"."sbom_digest" IS NOT NULL AND "sbom_vulnerability_scans"."status" = 2 ORDER BY created_at desc LIMIT 1postgres.aiconsole was down at the time of adding this, so there is no explain but there's also nosbom_digestdata. So the closest estimate would be scoped to aproject_idlookup.
Rollout plan
See issue for detail: #562694
How to set up and validate locally
This can be validated at the end of the MR stack.
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
-
This MR is added to the 18.7 release post, or the
release post item::nolabel is added