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

Fix cosign copy --only for signatures #3904

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
18 changes: 14 additions & 4 deletions cmd/cosign/cli/copy/copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,10 @@ func CopyCmd(ctx context.Context, regOpts options.RegistryOptions, srcImg, dstIm
}

onlyFlagSet := false
tags := parseOnlyOpt(copyOnly, sigOnly)
tags, err := parseOnlyOpt(copyOnly, sigOnly)
if err != nil {
return err
}
if len(tags) > 0 {
onlyFlagSet = true
} else {
Expand Down Expand Up @@ -180,13 +183,20 @@ func remoteCopy(ctx context.Context, pusher *remote.Pusher, src, dest name.Refer
return pusher.Push(ctx, dest, got)
}

func parseOnlyOpt(onlyFlag string, sigOnly bool) []tagMap {
func parseOnlyOpt(onlyFlag string, sigOnly bool) ([]tagMap, error) {
var tags []tagMap
tagSet := sets.New(strings.Split(onlyFlag, ",")...)

if sigOnly {
fmt.Fprintf(os.Stderr, "--sig-only is deprecated, use --only=sig instead")
tagSet.Insert("sign")
tagSet.Insert("sig")
}

validTags := sets.New("sig", "sbom", "att")
for tag := range tagSet {
if !validTags.Has(tag) {
return nil, fmt.Errorf("invalid value for --only: %s, only following values are supported, %s", tag, validTags)
}
}

if tagSet.Has("sig") {
Expand All @@ -198,5 +208,5 @@ func parseOnlyOpt(onlyFlag string, sigOnly bool) []tagMap {
if tagSet.Has("att") {
tags = append(tags, ociremote.AttestationTag)
}
return tags
return tags, nil
}
2 changes: 1 addition & 1 deletion cmd/cosign/cli/options/copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (o *CopyOptions) AddFlags(cmd *cobra.Command) {
o.Registry.AddFlags(cmd)

cmd.Flags().StringVar(&o.CopyOnly, "only", "",
"custom string array to only copy specific items, this flag is comma delimited. ex: --only=sbom,sign,att")
"custom string array to only copy specific items, this flag is comma delimited. ex: --only=sig,att,sbom")

cmd.Flags().BoolVar(&o.SignatureOnly, "sig-only", false,
"[DEPRECATED] only copy the image signature")
Expand Down
2 changes: 1 addition & 1 deletion doc/cosign_copy.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading