|
@@ -161,20 +161,16 @@ func (daemon *Daemon) setupIpcDirs(c *container.Container) error {
|
|
|
}
|
|
|
|
|
|
func (daemon *Daemon) setupSecretDir(c *container.Container) (setupErr error) {
|
|
|
- if len(c.SecretReferences) == 0 {
|
|
|
+ if len(c.SecretReferences) == 0 && len(c.ConfigReferences) == 0 {
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
- localMountPath, err := c.SecretMountPath()
|
|
|
- if err != nil {
|
|
|
- return errors.Wrap(err, "error getting secrets mount path for container")
|
|
|
- }
|
|
|
- if err := daemon.createSecretsDir(localMountPath); err != nil {
|
|
|
+ if err := daemon.createSecretsDir(c); err != nil {
|
|
|
return err
|
|
|
}
|
|
|
defer func() {
|
|
|
if setupErr != nil {
|
|
|
- daemon.cleanupSecretDir(localMountPath)
|
|
|
+ daemon.cleanupSecretDir(c)
|
|
|
}
|
|
|
}()
|
|
|
|
|
@@ -231,88 +227,16 @@ func (daemon *Daemon) setupSecretDir(c *container.Container) (setupErr error) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- return daemon.remountSecretDir(c.MountLabel, localMountPath)
|
|
|
-}
|
|
|
-
|
|
|
-// createSecretsDir is used to create a dir suitable for storing container secrets.
|
|
|
-// In practice this is using a tmpfs mount and is used for both "configs" and "secrets"
|
|
|
-func (daemon *Daemon) createSecretsDir(dir string) error {
|
|
|
- // retrieve possible remapped range start for root UID, GID
|
|
|
- rootIDs := daemon.idMappings.RootPair()
|
|
|
- // create tmpfs
|
|
|
- if err := idtools.MkdirAllAndChown(dir, 0700, rootIDs); err != nil {
|
|
|
- return errors.Wrap(err, "error creating secret local mount path")
|
|
|
- }
|
|
|
-
|
|
|
- tmpfsOwnership := fmt.Sprintf("uid=%d,gid=%d", rootIDs.UID, rootIDs.GID)
|
|
|
- if err := mount.Mount("tmpfs", dir, "tmpfs", "nodev,nosuid,noexec,"+tmpfsOwnership); err != nil {
|
|
|
- return errors.Wrap(err, "unable to setup secret mount")
|
|
|
- }
|
|
|
-
|
|
|
- return nil
|
|
|
-}
|
|
|
-
|
|
|
-func (daemon *Daemon) remountSecretDir(mountLabel, dir string) error {
|
|
|
- if err := label.Relabel(dir, mountLabel, false); err != nil {
|
|
|
- logrus.WithError(err).WithField("dir", dir).Warn("Error while attempting to set selinux label")
|
|
|
- }
|
|
|
- rootIDs := daemon.idMappings.RootPair()
|
|
|
- tmpfsOwnership := fmt.Sprintf("uid=%d,gid=%d", rootIDs.UID, rootIDs.GID)
|
|
|
-
|
|
|
- // remount secrets ro
|
|
|
- if err := mount.Mount("tmpfs", dir, "tmpfs", "remount,ro,"+tmpfsOwnership); err != nil {
|
|
|
- return errors.Wrap(err, "unable to remount dir as readonly")
|
|
|
- }
|
|
|
-
|
|
|
- return nil
|
|
|
-}
|
|
|
-
|
|
|
-func (daemon *Daemon) cleanupSecretDir(dir string) {
|
|
|
- if err := mount.RecursiveUnmount(dir); err != nil {
|
|
|
- logrus.WithField("dir", dir).WithError(err).Warn("Error while attmepting to unmount dir, this may prevent removal of container.")
|
|
|
- }
|
|
|
- if err := os.RemoveAll(dir); err != nil && !os.IsNotExist(err) {
|
|
|
- logrus.WithField("dir", dir).WithError(err).Error("Error removing dir.")
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-func (daemon *Daemon) setupConfigDir(c *container.Container) (setupErr error) {
|
|
|
- if len(c.ConfigReferences) == 0 {
|
|
|
- return nil
|
|
|
- }
|
|
|
-
|
|
|
- localPath, err := c.ConfigsDirPath()
|
|
|
- if err != nil {
|
|
|
- return err
|
|
|
- }
|
|
|
- logrus.Debugf("configs: setting up config dir: %s", localPath)
|
|
|
- if err := daemon.createSecretsDir(localPath); err != nil {
|
|
|
- return err
|
|
|
- }
|
|
|
- defer func() {
|
|
|
- if setupErr != nil {
|
|
|
- daemon.cleanupSecretDir(localPath)
|
|
|
- }
|
|
|
- }()
|
|
|
-
|
|
|
- if c.DependencyStore == nil {
|
|
|
- return errors.New("config store is not initialized")
|
|
|
- }
|
|
|
-
|
|
|
- // retrieve possible remapped range start for root UID, GID
|
|
|
- rootIDs := daemon.idMappings.RootPair()
|
|
|
-
|
|
|
for _, ref := range c.ConfigReferences {
|
|
|
// TODO (ehazlett): use type switch when more are supported
|
|
|
if ref.File == nil {
|
|
|
logrus.Error("config target type is not a file target")
|
|
|
continue
|
|
|
}
|
|
|
- // configs are created in the ConfigsDirPath on the host, at a
|
|
|
- // single level
|
|
|
- fPath, err := c.ConfigFilePath(*ref.ConfigReference)
|
|
|
+
|
|
|
+ fPath, err := c.ConfigFilePath(*ref)
|
|
|
if err != nil {
|
|
|
- return err
|
|
|
+ return errors.Wrap(err, "error getting config file path for container")
|
|
|
}
|
|
|
if err := idtools.MkdirAllAndChown(filepath.Dir(fPath), 0700, rootIDs); err != nil {
|
|
|
return errors.Wrap(err, "error creating config mount path")
|
|
@@ -342,14 +266,67 @@ func (daemon *Daemon) setupConfigDir(c *container.Container) (setupErr error) {
|
|
|
if err := os.Chown(fPath, rootIDs.UID+uid, rootIDs.GID+gid); err != nil {
|
|
|
return errors.Wrap(err, "error setting ownership for config")
|
|
|
}
|
|
|
- if err := os.Chmod(fPath, configRef.File.Mode); err != nil {
|
|
|
+ if err := os.Chmod(fPath, ref.File.Mode); err != nil {
|
|
|
return errors.Wrap(err, "error setting file mode for config")
|
|
|
}
|
|
|
+ }
|
|
|
+
|
|
|
+ return daemon.remountSecretDir(c)
|
|
|
+}
|
|
|
+
|
|
|
+// createSecretsDir is used to create a dir suitable for storing container secrets.
|
|
|
+// In practice this is using a tmpfs mount and is used for both "configs" and "secrets"
|
|
|
+func (daemon *Daemon) createSecretsDir(c *container.Container) error {
|
|
|
+ // retrieve possible remapped range start for root UID, GID
|
|
|
+ rootIDs := daemon.idMappings.RootPair()
|
|
|
+ dir, err := c.SecretMountPath()
|
|
|
+ if err != nil {
|
|
|
+ return errors.Wrap(err, "error getting container secrets dir")
|
|
|
+ }
|
|
|
+
|
|
|
+ // create tmpfs
|
|
|
+ if err := idtools.MkdirAllAndChown(dir, 0700, rootIDs); err != nil {
|
|
|
+ return errors.Wrap(err, "error creating secret local mount path")
|
|
|
+ }
|
|
|
+
|
|
|
+ tmpfsOwnership := fmt.Sprintf("uid=%d,gid=%d", rootIDs.UID, rootIDs.GID)
|
|
|
+ if err := mount.Mount("tmpfs", dir, "tmpfs", "nodev,nosuid,noexec,"+tmpfsOwnership); err != nil {
|
|
|
+ return errors.Wrap(err, "unable to setup secret mount")
|
|
|
+ }
|
|
|
|
|
|
- label.Relabel(fPath, c.MountLabel, false)
|
|
|
+ return nil
|
|
|
+}
|
|
|
+
|
|
|
+func (daemon *Daemon) remountSecretDir(c *container.Container) error {
|
|
|
+ dir, err := c.SecretMountPath()
|
|
|
+ if err != nil {
|
|
|
+ return errors.Wrap(err, "error getting container secrets path")
|
|
|
}
|
|
|
+ if err := label.Relabel(dir, c.MountLabel, false); err != nil {
|
|
|
+ logrus.WithError(err).WithField("dir", dir).Warn("Error while attempting to set selinux label")
|
|
|
+ }
|
|
|
+ rootIDs := daemon.idMappings.RootPair()
|
|
|
+ tmpfsOwnership := fmt.Sprintf("uid=%d,gid=%d", rootIDs.UID, rootIDs.GID)
|
|
|
|
|
|
- return daemon.remountSecretDir(c.MountLabel, localPath)
|
|
|
+ // remount secrets ro
|
|
|
+ if err := mount.Mount("tmpfs", dir, "tmpfs", "remount,ro,"+tmpfsOwnership); err != nil {
|
|
|
+ return errors.Wrap(err, "unable to remount dir as readonly")
|
|
|
+ }
|
|
|
+
|
|
|
+ return nil
|
|
|
+}
|
|
|
+
|
|
|
+func (daemon *Daemon) cleanupSecretDir(c *container.Container) {
|
|
|
+ dir, err := c.SecretMountPath()
|
|
|
+ if err != nil {
|
|
|
+ logrus.WithError(err).WithField("container", c.ID).Warn("error getting secrets mount path for container")
|
|
|
+ }
|
|
|
+ if err := mount.RecursiveUnmount(dir); err != nil {
|
|
|
+ logrus.WithField("dir", dir).WithError(err).Warn("Error while attmepting to unmount dir, this may prevent removal of container.")
|
|
|
+ }
|
|
|
+ if err := os.RemoveAll(dir); err != nil && !os.IsNotExist(err) {
|
|
|
+ logrus.WithField("dir", dir).WithError(err).Error("Error removing dir.")
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
func killProcessDirectly(cntr *container.Container) error {
|