Skip to content

Commit 8014d9f

Browse files
committed
Skip TLS verification for localhost
Signed-off-by: Aditi Sharma <[email protected]>
1 parent 10bbd1a commit 8014d9f

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
@@ -337,6 +337,9 @@ func (c *criService) registryHosts(auth *runtime.AuthConfig) docker.RegistryHost
337337
if err != nil {
338338
return nil, errors.Wrapf(err, "get TLSConfig for registry %q", e)
339339
}
340+
} else if isLocalHost(host) && u.Scheme == "http" {
341+
// Skipping TLS verification for localhost
342+
transport.TLSClientConfig.InsecureSkipVerify = true
340343
}
341344

342345
if auth == nil && config.Auth != nil {
@@ -366,13 +369,24 @@ func (c *criService) registryHosts(auth *runtime.AuthConfig) docker.RegistryHost
366369

367370
// defaultScheme returns the default scheme for a registry host.
368371
func defaultScheme(host string) string {
372+
if isLocalHost(host) {
373+
return "http"
374+
}
375+
return "https"
376+
}
377+
378+
// isLocalHost checks if the registry host is local.
379+
func isLocalHost(host string) bool {
369380
if h, _, err := net.SplitHostPort(host); err == nil {
370381
host = h
371382
}
372-
if host == "localhost" || host == "127.0.0.1" || host == "::1" {
373-
return "http"
383+
384+
if host == "localhost" {
385+
return true
374386
}
375-
return "https"
387+
388+
ip := net.ParseIP(host)
389+
return ip.IsLoopback()
376390
}
377391

378392
// addDefaultScheme returns the endpoint with default scheme

0 commit comments

Comments
 (0)