Skip to content

Commit

Permalink
Add attestation for replace images
Browse files Browse the repository at this point in the history
  • Loading branch information
errordeveloper committed Sep 28, 2023
1 parent 71ae72a commit 8645b1e
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
21 changes: 20 additions & 1 deletion attest/manifest/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ type ResolvedImageRef struct {
attestTypes.GenericStatement[ImageRefenceWithLocation]
}

type ReplacedImageRef struct {
attestTypes.GenericStatement[ImageRefenceWithLocation]
}

type ImageRefenceWithLocation struct {
Reference string `json:"reference"`
Line int `json:"line"`
Expand All @@ -34,7 +38,6 @@ type ImageRefenceWithLocation struct {
}

// TODO:
// - replaced
// - related tags (just the tags)
// - copy inline atteststations, and reference them
// - copy sigstore attestations, and reference them
Expand All @@ -56,6 +59,22 @@ func MakeOriginalImageRefStatements(images *manifestTypes.ImageList) attestTypes
return statements
}

func MakeReplacedImageRefStatements(images *manifestTypes.ImageList) attestTypes.Statements {
statements := attestTypes.Statements{}
forEachImage(images, func(subject attestTypes.Subject, ref ImageRefenceWithLocation) {
statements = append(statements, &ReplacedImageRef{
attestTypes.MakeStatement(
ReplacedImageRefPredicateType,
struct {
ImageRefenceWithLocation `json:"replacedImageReference"`
}{ref},
subject,
),
})
})
return statements
}

func MakeResovedImageRefStatements(images *manifestTypes.ImageList) attestTypes.Statements {
statements := attestTypes.Statements{}
forEachImage(images, func(subject attestTypes.Subject, ref ImageRefenceWithLocation) {
Expand Down
1 change: 1 addition & 0 deletions manifest/imagescanner/imagescanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,5 @@ func (s *DefaultImageScanner) GetImages() *types.ImageList {

func (s *DefaultImageScanner) Reset() {
s.trackers = []*Tracker{}
s.attestor = nil
}
11 changes: 11 additions & 0 deletions tape/app/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,17 @@ func (c *TapePackageCommand) Execute(args []string) error {
return fmt.Errorf("failed to update manifest files: %w", err)
}

scanner.Reset()
if err := scanner.Scan(loader.RelPaths()); err != nil {
return fmt.Errorf("failed to scan updated manifest files: %w", err)
}
replacedImages := scanner.GetImages()
replacedImages.Dedup()

if err := attreg.AssociateStatements(manifest.MakeReplacedImageRefStatements(replacedImages)...); err != nil {
return err
}

c.tape.log.DebugFn(func() []interface{} {
buf := bytes.NewBuffer(nil)
if err := attreg.EncodeAllAttestations(base64.NewEncoder(base64.StdEncoding, buf)); err != nil {
Expand Down

0 comments on commit 8645b1e

Please sign in to comment.