Show the package manager of the packages of a third-party SBOM

What does this MR do and why?

This MR gives each package of an SBOM that no GitLab analyzer wrote the package manager that the SBOM records, or else the default of its package URL type, so the Dependency List shows one where the SBOM records none. A package URL type does not name the tool, because pypi can be pip, poetry or uv. The code therefore takes the first of these that applies and does not read the name of the file that declares the package.

  • The package manager Trivy records on a package in aquasecurity:trivy:PkgType, mapped by master's existing map (pom gives maven).
    • Normalizer::Trivy#package_manager reads it from any SBOM that has the property, not only one that names Trivy.
    • The normalizer takes the package manager of the first format that records one, and Normalizer::Format#package_manager returns none.
  • The default of the package URL type: pypi gives pip, npm gives npm, maven gives maven, gem gives bundler, and the other types of the issue's table follow.
    • apk, deb, rpm, cbl-mariner and wolfi have none.
  • An operating system package gets no package manager from this code, so it keeps the one master reads for it.

The parser sets Component#package_manager to the package manager that the SBOM records, or else the default of the package URL type from Normalizer::PackageManager.for. OccurrenceMap reads it before the package manager in the properties of the component.

This MR is the last of 8 in a stack.

Example

A component of a cdxgen 13.0.1 SBOM of a yarn project (trimmed): no property names a package manager.

{
  "name": "lodash",
  "version": "4.17.20",
  "purl": "pkg:npm/lodash@4.17.20",
  "properties": [
    { "name": "internal:SrcFile", "value": "yarn.lock" }
  ]
}
  • Before this MR: the SBOM gives 4 rows at yarn.lock (debug 4.1.1, lodash 4.17.20, minimist 1.2.5, ms 2.1.3), each with no package manager (the GraphQL packager is null).
  • After this MR: the same 4 rows at yarn.lock, package manager npm, the default of npm.
    • Path and version equal GitLab's.
  • GitLab's own SBOM of the same project is unchanged: it has 4 rows at yarn.lock with package manager yarn.

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 cdxgen SBOM of a yarn project.
      • Expected: 4 rows at yarn.lock, package manager npm.
    • A Syft SBOM of a Maven project.
      • Expected: 3 rows at core/pom.xml, package manager maven.
    • An SBOM with no file and no property.
      • Expected: 4 rows at the default location, commons-io (maven), commons-text (maven), lodash (npm) and log4j-core (maven).
    • An SBOM with one package listed at poetry.lock.
      • Expected: 1 row at poetry.lock, requests (pip, the default of pypi).
      • Its property gitlab:dependency_scanning:package_manager:name with the value pip is ignored.
    • A Trivy SBOM of a Poetry project.
      • Expected: 8 rows at poetry.lock (poetry), the same as with master's Trivy map alone.
  4. Add a GitLab DS analyzer SBOM, for example the SBOM of the yarn project.
    • Expected: 4 rows at yarn.lock, package manager yarn.

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