Browse code

Disable legacy (v1) registries by default

Deprecation of interacting with v1 registries was
started in docker 1.8.3, which added a `--disable-legacy-registry`
flag.

This option was anounced to be the default starting
with docker 17.06, and v1 registries completely
removed in docker 17.12.

This patch updates the default, and disables
interaction with v1 registres by default.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>

Sebastiaan van Stijn authored on 2017/06/11 21:39:28
Showing 7 changed files
... ...
@@ -406,8 +406,12 @@ func loadDaemonCliConfig(opts *daemonOptions) (*config.Config, error) {
406 406
 		return nil, err
407 407
 	}
408 408
 
409
+	if conf.V2Only == false {
410
+		logrus.Warnf(`The "disable-legacy-registry" option is deprecated and wil be removed in Docker v17.12. Interacting with legacy (v1) registries will no longer be supported in Docker v17.12"`)
411
+	}
412
+
409 413
 	if flags.Changed("graph") {
410
-		logrus.Warnf(`the "-g / --graph" flag is deprecated. Please use "--data-root" instead`)
414
+		logrus.Warnf(`The "-g / --graph" flag is deprecated. Please use "--data-root" instead`)
411 415
 	}
412 416
 
413 417
 	// Labels of the docker engine used to allow multiple values associated with the same key.
... ...
@@ -102,7 +102,7 @@ func TestLoadDaemonConfigWithTrueDefaultValuesLeaveDefaults(t *testing.T) {
102 102
 }
103 103
 
104 104
 func TestLoadDaemonConfigWithLegacyRegistryOptions(t *testing.T) {
105
-	content := `{"disable-legacy-registry": true}`
105
+	content := `{"disable-legacy-registry": false}`
106 106
 	tempFile := tempfile.NewTempFile(t, "config", content)
107 107
 	defer tempFile.Remove()
108 108
 
... ...
@@ -110,5 +110,5 @@ func TestLoadDaemonConfigWithLegacyRegistryOptions(t *testing.T) {
110 110
 	loadedConfig, err := loadDaemonCliConfig(opts)
111 111
 	require.NoError(t, err)
112 112
 	require.NotNil(t, loadedConfig)
113
-	assert.True(t, loadedConfig.V2Only)
113
+	assert.False(t, loadedConfig.V2Only)
114 114
 }
... ...
@@ -13,6 +13,10 @@ import (
13 13
 )
14 14
 
15 15
 func (s *DockerRegistryAuthHtpasswdSuite) TestLogoutWithExternalAuth(c *check.C) {
16
+
17
+	// @TODO TestLogoutWithExternalAuth expects docker to fall back to a v1 registry, so has to be updated for v17.12, when v1 registries are no longer supported
18
+	s.d.StartWithBusybox(c, "--disable-legacy-registry=false")
19
+
16 20
 	osPath := os.Getenv("PATH")
17 21
 	defer os.Setenv("PATH", osPath)
18 22
 
... ...
@@ -28,6 +32,7 @@ func (s *DockerRegistryAuthHtpasswdSuite) TestLogoutWithExternalAuth(c *check.C)
28 28
 
29 29
 	tmp, err := ioutil.TempDir("", "integration-cli-")
30 30
 	c.Assert(err, checker.IsNil)
31
+	defer os.RemoveAll(tmp)
31 32
 
32 33
 	externalAuthConfig := `{ "credsStore": "shell-test" }`
33 34
 
... ...
@@ -35,24 +40,27 @@ func (s *DockerRegistryAuthHtpasswdSuite) TestLogoutWithExternalAuth(c *check.C)
35 35
 	err = ioutil.WriteFile(configPath, []byte(externalAuthConfig), 0644)
36 36
 	c.Assert(err, checker.IsNil)
37 37
 
38
-	dockerCmd(c, "--config", tmp, "login", "-u", s.reg.Username(), "-p", s.reg.Password(), privateRegistryURL)
38
+	_, err = s.d.Cmd("--config", tmp, "login", "-u", s.reg.Username(), "-p", s.reg.Password(), privateRegistryURL)
39
+	c.Assert(err, checker.IsNil)
39 40
 
40 41
 	b, err := ioutil.ReadFile(configPath)
41 42
 	c.Assert(err, checker.IsNil)
42 43
 	c.Assert(string(b), checker.Not(checker.Contains), "\"auth\":")
43 44
 	c.Assert(string(b), checker.Contains, privateRegistryURL)
44 45
 
45
-	dockerCmd(c, "--config", tmp, "tag", "busybox", repoName)
46
-	dockerCmd(c, "--config", tmp, "push", repoName)
47
-
48
-	dockerCmd(c, "--config", tmp, "logout", privateRegistryURL)
46
+	_, err = s.d.Cmd("--config", tmp, "tag", "busybox", repoName)
47
+	c.Assert(err, checker.IsNil)
48
+	_, err = s.d.Cmd("--config", tmp, "push", repoName)
49
+	c.Assert(err, checker.IsNil)
50
+	_, err = s.d.Cmd("--config", tmp, "logout", privateRegistryURL)
51
+	c.Assert(err, checker.IsNil)
49 52
 
50 53
 	b, err = ioutil.ReadFile(configPath)
51 54
 	c.Assert(err, checker.IsNil)
52 55
 	c.Assert(string(b), checker.Not(checker.Contains), privateRegistryURL)
53 56
 
54 57
 	// check I cannot pull anymore
55
-	out, _, err := dockerCmdWithError("--config", tmp, "pull", repoName)
58
+	out, err := s.d.Cmd("--config", tmp, "pull", repoName)
56 59
 	c.Assert(err, check.NotNil, check.Commentf(out))
57 60
 	c.Assert(out, checker.Contains, "Error: image dockercli/busybox:authtest not found")
58 61
 }
... ...
@@ -258,10 +258,13 @@ func (s *DockerHubPullSuite) TestPullClientDisconnect(c *check.C) {
258 258
 }
259 259
 
260 260
 func (s *DockerRegistryAuthHtpasswdSuite) TestPullNoCredentialsNotFound(c *check.C) {
261
+	// @TODO TestPullNoCredentialsNotFound expects docker to fall back to a v1 registry, so has to be updated for v17.12, when v1 registries are no longer supported
262
+	s.d.StartWithBusybox(c, "--disable-legacy-registry=false")
263
+
261 264
 	// we don't care about the actual image, we just want to see image not found
262 265
 	// because that means v2 call returned 401 and we fell back to v1 which usually
263 266
 	// gives a 404 (in this case the test registry doesn't handle v1 at all)
264
-	out, _, err := dockerCmdWithError("pull", privateRegistryURL+"/busybox")
267
+	out, err := s.d.Cmd("pull", privateRegistryURL+"/busybox")
265 268
 	c.Assert(err, check.NotNil, check.Commentf(out))
266 269
 	c.Assert(out, checker.Contains, "Error: image busybox:latest not found")
267 270
 }
... ...
@@ -98,8 +98,7 @@ func (s *DockerRegistrySuite) TestUserAgentPassThrough(c *check.C) {
98 98
 		"--insecure-registry", buildReg.URL(),
99 99
 		"--insecure-registry", pullReg.URL(),
100 100
 		"--insecure-registry", pushReg.URL(),
101
-		"--insecure-registry", loginReg.URL(),
102
-		"--disable-legacy-registry=true")
101
+		"--insecure-registry", loginReg.URL())
103 102
 
