Skip to content

Commit

Permalink
Use InsecureSkipVerify, if IP address is used for baseURL host (#445)
Browse files Browse the repository at this point in the history
Signed-off-by: Tamal Saha <[email protected]>
  • Loading branch information
tamalsaha authored Jul 11, 2024
1 parent 5565311 commit 5eb4986
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion pkg/identity/b3.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ import (
"crypto/tls"
"crypto/x509"
"io"
"net"
"net/http"
"net/url"
"path"

kmapi "kmodules.xyz/client-go/api/v1"
Expand Down Expand Up @@ -53,7 +55,18 @@ func NewClient(baseURL, token string, caCert []byte, kc client.Reader) (*Client,
kc: kc,
}
if len(caCert) == 0 {
c.client = http.DefaultClient
u, err := url.Parse(baseURL)
if err != nil {
return nil, err
}
// use InsecureSkipVerify, if IP address is used for baseURL host
if ip := net.ParseIP(u.Hostname()); ip != nil {
customTransport := http.DefaultTransport.(*http.Transport).Clone()
customTransport.TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
c.client = &http.Client{Transport: customTransport}
} else {
c.client = http.DefaultClient
}
} else {
caCertPool := x509.NewCertPool()
caCertPool.AppendCertsFromPEM(caCert)
Expand Down

0 comments on commit 5eb4986

Please sign in to comment.