@@ -25,11 +25,51 @@ func (daemon *Daemon) createSpec(c *container.Container) (*specs.Spec, error) {
25
25
// In base spec
26
26
s .Hostname = c .FullHostname ()
27
27
28
+ if err := daemon .setupSecretDir (c ); err != nil {
29
+ return nil , err
30
+ }
31
+
28
32
// In s.Mounts
29
33
mounts , err := daemon .setupMounts (c )
30
34
if err != nil {
31
35
return nil , err
32
36
}
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
+
33
73
for _ , mount := range mounts {
34
74
m := specs.Mount {
35
75
Source : mount .Source ,
@@ -64,14 +104,6 @@ func (daemon *Daemon) createSpec(c *container.Container) (*specs.Spec, error) {
64
104
s .Process .User .Username = c .Config .User
65
105
66
106
// 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
- }
75
107
if ! isHyperV {
76
108
s .Root .Path = c .BaseFS
77
109
}
0 commit comments