104 103
 	dockerfileName, cleanup1, err := makefile(fmt.Sprintf("FROM %s", buildRepoName))
105 104
 	c.Assert(err, check.IsNil, check.Commentf("Unable to create test dockerfile"))
... ...
@@ -34,7 +34,7 @@ func makefile(contents string) (string, func(), error) {
34 34
 
35 35
 }
36 36
 
37
-// TestV2Only ensures that a daemon in v2-only mode does not
37
+// TestV2Only ensures that a daemon by default does not
38 38
 // attempt to contact any v1 registry endpoints.
39 39
 func (s *DockerRegistrySuite) TestV2Only(c *check.C) {
40 40
 	reg, err := registry.NewMock(c)
... ...
@@ -51,7 +51,7 @@ func (s *DockerRegistrySuite) TestV2Only(c *check.C) {
51 51
 
52 52
 	repoName := fmt.Sprintf("%s/busybox", reg.URL())
53 53
 
54
-	s.d.Start(c, "--insecure-registry", reg.URL(), "--disable-legacy-registry=true")
54
+	s.d.Start(c, "--insecure-registry", reg.URL())
55 55
 
56 56
 	dockerfileName, cleanup, err := makefile(fmt.Sprintf("FROM %s/busybox", reg.URL()))
57 57
 	c.Assert(err, check.IsNil, check.Commentf("Unable to create test dockerfile"))
... ...
@@ -66,7 +66,7 @@ func (s *DockerRegistrySuite) TestV2Only(c *check.C) {
66 66
 	s.d.Cmd("pull", repoName)
67 67
 }
68 68
 
69
-// TestV1 starts a daemon in 'normal' mode
69
+// TestV1 starts a daemon with legacy registries enabled
70 70
 // and ensure v1 endpoints are hit for the following operations:
71 71
 // login, push, pull, build & run
72 72
 func (s *DockerRegistrySuite) TestV1(c *check.C) {
... ...
@@ -21,5 +21,5 @@ func cleanPath(s string) string {
21 21
 
22 22
 // installCliPlatformFlags handles any platform specific flags for the service.
23 23
 func (options *ServiceOptions) installCliPlatformFlags(flags *pflag.FlagSet) {
24
-	flags.BoolVar(&options.V2Only, "disable-legacy-registry", false, "Disable contacting legacy registries")
24
+	flags.BoolVar(&options.V2Only, "disable-legacy-registry", true, "Disable contacting legacy registries")
25 25
 }