Skip to content

Commit dd0ca1b

Browse files
committed
📝 Add python-sbom
1 parent 8558933 commit dd0ca1b

2 files changed

Lines changed: 62 additions & 15 deletions

File tree

‎CHANGELOG.rst‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ emergencies when we need to start branches for older versions.
2323
Added
2424
~~~~~
2525

26+
* 📝 Add python-sbom
2627
* 📝 Add git mergetool
2728
* 📝 Adopt Git 2.56 features
2829

‎docs/productive/security/sbom.rst‎

Lines changed: 61 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -157,24 +157,35 @@ PEP 770 – SBOMs in Python packages
157157
file when they install your package, for example:
158158

159159
.. code-block:: console
160+
:emphasize-lines: 4-
160161
161-
myapp-26.2.0.dist-info
162+
cusy_tasks-26.2.0.dist-info
162163
├── METADATA
163164
├── RECORD
164-
└── sboms/
165-
└── myapp.cdx.json
165+
└── sboms
166+
   └── cusy-tasks.cdx.json
166167
167-
Build backends such as Hatchling ≥ 1.28 already support this via the
168-
``sbom-files`` configuration:
168+
`python-sbom <https://python-sbom.readthedocs.io/en/latest/>`_ supports this for
169+
many build backends; for :term:`uv`, for example, with:
169170

170171
.. code-block:: toml
171172
:caption: pyproject.toml
172173
173-
[tool.hatch.build.targets.wheel]
174-
sbom-files = ["myapp.cdx.json"]
174+
[build-system]
175+
build-backend = "python_sbom.backend"
176+
requires = [ "uv-build", "python-sbom" ]
177+
...
178+
[tool.python-sbom]
179+
build-backend = "uv_build"
180+
supplier = { name = "Veit Schiele", url = [ "https://github.com/veit" ] }
175181
176-
Instead of generating the SBOM file from scratch during the build, a minimal
177-
CycloneDX SBOM file can be checked into the repository:
182+
.. seealso::
183+
184+
However, other backends are also supported: `Set it up for a build backend
185+
<https://python-sbom.readthedocs.io/en/latest/how-to/backends/index.html>`_.
186+
187+
Alternatively, you can also check the SBOM file into the repository using a
188+
minimal CycloneDX SBOM file:
178189

179190
.. code-block:: json
180191
@@ -185,7 +196,7 @@ CycloneDX SBOM file can be checked into the repository:
185196
"metadata": {
186197
"component": {
187198
"type": "library",
188-
"name": "mylib",
199+
"name": "cusy.tasks",
189200
"version": "0.0.0-placeholder"
190201
}
191202
},
@@ -200,11 +211,46 @@ the wheel is published to PyPI.
200211
Analysis
201212
--------
202213

203-
There are numerous tools available for security and licence checks, each
204-
focusing on different areas of concern. Two open-source tools for SBOM analysis
205-
are `Dependency Track <https://dependencytrack.org>`_ and `GUAC
206-
<https://guac.sh>`_. With ``sbomify-action``, you can upload SBOMs from the CI
207-
pipeline directly to your Dependency Track instance using:
214+
There are numerous tools available for validation, each focusing on different
215+
problem areas. You can easily validate the SBOM file using ``python-sbom
216+
validate``. To do this, you must first install the ``validate`` extra:
217+
218+
.. code-block:: console
219+
220+
$ uv add --group dev 'python-sbom[validate]'
221+
222+
You can then check your wheel using
223+
224+
.. code-block:: console
225+
226+
$ uv run python-sbom validate dist/
227+
SBOM in cusy_tasks-26.2.0-py3-none-any.whl is valid
228+
229+
You can also render the SBOM file as an SPDX using
230+
231+
.. code-block:: console
232+
233+
$ unzip -p dist/cusy_tasks-26.2.0-py3-none-any.whl '*/sboms/cusy-tasks.cdx.json' > cusy-tasks.cdx.json
234+
$ uv run python-sbom spdx cusy-tasks.cdx.json cusy-tasks.spdx.json
235+
236+
.. hint::
237+
Two things are omitted here, which SPDX 2.3 cannot include:
238+
239+
* the file-specific hashes, as SPDX 2.3 requires an SHA-1 hash for each file,
240+
whilst :file:`RECORD` files in :term:`Wheels <Wheel>` contain SHA-256
241+
* the build entry.
242+
243+
The SPDX rendering can also be checked using
244+
245+
.. code-block:: console
246+
247+
$ uv run python-sbom validate cusy-tasks.spdx.json
248+
249+
* `Dependency Track <https://dependencytrack.org>`_
250+
* `GUAC <https://guac.sh>`_
251+
252+
And with ``sbomify-action``, you can upload SBOMs from the CI pipeline directly
253+
to your Dependency Track instance using:
208254

209255
.. code-block:: yaml
210256

0 commit comments

Comments
 (0)