@@ -3,10 +3,8 @@ package main
33import (
44 "crypto/tls"
55 "fmt"
6- "io"
76 "os"
87 "path/filepath"
9- "runtime"
108 "strings"
119 "time"
1210
@@ -26,7 +24,6 @@ import (
2624 swarmrouter "github.com/docker/docker/api/server/router/swarm"
2725 systemrouter "github.com/docker/docker/api/server/router/system"
2826 "github.com/docker/docker/api/server/router/volume"
29- "github.com/docker/docker/cli"
3027 "github.com/docker/docker/cli/debug"
3128 cliflags "github.com/docker/docker/cli/flags"
3229 "github.com/docker/docker/daemon"
@@ -42,7 +39,6 @@ import (
4239 "github.com/docker/docker/pkg/pidfile"
4340 "github.com/docker/docker/pkg/plugingetter"
4441 "github.com/docker/docker/pkg/signal"
45- "github.com/docker/docker/pkg/system"
4642 "github.com/docker/docker/plugin"
4743 "github.com/docker/docker/registry"
4844 "github.com/docker/docker/runconfig"
@@ -66,52 +62,6 @@ func NewDaemonCli() *DaemonCli {
6662 return & DaemonCli {}
6763}
6864
69- func migrateKey (config * config.Config ) (err error ) {
70- // No migration necessary on Windows
71- if runtime .GOOS == "windows" {
72- return nil
73- }
74-
75- // Migrate trust key if exists at ~/.docker/key.json and owned by current user
76- oldPath := filepath .Join (cli .ConfigurationDir (), cliflags .DefaultTrustKeyFile )
77- newPath := filepath .Join (getDaemonConfDir (config .Root ), cliflags .DefaultTrustKeyFile )
78- if _ , statErr := os .Stat (newPath ); os .IsNotExist (statErr ) && currentUserIsOwner (oldPath ) {
79- defer func () {
80- // Ensure old path is removed if no error occurred
81- if err == nil {
82- err = os .Remove (oldPath )
83- } else {
84- logrus .Warnf ("Key migration failed, key file not removed at %s" , oldPath )
85- os .Remove (newPath )
86- }
87- }()
88-
89- if err := system .MkdirAll (getDaemonConfDir (config .Root ), os .FileMode (0644 )); err != nil {
90- return fmt .Errorf ("Unable to create daemon configuration directory: %s" , err )
91- }
92-
93- newFile , err := os .OpenFile (newPath , os .O_RDWR | os .O_CREATE | os .O_TRUNC , 0600 )
94- if err != nil {
95- return fmt .Errorf ("error creating key file %q: %s" , newPath , err )
96- }
97- defer newFile .Close ()
98-
99- oldFile , err := os .Open (oldPath )
100- if err != nil {
101- return fmt .Errorf ("error opening key file %q: %s" , oldPath , err )
102- }
103- defer oldFile .Close ()
104-
105- if _ , err := io .Copy (newFile , oldFile ); err != nil {
106- return fmt .Errorf ("error copying key: %s" , err )
107- }
108-
109- logrus .Infof ("Migrated key from %s to %s" , oldPath , newPath )
110- }
111-
112- return nil
113- }
114-
11565func (cli * DaemonCli ) start (opts daemonOptions ) (err error ) {
11666 stopc := make (chan bool )
11767 defer close (stopc )
@@ -127,12 +77,6 @@ func (cli *DaemonCli) start(opts daemonOptions) (err error) {
12777 cli .configFile = & opts .configFile
12878 cli .flags = opts .flags
12979
130- if opts .common .TrustKey == "" {
131- opts .common .TrustKey = filepath .Join (
132- getDaemonConfDir (cli .Config .Root ),
133- cliflags .DefaultTrustKeyFile )
134- }
135-
13680 if cli .Config .Debug {
13781 debug .Enable ()
13882 }
@@ -241,13 +185,6 @@ func (cli *DaemonCli) start(opts daemonOptions) (err error) {
241185 api .Accept (addr , ls ... )
242186 }
243187
244- if err := migrateKey (cli .Config ); err != nil {
245- return err
246- }
247-
248- // FIXME: why is this down here instead of with the other TrustKey logic above?
249- cli .TrustKeyPath = opts .common .TrustKey
250-
251188 registryService := registry .NewService (cli .Config .ServiceOptions )
252189 containerdRemote , err := libcontainerd .New (cli .getLibcontainerdRoot (), cli .getPlatformRemoteOptions ()... )
253190 if err != nil {
@@ -419,6 +356,12 @@ func loadDaemonCliConfig(opts daemonOptions) (*config.Config, error) {
419356 conf .CommonTLSOptions .KeyFile = opts .common .TLSOptions .KeyFile
420357 }
421358
359+ if conf .TrustKeyPath == "" {
360+ conf .TrustKeyPath = filepath .Join (
361+ getDaemonConfDir (conf .Root ),
362+ defaultTrustKeyFile )
363+ }
364+
422365 if flags .Changed ("graph" ) && flags .Changed ("data-root" ) {
423366 return nil , fmt .Errorf (`cannot specify both "--graph" and "--data-root" option` )
424367 }
0 commit comments