Convert SBOM Generation from Java to Python#4442
Conversation
clone repository -> clone repo
… path to placeholder
Replace cyclonedx-core-java with cyclonedx-python-lib, add temporary json post-processing script to inject workflows, since they are not currently supported in python, add sbom_venv to gitignore to ensure a clean python installation Co-authored-by: GitHub Copilot <copilot@github.com>
|
Thank you for creating a pull request! |
|
I am not sure injecting the missing support via a script is going to be a great solution in the long term, as it’s likely to be vulnerable to schema issues, and adds an extra step that the TemurinGenSBOM.py can’t use directly. The managing python venv is also a typical issue with Python, which we haven't had to resolve with temurin build.sh since we don't currently use Python. I have been also doing some work with the CycloneDX Attestation tool, which is also not available in python. I think although this may work, it's not architecturally the right direction, given the python libraries limited schema support. |
I agree, the "injection script" would only be a temporary solution until the official CycloneDX 1.6 support for python is released though. Feel free to archive this PR. |
Description
This PR transitions our SBOM generation from the Java tool to the official cyclonedx-python-lib.
The changes have only been tested on Linux so far.
Resolves #4421.
Note: Please merge #4429 before merging this PR.
Workarounds and Changes
1.
Currently, the official cyclonedx-python-lib does not natively support the CycloneDX 1.6 formulation objects/array. To still migrate to python while still having a valid JSON without patching the library's internals, I have implemented a temporary "post-processing" script (temporary_sbom_post_processing.py). It injects the formulation workflows into the finished JSON at the very end of the pipeline i.e. at the end of generateSBoM().
All locations related to this temporary workaround are tagged with "TODO (CycloneDX 1.6)" for easy searching. Once the upstream library adds native support, the migration will look like this:
You can find this text in the source code of build.sh as well.
2.
For some reason, the cyclonedx-python-lib has a adifferent key ordering in the json. For now, I fixed this using a hardcoded constant that defines the order of keys. This can be removed later, if I get confirmation that the order is indeed irrelevant (as it should be for jsons anyway)
3.
To avoid externally-managed-environment errors, the build script creates a temporary Python virtual environment now (sbom_venv) for the SBOM generation. sbom_venv has been added to .gitignore.
Showcase
Here are two SBOMs (not from the same JDK or build script), one generated with the current Java implementation, the other generated with the new Python implementation.
jdk-hotspot-sbom-python.json
jdk-hotspot-sbom-java.json