Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only supplement SBOMs with file-layer info for specified SBOMs #3422

Merged
merged 1 commit into from
Jan 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions docs/attestations/sbom-protocol.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,8 @@ by BuildKit:
This variable specifies the main target, passing the path to the root
filesystem of the final build result.

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

- `BUILDKIT_SCAN_SOURCE_EXTRAS` (optional)

Expand Down
8 changes: 8 additions & 0 deletions exporter/containerimage/attestations.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
gatewaypb "github.com/moby/buildkit/frontend/gateway/pb"
"github.com/moby/buildkit/session"
"github.com/moby/buildkit/solver"
"github.com/moby/buildkit/solver/result"
"github.com/moby/buildkit/version"
ocispecs "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/pkg/errors"
Expand All @@ -35,6 +36,13 @@ func supplementSBOM(ctx context.Context, s session.Group, target cache.Immutable
if att.InToto.PredicateType != intoto.PredicateSPDX {
return att, nil
}
name, ok := att.Metadata[result.AttestationSBOMCore]
if !ok {
return att, nil
}
if n, _, _ := strings.Cut(att.Path, "."); n != string(name) {
return att, nil
}

content, err := attestation.ReadAll(ctx, s, att)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions frontend/attestations/sbom/sbom.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ func CreateSBOMScanner(ctx context.Context, resolver llb.ImageMetaResolver, scan
Ref: stsbom,
Metadata: map[string][]byte{
result.AttestationReasonKey: []byte(result.AttestationReasonSBOM),
result.AttestationSBOMCore: []byte(CoreSBOMName),
},
InToto: result.InTotoAttestation{
PredicateType: intoto.PredicateSPDX,
Expand Down
1 change: 1 addition & 0 deletions solver/result/attestation.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

const (
AttestationReasonKey = "reason"
AttestationSBOMCore = "sbom-core"
AttestationInlineOnlyKey = "inline-only"
)

Expand Down