Merge pull request #5100 from adisky/skip-tls-localHost

Skip TLS verification for localhost
This commit is contained in:
Phil Estes 2021-05-12 14:56:53 -04:00 committed by GitHub
commit e47400cbd2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -373,6 +373,9 @@ func (c *criService) registryHosts(ctx context.Context, auth *runtime.AuthConfig
if err != nil {
return nil, errors.Wrapf(err, "get TLSConfig for registry %q", e)
}
} else if isLocalHost(host) && u.Scheme == "http" {
// Skipping TLS verification for localhost
transport.TLSClientConfig.InsecureSkipVerify = true
}
// Make a copy of `auth`, so that different authorizers would not reference
@ -406,15 +409,26 @@ func (c *criService) registryHosts(ctx context.Context, auth *runtime.AuthConfig
// defaultScheme returns the default scheme for a registry host.
func defaultScheme(host string) string {
if h, _, err := net.SplitHostPort(host); err == nil {
host = h
}
if host == "localhost" || host == "127.0.0.1" || host == "::1" {
if isLocalHost(host) {
return "http"
}
return "https"
}
// isLocalHost checks if the registry host is local.
func isLocalHost(host string) bool {
if h, _, err := net.SplitHostPort(host); err == nil {
host = h
}
if host == "localhost" {
return true
}
ip := net.ParseIP(host)
return ip.IsLoopback()
}
// addDefaultScheme returns the endpoint with default scheme
func addDefaultScheme(endpoint string) (string, error) {
if strings.Contains(endpoint, "://") {