Skip to content

Commit 2948389

Browse files
committed
attestation: only supplement file data for the core scan
Previously, we would attempt to add file data for every single SBOM - however, if these SBOMs were taken of layers that were not exported, then these could be wrong. To workaround this, for the file layer details to be added to the resulting SBOM, we require that the scanner add a metadata property to indicate the default value. This is configurable, since in the future we may want behavior that allows the frontend to specify no file layers, or wants an SBOM with layers other than the default. Signed-off-by: Justin Chadwell <[email protected]>
1 parent f47540f commit 2948389

File tree

4 files changed

+12
-3
lines changed

4 files changed

+12
-3
lines changed

docs/attestations/sbom-protocol.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,8 @@ by BuildKit:
4848
This variable specifies the main target, passing the path to the root
4949
filesystem of the final build result.
5050

51-
The scanner should scan this filesystem, and write its SBOM scans to
52-
`$BUILDKIT_SCAN_DESTINATION/<scan>.spdx.json`. If the scan name is not
53-
significant the scan can be named `$(basename $BUILDKIT_SCAN_SOURCE)`.
51+
The scanner should scan this filesystem, and write its SBOM result to
52+
`$BUILDKIT_SCAN_DESTINATION/$(basename $BUILDKIT_SCAN_SOURCE).spdx.json`.
5453

5554
- `BUILDKIT_SCAN_SOURCE_EXTRAS` (optional)
5655

exporter/containerimage/attestations.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
gatewaypb "github.com/moby/buildkit/frontend/gateway/pb"
1515
"github.com/moby/buildkit/session"
1616
"github.com/moby/buildkit/solver"
17+
"github.com/moby/buildkit/solver/result"
1718
"github.com/moby/buildkit/version"
1819
ocispecs "github.com/opencontainers/image-spec/specs-go/v1"
1920
"github.com/pkg/errors"
@@ -35,6 +36,13 @@ func supplementSBOM(ctx context.Context, s session.Group, target cache.Immutable
3536
if att.InToto.PredicateType != intoto.PredicateSPDX {
3637
return att, nil
3738
}
39+
name, ok := att.Metadata[result.AttestationSBOMCore]
40+
if !ok {
41+
return att, nil
42+
}
43+
if n, _, _ := strings.Cut(att.Path, "."); n != string(name) {
44+
return att, nil
45+
}
3846

3947
content, err := attestation.ReadAll(ctx, s, att)
4048
if err != nil {

frontend/attestations/sbom/sbom.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ func CreateSBOMScanner(ctx context.Context, resolver llb.ImageMetaResolver, scan
8989
Ref: stsbom,
9090
Metadata: map[string][]byte{
9191
result.AttestationReasonKey: []byte(result.AttestationReasonSBOM),
92+
result.AttestationSBOMCore: []byte(CoreSBOMName),
9293
},
9394
InToto: result.InTotoAttestation{
9495
PredicateType: intoto.PredicateSPDX,

solver/result/attestation.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99

1010
const (
1111
AttestationReasonKey = "reason"
12+
AttestationSBOMCore = "sbom-core"
1213
AttestationInlineOnlyKey = "inline-only"
1314
)
1415

0 commit comments

Comments
 (0)