@@ -177,10 +177,6 @@ func (daemon *Daemon) setupSecretDir(c *container.Container) (setupErr error) {
177177 }
178178
179179 targetPath := filepath .Clean (s .File .Name )
180- // ensure that the target is a filename only; no paths allowed
181- if targetPath != filepath .Base (targetPath ) {
182- return fmt .Errorf ("error creating secret: secret must not be a path" )
183- }
184180
185181 fPath := filepath .Join (localMountPath , targetPath )
186182 if err := idtools .MkdirAllAs (filepath .Dir (fPath ), 0700 , rootUID , rootGID ); err != nil {
@@ -195,8 +191,14 @@ func (daemon *Daemon) setupSecretDir(c *container.Container) (setupErr error) {
195191 if secret == nil {
196192 return fmt .Errorf ("unable to get secret from secret store" )
197193 }
198- if err := ioutil .WriteFile (fPath , secret .Spec .Data , s .File .Mode ); err != nil {
199- return errors .Wrap (err , "error injecting secret" )
194+ if s .File .Mode .IsDir () {
195+ if err := os .Mkdir (fPath , s .File .Mode ); err != nil {
196+ return errors .Wrap (err , "error injecting secret dir" )
197+ }
198+ } else {
199+ if err := ioutil .WriteFile (fPath , secret .Spec .Data , s .File .Mode ); err != nil {
200+ return errors .Wrap (err , "error injecting secret" )
201+ }
200202 }
201203
202204 uid , err := strconv .Atoi (s .File .UID )
@@ -213,6 +215,8 @@ func (daemon *Daemon) setupSecretDir(c *container.Container) (setupErr error) {
213215 }
214216 }
215217
218+ label .Relabel (localMountPath , c .MountLabel , false )
219+
216220 // remount secrets ro
217221 if err := mount .Mount ("tmpfs" , localMountPath , "tmpfs" , "remount,ro," + tmpfsOwnership ); err != nil {
218222 return errors .Wrap (err , "unable to remount secret dir as readonly" )
0 commit comments