Skip to content

Commit 1a683b2

Browse files
authored
sbom: Include predicate type as the output SBOM. (#2005)
Currently we use the generator key as the format in the generated SBOM (e.g. "spdx"). It's more useful if we can get the predicate type in the output so we can know how to handle and parse it.
1 parent 3f63815 commit 1a683b2

File tree

4 files changed

+19
-11
lines changed

4 files changed

+19
-11
lines changed

pkg/build/sbom.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,11 @@ func (bc *Context) GenerateImageSBOM(ctx context.Context, arch types.Architectur
129129
return nil, fmt.Errorf("generating %s sbom: %w", gen.Key(), err)
130130
}
131131
sboms = append(sboms, types.SBOM{
132-
Path: filename,
133-
Format: gen.Key(),
134-
Arch: arch.String(),
135-
Digest: h,
132+
Path: filename,
133+
Format: gen.Key(),
134+
PredicateType: gen.PredicateType(),
135+
Arch: arch.String(),
136+
Digest: h,
136137
})
137138
}
138139
return sboms, nil
@@ -259,9 +260,10 @@ func GenerateIndexSBOM(ctx context.Context, o options.Options, ic types.ImageCon
259260
return nil, fmt.Errorf("generating %s sbom: %w", gen.Key(), err)
260261
}
261262
sboms = append(sboms, types.SBOM{
262-
Path: filename,
263-
Format: gen.Key(),
264-
Digest: h,
263+
Path: filename,
264+
Format: gen.Key(),
265+
PredicateType: gen.PredicateType(),
266+
Digest: h,
265267
})
266268
}
267269

pkg/build/types/types.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -429,10 +429,11 @@ func ParseArchitectures(in []string) []Architecture {
429429
}
430430

431431
type SBOM struct {
432-
Arch string
433-
Path string
434-
Format string
435-
Digest v1.Hash
432+
Arch string
433+
Path string
434+
Format string
435+
PredicateType string
436+
Digest v1.Hash
436437
}
437438

438439
type Layering struct {

pkg/sbom/generator/generator.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
type Generator interface {
2626
Key() string
2727
Ext() string
28+
PredicateType() string
2829
Generate(context.Context, *options.Options, string) error
2930
GenerateIndex(*options.Options, string) error
3031
}

pkg/sbom/generator/spdx/spdx.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ func (sx *SPDX) Ext() string {
6666
return "spdx.json"
6767
}
6868

69+
func (sx *SPDX) PredicateType() string {
70+
return "https://spdx.dev/Document"
71+
}
72+
6973
func stringToIdentifier(in string) (out string) {
7074
in = strings.ReplaceAll(in, ":", "-")
7175
return validIDCharsRe.ReplaceAllStringFunc(in, func(s string) string {

0 commit comments

Comments
 (0)