savoirfairelinux / meta-cyclonedx

A Yocto meta-layer for generating CycloneDX SBOMs
Other
2 stars 1 forks source link

Add option to limit SBOM content to packages added to the rootfs #9

Open Jasper-Ben opened 2 weeks ago

Jasper-Ben commented 2 weeks ago

Currently, meta-cyclonedx will add any package that is built for the target architecture to the SBOM.

This might be desirable, as the package list might be incomplete otherwise (e.g. code might "spill over" from one package to another when doing static linking), however on the flip-side this also drastically increases the number of packages included in the sbom, with most of them not being relevant at runtime (see: https://github.com/savoirfairelinux/meta-cyclonedx/pull/3#issuecomment-2247573164).

So while both options are not ideal, it would be great to be able to leave it up to the user to decide whether drastically limiting the number of packages in the SBOM is worth the (probably manageable) risk of potentially losing track of a handful of packages that do somehow end up on the target "undetected".

For this to work, we need to restructure the way meta-cyclonedx creates the SBOM file, as the information which packages end up in the rootfs is only available after the image rootfs has been constructed and not in the context of a component recipe (see: https://github.com/savoirfairelinux/meta-cyclonedx/issues/7#issuecomment-2317327290)

groetingc commented 2 weeks ago

Hi @Jasper-Ben ! Could the way of creating a SBOM done similar as Yocto's default https://git.yoctoproject.org/poky/tree/meta/classes/create-spdx.bbclass?h=kirkstone class does a good starting point? It looks more complex but it also uses the image_list_installed_packages to ensure that only packages are listed in the SBOM, which are really installed. A usage of that class in conjunction of a transformation tool convertings a SPDX bom to CycloneDX bom could be also an option, isn't it? BR, Claus

Jasper-Ben commented 2 weeks ago

A usage of that class in conjunction of a transformation tool convertings a SPDX bom to CycloneDX bom could be also an option, isn't it?

@groetingc You could look into that if you want, but I am not sure how well these tools work. The output of the create-spdx class is quite complex with multiple SBOMs referencing each other. It also contains a lot of information that we (at least for our use-case of CVE monitoring) aren't currently interested in. I have tried working with the SPDX java and python tools in the past and had a horrible experience with large SPDX files such as the Yocto ones. Though, I am not sure how the current state of things are now.

Personally, I feel like for the time being it would be easier and quicker to just change our current setup to write the bom information into temporary files and then have a post build task collect these into the final output while using the image_list_installed_packages function.

Jasper-Ben commented 5 days ago

@groetingc FYI, I will start working on this next. However, I am on vacation for two weeks starting from next week. I don't think I'll be able to finish this before then, so there will be a slight delay

iat-coder commented 5 days ago

That would be a great feature to have. Instead of a switch - maybe just output both SBOMs (build-time and run-time)? I needed this recently and ended up hacking poky classes (sieve through the generated SBOM and only keep those that relate to the installed packages). Achieved what I needed but very messy. I think image_list_installed_packages is only available in the image layer, not sure how to get a list of installed packages otherwise.

A run-time SBOM is essential when it comes to cybersecurity risk analysis as it significantly reduced the number of components and therefore the number of CVEs associated with them.