Read the source files of a Trivy filesystem SBOM

What does this MR do and why?

This MR lists each package of a Trivy directory scan at the name of every manifest component whose dependency edges reach it, because Trivy sets no path on a package but adds a component for each scanned manifest, named after the file, and the issue lists a package at the manifest that declares it.

  • Normalizer::Trivy is a new format class, added after Cdxgen. It is built from the whole document and reads the dependency edges.
  • Normalizer::Trivy takes a component as a manifest when it has type application, no package URL and the property aquasecurity:trivy:Class set to lang-pkgs, which leaves out the operating system component of an image scan.
  • A manifest lists every package its edges reach, directly or through other packages. Trivy lists only the direct packages under a manifest, and the GitLab DS analyzer lists every package at its manifest.
    • A manifest name is listed once even when several manifest components have it.
  • A package that no manifest reaches keeps the default location.

This MR is the sixth of 8 in a stack. The next one is Read the location Trivy records on a package (!264256) • Unassigned • 19.7.

Example

Components of a Trivy 0.74.0 SBOM of a Maven project (trimmed): the manifest component foo/pom.xml and its dependency edge, which leads to the package foo and from there to the rest.

{
  "bom-ref": "5f27317f-1170-4a33-85e7-288b31eba9a3",
  "type": "application",
  "name": "foo/pom.xml",
  "properties": [
    { "name": "aquasecurity:trivy:Class", "value": "lang-pkgs" }
  ]
}
{
  "ref": "5f27317f-1170-4a33-85e7-288b31eba9a3",
  "dependsOn": [ "edc901c9-b119-4475-acb5-23326e28aac9" ]
}
  • Before this MR: the SBOM gives 11 rows at 3rd Party Input File Path Unknown.
  • After this MR: 27 rows.
    • core/pom.xml, 6 rows: the 5 GitLab lists and core 1.0.0.
    • foo/pom.xml, 10 rows: the 9 GitLab lists and foo 1.0.0.
    • pom.xml, 11 rows: the eleven packages of the SBOM, at the aggregate manifest GitLab does not list.
  • The 5 library rows at core/pom.xml and the 9 at foo/pom.xml match GitLab's on package and version.
    • The other rows are not in GitLab's result.
  • GitLab's own SBOM of the same project is unchanged: core/pom.xml has 5 rows and foo/pom.xml has 9 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 Trivy SBOM of a multi-module Maven project.
      • Expected: 27 rows, as above.
    • A Trivy SBOM of a Poetry project.
      • Expected: 8 rows at poetry.lock (certifi, chardet, idna, jinja2, markupsafe, pyyaml, requests, urllib3).
    • A Trivy SBOM of a container image, which has no manifest component.
      • Expected: 3 rows, accepts and commons-collections at the default location, and musl, an operating system package, with no path.
  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