Skip to content

Commit 6e08b89

Browse files
authored
feat: support new ID format on evidence annotation (#2521)
Signed-off-by: Miguel Martinez <miguel@chainloop.dev>
1 parent e53c6c8 commit 6e08b89

File tree

3 files changed

+33
-4
lines changed

3 files changed

+33
-4
lines changed

pkg/attestation/crafter/materials/evidence.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ type EvidenceCrafter struct {
4242
// customEvidence represents the expected structure of a custom Evidence JSON file
4343
type customEvidence struct {
4444
// ID is a unique identifier for the evidence
45-
ID string `json:"id"`
45+
// Deprecated: in favor of ChainloopID
46+
ID string `json:"id"`
47+
ChainloopID string `json:"chainloop.material.evidence.id"`
4648
// Schema is an optional schema reference for the evidence validation
4749
Schema string `json:"schema"`
4850
// Data contains the actual evidence content
@@ -93,8 +95,14 @@ func (i *EvidenceCrafter) tryExtractAnnotations(m *api.Attestation_Material, art
9395
return
9496
}
9597

98+
chainloopID := evidence.ChainloopID
99+
// fallback to deprecated id field
100+
if chainloopID == "" {
101+
chainloopID = evidence.ID
102+
}
103+
96104
// Check if it has the required structure (id and data fields)
97-
if evidence.ID == "" || len(evidence.Data) == 0 {
105+
if chainloopID == "" || len(evidence.Data) == 0 {
98106
i.logger.Debug().Msg("evidence JSON does not have required id and data fields, skipping annotation extraction")
99107
return
100108
}
@@ -105,7 +113,7 @@ func (i *EvidenceCrafter) tryExtractAnnotations(m *api.Attestation_Material, art
105113
}
106114

107115
// Extract id and schema as annotations
108-
m.Annotations[annotationEvidenceID] = evidence.ID
116+
m.Annotations[annotationEvidenceID] = chainloopID
109117
if evidence.Schema != "" {
110118
m.Annotations[annotationEvidenceSchema] = evidence.Schema
111119
}

pkg/attestation/crafter/materials/evidence_test.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ func TestEvidenceCraftWithJSONAnnotations(t *testing.T) {
166166
expectedAnnotations map[string]string
167167
}{
168168
{
169-
name: "JSON with id, data and schema fields extracts annotations",
169+
name: "JSON with deprecated id, data and schema fields extracts annotations",
170170
filePath: "./testdata/evidence-with-id-data-schema.json",
171171
expectedAnnotations: map[string]string{
172172
"chainloop.material.evidence.id": "custom-evidence-123",
@@ -180,6 +180,14 @@ func TestEvidenceCraftWithJSONAnnotations(t *testing.T) {
180180
"chainloop.material.evidence.id": "custom-evidence-456",
181181
},
182182
},
183+
{
184+
name: "JSON with new chainloop.material.evidence.id, data and schema fields extracts annotations",
185+
filePath: "./testdata/evidence-with-new-id-data-schema.json",
186+
expectedAnnotations: map[string]string{
187+
"chainloop.material.evidence.id": "custom-evidence-123",
188+
"chainloop.material.evidence.schema": "https://example.com/schema/v1",
189+
},
190+
},
183191
{
184192
name: "JSON without required structure does not extract annotations",
185193
filePath: "./testdata/evidence-invalid-structure.json",
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"chainloop.material.evidence.id": "custom-evidence-123",
3+
"schema": "https://example.com/schema/v1",
4+
"data": {
5+
"status": "approved",
6+
"approver": "john.doe@example.com",
7+
"timestamp": "2025-10-30T10:00:00Z",
8+
"details": {
9+
"review_type": "security",
10+
"findings": ["no issues found"]
11+
}
12+
}
13+
}

0 commit comments

Comments
 (0)