Skip to content

fix(materials): guard legacy tool annotations against empty values#2881

Open
jiparis wants to merge 2 commits intochainloop-dev:mainfrom
jiparis:jiparis/pfm-5009-investigate
Open

fix(materials): guard legacy tool annotations against empty values#2881
jiparis wants to merge 2 commits intochainloop-dev:mainfrom
jiparis:jiparis/pfm-5009-investigate

Conversation

@jiparis
Copy link
Member

@jiparis jiparis commented Mar 18, 2026

Summary

  • Guard all legacy tool annotation assignments (chainloop.material.tool.name, chainloop.material.tool.version) with non-empty checks across all material crafters (CycloneDX, SPDX, SARIF, CSAF)
  • Prevents SBOM uploads from failing when a tool entry has an empty version string

Fixes #2880

SBOM uploads fail when a tool entry has an empty version string because
the legacy annotation is set to "" and then rejected by the crafter
validation. Guard all legacy annotation assignments with non-empty
checks across all material crafters.

Fixes chainloop-dev#2880

Signed-off-by: Jose I. Paris <jiparis@chainloop.dev>
Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

2 issues found across 9 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="pkg/attestation/crafter/materials/csaf.go">

<violation number="1" location="pkg/attestation/crafter/materials/csaf.go:152">
P2: Add a CSAF test for empty `generator.engine.name` / `version` values; the new guard changes annotation behavior but is not covered.

(Based on your team's feedback about adding or updating tests for new paths.) [FEEDBACK_USED]</violation>
</file>

<file name="pkg/attestation/crafter/materials/spdxjson.go">

<violation number="1" location="pkg/attestation/crafter/materials/spdxjson.go:94">
P3: Add a SPDX JSON craft test case where the first tool has an empty name to exercise the new guard and assert the legacy name annotation is omitted.

(Based on your team's feedback about adding/updating tests for new paths.) [FEEDBACK_USED]</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

m.Annotations[AnnotationToolNameKey] = name
}
if version, ok := engine["version"].(string); ok {
if version, ok := engine["version"].(string); ok && version != "" {
Copy link

@cubic-dev-ai cubic-dev-ai bot Mar 18, 2026

Choose a reason for hiding this comment

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

P2: Add a CSAF test for empty generator.engine.name / version values; the new guard changes annotation behavior but is not covered.

(Based on your team's feedback about adding or updating tests for new paths.)

View Feedback

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At pkg/attestation/crafter/materials/csaf.go, line 152:

<comment>Add a CSAF test for empty `generator.engine.name` / `version` values; the new guard changes annotation behavior but is not covered.

(Based on your team's feedback about adding or updating tests for new paths.) </comment>

<file context>
@@ -146,10 +146,10 @@ func (i *CSAFCrafter) injectAnnotations(m *api.Attestation_Material, documentMap
 					m.Annotations[AnnotationToolNameKey] = name
 				}
-				if version, ok := engine["version"].(string); ok {
+				if version, ok := engine["version"].(string); ok && version != "" {
 					m.Annotations[AnnotationToolVersionKey] = version
 				}
</file context>
Fix with Cubic

if len(tools) > 0 {
m.Annotations[AnnotationToolNameKey] = tools[0].Name
m.Annotations[AnnotationToolVersionKey] = tools[0].Version
if tools[0].Name != "" {
Copy link

@cubic-dev-ai cubic-dev-ai bot Mar 18, 2026

Choose a reason for hiding this comment

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

P3: Add a SPDX JSON craft test case where the first tool has an empty name to exercise the new guard and assert the legacy name annotation is omitted.

(Based on your team's feedback about adding/updating tests for new paths.)

View Feedback

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At pkg/attestation/crafter/materials/spdxjson.go, line 94:

<comment>Add a SPDX JSON craft test case where the first tool has an empty name to exercise the new guard and assert the legacy name annotation is omitted.

(Based on your team's feedback about adding/updating tests for new paths.) </comment>

<file context>
@@ -91,7 +91,11 @@ func (i *SPDXJSONCrafter) injectAnnotations(m *api.Attestation_Material, doc *sp
 	if len(tools) > 0 {
-		m.Annotations[AnnotationToolNameKey] = tools[0].Name
-		m.Annotations[AnnotationToolVersionKey] = tools[0].Version
+		if tools[0].Name != "" {
+			m.Annotations[AnnotationToolNameKey] = tools[0].Name
+		}
</file context>
Fix with Cubic

@jiparis jiparis requested review from javirln and migmartri March 18, 2026 17:56
Add test for CSAF tool annotation assertions and SPDX empty tool name
case to cover the new guards added in the previous commit.

Signed-off-by: Jose I. Paris <jiparis@chainloop.dev>
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.

fix: empty tool version annotation blocks SBOM uploads

2 participants