Selaa lähdekoodia

Merge pull request #15313 from Microsoft/10662-fixcertdir

Windows: [TP3] Fix certificate directory for registry
Brian Goff 10 vuotta sitten
vanhempi
commit
5b289cd1aa

+ 20 - 0
registry/config.go

@@ -20,6 +20,26 @@ type Options struct {
 	InsecureRegistries opts.ListOpts
 }
 
+const (
+	// DefaultNamespace is the default namespace
+	DefaultNamespace = "docker.io"
+	// DefaultRegistryVersionHeader is the name of the default HTTP header
+	// that carries Registry version info
+	DefaultRegistryVersionHeader = "Docker-Distribution-Api-Version"
+	// DefaultV1Registry is the URI of the default v1 registry
+	DefaultV1Registry = "https://index.docker.io"
+
+	// IndexServer is the v1 registry server used for user auth + account creation
+	IndexServer = DefaultV1Registry + "/v1/"
+	// IndexName is the name of the index
+	IndexName = "docker.io"
+
+	// NotaryServer is the endpoint serving the Notary trust server
+	NotaryServer = "https://notary.docker.io"
+
+	// IndexServer = "https://registry-stage.hub.docker.com/v1/"
+)
+
 var (
 	// ErrInvalidRepositoryName is an error returned if the repository name did
 	// not have the correct form

+ 19 - 0
registry/config_unix.go

@@ -0,0 +1,19 @@
+// +build !windows
+
+package registry
+
+const (
+	// DefaultV2Registry is the URI of the default v2 registry
+	DefaultV2Registry = "https://registry-1.docker.io"
+
+	// CertsDir is the directory where certificates are stored
+	CertsDir = "/etc/docker/certs.d"
+)
+
+// cleanPath is used to ensure that a directory name is valid on the target
+// platform. It will be passed in something *similar* to a URL such as
+// https:/index.docker.io/v1. Not all platforms support directory names
+// which contain those characters (such as : on Windows)
+func cleanPath(s string) string {
+	return s
+}

+ 25 - 0
registry/config_windows.go

@@ -0,0 +1,25 @@
+package registry
+
+import (
+	"os"
+	"path/filepath"
+	"strings"
+)
+
+// DefaultV2Registry is the URI of the default (official) v2 registry.
+// This is the windows-specific endpoint.
+//
+// Currently it is a TEMPORARY link that allows Microsoft to continue
+// development of Docker Engine for Windows.
+const DefaultV2Registry = "https://ms-tp3.registry-1.docker.io"
+
+// CertsDir is the directory where certificates are stored
+var CertsDir = os.Getenv("programdata") + `\docker\certs.d`
+
+// cleanPath is used to ensure that a directory name is valid on the target
+// platform. It will be passed in something *similar* to a URL such as
+// https:\index.docker.io\v1. Not all platforms support directory names
+// which contain those characters (such as : on Windows)
+func cleanPath(s string) string {
+	return filepath.FromSlash(strings.Replace(s, ":", "", -1))
+}

+ 0 - 24
registry/consts.go

@@ -1,24 +0,0 @@
-package registry
-
-const (
-	// DefaultNamespace is the default namespace
-	DefaultNamespace = "docker.io"
-	// DefaultRegistryVersionHeader is the name of the default HTTP header
-	// that carries Registry version info
-	DefaultRegistryVersionHeader = "Docker-Distribution-Api-Version"
-	// DefaultV1Registry is the URI of the default v1 registry
-	DefaultV1Registry = "https://index.docker.io"
-
-	// CertsDir is the directory where certificates are stored
-	CertsDir = "/etc/docker/certs.d"
-
-	// IndexServer is the v1 registry server used for user auth + account creation
-	IndexServer = DefaultV1Registry + "/v1/"
-	// IndexName is the name of the index
-	IndexName = "docker.io"
-
-	// NotaryServer is the endpoint serving the Notary trust server
-	NotaryServer = "https://notary.docker.io"
-
-	// IndexServer = "https://registry-stage.hub.docker.com/v1/"
-)

+ 0 - 6
registry/consts_unix.go

@@ -1,6 +0,0 @@
-// +build !windows
-
-package registry
-
-// DefaultV2Registry is the URI of the default v2 registry
-const DefaultV2Registry = "https://registry-1.docker.io"

+ 0 - 10
registry/consts_windows.go

@@ -1,10 +0,0 @@
-// +build windows
-
-package registry
-
-// DefaultV2Registry is the URI of the default (official) v2 registry.
-// This is the windows-specific endpoint.
-//
-// Currently it is a TEMPORARY link that allows Microsoft to continue
-// development of Docker Engine for Windows.
-const DefaultV2Registry = "https://ms-tp3.registry-1.docker.io"

+ 1 - 1
registry/registry.go

@@ -58,7 +58,7 @@ func newTLSConfig(hostname string, isSecure bool) (*tls.Config, error) {
 	tlsConfig.InsecureSkipVerify = !isSecure
 
 	if isSecure {
-		hostDir := filepath.Join(CertsDir, hostname)
+		hostDir := filepath.Join(CertsDir, cleanPath(hostname))
 		logrus.Debugf("hostDir: %s", hostDir)
 		if err := ReadCertsDirectory(&tlsConfig, hostDir); err != nil {
 			return nil, err