1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Remove error return from RootPair

There is no case which would resolve in this error. The root user always exists, and if the id maps are empty, the default value of 0 is correct.

Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
Daniel Nephin 2017-05-31 17:56:23 -04:00
parent 6150ebf7b4
commit 93fbdb69ac
14 changed files with 28 additions and 63 deletions

View file

@ -375,7 +375,7 @@ func (daemon *Daemon) CopyOnBuild(cID, destPath, srcRoot, srcPath string, decomp
destExists := true destExists := true
destDir := false destDir := false
rootIDs, _ := daemon.idMappings.RootPair() rootIDs := daemon.idMappings.RootPair()
// Work in daemon-local OS specific file paths // Work in daemon-local OS specific file paths
destPath = filepath.FromSlash(destPath) destPath = filepath.FromSlash(destPath)

View file

@ -109,7 +109,7 @@ func (daemon *Daemon) setupIpcDirs(c *container.Container) error {
} }
c.ShmPath = "/dev/shm" c.ShmPath = "/dev/shm"
} else { } else {
rootIDs, _ := daemon.idMappings.RootPair() rootIDs := daemon.idMappings.RootPair()
if !c.HasMountFor("/dev/shm") { if !c.HasMountFor("/dev/shm") {
shmPath, err := c.ShmResourcePath() shmPath, err := c.ShmResourcePath()
if err != nil { if err != nil {
@ -147,7 +147,7 @@ func (daemon *Daemon) setupSecretDir(c *container.Container) (setupErr error) {
logrus.Debugf("secrets: setting up secret dir: %s", localMountPath) logrus.Debugf("secrets: setting up secret dir: %s", localMountPath)
// retrieve possible remapped range start for root UID, GID // retrieve possible remapped range start for root UID, GID
rootIDs, _ := daemon.idMappings.RootPair() rootIDs := daemon.idMappings.RootPair()
// create tmpfs // create tmpfs
if err := idtools.MkdirAllAndChown(localMountPath, 0700, rootIDs); err != nil { if err := idtools.MkdirAllAndChown(localMountPath, 0700, rootIDs); err != nil {
return errors.Wrap(err, "error creating secret local mount path") return errors.Wrap(err, "error creating secret local mount path")
@ -232,7 +232,7 @@ func (daemon *Daemon) setupConfigDir(c *container.Container) (setupErr error) {
logrus.Debugf("configs: setting up config dir: %s", localPath) logrus.Debugf("configs: setting up config dir: %s", localPath)
// retrieve possible remapped range start for root UID, GID // retrieve possible remapped range start for root UID, GID
rootIDs, _ := daemon.idMappings.RootPair() rootIDs := daemon.idMappings.RootPair()
// create tmpfs // create tmpfs
if err := idtools.MkdirAllAndChown(localPath, 0700, rootIDs); err != nil { if err := idtools.MkdirAllAndChown(localPath, 0700, rootIDs); err != nil {
return errors.Wrap(err, "error creating config dir") return errors.Wrap(err, "error creating config dir")

View file

@ -117,10 +117,7 @@ func (daemon *Daemon) create(params types.ContainerCreateConfig, managed bool) (
return nil, err return nil, err
} }
rootIDs, err := daemon.idMappings.RootPair() rootIDs := daemon.idMappings.RootPair()
if err != nil {
return nil, err
}
if err := idtools.MkdirAndChown(container.Root, 0700, rootIDs); err != nil { if err := idtools.MkdirAndChown(container.Root, 0700, rootIDs); err != nil {
return nil, err return nil, err
} }

View file

@ -22,7 +22,7 @@ func (daemon *Daemon) createContainerPlatformSpecificSettings(container *contain
} }
defer daemon.Unmount(container) defer daemon.Unmount(container)
rootIDs, _ := daemon.idMappings.RootPair() rootIDs := daemon.idMappings.RootPair()
if err := container.SetupWorkingDirectory(rootIDs); err != nil { if err := container.SetupWorkingDirectory(rootIDs); err != nil {
return err return err
} }

View file

@ -527,11 +527,7 @@ func NewDaemon(config *config.Config, registryService registry.Service, containe
if err != nil { if err != nil {
return nil, err return nil, err
} }
rootIDs, err := idMappings.RootPair() rootIDs := idMappings.RootPair()
if err != nil {
return nil, err
}
if err := setupDaemonProcess(config); err != nil { if err := setupDaemonProcess(config); err != nil {
return nil, err return nil, err
} }
@ -994,7 +990,7 @@ func prepareTempDir(rootDir string, rootIDs idtools.IDPair) (string, error) {
} }
func (daemon *Daemon) setupInitLayer(initPath string) error { func (daemon *Daemon) setupInitLayer(initPath string) error {
rootIDs, _ := daemon.idMappings.RootPair() rootIDs := daemon.idMappings.RootPair()
return initlayer.Setup(initPath, rootIDs) return initlayer.Setup(initPath, rootIDs)
} }
@ -1157,14 +1153,5 @@ func CreateDaemonRoot(config *config.Config) error {
if err != nil { if err != nil {
return err return err
} }
rootIDs, err := idMappings.RootPair() return setupDaemonRoot(config, realRoot, idMappings.RootPair())
if err != nil {
return err
}
if err := setupDaemonRoot(config, realRoot, rootIDs); err != nil {
return err
}
return nil
} }

View file

@ -28,10 +28,7 @@ func Init(home string, options []string, uidMaps, gidMaps []idtools.IDMap) (grap
home: home, home: home,
idMappings: idtools.NewIDMappingsFromMaps(uidMaps, gidMaps), idMappings: idtools.NewIDMappingsFromMaps(uidMaps, gidMaps),
} }
rootIDs, err := d.idMappings.RootPair() rootIDs := d.idMappings.RootPair()
if err != nil {
return nil, err
}
if err := idtools.MkdirAllAndChown(home, 0700, rootIDs); err != nil { if err := idtools.MkdirAllAndChown(home, 0700, rootIDs); err != nil {
return nil, err return nil, err
} }
@ -79,10 +76,7 @@ func (d *Driver) Create(id, parent string, opts *graphdriver.CreateOpts) error {
} }
dir := d.dir(id) dir := d.dir(id)
rootIDs, err := d.idMappings.RootPair() rootIDs := d.idMappings.RootPair()
if err != nil {
return err
}
if err := idtools.MkdirAllAndChown(filepath.Dir(dir), 0700, rootIDs); err != nil { if err := idtools.MkdirAllAndChown(filepath.Dir(dir), 0700, rootIDs); err != nil {
return err return err
} }

View file

@ -72,7 +72,7 @@ func (daemon *Daemon) SystemInfo() (*types.Info, error) {
if selinuxEnabled() { if selinuxEnabled() {
securityOptions = append(securityOptions, "name=selinux") securityOptions = append(securityOptions, "name=selinux")
} }
rootIDs, _ := daemon.idMappings.RootPair() rootIDs := daemon.idMappings.RootPair()
if rootIDs.UID != 0 || rootIDs.GID != 0 { if rootIDs.UID != 0 || rootIDs.GID != 0 {
securityOptions = append(securityOptions, "name=userns") securityOptions = append(securityOptions, "name=userns")
} }

View file

@ -611,8 +611,7 @@ func (daemon *Daemon) populateCommonSpec(s *specs.Spec, c *container.Container)
Path: c.BaseFS, Path: c.BaseFS,
Readonly: c.HostConfig.ReadonlyRootfs, Readonly: c.HostConfig.ReadonlyRootfs,
} }
rootIDs, _ := daemon.idMappings.RootPair() if err := c.SetupWorkingDirectory(daemon.idMappings.RootPair()); err != nil {
if err := c.SetupWorkingDirectory(rootIDs); err != nil {
return err return err
} }
cwd := c.Config.WorkingDir cwd := c.Config.WorkingDir

View file

@ -130,8 +130,7 @@ func (daemon *Daemon) populateCommonSpec(s *specs.Spec, c *container.Container)
Path: filepath.Dir(c.BaseFS), Path: filepath.Dir(c.BaseFS),
Readonly: c.HostConfig.ReadonlyRootfs, Readonly: c.HostConfig.ReadonlyRootfs,
} }
rootIDs, _ := daemon.idMappings.RootPair() if err := c.SetupWorkingDirectory(daemon.idMappings.RootPair()); err != nil {
if err := c.SetupWorkingDirectory(rootIDs); err != nil {
return err return err
} }
cwd := c.Config.WorkingDir cwd := c.Config.WorkingDir

View file

@ -54,8 +54,7 @@ func (daemon *Daemon) setupMounts(c *container.Container) ([]container.Mount, er
return nil return nil
} }
rootIDs, _ := daemon.idMappings.RootPair() path, err := m.Setup(c.MountLabel, daemon.idMappings.RootPair(), checkfunc)
path, err := m.Setup(c.MountLabel, rootIDs, checkfunc)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -85,7 +84,7 @@ func (daemon *Daemon) setupMounts(c *container.Container) ([]container.Mount, er
// if we are going to mount any of the network files from container // if we are going to mount any of the network files from container
// metadata, the ownership must be set properly for potential container // metadata, the ownership must be set properly for potential container
// remapped root (user namespaces) // remapped root (user namespaces)
rootIDs, _ := daemon.idMappings.RootPair() rootIDs := daemon.idMappings.RootPair()
for _, mount := range netMounts { for _, mount := range netMounts {
if err := os.Chown(mount.Source, rootIDs.UID, rootIDs.GID); err != nil { if err := os.Chown(mount.Source, rootIDs.UID, rootIDs.GID); err != nil {
return nil, err return nil, err

View file

@ -16,6 +16,5 @@ func (daemon *Daemon) ContainerCreateWorkdir(cID string) error {
return err return err
} }
defer daemon.Unmount(container) defer daemon.Unmount(container)
rootIDs, _ := daemon.idMappings.RootPair() return container.SetupWorkingDirectory(daemon.idMappings.RootPair())
return container.SetupWorkingDirectory(rootIDs)
} }

View file

@ -803,10 +803,7 @@ func Unpack(decompressedArchive io.Reader, dest string, options *TarOptions) err
var dirs []*tar.Header var dirs []*tar.Header
idMappings := idtools.NewIDMappingsFromMaps(options.UIDMaps, options.GIDMaps) idMappings := idtools.NewIDMappingsFromMaps(options.UIDMaps, options.GIDMaps)
rootIDs, err := idMappings.RootPair() rootIDs := idMappings.RootPair()
if err != nil {
return err
}
whiteoutConverter := getWhiteoutConverter(options.WhiteoutFormat) whiteoutConverter := getWhiteoutConverter(options.WhiteoutFormat)
// Iterate through the files in the archive. // Iterate through the files in the archive.
@ -1008,10 +1005,7 @@ func (archiver *Archiver) CopyWithTar(src, dst string) error {
// if this archiver is set up with ID mapping we need to create // if this archiver is set up with ID mapping we need to create
// the new destination directory with the remapped root UID/GID pair // the new destination directory with the remapped root UID/GID pair
// as owner // as owner
rootIDs, err := archiver.IDMappings.RootPair() rootIDs := archiver.IDMappings.RootPair()
if err != nil {
return err
}
// Create dst, copy src's content into it // Create dst, copy src's content into it
logrus.Debugf("Creating dest directory: %s", dst) logrus.Debugf("Creating dest directory: %s", dst)
if err := idtools.MkdirAllAndChownNew(dst, 0755, rootIDs); err != nil { if err := idtools.MkdirAllAndChownNew(dst, 0755, rootIDs); err != nil {

View file

@ -47,10 +47,7 @@ func untarHandler(tarArchive io.Reader, dest string, options *archive.TarOptions
} }
idMappings := idtools.NewIDMappingsFromMaps(options.UIDMaps, options.GIDMaps) idMappings := idtools.NewIDMappingsFromMaps(options.UIDMaps, options.GIDMaps)
rootIDs, err := idMappings.RootPair() rootIDs := idMappings.RootPair()
if err != nil {
return err
}
dest = filepath.Clean(dest) dest = filepath.Clean(dest)
if _, err := os.Stat(dest); os.IsNotExist(err) { if _, err := os.Stat(dest); os.IsNotExist(err) {

View file

@ -158,19 +158,19 @@ func NewIDMappingsFromMaps(uids []IDMap, gids []IDMap) *IDMappings {
return &IDMappings{uids: uids, gids: gids} return &IDMappings{uids: uids, gids: gids}
} }
// RootPair returns a uid and gid pair for the root user // RootPair returns a uid and gid pair for the root user. The error is ignored
func (i *IDMappings) RootPair() (IDPair, error) { // because a root user always exists, and the defaults are correct when the uid
uid, gid, err := GetRootUIDGID(i.uids, i.gids) // and gid maps are empty.
return IDPair{UID: uid, GID: gid}, err func (i *IDMappings) RootPair() IDPair {
uid, gid, _ := GetRootUIDGID(i.uids, i.gids)
return IDPair{UID: uid, GID: gid}
} }
// ToHost returns the host UID and GID for the container uid, gid. // ToHost returns the host UID and GID for the container uid, gid.
// Remapping is only performed if the ids aren't already the remapped root ids // Remapping is only performed if the ids aren't already the remapped root ids
func (i *IDMappings) ToHost(pair IDPair) (IDPair, error) { func (i *IDMappings) ToHost(pair IDPair) (IDPair, error) {
target, err := i.RootPair() var err error
if err != nil { target := i.RootPair()
return IDPair{}, err
}
if pair.UID != target.UID { if pair.UID != target.UID {
target.UID, err = toHost(pair.UID, i.uids) target.UID, err = toHost(pair.UID, i.uids)