Add props field to SBOM component CI parser class
Why are we doing this work
This issue covers the work needed to parse the SBOM report in JSON format, and include the components' Trivy properties should they exist.
Relevant links
Non-functional requirements
-
Documentation: -
Feature flag: -
Performance: -
Testing: Add unit tests/specs to verify that the CI parsing occurs as expected.
Implementation plan
-
Update the Gitlab::Ci::Parsers::Sbom::CyclonedxProperties
class.-
Add the Trivy CycloneDX properties to the supported properties const.
-
Add a
Gitlab::Ci::Parsers::Sbom::Source::Trivy
class that inherits from theSbom::Source::BaseSource
class. It should implement thetype
method so that it returns:trivy
. -
Add a
TRIVY_PREFIX = 'aquasecurity:trivy:'
const and allow it as a valid prefix. This will also need to be clipped if it exists. Alternatively, this can be refactored so that the class can validate aSUPPORTED_PREFIXES
list instead.return unless SUPPORTED_PREFIXES.any? { |prefix| name.start_with?(prefix) } namespaced_name = SUPPORTED_PREFIXES.find { |prefix| name.starts_with(prefix) }.then { |prefix| name.delete_prefix(prefix) }
-
-
Add specs to test that the Trivy properties are properly parsed into a namespaced hash.
Input
{ "aquasecurity:trivy:FilePath": "/usr/local/lib/node_modules/pkgA/package.json }
Expect
{ "trivy": { "FilePath": "/usr/local/lib/node_modules/pkgA/package.json" } }
-
Update the Gitlab::Ci::Parsers:Sbom::Component
class- Add a
props
attribute and an attribute reader. Initialize the class with this attribute as aprops
arg.
- Add a
-
Update the Gitlab::Ci::Parsers:Sbom::Cyclonedx
class- Update the
#parse_components
method so that it parses the properties with theCyclonedxProperties.parse_source
method.
- Update the
Verification steps
This won't be user visible, so we'll rely on the rspec test suites to verify that the tests work as expected. To manually test, do the following:
- Checkout the corresponding branch
- Parse an SBOM component JSON string that contains the Trivy properties
- Inspect the parsed component object's
props
attribute and verify that it contains the allowed Trivy properties.