Skip to content

Commit b492079

Browse files
authored
PEP 770: Add sections for Users, Projects, and SCA tools in 'How to Teach' (#4222)
1 parent 1fb889b commit b492079

File tree

1 file changed

+114
-27
lines changed

1 file changed

+114
-27
lines changed

peps/pep-0770.rst

Lines changed: 114 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,19 @@ Post-History:
1515
Abstract
1616
========
1717

18+
Almost all Python packages today are accurately measurable by software
19+
composition analysis (SCA) tools. For projects that are not accurately
20+
measurable, there is no existing mechanism to annotate a Python package
21+
with composition data to improve measurability.
22+
1823
Software Bill-of-Materials (SBOM) is a technology-and-ecosystem-agnostic
1924
method for describing software composition, provenance, heritage, and more.
20-
SBOMs are used as inputs for software composition analysis (SCA) tools,
21-
such as scanners for vulnerabilities and licenses, and have been gaining
22-
traction in global software regulations and frameworks.
25+
SBOMs are used as inputs for SCA tools, such as scanners for vulnerabilities and
26+
licenses, and have been gaining traction in global software regulations and
27+
frameworks.
2328

2429
This PEP proposes using SBOM documents included in Python packages as a
25-
means to improve software measurability for Python packages.
30+
means to improve automated software measurability for Python packages.
2631

2732
The changes will update the
2833
`Core Metadata specification <coremetadataspec_>`__ to version 2.5.
@@ -141,37 +146,60 @@ In addition to the above, an informational PEP will be created for tools
141146
consuming included SBOM documents and other Python package metadata to
142147
generate complete SBOM documents for Python packages.
143148

149+
Terminology
150+
-----------
151+
152+
This section describes terminology used later in the document:
153+
154+
.. glossary::
155+
156+
root SBOM directory
157+
The directory under which SBOM files are stored in a
158+
:term:`project source tree`, :term:`distribution archive`
159+
or :term:`installed project`.
160+
Also, the root directory that their paths
161+
recorded in the :ref:`Sbom-File <770-spec-sbom-file-field>`
162+
:term:`Core Metadata field` are relative to.
163+
Defined to be the :term:`project root directory`
164+
for a :term:`project source tree` or
165+
:term:`source distribution <Source Distribution (or "sdist")>`;
166+
and a subdirectory named ``sboms`` of
167+
the directory containing the :term:`built metadata`—
168+
i.e., the ``.dist-info/sboms`` directory—
169+
for a :term:`Built Distribution` or :term:`installed project`.
170+
144171
.. _770-spec-core-metadata:
145172

146173
Core Metadata
147174
-------------
148175

176+
.. _770-spec-sbom-file-field:
177+
149178
Add ``Sbom-File`` field
150179
~~~~~~~~~~~~~~~~~~~~~~~
151180

152-
The ``Sbom-File`` is an optional Core Metadata field. Each instance contains a
153-
string representation of the path of an SBOM document. The path is located
154-
within the project source tree, relative to the project root directory. It is a
181+
The ``Sbom-File`` is a new optional Core Metadata field. Each instance contains a
182+
string representation of the path to an SBOM document. The path is specified
183+
relative to the :term:`root SBOM directory` for all project types. It is a
155184
multi-use field that MAY appear zero or more times and each instance lists the
156185
path to one such file. Files specified under this field are SBOM documents
157186
that are distributed with the package.
158187

159188
As `specified by this PEP <#770-spec-project-formats>`__, its value is also
160-
that file's path relative to the root SBOM directory in both installed projects
161-
and the standardized Distribution Package types.
189+
that file's path relative to the :term:`root SBOM directory` in both installed
190+
projects and the standardized Distribution Package types.
162191

163192
If an ``Sbom-File`` is listed in a
164193
:term:`Source Distribution <Source Distribution (or "sdist")>` or
165194
:term:`Built Distribution`'s Core Metadata:
166195

167196
* That file MUST be included in the :term:`distribution archive` at the
168-
specified path relative to the root SBOM directory.
197+
specified path relative to the :term:`root SBOM directory`.
169198
* Installers MUST install the file with the :term:`project` at that same
170199
relative path.
171-
* Inside the root SBOM directory, packaging tools MUST reproduce the directory
172-
structure under which the source files are located relative to the project
173-
root. The root SBOM directory is
174-
`specified in a later section <#770-spec-project-formats>`__.
200+
* Inside the :term:`root SBOM directory`, packaging tools MUST reproduce the
201+
directory structure under which the source files are located relative to the
202+
project root.
175203
* Path delimiters MUST be the forward slash character (``/``), and parent
176204
directory indicators (``..``) MUST NOT be used.
177205

@@ -191,10 +219,10 @@ This PEP specifies changes to the project's source metadata under a
191219
Add ``sbom-files`` key
192220
~~~~~~~~~~~~~~~~~~~~~~
193221

194-
A new ``sbom-files`` key is added to the ``[project]`` table for specifying
195-
paths in the project source tree relative to ``pyproject.toml`` to file(s)
196-
containing SBOMs to be distributed with the package. This key corresponds to the
197-
``Sbom-File`` fields in the Core Metadata.
222+
A new optional ``sbom-files`` key is added to the ``[project]`` table for
223+
specifying paths in the project source tree relative to ``pyproject.toml`` to
224+
file(s) containing SBOMs to be distributed with the package. This key
225+
corresponds to the ``Sbom-File`` fields in the Core Metadata.
198226

199227
Its value is an array of strings which MUST contain valid glob patterns, as
200228
specified below:
@@ -371,18 +399,76 @@ of this standard. The details of this standard are most important to either
371399
maintainers of Python packages and developers of SCA tools such as
372400
SBOM generation tools and vulnerability scanners.
373401

374-
Most Python packages don't contain code from other software components and thus
375-
are already measurable by SCA tools without the need of this standard or
376-
additional SBOM documents. Pure-Python packages are about `~90% <pypi-data_>`__
377-
of popular packages on PyPI.
402+
What do Python package maintainers need to know?
403+
------------------------------------------------
404+
405+
Python package metadata can already describe the top-level software included in
406+
a package archive, but what if a package archive contains other software
407+
components beyond the top-level software? For example, the Python wheel for
408+
"Pillow" contains a handful of other software libraries bundled inside, like
409+
``libjpeg``, ``libpng``, ``libwebp``, and so on. This scenario is where this PEP
410+
is most useful, for adding metadata about bundled software to a Python package.
411+
412+
Some build tools may be able to automatically annotate bundled dependencies.
413+
Typically tools can automatically annotate bundled dependencies when those
414+
dependencies come from a "packaging ecosystem" (such as PyPI, Linux distros,
415+
Crates.io, NPM, etc).
416+
417+
For packages which cannot be automatically annotated and if the package author
418+
wishes to provide an SBOM the approach will be to generate or author SBOM files
419+
and then include those files using ``pyproject.toml``:
420+
421+
.. code-block:: toml
422+
423+
[project]
424+
...
425+
sbom-files = [
426+
"sboms/bom.cdx.json"
427+
]
428+
429+
For projects manually specifying an SBOM document the challenge will be
430+
keeping the document up-to-date. The CPython project has some
431+
`customized tooling <https://github.com/python/cpython/blob/main/Tools/build/generate_sbom.py>`__
432+
for this task, but it can likely be generalized into a tool reusable by other
433+
projects.
434+
435+
What do SBOM tool authors need to know?
436+
---------------------------------------
378437

379-
For projects that do contain other software components, documentation will be
380-
added to the Python Packaging User Guide for how to specify and maintain
381-
SBOM documents for Python packages in source code.
438+
Developers of SBOM generation tooling will need to know about the existence
439+
of this PEP and that Python packages may begin publishing SBOM documents
440+
within package archives. This information needs to be included as a part of
441+
generating an SBOM document for a particular Python package or Python
442+
environment.
382443

383444
A follow-up informational PEP will be authored to describe how to transform
384445
Python packaging metadata, including the mechanism described in this PEP,
385-
into an SBOM document describing Python packages.
446+
into an SBOM document describing Python packages. Once the informational PEP is
447+
complete, tracking issues will be opened specifically linking to the
448+
informational PEP to spur the adoption of PEP 770 by SBOM tools.
449+
450+
A `benchmark is being created <https://github.com/psf/sboms-for-python-packages/tree/main/benchmark>`__
451+
to compare the outputs of different SBOM tools when run with various Python
452+
packaging inputs (package archive, installed package, environment, container
453+
image) is being created to track the progress of different SBOM generation
454+
tools. This benchmark will inform where tools have gaps in support
455+
of this PEP and Python packages.
456+
457+
What do users of SBOM documents need to know?
458+
---------------------------------------------
459+
460+
Many users of this PEP won't know of its existence, instead their software
461+
composition analysis tools, SBOM tools, or vulnerability scanners will simply
462+
begin giving more comprehensive information after an upgrade. For users that are
463+
interested in the sources of this new information, the "tool" field of SBOM
464+
metadata already provides linkages to the projects generating their SBOMs.
465+
466+
For users who need SBOM documents describing their open source dependencies the
467+
first step should always be "create them yourself". Using the benchmarks above
468+
a list of tools that are known to be accurate for Python packages can be
469+
documented and recommended to users. For projects which require
470+
additional manual SBOM annotation: tips for contributing this data and tools for
471+
maintaining the data can be recommended.
386472

387473
Reference Implementation
388474
========================
@@ -433,7 +519,8 @@ Open Issues
433519
Conditional project source SBOM files
434520
-------------------------------------
435521

436-
How can a project specify an SBOM file that is conditional? Under what circumstances would an SBOM document be conditional?
522+
How can a project specify an SBOM file that is conditional? Under what
523+
circumstances would an SBOM document be conditional?
437524

438525
References
439526
==========

0 commit comments

Comments
 (0)