Skip to content

Validate Yocto documents before upload and fix the purls we inject - #436

Open
aurangzaib048 wants to merge 4 commits into
sbomify:masterfrom
aurangzaib048:fix/yocto-spdx22-relationships-warn
Open

aurangzaib048 wants to merge 4 commits into
sbomify:masterfrom
aurangzaib048:fix/yocto-spdx22-relationships-warn

Conversation

@aurangzaib048

Copy link
Copy Markdown
Contributor

What was wrong
The Yocto pipeline uploaded every document without validating it. Turning validation on as #326 asks turned up three problems:

  • Yocto writes relationship types SPDX added in 2.3, such as AMENDS, into documents that declare SPDX-2.2. The 2.2 schema refuses them, and nobody running the build can fix that.
  • Our SPDX 2.2 purl injector tagged each purl with PACKAGE-MANAGER, the 2.3 spelling. The 2.2 schema refuses it, so every document we touched failed 2.2 validation because of our own edit.
  • Our SPDX 3 purl injector wrote the bare packageUrl. The 3.0 schema refuses it; the property is software_packageUrl. It also missed software_packageVersion, so conformant documents got purls with no version.

The fix

  • The pipeline validates the document it is about to upload. SPDX 3 must pass its schema; a failing one is not uploaded and counts as an error. An SPDX 2 document that fails is uploaded with a warning naming the package, the path and the reason, so the package stays in the release.
  • The 2.2 injector writes PACKAGE_MANAGER, which both 2.2 and 2.3 accept.
  • The SPDX 3 injector reads either spelling and writes software_packageUrl.

Verified
A 2.2 document using AMENDS uploads with a warning that names AMENDS. An invalid SPDX 3 document is not uploaded. A valid Yocto 2.2 package document stays valid after purl injection. Each of these tests fails without its fix. A run against a stub API shows the warning, then one SBOM uploaded and no errors.

Refs #326

inject_yocto_purls_spdx3 wrote the bare packageUrl, which the SPDX 3.0
JSON-LD context and schema name software_packageUrl, so a Yocto image
the schema accepted was refused once a purl had been added to it. It also
read only the bare packageVersion and packageUrl, so it dropped the
version from the purl of a conformant document and could add a second
purl beside an existing software_packageUrl.

It now reads either spelling and writes software_packageUrl.
The Yocto pipeline uploaded every document unvalidated. It now checks the
document it is about to upload. SPDX 3 must pass its schema, and one that
fails is not uploaded and is counted as an error.

An SPDX 2 document that fails is uploaded with a warning naming the
package, the path and the reason. Yocto writes relationship types SPDX
added in 2.3, such as AMENDS, into documents that declare SPDX-2.2, which
the 2.2 schema refuses. Nobody running the build can fix that, and
refusing it would drop the package from the release.
inject_yocto_purls_spdx22 tagged each purl it added with referenceCategory
PACKAGE-MANAGER, the spelling SPDX 2.3 introduced. The 2.2 schema accepts
only PACKAGE_MANAGER, so every Yocto package document it touched failed
2.2 validation on account of the purl this tool added. PACKAGE_MANAGER is
valid in both 2.2 and 2.3.
Copilot AI lite review requested due to automatic review settings September 28, 2026 13:27

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

Review effort: Lite
Findings: 1 High severity · 1 Medium severity

Open (2)
What changed in this PR

Adds schema validation gating to the Yocto upload pipeline and fixes SPDX 2.2 / SPDX 3 PURL property spellings so injected PURLs remain schema-conformant.

Changes:

  • Validate SBOMs right before upload, warning+uploading invalid SPDX 2.x but rejecting invalid SPDX 3.
  • Fix SPDX 2.2 externalRef category spelling (PACKAGE_MANAGER) and update tests accordingly.
  • Fix SPDX 3 injector/tests to write software_packageUrl and read both prefixed/unprefixed spellings.
File Description
tests/​test_yocto_purl.py Updates expectations for corrected SPDX 2.2/3 spellings and adds validation regression coverage.
tests/​test_yocto_pipeline.py Adds pipeline-level tests for “warn+upload SPDX 2.2” vs “reject SPDX 3” validation behavior and updates SPDX 3 fixture.
sbomify_action/​_yocto/​purl.py Corrects injected SPDX 2.2 referenceCategory and SPDX 3 property names; reads both old/new spellings.
sbomify_action/​_yocto/​pipeline.py Adds pre-upload validation that warns for SPDX 2.x failures but errors out for SPDX 3 failures.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread sbomify_action/_yocto/purl.py
Comment thread tests/test_yocto_purl.py
Copilot AI lite review requested due to automatic review settings October 15, 2026 08:22
@aurangzaib048

Copy link
Copy Markdown
Contributor Author

I merged master into this branch in 87aeef7. Master had moved 8 commits since the last CI run: the uv group bump, the Dockerfile uv pin, the Linux-only runtime guard and the runtime id fix. None of them touched the files this PR changes, so the merge had no conflicts. ruff, the format check and mypy pass. The full suite passes apart from 26 tests in test_runtimes.py, test_ecosystem_routing.py and test_php_composer.py, which fail the same way on master when run on macOS, because the new guard refuses Linux tool runtimes there. CI runs on Linux.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The new _check_before_upload() treats “validation skipped” (valid=None) as success, which can allow uploads without any validation or warning when schemas are unavailable.

1 open finding
2 resolved since last review

🧠 Review effort: Lite

Comment on lines +46 to +53
result = validate_sbom_file_auto(sbom_file)
if result.valid is not False:
return
where = f" at {result.error_path}" if result.error_path else ""
reason = f"SPDX {result.spec_version} document failed validation{where}: {result.error_message}"
if result.spec_version.startswith("3"):
raise SBOMValidationError(f"{pkg_name}: {reason}")
logger.warning(f"{pkg_name}: {reason}. Uploading it anyway.")

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants