Backport SPDX kernel config and PACKAGECONFIG metadata export
cover Backport SPDX kernel config and PACKAGECONFIG metadata export
Hello,
This series backports upstream commits that add support for exporting kernel configuration and PACKAGECONFIG features to SPDX 3.0 documents.
Upstream commits:
- 228a968e7c47 ("kernel.bbclass: Add task to export kernel configuration to SPDX")
- 7ec61ac40345 ("spdx30_tasks: Add support for exporting PACKAGECONFIG to SPDX")
- 2f0ab110d752 ("oeqa/selftest: oe-selftest: Add SPDX tests for kernel config and PACKAGECONFIG")
Kamel Bouhara (Schneider Electric) (3):
kernel.bbclass: Add task to export kernel configuration to SPDX
spdx30_tasks: Add support for exporting PACKAGECONFIG to SPDX oeqa/selftest: oe-selftest: Add SPDX tests for kernel config and
PACKAGECONFIG
meta/classes-recipe/kernel.bbclass | 64 ++++++++++++++++++++++++++++ meta/classes/create-spdx-3.0.bbclass | 11 +++++ meta/lib/oe/spdx30_tasks.py | 20 +++++++++ meta/lib/oeqa/selftest/cases/spdx.py | 57 +++++++++++++++++++++++++ 4 files changed, 152 insertions(+)
--
2.43.0
PATCH 1/3 kernel.bbclass: Add task to export kernel configuration to SPDX
From: "Kamel Bouhara (Schneider Electric)" <[email protected]>
Introduce a new bitbake task do_create_kernel_config_spdx that extracts the kernel configuration from ${B}/.config and exports it into the recipe's SPDX document as a separate build_Build object.
The kernel config parameters are stored as SPDX DictionaryEntry objects and linked to the main kernel build using an ancestorOf relationship.
This enables the kernel build's configuration to be explicitly captured in the SPDX document for compliance, auditing, and reproducibility.
The task is gated by SPDX_INCLUDE_KERNEL_CONFIG (default = "0").
--- meta/classes-recipe/kernel.bbclass | 64 ++++++++++++++++++++++++++++ meta/classes/create-spdx-3.0.bbclass | 6 +++ 2 files changed, 70 insertions(+)
meta/classes-recipe/kernel.bbclass +64 -0
@@ -873,5 +873,69 @@ addtask deploy after do_populate_sysroot do_packagedata EXPORT_FUNCTIONS do_deploy +python __anonymous() { + inherits = (d.getVar("INHERIT") or "") + if "create-spdx" in inherits: + bb.build.addtask('do_create_kernel_config_spdx', 'do_populate_lic do_deploy', 'do_create_spdx', d) +} + +python do_create_kernel_config_spdx() { + if d.getVar("SPDX_INCLUDE_KERNEL_CONFIG", True) == "1": + import oe.spdx30 + import oe.spdx30_tasks + from pathlib import Path + from datetime import datetime, timezone + + pkg_arch = d.getVar("SSTATE_PKGARCH") + deploydir = Path(d.getVar("SPDXDEPLOY")) + pn = d.getVar("PN") + + config_path = d.expand("${B}/.config") + kernel_params = [] + if not os.path.exists(config_path): + bb.warn(f"SPDX: Kernel config file not found at: {config_path}") + return + + try: + with open(config_path, 'r') as f: + for line in f: + line = line.strip() + if not line or line.startswith("#"): + continue + if "=" in line: + key, value = line.split("=", 1) + kernel_params.append(oe.spdx30.DictionaryEntry( + key=key, + value=value.strip('"') + )) + bb.note(f"Parsed {len(kernel_params)} kernel config entries from {config_path}") + except Exception as e: + bb.error(f"Failed to parse kernel config file: {e}") + + build, build_objset = oe.sbom30.find_root_obj_in_jsonld( + d, "recipes", f"recipe-{pn}", oe.spdx30.build_Build + ) + + kernel_build = build_objset.add_root( + oe.spdx30.build_Build( + _id=build_objset.new_spdxid("kernel-config"), + creationInfo=build_objset.doc.creationInfo, + build_buildType="https://openembedded.org/kernel-configuration", + build_parameter=kernel_params + ) + ) + + oe.spdx30_tasks.set_timestamp_now(d, kernel_build, "build_buildStartTime") + + build_objset.new_relationship( + [build], + oe.spdx30.RelationshipType.ancestorOf, + [kernel_build] + ) + + oe.sbom30.write_jsonld_doc(d, build_objset, deploydir / pkg_arch / "recipes" / f"recipe-{pn}.spdx.json") +} +do_create_kernel_config_spdx[depends] = "virtual/kernel:do_configure" + # Add using Device Tree support inherit kernel-devicetree
meta/classes/create-spdx-3.0.bbclass +6 -0
@@ -50,6 +50,12 @@ SPDX_INCLUDE_TIMESTAMPS[doc] = "Include time stamps in SPDX output. This is \ useful if you want to know when artifacts were produced and when builds \ occurred, but will result in non-reproducible SPDX output" +SPDX_INCLUDE_KERNEL_CONFIG ??= "0" +SPDX_INCLUDE_KERNEL_CONFIG[doc] = "If set to '1', the .config file for the kernel will be parsed \ +and each CONFIG_* value will be included in the Build.build_parameter list as DictionaryEntry \ +items. Set to '0' to disable exporting kernel configuration to improve performance or reduce \ +SPDX document size." + SPDX_IMPORTS ??= "" SPDX_IMPORTS[doc] = "SPDX_IMPORTS is the base variable that describes how to \ reference external SPDX ids. Each import is defined as a key in this \
Signature · 1 line
2.43.0
PATCH 2/3 spdx30_tasks: Add support for exporting PACKAGECONFIG to SPDX
In reply to Kamel BouharaFrom: "Kamel Bouhara (Schneider Electric)" <[email protected]>
Introduce the SPDX_INCLUDE_PACKAGECONFIG variable, which when enabled causes PACKAGECONFIG features to be recorded in the SPDX document as build parameters.
Each feature is recorded as a DictionaryEntry with key PACKAGECONFIG:<feature> and value enabled or disabled, depending on whether the feature is active in the current build.
This makes the build-time configuration more transparent in SPDX output and improves reproducibility tracking.
This makes the build-time configuration more transparent in SPDX output and improves reproducibility tracking. In particular, it allows consumers of the SBOM to identify enabled/disabled features that may affect security posture or feature set.
--- meta/classes/create-spdx-3.0.bbclass | 5 +++++ meta/lib/oe/spdx30_tasks.py | 20 ++++++++++++++++++++ 2 files changed, 25 insertions(+)
meta/classes/create-spdx-3.0.bbclass +5 -0
@@ -56,6 +56,11 @@ and each CONFIG_* value will be included in the Build.build_parameter list as Di items. Set to '0' to disable exporting kernel configuration to improve performance or reduce \ SPDX document size." +SPDX_INCLUDE_PACKAGECONFIG ??= "0" +SPDX_INCLUDE_PACKAGECONFIG[doc] = "If set to '1', each PACKAGECONFIG feature is recorded in the \ +build_Build object's build_parameter list as a DictionaryEntry with key \ +'PACKAGECONFIG:<feature>' and value 'enabled' or 'disabled'" + SPDX_IMPORTS ??= "" SPDX_IMPORTS[doc] = "SPDX_IMPORTS is the base variable that describes how to \ reference external SPDX ids. Each import is defined as a key in this \
meta/lib/oe/spdx30_tasks.py +20 -0
@@ -809,6 +809,26 @@ def create_spdx(d): sorted(list(build_inputs)) + sorted(list(debug_source_ids)), ) + if d.getVar("SPDX_INCLUDE_PACKAGECONFIG", True) != "0": + packageconfig = (d.getVar("PACKAGECONFIG") or "").split() + all_features = (d.getVarFlags("PACKAGECONFIG") or {}).keys() + + if all_features: + enabled = set(packageconfig) + all_features_set = set(all_features) + disabled = all_features_set - enabled + + for feature in sorted(all_features): + status = "enabled" if feature in enabled else "disabled" + build.build_parameter.append( + oe.spdx30.DictionaryEntry( + key=f"PACKAGECONFIG:{feature}", + value=status + ) + ) + + bb.note(f"Added PACKAGECONFIG entries: {len(enabled)} enabled, {len(disabled)} disabled") + oe.sbom30.write_recipe_jsonld_doc(d, build_objset, "recipes", deploydir)
Signature · 1 line
2.43.0
PATCH 3/3 oeqa/selftest: oe-selftest: Add SPDX tests for kernel config and PACKAGECONFIG
In reply to Kamel BouharaFrom: "Kamel Bouhara (Schneider Electric)" <[email protected]>
Add test_kernel_config_spdx and test_packageconfig_spdx to verify SPDX document generation includes kernel configuration and package feature metadata when enabled.
--- meta/lib/oeqa/selftest/cases/spdx.py | 57 ++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+)
meta/lib/oeqa/selftest/cases/spdx.py +57 -0
@@ -286,3 +286,60 @@ class SPDX30Check(SPDX3CheckBase, OESelftestTestCase): break else: self.assertTrue(False, "Unable to find imported Host SpdxID") + + def test_kernel_config_spdx(self): + kernel_recipe = get_bb_var("PREFERRED_PROVIDER_virtual/kernel") + spdx_file = f"recipe-{kernel_recipe}.spdx.json" + spdx_path = f"{{DEPLOY_DIR_SPDX}}/{{SSTATE_PKGARCH}}/recipes/{spdx_file}" + + # Make sure kernel is configured first + bitbake(f"-c configure {kernel_recipe}") + + objset = self.check_recipe_spdx( + kernel_recipe, + spdx_path, + task="do_create_kernel_config_spdx", + extraconf="""\ + INHERIT += "create-spdx" + SPDX_INCLUDE_KERNEL_CONFIG = "1" + """, + ) + + # Check that at least one CONFIG_* entry exists + found_kernel_config = False + for build_obj in objset.foreach_type(oe.spdx30.build_Build): + if getattr(build_obj, "build_buildType", "") == "https://openembedded.org/kernel-configuration": + found_kernel_config = True + self.assertTrue( + len(getattr(build_obj, "build_parameter", [])) > 0, + "Kernel configuration build_Build has no CONFIG_* entries" + ) + break + + self.assertTrue(found_kernel_config, "Kernel configuration build_Build not found in SPDX output") + + def test_packageconfig_spdx(self): + objset = self.check_recipe_spdx( + "tar", + "{DEPLOY_DIR_SPDX}/{SSTATE_PKGARCH}/recipes/recipe-tar.spdx.json", + extraconf="""\ + SPDX_INCLUDE_PACKAGECONFIG = "1" + """, + ) + + found_entries = [] + for build_obj in objset.foreach_type(oe.spdx30.build_Build): + for param in getattr(build_obj, "build_parameter", []): + if param.key.startswith("PACKAGECONFIG:"): + found_entries.append((param.key, param.value)) + + self.assertTrue( + found_entries, + "No PACKAGECONFIG entries found in SPDX output for 'tar'" + ) + + for key, value in found_entries: + self.assertIn( + value, ["enabled", "disabled"], + f"Unexpected PACKAGECONFIG value '{value}' for {key}" + )
Signature · 1 line
2.43.0
Quoted 6 lines · Kamel Bouhara via lists.openembedded.org
Hello,
This series backports upstream commits that add support for exporting kernel configuration and PACKAGECONFIG features to SPDX 3.0 documents.
regardless of this being opt-in functionality, we should have extra justification for
adding features to old releases (LTS or not).
Apologies if I missed a discussion where this was already justified and approved,
I just can't remember it.
This is something that could actually sit in a layer, and not in core, for older releases.
Bruce
Quoted 29 lines
Upstream commits:
-228a968e7c47("kernel.bbclass: Add task to export kernel configuration to SPDX")
-7ec61ac40345("spdx30_tasks: Add support for exporting PACKAGECONFIG to SPDX")
-2f0ab110d752("oeqa/selftest: oe-selftest: Add SPDX tests for kernel config and PACKAGECONFIG")Kamel Bouhara (Schneider Electric) (3):
kernel.bbclass: Add task to export kernel configuration to SPDX
spdx30_tasks: Add support for exporting PACKAGECONFIG to SPDX oeqa/selftest: oe-selftest: Add SPDX tests for kernel config and
PACKAGECONFIGmeta/classes-recipe/kernel.bbclass | 64 ++++++++++++++++++++++++++++ meta/classes/create-spdx-3.0.bbclass | 11 +++++ meta/lib/oe/spdx30_tasks.py | 20 +++++++++ meta/lib/oeqa/selftest/cases/spdx.py | 57 +++++++++++++++++++++++++ 4 files changed, 152 insertions(+)--
2.43.0-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#227743): https://lists.openembedded.org/g/openembedded-core/message/227743
Mute This Topic: https://lists.openembedded.org/mt/116794215/1050810
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-
Signature · 3 lines
- Thou shalt not follow the NULL pointer, for chaos and madness await thee at its end - "Use the force Harry" - Gandalf, Star Trek II
Quoted 10 lines · Bruce Ashfield via lists.openembedded.org
Quoted 6 lines · Kamel Bouhara via lists.openembedded.org
Hello,
This series backports upstream commits that add support for exporting kernel configuration and PACKAGECONFIG features to SPDX 3.0 documents.
Hi Bruce,
Quoted 7 lines
regardless of this being opt-in functionality, we should have extra justification for
adding features to old releases (LTS or not).Apologies if I missed a discussion where this was already justified and approved,
I just can't remember it.
No worries the justification was discussed in the original upstream submission thread [1].
These patches address a real compliance and auditing need for tracking build-time configuration in SBOMs. Since Scarthgap is our LTS target for the next several years, having these features integrated rather than maintained as out-of-tree patches would significantly help our maintenance burden.
Quoted 4 lines
This is something that could actually sit in a layer, and not in core, for older releases.
That's certainly an option I'm happy to pursue if maintainers prefer. However, given that:
- The features are fully opt-in (both default to "0")
- They're already accepted in master
- Scarthgap is LTS with active maintenance
- The backport is clean with no modifications needed
I believe they fit the criteria for LTS backports.
Regards,
Kamel
[1]: https://lists.openembedded.org/g/openembedded-core/topic/114181881#msg220705
Quoted 33 lines
Bruce
Quoted 11 lines
Upstream commits:
-228a968e7c47("kernel.bbclass: Add task to export kernel configuration to SPDX")
-7ec61ac40345("spdx30_tasks: Add support for exporting PACKAGECONFIG to SPDX")
-2f0ab110d752("oeqa/selftest: oe-selftest: Add SPDX tests for kernel config and PACKAGECONFIG")Kamel Bouhara (Schneider Electric) (3):
kernel.bbclass: Add task to export kernel configuration to SPDX
spdx30_tasks: Add support for exporting PACKAGECONFIG to SPDX oeqa/selftest: oe-selftest: Add SPDX tests for kernel config and
PACKAGECONFIGQuoted 12 lines
meta/classes-recipe/kernel.bbclass | 64 ++++++++++++++++++++++++++++ meta/classes/create-spdx-3.0.bbclass | 11 +++++ meta/lib/oe/spdx30_tasks.py | 20 +++++++++ meta/lib/oeqa/selftest/cases/spdx.py | 57 +++++++++++++++++++++++++ 4 files changed, 152 insertions(+)--
2.43.0--
- Thou shalt not follow the NULL pointer, for chaos and madness await thee at its end
- "Use the force Harry" - Gandalf, Star Trek II
Quoted 8 lines
-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#227748): https://lists.openembedded.org/g/openembedded-core/message/227748
Mute This Topic: https://lists.openembedded.org/mt/116794215/5236779
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-
--
Kamel Bouhara, Bootlin
Embedded Linux and kernel engineering
https://bootlin.com