From 4d90ee78ae4afebf4fab29d22b4437575d570d09 Mon Sep 17 00:00:00 2001 From: Guilherme Rezende Date: Tue, 14 Aug 2018 10:21:15 -0300 Subject: [PATCH] Add support for insecure registry --- cmd/executor/cmd/root.go | 2 +- pkg/executor/executor.go | 19 +++++++++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/cmd/executor/cmd/root.go b/cmd/executor/cmd/root.go index 75ee38f3f5..0130e51f48 100644 --- a/cmd/executor/cmd/root.go +++ b/cmd/executor/cmd/root.go @@ -101,7 +101,7 @@ var RootCmd = &cobra.Command{ os.Exit(1) } - if err := executor.DoPush(image, destinations, tarPath); err != nil { + if err := executor.DoPush(image, destinations, tarPath, dockerInsecureSkipTLSVerify); err != nil { logrus.Error(err) os.Exit(1) } diff --git a/pkg/executor/executor.go b/pkg/executor/executor.go index 0ab0d98bbd..ddda87e467 100644 --- a/pkg/executor/executor.go +++ b/pkg/executor/executor.go @@ -18,6 +18,7 @@ package executor import ( "bytes" + "crypto/tls" "fmt" "io" "io/ioutil" @@ -180,7 +181,7 @@ func (w *withUserAgent) RoundTrip(r *http.Request) (*http.Response, error) { return w.t.RoundTrip(r) } -func DoPush(image v1.Image, destinations []string, tarPath string) error { +func DoPush(image v1.Image, destinations []string, tarPath string, dockerInsecureSkipTLSVerify bool) error { // continue pushing unless an error occurs for _, destination := range destinations { @@ -190,6 +191,14 @@ func DoPush(image v1.Image, destinations []string, tarPath string) error { return err } + if dockerInsecureSkipTLSVerify { + newReg, err := name.NewInsecureRegistry(destRef.Repository.Registry.Name(), name.WeakValidation) + if err != nil { + return err + } + destRef.Repository.Registry = newReg + } + if tarPath != "" { return tarball.WriteToFile(tarPath, destRef, image, nil) } @@ -205,7 +214,13 @@ func DoPush(image v1.Image, destinations []string, tarPath string) error { } // Create a transport to set our user-agent. - rt := &withUserAgent{t: http.DefaultTransport} + tr := http.DefaultTransport + if dockerInsecureSkipTLSVerify { + tr.(*http.Transport).TLSClientConfig = &tls.Config{ + InsecureSkipVerify: true, + } + } + rt := &withUserAgent{t: tr} if err := remote.Write(destRef, image, pushAuth, rt, remote.WriteOptions{}); err != nil { logrus.Error(fmt.Errorf("Failed to push to destination %s", destination))