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::CyclonedxPropertiesclass.-
Add the Trivy CycloneDX properties to the supported properties const.
-
Add a
Gitlab::Ci::Parsers::Sbom::Source::Trivyclass that inherits from theSbom::Source::BaseSourceclass. It should implement thetypemethod 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_PREFIXESlist 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::Componentclass- Add a
propsattribute and an attribute reader. Initialize the class with this attribute as apropsarg.
- Add a
-
Update the Gitlab::Ci::Parsers:Sbom::Cyclonedxclass- Update the
#parse_componentsmethod so that it parses the properties with theCyclonedxProperties.parse_sourcemethod.
- 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
propsattribute and verify that it contains the allowed Trivy properties.