Skip to content

Commit

Permalink
Use existing multi-image tars when generating SBOMs during package cr…
Browse files Browse the repository at this point in the history
…eate
  • Loading branch information
mikhailswift committed Apr 14, 2022
1 parent 4cd0da2 commit 29440c7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/internal/packager/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func Create() {
// Load seed images into their own happy little tarball for ease of import on init
pulledImages := images.PullAll([]string{seedImage}, tempPath.seedImage)
_ = utils.CreateDirectory(tempPath.sboms, 0700)
sbom.CatalogImages(pulledImages, tempPath.sboms)
sbom.CatalogImages(pulledImages, tempPath.sboms, tempPath.seedImage)
}

var combinedImageList []string
Expand All @@ -68,7 +68,7 @@ func Create() {
uniqueList := removeDuplicates(combinedImageList)
pulledImages := images.PullAll(uniqueList, tempPath.images)
_ = utils.CreateDirectory(tempPath.sboms, 0700)
sbom.CatalogImages(pulledImages, tempPath.sboms)
sbom.CatalogImages(pulledImages, tempPath.sboms, tempPath.images)
}

_ = os.RemoveAll(packageName)
Expand Down
12 changes: 9 additions & 3 deletions src/internal/sbom/catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ import (
"github.com/defenseunicorns/zarf/src/internal/message"
"github.com/google/go-containerregistry/pkg/name"
v1 "github.com/google/go-containerregistry/pkg/v1"
"github.com/google/go-containerregistry/pkg/v1/tarball"
"github.com/testifysec/witness/pkg/attestation"
"github.com/testifysec/witness/pkg/attestation/syft"
)

func CatalogImages(tagToImage map[name.Tag]v1.Image, sbomDir string) {
func CatalogImages(tagToImage map[name.Tag]v1.Image, sbomDir, tarPath string) {
imageCount := len(tagToImage)
spinner := message.NewProgressSpinner("Creating SBOMs for %d images.", imageCount)
defer spinner.Stop()
Expand All @@ -26,9 +27,14 @@ func CatalogImages(tagToImage map[name.Tag]v1.Image, sbomDir string) {

cachePath := images.CachePath()
currImage := 1
for tag, img := range tagToImage {
for tag := range tagToImage {
spinner.Updatef("Creating image SBOMs (%d of %d): %s", currImage, imageCount, tag)
sbomAttestor := syft.New(syft.WithImageSource(img, cachePath, tag.String()))
tarballImg, err := tarball.ImageFromPath(tarPath, &tag)
if err != nil {
spinner.Fatalf(err, "Unable to open image %s", tag.String())
}

sbomAttestor := syft.New(syft.WithImageSource(tarballImg, cachePath, tag.String()))
if err := sbomAttestor.Attest(actx); err != nil {
spinner.Fatalf(err, "Unable to build sbom for image %s", tag.String())
}
Expand Down

0 comments on commit 29440c7

Please sign in to comment.