From patchwork Wed Nov 18 09:29:24 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Tondo X-Patchwork-Id: 104735 Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) by mx.groups.io with SMTP id smtpd.msgproc01-g2.9017.1794994172322220321 for ; Wed, 18 Nov 2026 01:29:32 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@gmail.com header.s=20260707 header.b=H2brYiby; spf=pass (domain: gmail.com, ip: 209.85.128.44, mailfrom: stondo@gmail.com) Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-4a9a8d6cea8so6471265e9.1 for ; Wed, 18 Nov 2026 01:29:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1794994170; x=1795598970; darn=lists.openembedded.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=xO0OOZkadpAthd17lMA31hFxO3/QewgAd0/TDcrDg1w=; b=H2brYibysgaWw32mvARCZNPr1Buu47UQ0zW8IPNXr97MaCeSd/zyPtfT9fX4d6G/lu kv1IC7cw7DtCXHkZQ7p8j07zeaNm3EbA8zig2jcIh79ktR5+Y23UXoR0l47OqwrL1FL8 agg/ocIPw1hfKeEYBxUeyh93/IEA5f3BefwDTub1L0uOmyiaI48MPpNjxf7JWlY76ulH TZ0LAxD86w4x0C7G08fUYza/Eg0uuLkEdsXWi8d32+nk2w2MMpkRi/DwM553Czswwwn2 Zh16Bgwixpeh1L4jSjuRlXSenOOkxIcwz7VKqIYozn7AHOPwSIgAzxsRf6rd5Gj4zjkK NApw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794994170; x=1795598970; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=xO0OOZkadpAthd17lMA31hFxO3/QewgAd0/TDcrDg1w=; b=Vfi/lGUQuM6esABvk5Qdz3dQW8tTV9cJuW9kFVUbiFi/dC1h6WV8nKG04CfP4VT2x7 mQ133OC4bZWjO5JSpvJw2jxq1wFM3m9djKGOLjUNZ2/3OFETs9HUk7h4Ni7dv4dcZCKk 1mO2BVP/0y6w1bL6Y/KFkqfbsHa2wbpMM0hc9WogPQYCehSe75Nuwyx4vfEkovnoONoC IB7TeKhmaZsRiqqbA3NsHPBdI1n1oi8nvkHW+2I2iQcXZFtnwx8IabxHQFZCHiOdbqTj PHjqk4Q6stLn4WT+R5BdWREIQLKsC7M1jsq3YETAFMzpBvGHt7QO85RhRgqhyHtydN9B HRrw== X-Gm-Message-State: APuU4Z+j8+pni6gGUYRGu9FB91kZ2da6hzeU58qYIIYB2qBi2CCfNtLp /Rp3xsvt+PHzg3ks7uQOx/1VnjZVF/n4u6S3DkbHlZI3mF2XdY7Hc1xeQNGuvQ== X-Gm-Gg: AYBFou1edqkwkWcYCyOPMp/SviLGGKmCKkJvsHeXzcQEeCqX7t4UmJlosfWKZcVc+s8 pYq4V5ScehRkUPPKj7ZJ77VUZjlCQZ354PxIK2s9gEwf2Dweedt1p4TzoGNVi0SZEEFlWA860P8 deuWTd/ragmitmdCQDvyMBTJsaDTUiy62FrWYWJKsUTjteU2hVu1N+a9fx2xZEbVF22BURsjvQK /pq5e5HHdnXlCVVKkLXy/SDoYtCN5azREEbaMUOJwmXIpl25btdlfsAQb8/blad2QG98hNhWJj+ yfW78OHigxm0MfqHwi0Jke4h74Qmyy68vZy5nSH2LF+sMxSxOPON2YOCcMz8XpbdzpOKle/0SNY Cr1RQ8FswoOPRZv8GBdKrkOZl+PcS9WZrD0cTsmqk1s0EETyUoFkT7dAzN81E/NAsg1dyxomBHr QSwFyUZ2Keuez+w01ROI4EUFm77qjokFz3KQYkT6m10u+O1rfsohTDkZKK+5DqZyEikrNIsUi5l IGubibUlZZK3Csj9nduheNR3bOF/hc8yrhl1thhMrrrITUOBCJ8OYPN2KCH/EncnUNc+GvOJIrv mIxeAmTZjam3Rof1bOdynkdJ6/nXcmGX X-Received: by 2002:a05:600c:c167:b0:4b5:d95c:2380 with SMTP id 5b1f17b1804b1-4bb7da238cemr34896085e9.11.1794994170544; Wed, 18 Nov 2026 01:29:30 -0800 (PST) Return-Path: Received: from fedora ([165.225.94.251]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bb7d28ec3asm55486755e9.0.2026.11.18.01.29.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Nov 2026 01:29:29 -0800 (PST) From: Stefano Tondo To: openembedded-core@lists.openembedded.org Cc: Joshua Watt , Alexander Kanavin , Stefan Herbrechtsmeier , Stefano Tondo , Stefano Tondo Subject: [PATCH 1/4] spdx30: Take name, version and PURL of downloads from the fetcher Date: Wed, 18 Nov 2026 10:29:24 +0100 Message-ID: <20261118092927.204959-2-stondo@gmail.com> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261118092927.204959-1-stondo@gmail.com> References: <20261118092927.204959-1-stondo@gmail.com> MIME-Version: 1.0 List-Id: X-Webhook-Received: from 45-33-107-173.ip.linodeusercontent.com [45.33.107.173] by lin-tor-korg-lkml-alma10-1 with HTTPS for ; Wed, 18 Nov 2026 09:29:42 -0000 X-Groupsio-URL: https://lists.openembedded.org/g/openembedded-core/message/250527 From: Stefano Tondo The fetchers of package registries (crate, gomod, npm) know the name and the version of each package they download. Today the SPDX of such a download only has the file name, so an SBOM scanner cannot match the dependency. Ask the fetcher with package_identity() and set the name, the version and the PURL of the download. This needs package_identity() in bitbake. Signed-off-by: Stefano Tondo --- meta/lib/oe/spdx30_tasks.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/meta/lib/oe/spdx30_tasks.py b/meta/lib/oe/spdx30_tasks.py index 6eaa74ce3d..58fe45ec7e 100644 --- a/meta/lib/oe/spdx30_tasks.py +++ b/meta/lib/oe/spdx30_tasks.py @@ -463,6 +463,19 @@ def enrich_source_package(d, dl, fd, file_name, primary_purpose): ) +def set_package_identity(d, dl, fd): + """Set name, version and PURL of a download that names a package. + + Fetchers of package registries (crate, gomod, npm) know which package + a URL downloads, see FetchMethod.package_identity() in bitbake. + """ + identity = fd.method.package_identity(fd, d) + if identity: + dl.name = identity["name"] + dl.software_packageVersion = identity["version"] + dl.software_packageUrl = identity["purl"] + + def add_download_files(d, objset): inputs = set() release_date = get_release_date(d) @@ -528,6 +541,7 @@ def add_download_files(d, objset): ) enrich_source_package(d, dl, fd, file_name, primary_purpose) + set_package_identity(d, dl, fd) if release_date is not None: dl.releaseTime = release_date From patchwork Wed Nov 18 09:29:25 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Tondo X-Patchwork-Id: 104736 Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) by mx.groups.io with SMTP id smtpd.msgproc01-g2.9018.1794994173657344978 for ; Wed, 18 Nov 2026 01:29:33 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@gmail.com header.s=20260707 header.b=WwXSyNuh; spf=pass (domain: gmail.com, ip: 209.85.128.45, mailfrom: stondo@gmail.com) Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-4b467581b98so8620695e9.0 for ; Wed, 18 Nov 2026 01:29:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1794994172; x=1795598972; darn=lists.openembedded.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=CCnKPtUQHSdJWUcsI8ObwiYmflzjvVZtTz8DgENpeSE=; b=WwXSyNuhOy+3FwDDJ9ueaAjix5Nowr7Wix7CgK6IXXHX+Pj2egXTwcvQv8CPXZB1Cl WYR7Z+1XfPEqbrO7ipudu+G8e5LvysuDpsDpND/YZWLX/OfaWWHex3BChLqNAOE5cbtv f332C84QBtEgA2glKL+Rh1Ya3Vfn2ZDN0KXma8MPzUFQlq/HoWSwSg8z5aIy6JgwuJq0 D+sfYIphrHnZ0jlUXfH9cBr+7z/ykJ56Y+xWunJDDLPmbmfXFoKVJAokYYjQLMM7860s z6gjpR0lNZk28+XZz6BnMIIZuutT2AAyHofYJ9LYfK7dSMLA6ZEGVlnejUV9X3wgRx+I eUVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794994172; x=1795598972; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=CCnKPtUQHSdJWUcsI8ObwiYmflzjvVZtTz8DgENpeSE=; b=cL3NbKb7Pv0rj+JG7ttp5INtacHf+Oki2/G36d0f7dP4WEgWW3Du1LWYH9avCCmMmC wUTiouaWvD+lwA5coRyzl4K+r0A+Yfald6PE6CAFIUmqt2Dsd+4f3CRmWO2H+NsqdEBK EdAH7ICEmO4Hcg3rFK4KPYOFtulKnkyZN8IZVmSebpgb/hgB+AtFmP/wXXGkqKnq+RJq vNxkgJ3GCNkLupfCImS80bHA3s3rJmqOYD7HPqZ/1gK7x5r8n9XhDsszsFsOYbhkMrKm R9KLDh1oV6Fr3+Cm1o+C5xuo6jPlPZcuX1FqTC+EEA3MfAMtqKc+ggRECQ+N3WjG8jNL YYWw== X-Gm-Message-State: APuU4Z/ed0EN7GrpqJ3TdYmWXIsN15UV616BaQaeT0iwaJtRkllo9vuq rRmMzlK8XpDCQDEFuPH0rlfrVbSzDg6ZwCADl3acV5IGKyOxsh7HDtJERT/QbQ== X-Gm-Gg: AYBFou0DpVDAI6ojuq2UELhYdR1KUllEY3TBHHDNr2gdTDcl4iQg8zKT6H5caTA4pSM UtKlzva3SXSac+/BGQKWfm7sHaMlyWKRbTs4KKs+oP+gaga/KuuCMSDLwiUz44DQlEfJmiuQXU5 MvwO+4ZXEFsEV5YGx/ONtelKEeiCVjfAxFpbyeSOp3gjNKSvH2bnak3jL++cpvnGiS8kx0ROndb e9yrseNfd9FxRkLGMeuZQF5FW8jUMXGU8oDT5Cngta0AsYmiFfrtkGHpg8/yzmRlEui8AsheanS Ex7iX4PTwV7T0UDVcCQRWQIlXZUdL5lamIaWAwRjv9k7Ohabfs1QN6L9+U8LljPnhYIrrSiwYb+ uX97HGpl5/YpomXLsoy2Pr5AfSHyQR7to/w4qYUsi1XiKNW3Eq3JCbuRcdyART3lXpKhoFfCGmd kFj28GN78vFeKqSV5+KYmTQJ0S2x7hZmu1H0pIpG1KkhZuMEkBOiwc44Hw4J63biPvLHdZiahlo hqOwuBoNUPE6aNIXHQkGkodW03RUs2x6Du7jZDeuTY8IHF+UO8wBgCDyYJfBoShWjaZuyKUmQZJ qYUb2fFBL+Q= X-Received: by 2002:a05:600c:4e44:b0:4a2:a9:ed5a with SMTP id 5b1f17b1804b1-4bb7da0f78dmr32647475e9.8.1794994171802; Wed, 18 Nov 2026 01:29:31 -0800 (PST) Return-Path: Received: from fedora ([165.225.94.251]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bb7d28ec3asm55486755e9.0.2026.11.18.01.29.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Nov 2026 01:29:31 -0800 (PST) From: Stefano Tondo To: openembedded-core@lists.openembedded.org Cc: Joshua Watt , Alexander Kanavin , Stefan Herbrechtsmeier , Stefano Tondo , Stefano Tondo Subject: [PATCH 2/4] spdx30: Record the lifecycle scope of crate dependencies Date: Wed, 18 Nov 2026 10:29:25 +0100 Message-ID: <20261118092927.204959-3-stondo@gmail.com> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261118092927.204959-1-stondo@gmail.com> References: <20261118092927.204959-1-stondo@gmail.com> MIME-Version: 1.0 List-Id: X-Webhook-Received: from 45-33-107-173.ip.linodeusercontent.com [45.33.107.173] by lin-tor-korg-lkml-alma10-1 with HTTPS for ; Wed, 18 Nov 2026 09:29:42 -0000 X-Groupsio-URL: https://lists.openembedded.org/g/openembedded-core/message/250528 From: Stefano Tondo A Cargo.lock file lists the crates for all targets, and some crates only run at build time (build scripts, proc-macros and the crates they use). The fetcher downloads all of them, but only some end up in the binary. Add a do_cargo_metadata task that writes the dependency graph for the target with cargo metadata --filter-platform. The create_spdx task reads this graph. It links the build to each crate download with a scoped dependsOn relationship: runtime, build or test. A crate that is not used on the target gets an annotation instead. Signed-off-by: Stefano Tondo --- meta/classes-recipe/cargo.bbclass | 17 +++++++ meta/lib/oe/spdx30_tasks.py | 81 +++++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+) diff --git a/meta/classes-recipe/cargo.bbclass b/meta/classes-recipe/cargo.bbclass index 586071988a..b3e82f9d5b 100644 --- a/meta/classes-recipe/cargo.bbclass +++ b/meta/classes-recipe/cargo.bbclass @@ -26,6 +26,23 @@ cargo_do_compile () { "${CARGO}" build ${CARGO_BUILD_FLAGS} ${PACKAGECONFIG_CONFARGS} "$@" } +# The crate dependency graph for the target, with the crates that are not +# used on it removed. create-spdx uses it to give each crate download a +# lifecycle scope. +CARGO_METADATA_FILE = "${WORKDIR}/cargo-metadata.json" + +do_cargo_metadata () { + rm -f "${CARGO_METADATA_FILE}" + # Some recipes inherit cargo without being a cargo project + if [ ! -f "${CARGO_MANIFEST_PATH}" ]; then + return + fi + "${CARGO}" metadata --format-version 1 --offline --locked \ + --manifest-path "${CARGO_MANIFEST_PATH}" \ + --filter-platform "${RUST_HOST_SYS}" > "${CARGO_METADATA_FILE}" +} +addtask cargo_metadata after do_configure before do_compile do_create_spdx + cargo_do_install () { local have_installed=false for tgt in "${B}/target/${CARGO_TARGET_SUBDIR}/"*; do diff --git a/meta/lib/oe/spdx30_tasks.py b/meta/lib/oe/spdx30_tasks.py index 58fe45ec7e..e40716a6df 100644 --- a/meta/lib/oe/spdx30_tasks.py +++ b/meta/lib/oe/spdx30_tasks.py @@ -476,6 +476,85 @@ def set_package_identity(d, dl, fd): dl.software_packageUrl = identity["purl"] +def get_cargo_scopes(d): + """Return {(crate, version): scope} from CARGO_METADATA_FILE. + + The file is the output of cargo metadata --filter-platform for the + target, so crates used only on other targets are absent. Walks the + dependency graph from the workspace members: normal dependencies are + runtime, build dependencies and proc-macro crates (and everything they + pull in) are build, dev dependencies of the members are test. + """ + path = d.getVar("CARGO_METADATA_FILE") + if not path or not os.path.exists(path): + return None + + with open(path) as f: + metadata = json.load(f) + + packages = {p["id"]: p for p in metadata["packages"]} + nodes = {n["id"]: n for n in metadata["resolve"]["nodes"]} + members = set(metadata["workspace_members"]) + rank = {"test": 1, "build": 2, "runtime": 3} + + def is_proc_macro(pkg_id): + return any("proc-macro" in t["kind"] for t in packages[pkg_id]["targets"]) + + scopes = {} + stack = [(m, "runtime") for m in members] + while stack: + pkg_id, scope = stack.pop() + if pkg_id not in members: + if scope == "runtime" and is_proc_macro(pkg_id): + scope = "build" + if rank.get(scopes.get(pkg_id), 0) >= rank[scope]: + continue + scopes[pkg_id] = scope + for dep in nodes[pkg_id]["deps"]: + for kind in (k["kind"] for k in dep["dep_kinds"]): + if kind == "dev": + if pkg_id in members: + stack.append((dep["pkg"], "test")) + elif kind == "build": + stack.append((dep["pkg"], "test" if scope == "test" else "build")) + else: + stack.append((dep["pkg"], scope)) + + return { + (packages[i]["name"], packages[i]["version"]): s for i, s in scopes.items() + } + + +def add_dependency_scopes(d, objset, build, source_files): + """Give crate downloads a lifecycle scope, see get_cargo_scopes().""" + scopes = get_cargo_scopes(d) + if scopes is None: + return + + by_scope = {} + for dl in source_files: + if not (getattr(dl, "software_packageUrl", None) or "").startswith("pkg:cargo/"): + continue + scope = scopes.get((dl.name, dl.software_packageVersion)) + if scope: + by_scope.setdefault(scope, []).append(dl) + else: + objset.new_annotation( + dl, + "%s %s is fetched but not built: not used on target %s" + % (dl.name, dl.software_packageVersion, d.getVar("RUST_HOST_SYS")), + oe.spdx30.AnnotationType.other, + ) + + for scope, dls in sorted(by_scope.items()): + objset.new_scoped_relationship( + [build], + oe.spdx30.RelationshipType.dependsOn, + getattr(oe.spdx30.LifecycleScopeType, scope), + sorted(oe.sbom30.get_element_link_id(dl) for dl in dls), + ) + + def add_download_files(d, objset): inputs = set() release_date = get_release_date(d) @@ -978,6 +1057,8 @@ def create_spdx(d): source_files = add_download_files(d, build_objset) build_inputs |= source_files + if bb.data.inherits_class("cargo", d): + add_dependency_scopes(d, build_objset, build, source_files) recipe_spdx_license = add_license_expression( d, build_objset, d.getVar("LICENSE"), license_data, [recipe_objset] From patchwork Wed Nov 18 09:29:26 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Tondo X-Patchwork-Id: 104737 Received: from mail-wr1-f47.google.com (mail-wr1-f47.google.com [209.85.221.47]) by mx.groups.io with SMTP id smtpd.msgproc02-g2.9018.1794994174894705442 for ; Wed, 18 Nov 2026 01:29:35 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@gmail.com header.s=20260707 header.b=vQhzAFha; spf=pass (domain: gmail.com, ip: 209.85.221.47, mailfrom: stondo@gmail.com) Received: by mail-wr1-f47.google.com with SMTP id ffacd0b85a97d-4a33359c1b3so435617f8f.3 for ; Wed, 18 Nov 2026 01:29:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1794994173; x=1795598973; darn=lists.openembedded.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=1kl6VU6VdpKismv/dpDsJcyLqr9MXcp0WnD4sSJdUj4=; b=vQhzAFhau4VTm3nSqStrN6F4oSH1AdxQvAFcp8NLOV8jlKTY8fEmskD+f5IPRudHbG ElYTCzVp8gjZEPzKYT36zvFZaqeXb3W+1qg+MzvxXjdAzdTd5xiC7shmDsuJPaRaMh17 YEnu446P47mzpR2SxiuRAI38i2sNQGWD9acODqnWSSXbBH63CZTnkzIIaH8xZmzLrCK4 SkiE1a1frNgYztOx65kCnOyB8RXUzQXo+BE5DV+ulTaiTL5p/yIFdbQ7VtYiAONNSfls eYVbB4kN/ot5b+8FETJ65heEChjxyx44mduBfOErC+pAe7iF5bmsRHuCU70Dma9X2OYs Vnyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794994173; x=1795598973; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=1kl6VU6VdpKismv/dpDsJcyLqr9MXcp0WnD4sSJdUj4=; b=HqfQ+KWcjtYBih2QPahSNsNKcL/PhY6YMsfN5uDayOj+tG7E3spDX65V5JX6mo8PvS Ji3tihdOQ3S5IJZ25q4D/cFs5LHQbq2vxeKHJ6QTqMvyjWn/hA8GEM2JXUWCMmi0mO98 j2/ERKVBJUPhscKMJdc13cVmAn+A8Wyno9I68ewIHQ0nZq8Zqnu+lrUb1WbfXKUXjvLc /6Rq3wqUlbWkyELOqgWLmYCyL1ulu6R2lj/xEbmLWYuED1SABvXPlqvzdPReOjm+T4NX BIqcxwt7XUtEnMMp4sUcCs7m1wGHZUn807nUFxlHW7MUfPutm79HHXzjiB6bMeC8o84F vTvw== X-Gm-Message-State: APuU4Z93X8LADZIVuOf4egFXPUSxEAHgpG6rdROfHhWz96TuTMrnLm05 k0FZKRZKdFUmJQDXh07RF/4GhCU8kEeXltw3TjEUQXXRwySpy6uQg+iNT0muLQ== X-Gm-Gg: AYBFou2ZSAPN+wwKtw3p1sLPvBX/a3dZXvhThTVre0VQsNoZFLqMGfjV2hI0+4WkVld lcJSoPjoF4nLdq6GgfiUAGRHxwKYW2EuO4R7ATKeqk5zYy5CNWGtZm1K2tm3cMIAdS3Yv4VCbAj zwh9Y0AegVKd4lqb+23hKSmZJwf+Tt1azAK2FTmFOLo7uWr/gm7fdC+5MUkLWotVsHzHRMREvHY PNbfL0df/e72mC6xiK6a0MG7FZYtfrOe6f3naVsf+eAI34vuaIslUwhFXDsmBXjcOKYPYWmbW1L w+pLmC5Z2VLeKSOZAXWQTvrD3xRRLCq2UD3rzixVEh2RopdWW/wxUDeRPR+I1ysaANm2NF1wK6T J1lUN42Rd0SYTINdBbXarAF1K+T6vL/uRm5n5LFuvQNZ8dtQ1nbdg4r6+1BuFcgLOvn/WacFPAh YGB5gCVi1CWv7JwI3C0EUAI9YwAW/jt27jzEcpdb54rk2aOpkqS/LKDY40e42KZBvKyM4h5RB/W JwfUK/UbEmI+HGwEFrFq8OUNxDRIpEyiqaq9lZ6Fd5V5OWuyXN1xr8M4CR6F9SvPN6p521pMnIK URriHOI2ZGsqlD+UUjszGDjUPdNrBkp3 X-Received: by 2002:a05:600c:a112:b0:4bb:7e4e:de69 with SMTP id 5b1f17b1804b1-4bb7e4edf78mr17121755e9.20.1794994173089; Wed, 18 Nov 2026 01:29:33 -0800 (PST) Return-Path: Received: from fedora ([165.225.94.251]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bb7d28ec3asm55486755e9.0.2026.11.18.01.29.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Nov 2026 01:29:32 -0800 (PST) From: Stefano Tondo To: openembedded-core@lists.openembedded.org Cc: Joshua Watt , Alexander Kanavin , Stefan Herbrechtsmeier , Stefano Tondo , Stefano Tondo Subject: [PATCH 3/4] spdx30: Add the PURLs of the source downloads to the output packages Date: Wed, 18 Nov 2026 10:29:26 +0100 Message-ID: <20261118092927.204959-4-stondo@gmail.com> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261118092927.204959-1-stondo@gmail.com> References: <20261118092927.204959-1-stondo@gmail.com> MIME-Version: 1.0 List-Id: X-Webhook-Received: from 45-33-107-173.ip.linodeusercontent.com [45.33.107.173] by lin-tor-korg-lkml-alma10-1 with HTTPS for ; Wed, 18 Nov 2026 09:29:42 -0000 X-Groupsio-URL: https://lists.openembedded.org/g/openembedded-core/message/250529 From: Stefano Tondo Statically linked code, for example a Rust crate, is part of the binary, but the SPDX of the output package only names the recipe. 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. Leave out the crates that the cargo dependency graph proves are not built into the target. The software_packageUrl of the package stays the first PURL in SPDX_PACKAGE_URLS. Signed-off-by: Stefano Tondo --- meta/lib/oe/spdx30_tasks.py | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/meta/lib/oe/spdx30_tasks.py b/meta/lib/oe/spdx30_tasks.py index e40716a6df..441df709a4 100644 --- a/meta/lib/oe/spdx30_tasks.py +++ b/meta/lib/oe/spdx30_tasks.py @@ -526,16 +526,24 @@ def get_cargo_scopes(d): def add_dependency_scopes(d, objset, build, source_files): - """Give crate downloads a lifecycle scope, see get_cargo_scopes().""" + """Give crate downloads a lifecycle scope, see get_cargo_scopes(). + + Returns the crate downloads that are not built into the target: crates + that are not used on it, build scripts, proc-macros and the crates + they use, and test-only crates. + """ scopes = get_cargo_scopes(d) if scopes is None: - return + return set() by_scope = {} + not_in_target = set() for dl in source_files: if not (getattr(dl, "software_packageUrl", None) or "").startswith("pkg:cargo/"): continue scope = scopes.get((dl.name, dl.software_packageVersion)) + if scope != "runtime": + not_in_target.add(dl) if scope: by_scope.setdefault(scope, []).append(dl) else: @@ -554,6 +562,8 @@ def add_dependency_scopes(d, objset, build, source_files): sorted(oe.sbom30.get_element_link_id(dl) for dl in dls), ) + return not_in_target + def add_download_files(d, objset): inputs = set() @@ -1057,8 +1067,20 @@ 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. Only + # the downloads known not to be built into the target are left out. + not_in_target = set() if bb.data.inherits_class("cargo", d): - add_dependency_scopes(d, build_objset, build, source_files) + not_in_target = add_dependency_scopes(d, build_objset, build, source_files) + dependency_purls = sorted( + { + dl.software_packageUrl + for dl in source_files + if getattr(dl, "software_packageUrl", None) and dl not in not_in_target + } + ) recipe_spdx_license = add_license_expression( d, build_objset, d.getVar("LICENSE"), license_data, [recipe_objset] @@ -1171,7 +1193,7 @@ def create_spdx(d): d.getVar("SPDX_PACKAGE_URLS:%s" % package) or d.getVar("SPDX_PACKAGE_URLS") or "" - ).split() + ).split() + dependency_purls set_purls(spdx_package, purls) From patchwork Wed Nov 18 09:29:27 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Tondo X-Patchwork-Id: 104738 Received: from mail-wr1-f52.google.com (mail-wr1-f52.google.com [209.85.221.52]) by mx.groups.io with SMTP id smtpd.msgproc01-g2.9020.1794994176464018302 for ; Wed, 18 Nov 2026 01:29:36 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@gmail.com header.s=20260707 header.b=E/5J1K3+; spf=pass (domain: gmail.com, ip: 209.85.221.52, mailfrom: stondo@gmail.com) Received: by mail-wr1-f52.google.com with SMTP id ffacd0b85a97d-48e46e449e8so432552f8f.3 for ; Wed, 18 Nov 2026 01:29:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1794994175; x=1795598975; darn=lists.openembedded.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=0ddKFm4edcu46UL0qqikK24536Nx+0m4JDW2BPdxXAg=; b=E/5J1K3+QiLMncwnnUSCXyF3FQvUUThFdLs8aVgKi19ABQ3ENwguNRVLab41AwTW5E uNudatCDjZVI3ns07Zo6sYFVnaeRP7b/rcVsBsD3JIlf4NpwOh0Z2FWtac/8gAlMuwWR MI03XWBEgacEugT+hPP7b+FOlEf1NTUfnJVrMWtikpQFvWQU0+SnP8GIYPGMri7fwj3t dhvcXqP73FesktypfDlVe0LyMJYV7TxhPIpr9NsYKyFQe/YuC6RtFwqImz700FaYehT0 wS4ZweL8hl6OPdi3VnS3FiXKH9pSqiPAXKzXEqSuBgY6scS49gTxdqXGnjhoLBbsflQu nqgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794994175; x=1795598975; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=0ddKFm4edcu46UL0qqikK24536Nx+0m4JDW2BPdxXAg=; b=Nxo5D/vLr2ToUzvQKJ8mhbQZo+sCWMW4VIqRHigV0hW1kxH8TcSFLJbeEV0igjyNNI LJKm2oT3jH4yJwu7yfHxR6h/gqxtlrHd4625ZplSagyZd9crqfZLigs+GjyliG0wQMcm pd6baUTl0vN1UTQU93elRbKOf2B58dpXGKtv7wzuEO54lWf8K270HWvQTkh8AsFYxT1m Sub0UXyRnf+U+gGOTSGnXsS44EaR4uNYx5MY7f7bE1jVCggJ3KYWwydMCaq67M+6azc7 FaCo/nQiaQbgv+yQNI36ZE20ORLaPf6lgVPH9BFcQ1D1nSa6n0/PQRdAdZdD4OHn9dv4 WGQA== X-Gm-Message-State: APuU4Z96RvMpBPglrsPRhjmarXnnDDl3bahsxBjSCM7XG5mjwJEDZ1w/ kNxmy2e59sVHN1+WpheMd8DklUBcTuV4RI1HVanNzarkQCt1lcBISNqSTkI3hg== X-Gm-Gg: AYBFou2IhZquzW/qo+Onx+6h+imNRGMn96H3oZRQb9iwoyS0vGntk6JJN4oqDJ4/ltC +Ncvdw0U8Qiy9MDLa3spzwCNVpXmSQR7iM40OhZujcKfwN98kKP2NczH3kcmFkE5tdAVxORGJ2a zY1182el8QdRhITDaR7s/01snx2Xn9fPdtxzXg1+1hKa7PfuBWlfRnpFJqJCiNN21BC/SLlqeDQ 2D0AT11D6VpDK8hMe7pLNw/XEU9pa1gX1TFahLC1HgFfmMvMkgJSoa5R8CIu5kADUaXM6fetijc Ek7U4m7KEgesTu41y7f+rO6hhL882PYgQo2Wa9vW7YRYtJ2WwgWVYDosYBjad1hMHgKBDRHHDdv yCgJhIyj8FvoU+j6IdVcZlGv7NxZHYZDV4PhxPCMDfKDBAdJA3pmomi3ThiL4VPHnd4AWtt9M8D uXaPXvuyBoOWtVutLYr6t/8/TkJouHYev8MmiZWh+ATuF3lXZ5nax46bAgQ1ut4Nv6j3s2087ZG IhrNmsbfpSLM+VxjCEpi92ZsFFDpZi+nwfZgu1cd8Uw/fKaP3l4yZIeaUf5qnhOHbVjVGenZNpf 6eJcbBD+8BE= X-Received: by 2002:a05:600c:4fc6:b0:4a1:83f0:7c91 with SMTP id 5b1f17b1804b1-4bb7da26333mr36482245e9.18.1794994174456; Wed, 18 Nov 2026 01:29:34 -0800 (PST) Return-Path: Received: from fedora ([165.225.94.251]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bb7d28ec3asm55486755e9.0.2026.11.18.01.29.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Nov 2026 01:29:33 -0800 (PST) From: Stefano Tondo To: openembedded-core@lists.openembedded.org Cc: Joshua Watt , Alexander Kanavin , Stefan Herbrechtsmeier , Stefano Tondo , Stefano Tondo Subject: [PATCH 4/4] oeqa/selftest: spdx: Test crate identity, scope and output PURLs Date: Wed, 18 Nov 2026 10:29:27 +0100 Message-ID: <20261118092927.204959-5-stondo@gmail.com> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261118092927.204959-1-stondo@gmail.com> References: <20261118092927.204959-1-stondo@gmail.com> MIME-Version: 1.0 List-Id: X-Webhook-Received: from 45-33-107-173.ip.linodeusercontent.com [45.33.107.173] by lin-tor-korg-lkml-alma10-1 with HTTPS for ; Wed, 18 Nov 2026 09:29:42 -0000 X-Groupsio-URL: https://lists.openembedded.org/g/openembedded-core/message/250530 From: Stefano Tondo python3-bcrypt fetches 42 crates. The new tests check three things: - Each crate download has its name, version and PURL. - Each crate download has a lifecycle scope, or an annotation that it is not built. - The output package gets the PURLs of the runtime crates only. The tests name only crates that do not change on recipe upgrades. blowfish is the cipher of bcrypt. Only the pyo3 proc-macros use syn, at build time. The other checks do not use crate names. Signed-off-by: Stefano Tondo --- meta/lib/oeqa/selftest/cases/spdx.py | 122 +++++++++++++++++++++++++++ 1 file changed, 122 insertions(+) diff --git a/meta/lib/oeqa/selftest/cases/spdx.py b/meta/lib/oeqa/selftest/cases/spdx.py index ce9a8af4f6..d75c6146c7 100644 --- a/meta/lib/oeqa/selftest/cases/spdx.py +++ b/meta/lib/oeqa/selftest/cases/spdx.py @@ -9,6 +9,7 @@ import hashlib from datetime import datetime, timezone from oeqa.selftest.case import OESelftestTestCase from oeqa.utils.commands import bitbake, get_bb_var, get_bb_vars +import oe.purl import oe.spdx30 @@ -543,3 +544,124 @@ class SPDX30Check(SPDX3CheckBase, OESelftestTestCase): # Document should be fully linked self.check_objset_missing_ids(objset) + + def test_crate_package_identity(self): + """Test that crate downloads carry name, version and a cargo PURL.""" + objset = self.check_recipe_spdx( + "python3-bcrypt", + "{DEPLOY_DIR_SPDX}/{SSTATE_PKGARCH}/builds/build-python3-bcrypt.spdx.json", + ) + + prefix = "https://static.crates.io/crates/" + crates = 0 + for pkg in objset.foreach_type(oe.spdx30.software_Package): + location = pkg.software_downloadLocation or "" + if not location.startswith(prefix): + continue + name, version, _ = location[len(prefix):].split("/") + self.assertEqual(pkg.name, name) + self.assertEqual(pkg.software_packageVersion, version) + self.assertEqual( + pkg.software_packageUrl, + f"pkg:cargo/{oe.purl.quote(name)}@{oe.purl.quote(version)}", + ) + crates += 1 + + self.assertGreater(crates, 0, "no crate downloads found") + + def test_crate_dependency_scope(self): + """Test that crate downloads get a lifecycle scope for the target. + + Every crate download is either the target of one scoped dependsOn + relationship or annotated as not built. python3-bcrypt fetches crates + for other platforms (WebAssembly, UEFI), which are never built for a + Linux target. blowfish is the cipher of bcrypt, and syn only runs at + build time in proc-macros, so these names do not change on upgrades. + """ + objset = self.check_recipe_spdx( + "python3-bcrypt", + "{DEPLOY_DIR_SPDX}/{SSTATE_PKGARCH}/builds/build-python3-bcrypt.spdx.json", + ) + + crates = { + pkg._id: pkg.name + for pkg in objset.foreach_type(oe.spdx30.software_Package) + if (pkg.software_packageUrl or "").startswith("pkg:cargo/") + and (pkg.software_downloadLocation or "").startswith("https://static.crates.io/") + } + + scope_of = {} + for rel in objset.foreach_type(oe.spdx30.LifecycleScopedRelationship): + if rel.relationshipType != oe.spdx30.RelationshipType.dependsOn: + continue + for to in rel.to: + to_id = to if isinstance(to, str) else to._id + if to_id in crates: + self.assertNotIn(crates[to_id], scope_of) + scope_of[crates[to_id]] = rel.scope + + not_built = set() + for annotation in objset.foreach_type(oe.spdx30.Annotation): + subject = annotation.subject + subject_id = subject if isinstance(subject, str) else subject._id + if subject_id in crates and "not built" in annotation.statement: + not_built.add(crates[subject_id]) + + self.assertEqual(set(scope_of) | not_built, set(crates.values())) + self.assertFalse(set(scope_of) & not_built) + self.assertTrue(not_built, "no crate for another platform found") + self.assertEqual(scope_of["syn"], oe.spdx30.LifecycleScopeType.build) + self.assertEqual(scope_of["blowfish"], oe.spdx30.LifecycleScopeType.runtime) + + def test_crate_purls_in_output_package(self): + """Test that the output package inherits the PURLs of its crates. + + The package gets the PURLs of the crates with the runtime scope in + the build SPDX, and no other crate PURLs. syn only runs at build + time in proc-macros, so it is not in the binary. + """ + objset = self.check_recipe_spdx( + "python3-bcrypt", + "{DEPLOY_DIR_SPDX}/{SSTATE_PKGARCH}/packages/package-python3-bcrypt.spdx.json", + ) + + package = next( + pkg + for pkg in objset.foreach_type(oe.spdx30.software_Package) + if pkg.name == "python3-bcrypt" + ) + purls = { + e.identifier + for e in package.externalIdentifier + if e.externalIdentifierType == oe.spdx30.ExternalIdentifierType.packageUrl + } + crates = {p[len("pkg:cargo/"):].split("@")[0] for p in purls if p.startswith("pkg:cargo/")} + + # The package's own PURL stays first + own_purls = get_bb_var("SPDX_PACKAGE_URLS", "python3-bcrypt").split() + self.assertEqual(package.software_packageUrl, own_purls[0]) + self.assertTrue(set(own_purls) <= purls) + self.assertIn("blowfish", crates) + self.assertNotIn("syn", crates) + + spdx_vars = get_bb_vars(["DEPLOY_DIR_SPDX", "SSTATE_PKGARCH"], "python3-bcrypt") + build_objset = self.check_spdx_file( + "{DEPLOY_DIR_SPDX}/{SSTATE_PKGARCH}/builds/build-python3-bcrypt.spdx.json".format(**spdx_vars) + ) + downloads = { + pkg._id: pkg.software_packageUrl + for pkg in build_objset.foreach_type(oe.spdx30.software_Package) + if (pkg.software_packageUrl or "").startswith("pkg:cargo/") + } + runtime = set() + for rel in build_objset.foreach_type(oe.spdx30.LifecycleScopedRelationship): + if rel.scope != oe.spdx30.LifecycleScopeType.runtime: + continue + for to in rel.to: + to_id = to if isinstance(to, str) else to._id + if to_id in downloads: + runtime.add(downloads[to_id]) + + self.assertTrue(runtime, "no crate with the runtime scope found") + cargo_purls = {p for p in purls if p.startswith("pkg:cargo/")} + self.assertEqual(cargo_purls - set(own_purls), runtime)