diff mbox series

[v5,2/3] spdx30: Add the PURLs of the source downloads to the output packages

Message ID 20261126230732.2708012-3-stondo@gmail.com
State New
Headers show
Series spdx30: identity and purls of dependency downloads | expand

Commit Message

Stefano Tondo Nov. 26, 2026, 11:07 p.m. UTC
From: Stefano Tondo <stefano.tondo.ext@siemens.com>

Statically linked code, for example a Rust crate, is part of the
binary. But the SPDX of the output package only names the recipe, so
a vulnerability scanner that checks the packages of an image does not
find the dependency.

Add the PURLs of the source downloads to the external identifiers of
each output package. The software_packageUrl of the package stays the
first PURL in SPDX_PACKAGE_URLS.

All downloads with a PURL go in, also the ones that are not in the
binary. For example, a Cargo.lock lists crates that only run at build
time and crates for other platforms. So a scanner can report a crate
that the package does not contain. To leave such downloads out, the
SPDX needs a lifecycle scope for each dependency. That is a separate
proposal.

Signed-off-by: Stefano Tondo <stefano.tondo.ext@siemens.com>
---
 meta/lib/oe/spdx30_tasks.py | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/meta/lib/oe/spdx30_tasks.py b/meta/lib/oe/spdx30_tasks.py
index eded315819..8f4e3dc4fc 100644
--- a/meta/lib/oe/spdx30_tasks.py
+++ b/meta/lib/oe/spdx30_tasks.py
@@ -597,11 +597,11 @@  def add_custom_annotations(d, objset, obj):
         )
 
 
-def set_purls(spdx_package, purls):
+def set_purls(spdx_package, purls, dependency_purls=()):
     if purls:
         spdx_package.software_packageUrl = purls[0]
 
-    for p in sorted(set(purls)):
+    for p in sorted(set(purls) | set(dependency_purls)):
         spdx_package.externalIdentifier.append(
             oe.spdx30.ExternalIdentifier(
                 externalIdentifierType=oe.spdx30.ExternalIdentifierType.packageUrl,
@@ -979,6 +979,14 @@  def create_spdx(d):
     source_files = add_download_files(d, build_objset)
     build_inputs |= source_files
 
+    # The output packages inherit the PURLs of the downloads they are built
+    # from, as the code of statically linked dependencies is in them.
+    dependency_purls = {
+        dl.software_packageUrl
+        for dl in source_files
+        if getattr(dl, "software_packageUrl", None)
+    }
+
     recipe_spdx_license = add_license_expression(
         d, build_objset, d.getVar("LICENSE"), license_data, [recipe_objset]
     )
@@ -1092,7 +1100,7 @@  def create_spdx(d):
                 or ""
             ).split()
 
-            set_purls(spdx_package, purls)
+            set_purls(spdx_package, purls, dependency_purls)
 
             pkg_objset.new_scoped_relationship(
                 [oe.sbom30.get_element_link_id(build)],