Skip to content

Commit d956110

Browse files
authored
Merge pull request #1581 from thaJeztah/dont_use_tls_for_sockets
Don't use TLS for socket connections
2 parents c108da5 + 67f029e commit d956110

File tree

1 file changed

+24
-7
lines changed

1 file changed

+24
-7
lines changed

cli/context/docker/load.go

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"encoding/pem"
77
"net"
88
"net/http"
9+
"strings"
910
"time"
1011

1112
"github.com/docker/cli/cli/connhelper"
@@ -90,14 +91,19 @@ func (ep *Endpoint) ClientOpts() ([]client.Opt, error) {
9091
return nil, err
9192
}
9293
if helper == nil {
93-
tlsConfig, err := ep.tlsConfig()
94-
if err != nil {
95-
return nil, err
94+
// Check if we're connecting over a socket, because there's no
95+
// need to configure TLS for a socket connection.
96+
//
97+
// TODO(thaJeztah); make resolveDockerEndpoint and resolveDefaultDockerEndpoint not load TLS data,
98+
// and load TLS files lazily; see https://github.com/docker/cli/pull/1581
99+
if !isSocket(ep.Host) {
100+
tlsConfig, err := ep.tlsConfig()
101+
if err != nil {
102+
return nil, err
103+
}
104+
result = append(result, withHTTPClient(tlsConfig))
96105
}
97-
result = append(result,
98-
withHTTPClient(tlsConfig),
99-
client.WithHost(ep.Host),
100-
)
106+
result = append(result, client.WithHost(ep.Host))
101107
} else {
102108
result = append(result,
103109
client.WithHTTPClient(&http.Client{
@@ -116,6 +122,17 @@ func (ep *Endpoint) ClientOpts() ([]client.Opt, error) {
116122
return result, nil
117123
}
118124

125+
// isSocket checks if the given address is a Unix-socket (linux),
126+
// named pipe (Windows), or file-descriptor.
127+
func isSocket(addr string) bool {
128+
switch proto, _, _ := strings.Cut(addr, "://"); proto {
129+
case "unix", "npipe", "fd":
130+
return true
131+
default:
132+
return false
133+
}
134+
}
135+
119136
func withHTTPClient(tlsConfig *tls.Config) func(*client.Client) error {
120137
return func(c *client.Client) error {
121138
if tlsConfig == nil {

0 commit comments

Comments
 (0)