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

sbom: fix minor inconsistencies in sbom protocol #3290

Merged
merged 2 commits into from
Nov 23, 2022
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
3 changes: 1 addition & 2 deletions frontend/attestations/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ const (
)

const (
// TODO: update this before next buildkit release
defaultSBOMGenerator = "jedevc/buildkit-syft-scanner:master@sha256:de630f621eb0ab1bb1245cea76d01c5bddfe78af4f5b9adecde424cb7ec5605e"
defaultSBOMGenerator = "docker/buildkit-syft-scanner:stable-1"
)

func Filter(v map[string]string) map[string]string {
Expand Down
37 changes: 26 additions & 11 deletions frontend/attestations/sbom/sbom.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"fmt"
"path"
"strings"

intoto "github.com/in-toto/in-toto-golang/in_toto"
"github.com/moby/buildkit/client/llb"
Expand All @@ -14,6 +15,11 @@ import (
"github.com/pkg/errors"
)

const (
srcDir = "/run/src/"
outDir = "/run/out/"
)

// Scanner is a function type for scanning the contents of a state and
// returning a new attestation and state representing the scan results.
//
Expand All @@ -38,25 +44,34 @@ func CreateSBOMScanner(ctx context.Context, resolver llb.ImageMetaResolver, scan
if err := json.Unmarshal(dt, &cfg); err != nil {
return nil, err
}
if len(cfg.Config.Cmd) == 0 {

var args []string
args = append(args, cfg.Config.Entrypoint...)
args = append(args, cfg.Config.Cmd...)
if len(args) == 0 {
return nil, errors.Errorf("scanner %s does not have cmd", scanner)
}

return func(ctx context.Context, name string, ref llb.State, extras map[string]llb.State) (result.Attestation, llb.State, error) {
srcDir := "/run/src/"
outDir := "/run/out/"
var env []string
env = append(env, cfg.Config.Env...)
env = append(env, "BUILDKIT_SCAN_DESTINATION="+outDir)
env = append(env, "BUILDKIT_SCAN_SOURCE="+path.Join(srcDir, "core"))
if len(extras) > 0 {
env = append(env, "BUILDKIT_SCAN_SOURCE_EXTRAS="+path.Join(srcDir, "extras/"))
}

args := []string{}
args = append(args, cfg.Config.Entrypoint...)
args = append(args, cfg.Config.Cmd...)
runscan := llb.Image(scanner).Run(
opts := []llb.RunOption{
llb.Dir(cfg.Config.WorkingDir),
llb.AddEnv("BUILDKIT_SCAN_SOURCE", path.Join(srcDir, "core")),
llb.AddEnv("BUILDKIT_SCAN_SOURCE_EXTRAS", path.Join(srcDir, "extras/")),
llb.AddEnv("BUILDKIT_SCAN_DESTINATION", outDir),
llb.Args(args),
llb.WithCustomName(fmt.Sprintf("[%s] generating sbom using %s", name, scanner)))
llb.WithCustomName(fmt.Sprintf("[%s] generating sbom using %s", name, scanner)),
}
for _, e := range env {
k, v, _ := strings.Cut(e, "=")
opts = append(opts, llb.AddEnv(k, v))
}

runscan := llb.Image(scanner).Run(opts...)
runscan.AddMount(path.Join(srcDir, "core"), ref, llb.Readonly)
for k, extra := range extras {
runscan.AddMount(path.Join(srcDir, "extras", k), extra, llb.Readonly)
Expand Down
2 changes: 1 addition & 1 deletion frontend/dockerfile/dockerfile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6187,7 +6187,7 @@ COPY <<-"EOF" /scan.sh
"predicate": {"core": true}
}
BUNDLE
if [ -d "${BUILDKIT_SCAN_SOURCE_EXTRAS:?}" ]; then
if [ "${BUILDKIT_SCAN_SOURCE_EXTRAS}" ]; then
for src in "${BUILDKIT_SCAN_SOURCE_EXTRAS}"/*; do
cat <<BUNDLE > $BUILDKIT_SCAN_DESTINATION/$(basename $src).spdx.json
{
Expand Down