Skip to contentSkip to conversation

spdx3: Add optional support for exporting

PATCH Superseded Kamel Bouhara 2 participants 6 messages Jul 28, 2025 – Jul 30, 2025

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v2 cover spdx3: Add optional support for exporting

Hi all,

This v2 patch series introduces *optional* support for exporting build-time configuration metadata into SPDX 3.0 documents.

The goal is to improve traceability and reproducibility in SPDX output, particularly for security-critical settings.

The series adds support for two types of build metadata:

1. Linux kernel configuration (.config)
- Exported as a dedicated build_Build object
- Each CONFIG_* line becomes a 'DictionaryEntry' in 'build_parameter'
- Linked to the main recipe build using an 'ancestorOf' relationship
- Controlled via 'SPDX_INCLUDE_KERNEL_CONFIG' (default: "0")

2. PACKAGECONFIG feature set
- Each PACKAGECONFIG feature is recorded as a DictionaryEntry
- Captures whether a feature is enabled or disabled
- Stored in the recipe's build_Build.build_parameter
- Controlled via 'SPDX_INCLUDE_PACKAGECONFIG' (default: "0")

Both features are fully opt-in and have negligible runtime cost when disabled.

This makes it easy for users to selectively enable metadata export only when needed; for example, in CI pipelines, security audits, or diffing builds for regressions.

As discussed in [1], the kernel's .config is a good candidate for inclusion in SPDX.

The approach follows SPDX modeling by introducing a *separate build object* for kernel configuration, avoiding overloading the meaning of the main recipe build. This is linked via a 'ancestorOf' relationship to preserve traceability.

Similarly, PACKAGECONFIG settings are metadata that can help detect build-time feature toggles, especially across different configurations or product variants.

While this doesn't aim to turn SPDX into a full build tracker, it *does* provide a consistent, machine-readable way to surface relevant build decisions in SBOMs already being generated.

This approach was validated internally to track hardening flags and kernel changes.

[1] https://lists.openembedded.org/g/openembedded-core/message/220705

Kamel Bouhara (2):
kernel.bbclass: Add task to export kernel configuration to SPDX
spdx30_tasks: Add support for exporting PACKAGECONFIG to SPDX

 meta/classes-recipe/kernel.bbclass   | 62 ++++++++++++++++++++++++++++
 meta/classes/create-spdx-3.0.bbclass | 11 +++++
 meta/lib/oe/spdx30_tasks.py          | 20 +++++++++
 3 files changed, 93 insertions(+)

--
2.43.0

#1 lore raw

PATCH v2 1/2 kernel.bbclass: Add task to export kernel configuration to SPDX

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").

---
v2:
- Disable exporting kernel config metadata by default
- Move kernel config SPDX logic from spdx30_tasks to kernel.bbclass
- Generate a separate build_Build for kernel config and relate via ancestorOf

 meta/classes-recipe/kernel.bbclass   | 62 ++++++++++++++++++++++++++++
 meta/classes/create-spdx-3.0.bbclass |  6 +++
 2 files changed, 68 insertions(+)
meta/classes-recipe/kernel.bbclass +62 -0
index eb03424dfc..2ba8903ace 100644
@@ -863,5 +863,67 @@ addtask deploy after do_populate_sysroot do_packagedata
 
 EXPORT_FUNCTIONS do_deploy
 
+python __anonymous() {
+    if bb.data.inherits_class("create-spdx", d):
+        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")
+}
+
 # Add using Device Tree support
 inherit kernel-devicetree
meta/classes/create-spdx-3.0.bbclass +6 -0
index c0a5436ad6..15c31ba9a3 100644
@@ -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 \

--
2.43.0

#2 lore raw

PATCH v2 2/2 spdx30_tasks: Add support for exporting PACKAGECONFIG to SPDX

In reply to Kamel Bouhara

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
index 15c31ba9a3..6125e8b547 100644
@@ -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
index c352dab152..d708715981 100644
@@ -815,6 +815,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
#3 lore raw

Re: [PATCH v2 2/2] spdx30_tasks: Add support for exporting PACKAGECONFIG to SPDX

I'm not quite sure about this. The PACKAGECONFIG value is already captured if you do SPDX_INCLUDE_BUILD_VARIABLES = "1", so having a explicit way to capture it doesn't seem necessary.

If the build variables are too much data, I'd prefer some way to filter which ones get included in the SPDX data rather than add special cases for special variables (for example, maybe SPDX_INCLUDE_BUILD_VARIABLES = "1" include all variables, but SPDX_INCLUDE_BUILD_VARIABLES = "PACKAGECONFIG" would only include the value of PACKAGECONFIG)

Quoted 84 lines · Kamel Bouhara

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 +0 -0
index 15c31ba9a3..6125e8b547 100644
@@ -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."

