mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Disable v1 protocol for the default registry
All images in the default registry (AKA docker.io, index.docker.io, and registry-1.docker.io) are available via the v2 protocol, so there's no reason to use the v1 protocol. Disabling it prevents useless fallbacks. Signed-off-by: Noah Treuhaft <noah.treuhaft@docker.com>
This commit is contained in:
parent
90d10203a4
commit
7ffb4ad81a
4 changed files with 32 additions and 25 deletions
|
@ -36,20 +36,16 @@ var (
|
||||||
// that carries Registry version info
|
// that carries Registry version info
|
||||||
DefaultRegistryVersionHeader = "Docker-Distribution-Api-Version"
|
DefaultRegistryVersionHeader = "Docker-Distribution-Api-Version"
|
||||||
|
|
||||||
// IndexServer is the v1 registry server used for user auth + account creation
|
// IndexHostname is the index hostname
|
||||||
IndexServer = DefaultV1Registry.String() + "/v1/"
|
IndexHostname = "index.docker.io"
|
||||||
|
// IndexServer is used for user auth and image search
|
||||||
|
IndexServer = "https://" + IndexHostname + "/v1/"
|
||||||
// IndexName is the name of the index
|
// IndexName is the name of the index
|
||||||
IndexName = "docker.io"
|
IndexName = "docker.io"
|
||||||
|
|
||||||
// NotaryServer is the endpoint serving the Notary trust server
|
// NotaryServer is the endpoint serving the Notary trust server
|
||||||
NotaryServer = "https://notary.docker.io"
|
NotaryServer = "https://notary.docker.io"
|
||||||
|
|
||||||
// DefaultV1Registry is the URI of the default v1 registry
|
|
||||||
DefaultV1Registry = &url.URL{
|
|
||||||
Scheme: "https",
|
|
||||||
Host: "index.docker.io",
|
|
||||||
}
|
|
||||||
|
|
||||||
// DefaultV2Registry is the URI of the default v2 registry
|
// DefaultV2Registry is the URI of the default v2 registry
|
||||||
DefaultV2Registry = &url.URL{
|
DefaultV2Registry = &url.URL{
|
||||||
Scheme: "https",
|
Scheme: "https",
|
||||||
|
|
|
@ -1,25 +1,13 @@
|
||||||
package registry
|
package registry
|
||||||
|
|
||||||
import (
|
import "net/url"
|
||||||
"net/url"
|
|
||||||
|
|
||||||
"github.com/docker/go-connections/tlsconfig"
|
|
||||||
)
|
|
||||||
|
|
||||||
func (s *DefaultService) lookupV1Endpoints(hostname string) (endpoints []APIEndpoint, err error) {
|
func (s *DefaultService) lookupV1Endpoints(hostname string) (endpoints []APIEndpoint, err error) {
|
||||||
tlsConfig := tlsconfig.ServerDefault()
|
if hostname == DefaultNamespace || hostname == DefaultV2Registry.Host || hostname == IndexHostname {
|
||||||
if hostname == DefaultNamespace {
|
return []APIEndpoint{}, nil
|
||||||
endpoints = append(endpoints, APIEndpoint{
|
|
||||||
URL: DefaultV1Registry,
|
|
||||||
Version: APIVersion1,
|
|
||||||
Official: true,
|
|
||||||
TrimHostname: true,
|
|
||||||
TLSConfig: tlsConfig,
|
|
||||||
})
|
|
||||||
return endpoints, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tlsConfig, err = s.tlsConfig(hostname)
|
tlsConfig, err := s.tlsConfig(hostname)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
23
registry/service_v1_test.go
Normal file
23
registry/service_v1_test.go
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
package registry
|
||||||
|
|
||||||
|
import "testing"
|
||||||
|
|
||||||
|
func TestLookupV1Endpoints(t *testing.T) {
|
||||||
|
s := NewService(ServiceOptions{})
|
||||||
|
|
||||||
|
cases := []struct {
|
||||||
|
hostname string
|
||||||
|
expectedLen int
|
||||||
|
}{
|
||||||
|
{"example.com", 1},
|
||||||
|
{DefaultNamespace, 0},
|
||||||
|
{DefaultV2Registry.Host, 0},
|
||||||
|
{IndexHostname, 0},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, c := range cases {
|
||||||
|
if ret, err := s.lookupV1Endpoints(c.hostname); err != nil || len(ret) != c.expectedLen {
|
||||||
|
t.Errorf("lookupV1Endpoints(`"+c.hostname+"`) returned %+v and %+v", ret, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -9,7 +9,7 @@ import (
|
||||||
|
|
||||||
func (s *DefaultService) lookupV2Endpoints(hostname string) (endpoints []APIEndpoint, err error) {
|
func (s *DefaultService) lookupV2Endpoints(hostname string) (endpoints []APIEndpoint, err error) {
|
||||||
tlsConfig := tlsconfig.ServerDefault()
|
tlsConfig := tlsconfig.ServerDefault()
|
||||||
if hostname == DefaultNamespace || hostname == DefaultV1Registry.Host {
|
if hostname == DefaultNamespace || hostname == IndexHostname {
|
||||||
// v2 mirrors
|
// v2 mirrors
|
||||||
for _, mirror := range s.config.Mirrors {
|
for _, mirror := range s.config.Mirrors {
|
||||||
if !strings.HasPrefix(mirror, "http://") && !strings.HasPrefix(mirror, "https://") {
|
if !strings.HasPrefix(mirror, "http://") && !strings.HasPrefix(mirror, "https://") {
|
||||||
|
|
Loading…
Add table
Reference in a new issue