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 (pomgivesmaven).Normalizer::Trivy#package_managerreads 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_managerreturns none.
- The default of the package URL type:
pypigives pip,npmgives npm,mavengives maven,gemgives bundler, and the other types of the issue's table follow.apk,deb,rpm,cbl-marinerandwolfihave 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 GraphQLpackageris null). - After this MR: the same 4 rows at
yarn.lock, package manager npm, the default ofnpm.- Path and version equal GitLab's.
- GitLab's own SBOM of the same project is unchanged: it has 4 rows at
yarn.lockwith package manager yarn.
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 cdxgen SBOM of a yarn project.
- Expected: 4 rows at
yarn.lock, package manager npm.
- Expected: 4 rows at
- A Syft SBOM of a Maven project.
- Expected: 3 rows at
core/pom.xml, package manager maven.
- Expected: 3 rows at
- 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 ofpypi). - Its property
gitlab:dependency_scanning:package_manager:namewith the valuepipis ignored.
- Expected: 1 row at
- A Trivy SBOM of a Poetry project.
- Expected: 8 rows at
poetry.lock(poetry), the same as with master's Trivy map alone.
- Expected: 8 rows at
- A cdxgen SBOM of a yarn project.
- Add a GitLab DS analyzer SBOM, for example the SBOM of the yarn project.
- Expected: 4 rows at
yarn.lock, package manager yarn.
- Expected: 4 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.