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

accepts attachment-tag-prefix for cosign copy #3014

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 10 additions & 2 deletions cmd/cosign/cli/copy/copy.go
Expand Up @@ -49,17 +49,24 @@ func CopyCmd(ctx context.Context, regOpts options.RegistryOptions, srcImg, dstIm
}
dstRepoRef := dstRef.Context()

ociRemoteOpts, err := regOpts.ClientOpts(ctx)
if err != nil {
return err
}

remoteOpts := regOpts.GetRegistryClientOpts(ctx)

pusher, err := remote.NewPusher(remoteOpts...)
if err != nil {
return err
}

ociRemoteOpts = append(ociRemoteOpts, ociremote.WithRemoteOptions(remoteOpts...))

g, gctx := errgroup.WithContext(ctx)
g.SetLimit(runtime.GOMAXPROCS(0))

root, err := ociremote.SignedEntity(srcRef, ociremote.WithRemoteOptions(remoteOpts...))
root, err := ociremote.SignedEntity(srcRef, ociRemoteOpts...)
if err != nil {
return err
}
Expand All @@ -73,7 +80,7 @@ func CopyCmd(ctx context.Context, regOpts options.RegistryOptions, srcImg, dstIm
srcDigest := srcRepoRef.Digest(h.String())

copyTag := func(tm tagMap) error {
src, err := tm(srcDigest, ociremote.WithRemoteOptions(remoteOpts...))
src, err := tm(srcDigest, ociRemoteOpts...)
if err != nil {
return err
}
Expand Down Expand Up @@ -102,6 +109,7 @@ func CopyCmd(ctx context.Context, regOpts options.RegistryOptions, srcImg, dstIm
// Copy the entity itself.
g.Go(func() error {
dst := dstRepoRef.Tag(srcDigest.Identifier())
dst = dst.Tag(fmt.Sprint(regOpts.RefOpts.TagPrefix, h.Algorithm, "-", h.Hex))
Copy link
Member

Choose a reason for hiding this comment

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

This means we will never copy the tag itself 🤔

cc @haydentherapper

Copy link
Member

Choose a reason for hiding this comment

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

Honestly, I'm not sure what dstRepoRef.Tag(srcDigest.Identifier()) is even meant to do either 😅

return remoteCopy(ctx, pusher, srcDigest, dst, force, remoteOpts...)
})

Expand Down
40 changes: 40 additions & 0 deletions cmd/cosign/cli/copy/copy_test.go
@@ -0,0 +1,40 @@
// Copyright 2023 the Sigstore Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package copy

import (
"context"
"testing"

"github.com/sigstore/cosign/v2/cmd/cosign/cli/options"
)

func TestCopyAttachmentTagPrefix(t *testing.T) {
ctx := context.Background()

refOpts := options.ReferenceOptions{
TagPrefix: "test-tag",
}

srcImg := "alpine"
destImg := "test-alpine"

err := CopyCmd(ctx, options.RegistryOptions{
RefOpts: refOpts,
}, srcImg, destImg, false, true)
if err == nil {
t.Fatal("failed to copy with attachment-tag-prefix")
}
}