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

Feature: adds '--allow-insecure-registry' for cosign load #3000

Merged
merged 2 commits into from
May 23, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
19 changes: 16 additions & 3 deletions cmd/cosign/cli/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,16 @@ package cli

import (
"context"
"crypto/tls"
"fmt"
"net/http"

"github.com/google/go-containerregistry/pkg/name"
"github.com/google/go-containerregistry/pkg/v1/remote"
"github.com/sigstore/cosign/v2/cmd/cosign/cli/options"
"github.com/sigstore/cosign/v2/pkg/oci/layout"
"github.com/sigstore/cosign/v2/pkg/oci/remote"

ociremote "github.com/sigstore/cosign/v2/pkg/oci/remote"
"github.com/spf13/cobra"
)

Expand All @@ -45,16 +49,25 @@ func Load() *cobra.Command {
return cmd
}

func LoadCmd(_ context.Context, opts options.LoadOptions, imageRef string) error {
func LoadCmd(ctx context.Context, opts options.LoadOptions, imageRef string) error {
ref, err := name.ParseReference(imageRef)
if err != nil {
return fmt.Errorf("parsing image name %s: %w", imageRef, err)
}

remoteOpts := []remote.Option{
remote.WithContext(ctx),
remote.WithUserAgent(options.UserAgent()),
}
// get the signed image from disk
sii, err := layout.SignedImageIndex(opts.Directory)
if err != nil {
return fmt.Errorf("signed image index: %w", err)
}
return remote.WriteSignedImageIndexImages(ref, sii)

if opts.AllowInsecure {
remoteOpts = append(remoteOpts, remote.WithTransport(&http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: true}})) // #nosec G402
}

return ociremote.WriteSignedImageIndexImages(ref, sii, ociremote.WithRemoteOptions(remoteOpts...))
}
6 changes: 5 additions & 1 deletion cmd/cosign/cli/options/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ import (

// LoadOptions is the top level wrapper for the load command.
type LoadOptions struct {
Directory string
Directory string
AllowInsecure bool
}

var _ Interface = (*LoadOptions)(nil)
Expand All @@ -32,4 +33,7 @@ func (o *LoadOptions) AddFlags(cmd *cobra.Command) {
"path to directory where the signed image is stored on disk")
_ = cmd.Flags().SetAnnotation("dir", cobra.BashCompSubdirsInDir, []string{})
_ = cmd.MarkFlagRequired("dir")

cmd.Flags().BoolVar(&o.AllowInsecure, "allow-insecure-registry", false,
"whether to allow insecure connections to registries (e.g., with expired or self-signed TLS certificates). Don't use this for anything but testing")
}
5 changes: 3 additions & 2 deletions doc/cosign_load.md

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