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::Trivyis a new format class, added afterCdxgen. It is built from the whole document and reads the dependency edges.Normalizer::Trivytakes a component as a manifest when it has typeapplication, no package URL and the propertyaquasecurity:trivy:Classset tolang-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.xmland the 9 atfoo/pom.xmlmatch 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.xmlhas 5 rows andfoo/pom.xmlhas 9 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 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).
- Expected: 8 rows at
- 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.
- A Trivy SBOM of a multi-module 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.