From 070da63310cabb855bc0b34ce0fde229949ff303 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Tue, 3 May 2022 23:10:14 +0200 Subject: [PATCH] daemon: only create trust-key if DOCKER_ALLOW_SCHEMA1_PUSH_DONOTUSE is set The libtrust trust-key is only used for pushing legacy image manifests; pushing these images has been deprecated, and we only need to be able to push them in our CI. This patch disables generating the trust-key (and related paths) unless the DOCKER_ALLOW_SCHEMA1_PUSH_DONOTUSE env-var is set (which we do in our CI). Signed-off-by: Sebastiaan van Stijn --- daemon/daemon.go | 25 ++++++++++++----------- integration-cli/docker_cli_daemon_test.go | 2 ++ 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/daemon/daemon.go b/daemon/daemon.go index 5dc4b0cd8a..dd97426035 100644 --- a/daemon/daemon.go +++ b/daemon/daemon.go @@ -985,17 +985,6 @@ func NewDaemon(ctx context.Context, config *config.Config, pluginStore *plugin.S logrus.WithError(err).Warnf("unable to migrate engine ID; a new engine ID will be generated") } - trustKey, err := loadOrCreateTrustKey(config.TrustKeyPath) - if err != nil { - return nil, err - } - - trustDir := filepath.Join(config.Root, "trust") - - if err := system.MkdirAll(trustDir, 0700); err != nil { - return nil, err - } - // We have a single tag/reference store for the daemon globally. However, it's // stored under the graphdriver. On host platforms which only support a single // container OS, but multiple selectable graphdrivers, this means depending on which @@ -1057,10 +1046,22 @@ func NewDaemon(ctx context.Context, config *config.Config, pluginStore *plugin.S MaxDownloadAttempts: *config.MaxDownloadAttempts, ReferenceStore: rs, RegistryService: registryService, - TrustKey: trustKey, ContentNamespace: config.ContainerdNamespace, } + // This is a temporary environment variables used in CI to allow pushing + // manifest v2 schema 1 images to test-registries used for testing *pulling* + // these images. + if os.Getenv("DOCKER_ALLOW_SCHEMA1_PUSH_DONOTUSE") != "" { + imgSvcConfig.TrustKey, err = loadOrCreateTrustKey(config.TrustKeyPath) + if err != nil { + return nil, err + } + if err = system.MkdirAll(filepath.Join(config.Root, "trust"), 0700); err != nil { + return nil, err + } + } + // containerd is not currently supported with Windows. // So sometimes d.containerdCli will be nil // In that case we'll create a local content store... but otherwise we'll use containerd diff --git a/integration-cli/docker_cli_daemon_test.go b/integration-cli/docker_cli_daemon_test.go index 94f07f56b4..96c0d0a906 100644 --- a/integration-cli/docker_cli_daemon_test.go +++ b/integration-cli/docker_cli_daemon_test.go @@ -559,6 +559,7 @@ func (s *DockerDaemonSuite) TestDaemonAllocatesListeningPort(c *testing.T) { func (s *DockerDaemonSuite) TestDaemonKeyGeneration(c *testing.T) { // TODO: skip or update for Windows daemon os.Remove("/etc/docker/key.json") + c.Setenv("DOCKER_ALLOW_SCHEMA1_PUSH_DONOTUSE", "1") s.d.Start(c) s.d.Stop(c) @@ -1212,6 +1213,7 @@ func (s *DockerDaemonSuite) TestDaemonWithWrongkey(c *testing.T) { } os.Remove("/etc/docker/key.json") + c.Setenv("DOCKER_ALLOW_SCHEMA1_PUSH_DONOTUSE", "1") s.d.Start(c) s.d.Stop(c)