Skip to content

Commit

Permalink
crane: ignore TLS certificate validation when using --insecure flag (#…
Browse files Browse the repository at this point in the history
…1054)

* crane: ignore TLS certificate validation when using --insecure flag

Signed-off-by: Carlos Panato <ctadeu@gmail.com>

* crane: update code per feedback

Signed-off-by: Carlos Panato <ctadeu@gmail.com>
  • Loading branch information
cpanato committed Jun 18, 2021
1 parent 529b437 commit 3bfd0b5
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion cmd/crane/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
package cmd

import (
"crypto/tls"
"fmt"
"net/http"
"os"
Expand Down Expand Up @@ -63,16 +64,21 @@ func New(use, short string, options []crane.Option) *cobra.Command {

options = append(options, crane.WithPlatform(platform.platform))

transport := http.DefaultTransport.(*http.Transport).Clone()
transport.TLSClientConfig = &tls.Config{InsecureSkipVerify: insecure}

// Add any http headers if they are set in the config file.
cf, err := config.Load(os.Getenv("DOCKER_CONFIG"))
if err != nil {
logs.Debug.Printf("failed to read config file: %v", err)
} else if len(cf.HTTPHeaders) != 0 {
options = append(options, crane.WithTransport(&headerTransport{
inner: http.DefaultTransport,
inner: transport,
httpHeaders: cf.HTTPHeaders,
}))
}

options = append(options, crane.WithTransport(transport))
},
}

Expand Down

0 comments on commit 3bfd0b5

Please sign in to comment.