Skip to content

Commit

Permalink
fix pull oci chart with --insecure-skip-tls-verify
Browse files Browse the repository at this point in the history
Signed-off-by: tfwang <[email protected]>
  • Loading branch information
davidwtf committed Jan 16, 2023
1 parent 835b733 commit 36d590e
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 4 deletions.
6 changes: 6 additions & 0 deletions cmd/helm/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,11 @@ func newPullCmd(cfg *action.Configuration, out io.Writer) *cobra.Command {
log.Fatal(err)
}

if client.InsecureSkipTLSverify {
if err := cfg.RegistryClient.WithInsecureResolver(); err != nil {
log.Fatal(err)
}
}

return cmd
}
6 changes: 6 additions & 0 deletions pkg/getter/ocigetter.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ func (g *OCIGetter) Get(href string, options ...Option) (*bytes.Buffer, error) {
func (g *OCIGetter) get(href string) (*bytes.Buffer, error) {
client := g.opts.registryClient

if g.opts.insecureSkipVerifyTLS {
if err := client.WithInsecureResolver(); err != nil {
return nil, err
}
}

ref := strings.TrimPrefix(href, fmt.Sprintf("%s://", registry.OCIScheme))

var pullOpts []registry.PullOption
Expand Down
36 changes: 32 additions & 4 deletions pkg/registry/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package registry // import "helm.sh/helm/v3/pkg/registry"

import (
"context"
"crypto/tls"
"encoding/json"
"fmt"
"io"
Expand Down Expand Up @@ -87,10 +88,7 @@ func NewClient(options ...ClientOption) (*Client, error) {
client.authorizer = authClient
}
if client.resolver == nil {
headers := http.Header{}
headers.Set("User-Agent", version.GetUserAgent())
opts := []auth.ResolverOption{auth.WithResolverHeaders(headers)}
resolver, err := client.authorizer.ResolverWithOpts(opts...)
resolver, err := client.newResolver(false)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -138,6 +136,36 @@ func NewClient(options ...ClientOption) (*Client, error) {
return client, nil
}

func (c *Client) newResolver(insecure bool) (remotes.Resolver, error) {
headers := http.Header{}
headers.Set("User-Agent", version.GetUserAgent())
opts := []auth.ResolverOption{auth.WithResolverHeaders(headers)}

if insecure {
insecureClient := &http.Client{
Transport: &http.Transport{
DisableCompression: true,
Proxy: http.ProxyFromEnvironment,
TLSClientConfig: &tls.Config{
InsecureSkipVerify: true,
},
},
}
opts = append(opts, auth.WithResolverClient(insecureClient))
}

return c.authorizer.ResolverWithOpts(opts...)
}

func (c *Client) WithInsecureResolver() error {
resolver, err := c.newResolver(true)
if err != nil {
return err
}
c.resolver = resolver
return nil
}

// ClientOptDebug returns a function that sets the debug setting on client options set
func ClientOptDebug(debug bool) ClientOption {
return func(client *Client) {
Expand Down

0 comments on commit 36d590e

Please sign in to comment.