Read the source files of a Syft or Grype SBOM

What does this MR do and why?

This MR reads the first location, syft:location:0:path, that Syft and Grype write on a package and lists the package at that path, so each package appears at the file that declares it, as GitLab lists the packages of its own analyzer. Syft also writes supporting-evidence files as further locations and nothing marks them, so only the first location is read.

  • Normalizer::Format is a new base class for the format of a generator, and Normalizer::Syft is the first format class. The normalizer builds one entry for each source file of a package.
  • Normalizer::Syft#source_files returns the first location without its leading slash, because the GitLab DS analyzer's paths are relative.
    • A blank value and a value that is only / are ignored.
  • Normalizer::Properties.values reads the values of the properties whose name the caller accepts, and leaves out a property without a value.
  • The normalizer lists a package at the files of the first format that records any, and at the default location when none does.
    • Normalizer::Format#source_files returns no file, so a format that records none leaves the package at the default location.
    • An operating system package keeps no path, also when Syft records its locations.

This MR is the fourth of 8 in a stack. The next one is Read the source files of a cdxgen SBOM (!264254) • Igor Frenkel • 19.7.

Example

A component of a Syft 1.52.0 SBOM of a Maven project (trimmed): the location is written with a leading slash.

{
  "type": "library",
  "name": "commons-io",
  "version": "2.4",
  "purl": "pkg:maven/commons-io/commons-io@2.4",
  "properties": [
    { "name": "syft:location:0:path", "value": "/core/pom.xml" }
  ]
}
  • Before this MR: the SBOM gives 3 rows at 3rd Party Input File Path Unknown (commons-io, commons-text, log4j-core).
  • After this MR: the same 3 rows at core/pom.xml, the path GitLab gives these packages.
  • GitLab's own SBOM of the same project is unchanged: core/pom.xml has 5 rows.

References

Screenshots or screen recordings

No UI change.

How to set up and validate locally

  1. In a Rails console on a development instance run Feature.enable(:third_party_sbom_support).
  2. Create a project, add an SBOM of one of the kinds below and a .gitlab-ci.yml job that uploads it as artifacts:reports:cyclonedx, and run the pipeline.
  3. Open the Dependency List and read the location of each row, or the dependencies GraphQL field (name, version, packager, location { path }).
    • A Syft SBOM of a Maven project.
      • Expected: 3 rows at core/pom.xml (commons-io, commons-text, log4j-core).
    • A Grype SBOM trimmed to three packages, with vulnerabilities removed.
      • Expected: 3 rows, app/package-lock.json for accepts and express, java/pom.xml for commons-collections.
    • An SBOM with no Syft properties.
      • Expected: 4 rows at the default location (commons-io, commons-text, log4j-core and lodash).
  4. Add a GitLab DS analyzer SBOM, for example the SBOM of the Maven core module.
    • Expected: 5 rows at core/pom.xml, package manager maven.

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.

Edited by Igor Frenkel

Merge request reports

Loading
Loading