Kaynağa Gözat

Update auth client configuration to use proper tls config

Currently the http clients used by auth use the default tls config.  The config needs to be updated to only support TLS1.0 and newer as well as respect registry insecure configuration.

Signed-off-by: Derek McGowan <derek@mcgstyle.net> (github: dmcgowan)
Derek McGowan 10 yıl önce
ebeveyn
işleme
959b35d974
1 değiştirilmiş dosya ile 19 ekleme ve 1 silme
  1. 19 1
      registry/auth.go

+ 19 - 1
registry/auth.go

@@ -1,6 +1,7 @@
 package registry
 package registry
 
 
 import (
 import (
+	"crypto/tls"
 	"encoding/base64"
 	"encoding/base64"
 	"encoding/json"
 	"encoding/json"
 	"errors"
 	"errors"
@@ -70,10 +71,19 @@ func (auth *RequestAuthorization) getToken() (string, error) {
 		return auth.tokenCache, nil
 		return auth.tokenCache, nil
 	}
 	}
 
 
+	tlsConfig := tls.Config{
+		MinVersion: tls.VersionTLS10,
+	}
+	if !auth.registryEndpoint.IsSecure {
+		tlsConfig.InsecureSkipVerify = true
+	}
+
 	client := &http.Client{
 	client := &http.Client{
 		Transport: &http.Transport{
 		Transport: &http.Transport{
 			DisableKeepAlives: true,
 			DisableKeepAlives: true,
-			Proxy:             http.ProxyFromEnvironment},
+			Proxy:             http.ProxyFromEnvironment,
+			TLSClientConfig:   &tlsConfig,
+		},
 		CheckRedirect: AddRequiredHeadersToRedirectedRequests,
 		CheckRedirect: AddRequiredHeadersToRedirectedRequests,
 	}
 	}
 	factory := HTTPRequestFactory(nil)
 	factory := HTTPRequestFactory(nil)
@@ -362,10 +372,18 @@ func loginV1(authConfig *AuthConfig, registryEndpoint *Endpoint, factory *utils.
 func loginV2(authConfig *AuthConfig, registryEndpoint *Endpoint, factory *utils.HTTPRequestFactory) (string, error) {
 func loginV2(authConfig *AuthConfig, registryEndpoint *Endpoint, factory *utils.HTTPRequestFactory) (string, error) {
 	log.Debugf("attempting v2 login to registry endpoint %s", registryEndpoint)
 	log.Debugf("attempting v2 login to registry endpoint %s", registryEndpoint)
 
 
+	tlsConfig := tls.Config{
+		MinVersion: tls.VersionTLS10,
+	}
+	if !registryEndpoint.IsSecure {
+		tlsConfig.InsecureSkipVerify = true
+	}
+
 	client := &http.Client{
 	client := &http.Client{
 		Transport: &http.Transport{
 		Transport: &http.Transport{
 			DisableKeepAlives: true,
 			DisableKeepAlives: true,
 			Proxy:             http.ProxyFromEnvironment,
 			Proxy:             http.ProxyFromEnvironment,
+			TLSClientConfig:   &tlsConfig,
 		},
 		},
 		CheckRedirect: AddRequiredHeadersToRedirectedRequests,
 		CheckRedirect: AddRequiredHeadersToRedirectedRequests,
 	}
 	}