Skip to content

Commit e47400c

Browse files
authored
Merge pull request #5100 from adisky/skip-tls-localHost
Skip TLS verification for localhost
2 parents 28e29af + 8014d9f commit e47400c

1 file changed

Lines changed: 17 additions & 3 deletions

File tree

pkg/cri/server/image_pull.go

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,9 @@ func (c *criService) registryHosts(ctx context.Context, auth *runtime.AuthConfig
373373
if err != nil {
374374
return nil, errors.Wrapf(err, "get TLSConfig for registry %q", e)
375375
}
376+
} else if isLocalHost(host) && u.Scheme == "http" {
377+
// Skipping TLS verification for localhost
378+
transport.TLSClientConfig.InsecureSkipVerify = true
376379
}
377380

378381
// Make a copy of `auth`, so that different authorizers would not reference
@@ -406,13 +409,24 @@ func (c *criService) registryHosts(ctx context.Context, auth *runtime.AuthConfig
406409

407410
// defaultScheme returns the default scheme for a registry host.
408411
func defaultScheme(host string) string {
412+
if isLocalHost(host) {
413+
return "http"
414+
}
415+
return "https"
416+
}
417+
418+
// isLocalHost checks if the registry host is local.
419+
func isLocalHost(host string) bool {
409420
if h, _, err := net.SplitHostPort(host); err == nil {
410421
host = h
411422
}
412-
if host == "localhost" || host == "127.0.0.1" || host == "::1" {
413-
return "http"
423+
424+
if host == "localhost" {
425+
return true
414426
}
415-
return "https"
427+
428+
ip := net.ParseIP(host)
429+
return ip.IsLoopback()
416430
}
417431

418432
// addDefaultScheme returns the endpoint with default scheme

0 commit comments

Comments
 (0)