Bladeren bron

Correct secrets permissions when userns enabled

Docker-DCO-1.1-Signed-off-by: Phil Estes <estesp@linux.vnet.ibm.com>
Phil Estes 8 jaren geleden
bovenliggende
commit
8119809b68
1 gewijzigde bestanden met toevoegingen van 8 en 5 verwijderingen
  1. 8 5
      daemon/container_operations_unix.go

+ 8 - 5
daemon/container_operations_unix.go

@@ -163,11 +163,14 @@ func (daemon *Daemon) setupSecretDir(c *container.Container) (setupErr error) {
 		}
 		}
 	}()
 	}()
 
 
+	// retrieve possible remapped range start for root UID, GID
+	rootUID, rootGID := daemon.GetRemappedUIDGID()
 	// create tmpfs
 	// create tmpfs
-	if err := os.MkdirAll(localMountPath, 0700); err != nil {
+	if err := idtools.MkdirAllAs(localMountPath, 0700, rootUID, rootGID); err != nil {
 		return errors.Wrap(err, "error creating secret local mount path")
 		return errors.Wrap(err, "error creating secret local mount path")
 	}
 	}
-	if err := mount.Mount("tmpfs", localMountPath, "tmpfs", "nodev,nosuid,noexec"); err != nil {
+	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")
 		return errors.Wrap(err, "unable to setup secret mount")
 	}
 	}
 
 
@@ -179,7 +182,7 @@ func (daemon *Daemon) setupSecretDir(c *container.Container) (setupErr error) {
 		}
 		}
 
 
 		fPath := filepath.Join(localMountPath, targetPath)
 		fPath := filepath.Join(localMountPath, targetPath)
-		if err := os.MkdirAll(filepath.Dir(fPath), 0700); err != nil {
+		if err := idtools.MkdirAllAs(filepath.Dir(fPath), 0700, rootUID, rootGID); err != nil {
 			return errors.Wrap(err, "error creating secret mount path")
 			return errors.Wrap(err, "error creating secret mount path")
 		}
 		}
 
 
@@ -200,13 +203,13 @@ func (daemon *Daemon) setupSecretDir(c *container.Container) (setupErr error) {
 			return err
 			return err
 		}
 		}
 
 
-		if err := os.Chown(fPath, uid, gid); err != nil {
+		if err := os.Chown(fPath, rootUID+uid, rootGID+gid); err != nil {
 			return errors.Wrap(err, "error setting ownership for secret")
 			return errors.Wrap(err, "error setting ownership for secret")
 		}
 		}
 	}
 	}
 
 
 	// remount secrets ro
 	// remount secrets ro
-	if err := mount.Mount("tmpfs", localMountPath, "tmpfs", "remount,ro"); err != nil {
+	if err := mount.Mount("tmpfs", localMountPath, "tmpfs", "remount,ro,"+tmpfsOwnership); err != nil {
 		return errors.Wrap(err, "unable to remount secret dir as readonly")
 		return errors.Wrap(err, "unable to remount secret dir as readonly")
 	}
 	}