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::Formatis a new base class for the format of a generator, andNormalizer::Syftis the first format class. The normalizer builds one entry for each source file of a package.Normalizer::Syft#source_filesreturns 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.
- A blank value and a value that is only
Normalizer::Properties.valuesreads 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_filesreturns 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.xmlhas 5 rows.
References
Screenshots or screen recordings
No UI change.
How to set up and validate locally
- In a Rails console on a development instance run
Feature.enable(:third_party_sbom_support). - Create a project, add an SBOM of one of the kinds below and a
.gitlab-ci.ymljob that uploads it asartifacts:reports:cyclonedx, and run the pipeline. - Open the Dependency List and read the location of each row, or the
dependenciesGraphQL 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).
- Expected: 3 rows at
- A Grype SBOM trimmed to three packages, with vulnerabilities removed.
- Expected: 3 rows,
app/package-lock.jsonfor accepts and express,java/pom.xmlfor commons-collections.
- Expected: 3 rows,
- An SBOM with no Syft properties.
- Expected: 4 rows at the default location (commons-io, commons-text, log4j-core and lodash).
- A Syft SBOM of a Maven project.
- Add a GitLab DS analyzer SBOM, for example the SBOM of the Maven
coremodule.- Expected: 5 rows at
core/pom.xml, package manager maven.
- Expected: 5 rows at
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.