meta/classes/create-spdx-3.0.bbclass +2 -0
+SPDX_INCLUDE_PACKAGECONFIG ??= "0"
+SPDX_INCLUDE_PACKAGECONFIG[doc] = "If set to '1', each PACKAGECONFIG

feature is recorded in the \

meta/classes/create-spdx-3.0.bbclass +3 -0
+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 -1
index c352dab152..d708715981 100644
@@ -815,6 +815,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)
 
 
--

2.43.0

#4 lore raw

Re: [PATCH v2 2/2] spdx30_tasks: Add support for exporting PACKAGECONFIG to SPDX

Quoted 8 lines · Joshua Watt

I'm not quite sure about this. The PACKAGECONFIG value is already captured if you do SPDX_INCLUDE_BUILD_VARIABLES = "1", so having a explicit way to capture it doesn't seem necessary.
If the build variables are too much data, I'd prefer some way to filter which ones get included in the SPDX data rather than add special cases for special variables (for example, maybe SPDX_INCLUDE_BUILD_VARIABLES = "1" include all variables, but SPDX_INCLUDE_BUILD_VARIABLES = "PACKAGECONFIG" would only include the value of PACKAGECONFIG)

Hello Joshua,

You are right, parsing the raw PACKAGECONFIG string isn’t fundamentally more complex for most SPDX consumers, especially for diff or comparison tooling where raw strings are straightforward to compare.

I’m happy to revise the patch accordingly if that sounds good.

Cheers,
Kamel

Quoted 86 lines

On Mon, Jul 28, 2025 at 7:30 AM Kamel Bouhara
<[1][email protected]> wrote:

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(+)
diff --git a/meta/classes/create-spdx-3.0.bbclass b/meta/classes/create-spdx-3.0.bbclass
index 15c31ba9a3..6125e8b547 100644
--- a/meta/classes/create-spdx-3.0.bbclass
+++ b/meta/classes/create-spdx-3.0.bbclass
@@ -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 \
diff --git a/meta/lib/oe/spdx30_tasks.py b/meta/lib/oe/spdx30_tasks.py
index c352dab152..d708715981 100644
--- a/meta/lib/oe/spdx30_tasks.py
+++ b/meta/lib/oe/spdx30_tasks.py
@@ -815,6 +815,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)
--
2.43.0

Quoted 4 lines

References

1. mailto:[email protected]
2. mailto:[email protected]

--
Kamel Bouhara, Bootlin
Embedded Linux and kernel engineering
https://bootlin.com

#5 lore raw

Re: [PATCH v2 2/2] spdx30_tasks: Add support for exporting PACKAGECONFIG to SPDX

Quoted 10 lines · Kamel Bouhara
Quoted 8 lines · Joshua Watt

I'm not quite sure about this. The PACKAGECONFIG value is already captured if you do SPDX_INCLUDE_BUILD_VARIABLES = "1", so having a explicit way to capture it doesn't seem necessary.
If the build variables are too much data, I'd prefer some way to filter which ones get included in the SPDX data rather than add special cases for special variables (for example, maybe SPDX_INCLUDE_BUILD_VARIABLES = "1" include all variables, but SPDX_INCLUDE_BUILD_VARIABLES = "PACKAGECONFIG" would only include the value of PACKAGECONFIG)

Quoted 8 lines

Hello Joshua,

You are right, parsing the raw PACKAGECONFIG string isn’t fundamentally more complex for most SPDX consumers, especially for diff or comparison tooling where raw strings are straightforward to compare.

I’m happy to revise the patch accordingly if that sounds good.

Hi Joshua,

I took a closer look at what SPDX_INCLUDE_BUILD_VARIABLES actually exports, and you're right that PACKAGECONFIG is included but only as a raw, unevaluated string like:

	{ "key": "PACKAGECONFIG", "value": "editline gdbm ${@bb.utils.filter('DISTRO_FEATURES', 'lto', d)}" }

This doesn't show which features are enabled or disabled, nor does it reflect the final evaluated configuration. So from a consumer/tooling perspective, it lacks the granularity needed to understand the actual build toggles.

That’s why I originally chose to export each PACKAGECONFIG feature explicitly as a DictionaryEntry, with enabled/disabled values. It makes feature selection clear and machine-readable, which is especially helpful when diffing builds.

Given this, would you reconsider accepting the original approach with structured PACKAGECONFIG export as an optional feature?

Alternatively, I could still integrate this into a filtered variable export system, but with special logic just for how PACKAGECONFIG is interpreted.

Let me know what you'd prefer to adjust accordingly!

Kamel

--
Kamel Bouhara, Bootlin
Embedded Linux and kernel engineering
https://bootlin.com