added --insecure-skip-tls-verify for chart repos

Signed-off-by: Matthias Riegler <me@xvzf.tech>
pull/7254/head
Matthias Riegler 6 years ago
parent 0edb09e4fa
commit 1847ceb02f

@ -43,9 +43,10 @@ type repoAddOptions struct {
password string password string
noUpdate bool noUpdate bool
certFile string certFile string
keyFile string keyFile string
caFile string caFile string
insecureSkipTLSverify bool
repoFile string repoFile string
repoCache string repoCache string
@ -75,6 +76,7 @@ func newRepoAddCmd(out io.Writer) *cobra.Command {
f.StringVar(&o.certFile, "cert-file", "", "identify HTTPS client using this SSL certificate file") f.StringVar(&o.certFile, "cert-file", "", "identify HTTPS client using this SSL certificate file")
f.StringVar(&o.keyFile, "key-file", "", "identify HTTPS client using this SSL key file") f.StringVar(&o.keyFile, "key-file", "", "identify HTTPS client using this SSL key file")
f.StringVar(&o.caFile, "ca-file", "", "verify certificates of HTTPS-enabled servers using this CA bundle") f.StringVar(&o.caFile, "ca-file", "", "verify certificates of HTTPS-enabled servers using this CA bundle")
f.BoolVar(&o.insecureSkipTLSverify, "insecure-skip-tls-verify", false, "skip tls certificate checks for the repository")
return cmd return cmd
} }

@ -28,13 +28,14 @@ import (
// //
// Getters may or may not ignore these parameters as they are passed in. // Getters may or may not ignore these parameters as they are passed in.
type options struct { type options struct {
url string url string
certFile string certFile string
keyFile string keyFile string
caFile string caFile string
username string insecureSkipVerifyTLS bool
password string username string
userAgent string password string
userAgent string
} }
// Option allows specifying various settings configurable by the user for overriding the defaults // Option allows specifying various settings configurable by the user for overriding the defaults
@ -64,6 +65,13 @@ func WithUserAgent(userAgent string) Option {
} }
} }
// WithInsecureSkipVerifyTLS determines if a TLS Certificate will be checked
func WithInsecureSkipVerifyTLS(insecureSkipVerifyTLS bool) Option {
return func(opts *options) {
opts.insecureSkipVerifyTLS = insecureSkipVerifyTLS
}
}
// WithTLSClientConfig sets the client client auth with the provided credentials. // WithTLSClientConfig sets the client client auth with the provided credentials.
func WithTLSClientConfig(certFile, keyFile, caFile string) Option { func WithTLSClientConfig(certFile, keyFile, caFile string) Option {
return func(opts *options) { return func(opts *options) {

@ -17,6 +17,7 @@ package getter
import ( import (
"bytes" "bytes"
"crypto/tls"
"io" "io"
"net/http" "net/http"
@ -111,5 +112,18 @@ func (g *HTTPGetter) httpClient() (*http.Client, error) {
return client, nil return client, nil
} }
if g.opts.insecureSkipVerifyTLS {
client := &http.Client{
Transport: &http.Transport{
TLSClientConfig: &tls.Config{
InsecureSkipVerify: true,
},
},
}
return client, nil
}
return http.DefaultClient, nil return http.DefaultClient, nil
} }

@ -38,13 +38,14 @@ import (
// Entry represents a collection of parameters for chart repository // Entry represents a collection of parameters for chart repository
type Entry struct { type Entry struct {
Name string `json:"name"` Name string `json:"name"`
URL string `json:"url"` URL string `json:"url"`
Username string `json:"username"` Username string `json:"username"`
Password string `json:"password"` Password string `json:"password"`
CertFile string `json:"certFile"` CertFile string `json:"certFile"`
KeyFile string `json:"keyFile"` KeyFile string `json:"keyFile"`
CAFile string `json:"caFile"` CAFile string `json:"caFile"`
InsecureSkipTLSverify bool `json:"insecure_skip_tls_verify"`
} }
// ChartRepository represents a chart repository // ChartRepository represents a chart repository
@ -121,6 +122,7 @@ func (r *ChartRepository) DownloadIndexFile() (string, error) {
// TODO add user-agent // TODO add user-agent
resp, err := r.Client.Get(indexURL, resp, err := r.Client.Get(indexURL,
getter.WithURL(r.Config.URL), getter.WithURL(r.Config.URL),
getter.WithInsecureSkipVerifyTLS(r.Config.InsecureSkipTLSverify),
getter.WithTLSClientConfig(r.Config.CertFile, r.Config.KeyFile, r.Config.CAFile), getter.WithTLSClientConfig(r.Config.CertFile, r.Config.KeyFile, r.Config.CAFile),
getter.WithBasicAuth(r.Config.Username, r.Config.Password), getter.WithBasicAuth(r.Config.Username, r.Config.Password),
) )

Loading…
Cancel
Save