|
@@ -145,6 +145,13 @@ func (daemon *Daemon) setupSecretDir(c *container.Container) (setupErr error) {
|
|
|
localMountPath := c.SecretMountPath()
|
|
|
logrus.Debugf("secrets: setting up secret dir: %s", localMountPath)
|
|
|
|
|
|
+ // retrieve possible remapped range start for root UID, GID
|
|
|
+ rootUID, rootGID := daemon.GetRemappedUIDGID()
|
|
|
+ // create tmpfs
|
|
|
+ if err := idtools.MkdirAllAs(localMountPath, 0700, rootUID, rootGID); err != nil {
|
|
|
+ return errors.Wrap(err, "error creating secret local mount path")
|
|
|
+ }
|
|
|
+
|
|
|
defer func() {
|
|
|
if setupErr != nil {
|
|
|
// cleanup
|
|
@@ -156,25 +163,20 @@ func (daemon *Daemon) setupSecretDir(c *container.Container) (setupErr error) {
|
|
|
}
|
|
|
}()
|
|
|
|
|
|
- // retrieve possible remapped range start for root UID, GID
|
|
|
- rootUID, rootGID := daemon.GetRemappedUIDGID()
|
|
|
- // create tmpfs
|
|
|
- if err := idtools.MkdirAllAs(localMountPath, 0700, rootUID, rootGID); err != nil {
|
|
|
- return errors.Wrap(err, "error creating secret local mount path")
|
|
|
- }
|
|
|
tmpfsOwnership := fmt.Sprintf("uid=%d,gid=%d", rootUID, rootGID)
|
|
|
if err := mount.Mount("tmpfs", localMountPath, "tmpfs", "nodev,nosuid,noexec,"+tmpfsOwnership); err != nil {
|
|
|
return errors.Wrap(err, "unable to setup secret mount")
|
|
|
}
|
|
|
|
|
|
- for _, s := range c.SecretReferences {
|
|
|
- if c.SecretStore == nil {
|
|
|
- return fmt.Errorf("secret store is not initialized")
|
|
|
- }
|
|
|
+ if c.DependencyStore == nil {
|
|
|
+ return fmt.Errorf("secret store is not initialized")
|
|
|
+ }
|
|
|
|
|
|
+ for _, s := range c.SecretReferences {
|
|
|
// TODO (ehazlett): use type switch when more are supported
|
|
|
if s.File == nil {
|
|
|
- return fmt.Errorf("secret target type is not a file target")
|
|
|
+ logrus.Error("secret target type is not a file target")
|
|
|
+ continue
|
|
|
}
|
|
|
|
|
|
// secrets are created in the SecretMountPath on the host, at a
|
|
@@ -188,7 +190,7 @@ func (daemon *Daemon) setupSecretDir(c *container.Container) (setupErr error) {
|
|
|
"name": s.File.Name,
|
|
|
"path": fPath,
|
|
|
}).Debug("injecting secret")
|
|
|
- secret := c.SecretStore.Get(s.SecretID)
|
|
|
+ secret := c.DependencyStore.Secrets().Get(s.SecretID)
|
|
|
if secret == nil {
|
|
|
return fmt.Errorf("unable to get secret from secret store")
|
|
|
}
|
|
@@ -220,6 +222,74 @@ func (daemon *Daemon) setupSecretDir(c *container.Container) (setupErr error) {
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
+func (daemon *Daemon) setupConfigDir(c *container.Container) (setupErr error) {
|
|
|
+ if len(c.ConfigReferences) == 0 {
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+
|
|
|
+ localPath := c.ConfigsDirPath()
|
|
|
+ logrus.Debugf("configs: setting up config dir: %s", localPath)
|
|
|
+
|
|
|
+ // retrieve possible remapped range start for root UID, GID
|
|
|
+ rootUID, rootGID := daemon.GetRemappedUIDGID()
|
|
|
+ // create tmpfs
|
|
|
+ if err := idtools.MkdirAllAs(localPath, 0700, rootUID, rootGID); err != nil {
|
|
|
+ return errors.Wrap(err, "error creating config dir")
|
|
|
+ }
|
|
|
+
|
|
|
+ defer func() {
|
|
|
+ if setupErr != nil {
|
|
|
+ if err := os.RemoveAll(localPath); err != nil {
|
|
|
+ logrus.Errorf("error cleaning up config dir: %s", err)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }()
|
|
|
+
|
|
|
+ if c.DependencyStore == nil {
|
|
|
+ return fmt.Errorf("config store is not initialized")
|
|
|
+ }
|
|
|
+
|
|
|
+ for _, configRef := range c.ConfigReferences {
|
|
|
+ // TODO (ehazlett): use type switch when more are supported
|
|
|
+ if configRef.File == nil {
|
|
|
+ logrus.Error("config target type is not a file target")
|
|
|
+ continue
|
|
|
+ }
|
|
|
+
|
|
|
+ fPath := c.ConfigFilePath(*configRef)
|
|
|
+
|
|
|
+ log := logrus.WithFields(logrus.Fields{"name": configRef.File.Name, "path": fPath})
|
|
|
+
|
|
|
+ if err := idtools.MkdirAllAs(filepath.Dir(fPath), 0700, rootUID, rootGID); err != nil {
|
|
|
+ return errors.Wrap(err, "error creating config path")
|
|
|
+ }
|
|
|
+
|
|
|
+ log.Debug("injecting config")
|
|
|
+ config := c.DependencyStore.Configs().Get(configRef.ConfigID)
|
|
|
+ if config == nil {
|
|
|
+ return fmt.Errorf("unable to get config from config store")
|
|
|
+ }
|
|
|
+ if err := ioutil.WriteFile(fPath, config.Spec.Data, configRef.File.Mode); err != nil {
|
|
|
+ return errors.Wrap(err, "error injecting config")
|
|
|
+ }
|
|
|
+
|
|
|
+ uid, err := strconv.Atoi(configRef.File.UID)
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ gid, err := strconv.Atoi(configRef.File.GID)
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+
|
|
|
+ if err := os.Chown(fPath, rootUID+uid, rootGID+gid); err != nil {
|
|
|
+ return errors.Wrap(err, "error setting ownership for config")
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return nil
|
|
|
+}
|
|
|
+
|
|
|
func killProcessDirectly(container *container.Container) error {
|
|
|
if _, err := container.WaitStop(10 * time.Second); err != nil {
|
|
|
// Ensure that we don't kill ourselves
|