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

Several cleanups to SignCmd #674

Merged
merged 1 commit into from
Sep 15, 2021
Merged
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
34 changes: 16 additions & 18 deletions cmd/cosign/cli/sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import (
"path/filepath"
"strings"

"github.com/google/go-containerregistry/pkg/authn"
"github.com/google/go-containerregistry/pkg/name"
"github.com/google/go-containerregistry/pkg/v1/remote"
"github.com/peterbourgon/ff/v3/ffcli"
Expand Down Expand Up @@ -259,12 +258,9 @@ func SignCmd(ctx context.Context, ko KeyOpts, annotations map[string]interface{}
}
}

remoteOpts := []remote.Option{
remote.WithAuthFromKeychain(authn.DefaultKeychain),
remote.WithContext(ctx),
}
remoteOpts := DefaultRegistryClientOpts(ctx)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#669 :p


var toSign []name.Digest
toSign := make([]name.Digest, 0, len(imgs))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unnecessary, but not worse than what exists. @jonjohnsonjr assures me that the number of recursive images is unbounded

for _, inputImg := range imgs {

// A key file or token is required unless we're in experimental mode!
Expand All @@ -273,20 +269,24 @@ func SignCmd(ctx context.Context, ko KeyOpts, annotations map[string]interface{}
return fmt.Errorf("unable to resolve attachment %s for image %s", attachment, inputImg)
}

get, err := remote.Get(ref, remoteOpts...)
h, err := Digest(ctx, ref)
if err != nil {
return errors.Wrap(err, "getting remote image")
return errors.Wrap(err, "resolving digest")
}
toSign = append(toSign, ref.Context().Digest(h.String()))

repo := ref.Context()
toSign = append(toSign, repo.Digest(get.Digest.String()))

if recursive && get.MediaType.IsIndex() {
imgs, err := getTransitiveImages(get, repo, remoteOpts...)
if recursive {
get, err := remote.Get(ref, remoteOpts...)
if err != nil {
return err
return errors.Wrap(err, "getting remote image")
}
if get.MediaType.IsIndex() {
imgs, err := getTransitiveImages(get, ref.Context(), remoteOpts...)
if err != nil {
return err
}
toSign = append(toSign, imgs...)
}
toSign = append(toSign, imgs...)
}
}

Expand All @@ -304,9 +304,7 @@ func SignCmd(ctx context.Context, ko KeyOpts, annotations map[string]interface{}
}
}

for len(toSign) > 0 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch, didn't simplify this after refining the recursion

img := toSign[0]
toSign = toSign[1:]
for _, img := range toSign {
// The payload can be specified via a flag to skip generation.
payload := staticPayload
if len(payload) == 0 {
Expand Down