@@ -161,20 +161,16 @@ func (daemon *Daemon) setupIpcDirs(c *container.Container) error {
161
161
}
162
162
163
163
func (daemon * Daemon ) setupSecretDir (c * container.Container ) (setupErr error ) {
164
- if len (c .SecretReferences ) == 0 {
164
+ if len (c .SecretReferences ) == 0 && len ( c . ConfigReferences ) == 0 {
165
165
return nil
166
166
}
167
167
168
- localMountPath , err := c .SecretMountPath ()
169
- if err != nil {
170
- return errors .Wrap (err , "error getting secrets mount path for container" )
171
- }
172
- if err := daemon .createSecretsDir (localMountPath ); err != nil {
168
+ if err := daemon .createSecretsDir (c ); err != nil {
173
169
return err
174
170
}
175
171
defer func () {
176
172
if setupErr != nil {
177
- daemon .cleanupSecretDir (localMountPath )
173
+ daemon .cleanupSecretDir (c )
178
174
}
179
175
}()
180
176
@@ -231,88 +227,16 @@ func (daemon *Daemon) setupSecretDir(c *container.Container) (setupErr error) {
231
227
}
232
228
}
233
229
234
- return daemon .remountSecretDir (c .MountLabel , localMountPath )
235
- }
236
-
237
- // createSecretsDir is used to create a dir suitable for storing container secrets.
238
- // In practice this is using a tmpfs mount and is used for both "configs" and "secrets"
239
- func (daemon * Daemon ) createSecretsDir (dir string ) error {
240
- // retrieve possible remapped range start for root UID, GID
241
- rootIDs := daemon .idMappings .RootPair ()
242
- // create tmpfs
243
- if err := idtools .MkdirAllAndChown (dir , 0700 , rootIDs ); err != nil {
244
- return errors .Wrap (err , "error creating secret local mount path" )
245
- }
246
-
247
- tmpfsOwnership := fmt .Sprintf ("uid=%d,gid=%d" , rootIDs .UID , rootIDs .GID )
248
- if err := mount .Mount ("tmpfs" , dir , "tmpfs" , "nodev,nosuid,noexec," + tmpfsOwnership ); err != nil {
249
- return errors .Wrap (err , "unable to setup secret mount" )
250
- }
251
-
252
- return nil
253
- }
254
-
255
- func (daemon * Daemon ) remountSecretDir (mountLabel , dir string ) error {
256
- if err := label .Relabel (dir , mountLabel , false ); err != nil {
257
- logrus .WithError (err ).WithField ("dir" , dir ).Warn ("Error while attempting to set selinux label" )
258
- }
259
- rootIDs := daemon .idMappings .RootPair ()
260
- tmpfsOwnership := fmt .Sprintf ("uid=%d,gid=%d" , rootIDs .UID , rootIDs .GID )
261
-
262
- // remount secrets ro
263
- if err := mount .Mount ("tmpfs" , dir , "tmpfs" , "remount,ro," + tmpfsOwnership ); err != nil {
264
- return errors .Wrap (err , "unable to remount dir as readonly" )
265
- }
266
-
267
- return nil
268
- }
269
-
270
- func (daemon * Daemon ) cleanupSecretDir (dir string ) {
271
- if err := mount .RecursiveUnmount (dir ); err != nil {
272
- logrus .WithField ("dir" , dir ).WithError (err ).Warn ("Error while attmepting to unmount dir, this may prevent removal of container." )
273
- }
274
- if err := os .RemoveAll (dir ); err != nil && ! os .IsNotExist (err ) {
275
- logrus .WithField ("dir" , dir ).WithError (err ).Error ("Error removing dir." )
276
- }
277
- }
278
-
279
- func (daemon * Daemon ) setupConfigDir (c * container.Container ) (setupErr error ) {
280
- if len (c .ConfigReferences ) == 0 {
281
- return nil
282
- }
283
-
284
- localPath , err := c .ConfigsDirPath ()
285
- if err != nil {
286
- return err
287
- }
288
- logrus .Debugf ("configs: setting up config dir: %s" , localPath )
289
- if err := daemon .createSecretsDir (localPath ); err != nil {
290
- return err
291
- }
292
- defer func () {
293
- if setupErr != nil {
294
- daemon .cleanupSecretDir (localPath )
295
- }
296
- }()
297
-
298
- if c .DependencyStore == nil {
299
- return errors .New ("config store is not initialized" )
300
- }
301
-
302
- // retrieve possible remapped range start for root UID, GID
303
- rootIDs := daemon .idMappings .RootPair ()
304
-
305
230
for _ , ref := range c .ConfigReferences {
306
231
// TODO (ehazlett): use type switch when more are supported
307
232
if ref .File == nil {
308
233
logrus .Error ("config target type is not a file target" )
309
234
continue
310
235
}
311
- // configs are created in the ConfigsDirPath on the host, at a
312
- // single level
313
- fPath , err := c .ConfigFilePath (* ref .ConfigReference )
236
+
237
+ fPath , err := c .ConfigFilePath (* ref )
314
238
if err != nil {
315
- return err
239
+ return errors . Wrap ( err , "error getting config file path for container" )
316
240
}
317
241
if err := idtools .MkdirAllAndChown (filepath .Dir (fPath ), 0700 , rootIDs ); err != nil {
318
242
return errors .Wrap (err , "error creating config mount path" )
@@ -342,14 +266,67 @@ func (daemon *Daemon) setupConfigDir(c *container.Container) (setupErr error) {
342
266
if err := os .Chown (fPath , rootIDs .UID + uid , rootIDs .GID + gid ); err != nil {
343
267
return errors .Wrap (err , "error setting ownership for config" )
344
268
}
345
- if err := os .Chmod (fPath , configRef .File .Mode ); err != nil {
269
+ if err := os .Chmod (fPath , ref .File .Mode ); err != nil {
346
270
return errors .Wrap (err , "error setting file mode for config" )
347
271
}
272
+ }
273
+
274
+ return daemon .remountSecretDir (c )
275
+ }
276
+
277
+ // createSecretsDir is used to create a dir suitable for storing container secrets.
278
+ // In practice this is using a tmpfs mount and is used for both "configs" and "secrets"
279
+ func (daemon * Daemon ) createSecretsDir (c * container.Container ) error {
280
+ // retrieve possible remapped range start for root UID, GID
281
+ rootIDs := daemon .idMappings .RootPair ()
282
+ dir , err := c .SecretMountPath ()
283
+ if err != nil {
284
+ return errors .Wrap (err , "error getting container secrets dir" )
285
+ }
286
+
287
+ // create tmpfs
288
+ if err := idtools .MkdirAllAndChown (dir , 0700 , rootIDs ); err != nil {
289
+ return errors .Wrap (err , "error creating secret local mount path" )
290
+ }
291
+
292
+ tmpfsOwnership := fmt .Sprintf ("uid=%d,gid=%d" , rootIDs .UID , rootIDs .GID )
293
+ if err := mount .Mount ("tmpfs" , dir , "tmpfs" , "nodev,nosuid,noexec," + tmpfsOwnership ); err != nil {
294
+ return errors .Wrap (err , "unable to setup secret mount" )
295
+ }
348
296
349
- label .Relabel (fPath , c .MountLabel , false )
297
+ return nil
298
+ }
299
+
300
+ func (daemon * Daemon ) remountSecretDir (c * container.Container ) error {
301
+ dir , err := c .SecretMountPath ()
302
+ if err != nil {
303
+ return errors .Wrap (err , "error getting container secrets path" )
350
304
}
305
+ if err := label .Relabel (dir , c .MountLabel , false ); err != nil {
306
+ logrus .WithError (err ).WithField ("dir" , dir ).Warn ("Error while attempting to set selinux label" )
307
+ }
308
+ rootIDs := daemon .idMappings .RootPair ()
309
+ tmpfsOwnership := fmt .Sprintf ("uid=%d,gid=%d" , rootIDs .UID , rootIDs .GID )
351
310
352
- return daemon .remountSecretDir (c .MountLabel , localPath )
311
+ // remount secrets ro
312
+ if err := mount .Mount ("tmpfs" , dir , "tmpfs" , "remount,ro," + tmpfsOwnership ); err != nil {
313
+ return errors .Wrap (err , "unable to remount dir as readonly" )
314
+ }
315
+
316
+ return nil
317
+ }
318
+
319
+ func (daemon * Daemon ) cleanupSecretDir (c * container.Container ) {
320
+ dir , err := c .SecretMountPath ()
321
+ if err != nil {
322
+ logrus .WithError (err ).WithField ("container" , c .ID ).Warn ("error getting secrets mount path for container" )
323
+ }
324
+ if err := mount .RecursiveUnmount (dir ); err != nil {
325
+ logrus .WithField ("dir" , dir ).WithError (err ).Warn ("Error while attmepting to unmount dir, this may prevent removal of container." )
326
+ }
327
+ if err := os .RemoveAll (dir ); err != nil && ! os .IsNotExist (err ) {
328
+ logrus .WithField ("dir" , dir ).WithError (err ).Error ("Error removing dir." )
329
+ }
353
330
}
354
331
355
332
func killProcessDirectly (cntr * container.Container ) error {
0 commit comments