@@ -25,11 +25,51 @@ func (daemon *Daemon) createSpec(c *container.Container) (*specs.Spec, error) {
2525 // In base spec
2626 s .Hostname = c .FullHostname ()
2727
28+ if err := daemon .setupSecretDir (c ); err != nil {
29+ return nil , err
30+ }
31+
2832 // In s.Mounts
2933 mounts , err := daemon .setupMounts (c )
3034 if err != nil {
3135 return nil , err
3236 }
37+
38+ var isHyperV bool
39+ if c .HostConfig .Isolation .IsDefault () {
40+ // Container using default isolation, so take the default from the daemon configuration
41+ isHyperV = daemon .defaultIsolation .IsHyperV ()
42+ } else {
43+ // Container may be requesting an explicit isolation mode.
44+ isHyperV = c .HostConfig .Isolation .IsHyperV ()
45+ }
46+
47+ // If the container has not been started, and has secrets, create symlinks
48+ // to each secret. If it has been started before, the symlinks should have
49+ // already been created. Also, it is important to not mount a Hyper-V
50+ // container that has been started before, to protect the host from the
51+ // container; for example, from malicious mutation of NTFS data structures.
52+ if ! c .HasBeenStartedBefore && len (c .SecretReferences ) > 0 {
53+ // The container file system is mounted before this function is called,
54+ // except for Hyper-V containers, so mount it here in that case.
55+ if isHyperV {
56+ if err := daemon .Mount (c ); err != nil {
57+ return nil , err
58+ }
59+ }
60+ err := c .CreateSecretSymlinks ()
61+ if isHyperV {
62+ daemon .Unmount (c )
63+ }
64+ if err != nil {
65+ return nil , err
66+ }
67+ }
68+
69+ if m := c .SecretMounts (); m != nil {
70+ mounts = append (mounts , m ... )
71+ }
72+
3373 for _ , mount := range mounts {
3474 m := specs.Mount {
3575 Source : mount .Source ,
@@ -64,14 +104,6 @@ func (daemon *Daemon) createSpec(c *container.Container) (*specs.Spec, error) {
64104 s .Process .User .Username = c .Config .User
65105
66106 // In spec.Root. This is not set for Hyper-V containers
67- var isHyperV bool
68- if c .HostConfig .Isolation .IsDefault () {
69- // Container using default isolation, so take the default from the daemon configuration
70- isHyperV = daemon .defaultIsolation .IsHyperV ()
71- } else {
72- // Container may be requesting an explicit isolation mode.
73- isHyperV = c .HostConfig .Isolation .IsHyperV ()
74- }
75107 if ! isHyperV {
76108 s .Root .Path = c .BaseFS
77109 }
0 commit comments