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>
| ... | ... |
@@ -375,7 +375,7 @@ func (daemon *Daemon) CopyOnBuild(cID, destPath, srcRoot, srcPath string, decomp |
| 375 | 375 |
|
| 376 | 376 |
destExists := true |
| 377 | 377 |
destDir := false |
| 378 |
- rootIDs, _ := daemon.idMappings.RootPair() |
|
| 378 |
+ rootIDs := daemon.idMappings.RootPair() |
|
| 379 | 379 |
|
| 380 | 380 |
// Work in daemon-local OS specific file paths |
| 381 | 381 |
destPath = filepath.FromSlash(destPath) |
| ... | ... |
@@ -109,7 +109,7 @@ func (daemon *Daemon) setupIpcDirs(c *container.Container) error {
|
| 109 | 109 |
} |
| 110 | 110 |
c.ShmPath = "/dev/shm" |
| 111 | 111 |
} else {
|
| 112 |
- rootIDs, _ := daemon.idMappings.RootPair() |
|
| 112 |
+ rootIDs := daemon.idMappings.RootPair() |
|
| 113 | 113 |
if !c.HasMountFor("/dev/shm") {
|
| 114 | 114 |
shmPath, err := c.ShmResourcePath() |
| 115 | 115 |
if err != nil {
|
| ... | ... |
@@ -147,7 +147,7 @@ func (daemon *Daemon) setupSecretDir(c *container.Container) (setupErr error) {
|
| 147 | 147 |
logrus.Debugf("secrets: setting up secret dir: %s", localMountPath)
|
| 148 | 148 |
|
| 149 | 149 |
// retrieve possible remapped range start for root UID, GID |
| 150 |
- rootIDs, _ := daemon.idMappings.RootPair() |
|
| 150 |
+ rootIDs := daemon.idMappings.RootPair() |
|
| 151 | 151 |
// create tmpfs |
| 152 | 152 |
if err := idtools.MkdirAllAndChown(localMountPath, 0700, rootIDs); err != nil {
|
| 153 | 153 |
return errors.Wrap(err, "error creating secret local mount path") |
| ... | ... |
@@ -232,7 +232,7 @@ func (daemon *Daemon) setupConfigDir(c *container.Container) (setupErr error) {
|
| 232 | 232 |
logrus.Debugf("configs: setting up config dir: %s", localPath)
|
| 233 | 233 |
|
| 234 | 234 |
// retrieve possible remapped range start for root UID, GID |
| 235 |
- rootIDs, _ := daemon.idMappings.RootPair() |
|
| 235 |
+ rootIDs := daemon.idMappings.RootPair() |
|
| 236 | 236 |
// create tmpfs |
| 237 | 237 |
if err := idtools.MkdirAllAndChown(localPath, 0700, rootIDs); err != nil {
|
| 238 | 238 |
return errors.Wrap(err, "error creating config dir") |
| ... | ... |
@@ -117,10 +117,7 @@ func (daemon *Daemon) create(params types.ContainerCreateConfig, managed bool) ( |
| 117 | 117 |
return nil, err |
| 118 | 118 |
} |
| 119 | 119 |
|
| 120 |
- rootIDs, err := daemon.idMappings.RootPair() |
|
| 121 |
- if err != nil {
|
|
| 122 |
- return nil, err |
|
| 123 |
- } |
|
| 120 |
+ rootIDs := daemon.idMappings.RootPair() |
|
| 124 | 121 |
if err := idtools.MkdirAndChown(container.Root, 0700, rootIDs); err != nil {
|
| 125 | 122 |
return nil, err |
| 126 | 123 |
} |
| ... | ... |
@@ -22,7 +22,7 @@ func (daemon *Daemon) createContainerPlatformSpecificSettings(container *contain |
| 22 | 22 |
} |
| 23 | 23 |
defer daemon.Unmount(container) |
| 24 | 24 |
|
| 25 |
- rootIDs, _ := daemon.idMappings.RootPair() |
|
| 25 |
+ rootIDs := daemon.idMappings.RootPair() |
|
| 26 | 26 |
if err := container.SetupWorkingDirectory(rootIDs); err != nil {
|
| 27 | 27 |
return err |
| 28 | 28 |
} |
| ... | ... |
@@ -527,11 +527,7 @@ func NewDaemon(config *config.Config, registryService registry.Service, containe |
| 527 | 527 |
if err != nil {
|
| 528 | 528 |
return nil, err |
| 529 | 529 |
} |
| 530 |
- rootIDs, err := idMappings.RootPair() |
|
| 531 |
- if err != nil {
|
|
| 532 |
- return nil, err |
|
| 533 |
- } |
|
| 534 |
- |
|
| 530 |
+ rootIDs := idMappings.RootPair() |
|
| 535 | 531 |
if err := setupDaemonProcess(config); err != nil {
|
| 536 | 532 |
return nil, err |
| 537 | 533 |
} |
| ... | ... |
@@ -994,7 +990,7 @@ func prepareTempDir(rootDir string, rootIDs idtools.IDPair) (string, error) {
|
| 994 | 994 |
} |
| 995 | 995 |
|
| 996 | 996 |
func (daemon *Daemon) setupInitLayer(initPath string) error {
|
| 997 |
- rootIDs, _ := daemon.idMappings.RootPair() |
|
| 997 |
+ rootIDs := daemon.idMappings.RootPair() |
|
| 998 | 998 |
return initlayer.Setup(initPath, rootIDs) |
| 999 | 999 |
} |
| 1000 | 1000 |
|
| ... | ... |
@@ -1157,14 +1153,5 @@ func CreateDaemonRoot(config *config.Config) error {
|
| 1157 | 1157 |
if err != nil {
|
| 1158 | 1158 |
return err |
| 1159 | 1159 |
} |
| 1160 |
- rootIDs, err := idMappings.RootPair() |
|
| 1161 |
- if err != nil {
|
|
| 1162 |
- return err |
|
| 1163 |
- } |
|
| 1164 |
- |
|
| 1165 |
- if err := setupDaemonRoot(config, realRoot, rootIDs); err != nil {
|
|
| 1166 |
- return err |
|
| 1167 |
- } |
|
| 1168 |
- |
|
| 1169 |
- return nil |
|
| 1160 |
+ return setupDaemonRoot(config, realRoot, idMappings.RootPair()) |
|
| 1170 | 1161 |
} |
| ... | ... |
@@ -28,10 +28,7 @@ func Init(home string, options []string, uidMaps, gidMaps []idtools.IDMap) (grap |
| 28 | 28 |
home: home, |
| 29 | 29 |
idMappings: idtools.NewIDMappingsFromMaps(uidMaps, gidMaps), |
| 30 | 30 |
} |
| 31 |
- rootIDs, err := d.idMappings.RootPair() |
|
| 32 |
- if err != nil {
|
|
| 33 |
- return nil, err |
|
| 34 |
- } |
|
| 31 |
+ rootIDs := d.idMappings.RootPair() |
|
| 35 | 32 |
if err := idtools.MkdirAllAndChown(home, 0700, rootIDs); err != nil {
|
| 36 | 33 |
return nil, err |
| 37 | 34 |
} |
| ... | ... |
@@ -79,10 +76,7 @@ func (d *Driver) Create(id, parent string, opts *graphdriver.CreateOpts) error {
|
| 79 | 79 |
} |
| 80 | 80 |
|
| 81 | 81 |
dir := d.dir(id) |
| 82 |
- rootIDs, err := d.idMappings.RootPair() |
|
| 83 |
- if err != nil {
|
|
| 84 |
- return err |
|
| 85 |
- } |
|
| 82 |
+ rootIDs := d.idMappings.RootPair() |
|
| 86 | 83 |
if err := idtools.MkdirAllAndChown(filepath.Dir(dir), 0700, rootIDs); err != nil {
|
| 87 | 84 |
return err |
| 88 | 85 |
} |
| ... | ... |
@@ -72,7 +72,7 @@ func (daemon *Daemon) SystemInfo() (*types.Info, error) {
|
| 72 | 72 |
if selinuxEnabled() {
|
| 73 | 73 |
securityOptions = append(securityOptions, "name=selinux") |
| 74 | 74 |
} |
| 75 |
- rootIDs, _ := daemon.idMappings.RootPair() |
|
| 75 |
+ rootIDs := daemon.idMappings.RootPair() |
|
| 76 | 76 |
if rootIDs.UID != 0 || rootIDs.GID != 0 {
|
| 77 | 77 |
securityOptions = append(securityOptions, "name=userns") |
| 78 | 78 |
} |
| ... | ... |
@@ -611,8 +611,7 @@ func (daemon *Daemon) populateCommonSpec(s *specs.Spec, c *container.Container) |
| 611 | 611 |
Path: c.BaseFS, |
| 612 | 612 |
Readonly: c.HostConfig.ReadonlyRootfs, |
| 613 | 613 |
} |
| 614 |
- rootIDs, _ := daemon.idMappings.RootPair() |
|
| 615 |
- if err := c.SetupWorkingDirectory(rootIDs); err != nil {
|
|
| 614 |
+ if err := c.SetupWorkingDirectory(daemon.idMappings.RootPair()); err != nil {
|
|
| 616 | 615 |
return err |
| 617 | 616 |
} |
| 618 | 617 |
cwd := c.Config.WorkingDir |
| ... | ... |
@@ -130,8 +130,7 @@ func (daemon *Daemon) populateCommonSpec(s *specs.Spec, c *container.Container) |
| 130 | 130 |
Path: filepath.Dir(c.BaseFS), |
| 131 | 131 |
Readonly: c.HostConfig.ReadonlyRootfs, |
| 132 | 132 |
} |
| 133 |
- rootIDs, _ := daemon.idMappings.RootPair() |
|
| 134 |
- if err := c.SetupWorkingDirectory(rootIDs); err != nil {
|
|
| 133 |
+ if err := c.SetupWorkingDirectory(daemon.idMappings.RootPair()); err != nil {
|
|
| 135 | 134 |
return err |
| 136 | 135 |
} |
| 137 | 136 |
cwd := c.Config.WorkingDir |
| ... | ... |
@@ -54,8 +54,7 @@ func (daemon *Daemon) setupMounts(c *container.Container) ([]container.Mount, er |
| 54 | 54 |
return nil |
| 55 | 55 |
} |
| 56 | 56 |
|
| 57 |
- rootIDs, _ := daemon.idMappings.RootPair() |
|
| 58 |
- path, err := m.Setup(c.MountLabel, rootIDs, checkfunc) |
|
| 57 |
+ path, err := m.Setup(c.MountLabel, daemon.idMappings.RootPair(), checkfunc) |
|
| 59 | 58 |
if err != nil {
|
| 60 | 59 |
return nil, err |
| 61 | 60 |
} |
| ... | ... |
@@ -85,7 +84,7 @@ func (daemon *Daemon) setupMounts(c *container.Container) ([]container.Mount, er |
| 85 | 85 |
// if we are going to mount any of the network files from container |
| 86 | 86 |
// metadata, the ownership must be set properly for potential container |
| 87 | 87 |
// remapped root (user namespaces) |
| 88 |
- rootIDs, _ := daemon.idMappings.RootPair() |
|
| 88 |
+ rootIDs := daemon.idMappings.RootPair() |
|
| 89 | 89 |
for _, mount := range netMounts {
|
| 90 | 90 |
if err := os.Chown(mount.Source, rootIDs.UID, rootIDs.GID); err != nil {
|
| 91 | 91 |
return nil, err |
| ... | ... |
@@ -16,6 +16,5 @@ func (daemon *Daemon) ContainerCreateWorkdir(cID string) error {
|
| 16 | 16 |
return err |
| 17 | 17 |
} |
| 18 | 18 |
defer daemon.Unmount(container) |
| 19 |
- rootIDs, _ := daemon.idMappings.RootPair() |
|
| 20 |
- return container.SetupWorkingDirectory(rootIDs) |
|
| 19 |
+ return container.SetupWorkingDirectory(daemon.idMappings.RootPair()) |
|
| 21 | 20 |
} |
| ... | ... |
@@ -803,10 +803,7 @@ func Unpack(decompressedArchive io.Reader, dest string, options *TarOptions) err |
| 803 | 803 |
|
| 804 | 804 |
var dirs []*tar.Header |
| 805 | 805 |
idMappings := idtools.NewIDMappingsFromMaps(options.UIDMaps, options.GIDMaps) |
| 806 |
- rootIDs, err := idMappings.RootPair() |
|
| 807 |
- if err != nil {
|
|
| 808 |
- return err |
|
| 809 |
- } |
|
| 806 |
+ rootIDs := idMappings.RootPair() |
|
| 810 | 807 |
whiteoutConverter := getWhiteoutConverter(options.WhiteoutFormat) |
| 811 | 808 |
|
| 812 | 809 |
// Iterate through the files in the archive. |
| ... | ... |
@@ -1008,10 +1005,7 @@ func (archiver *Archiver) CopyWithTar(src, dst string) error {
|
| 1008 | 1008 |
// if this archiver is set up with ID mapping we need to create |
| 1009 | 1009 |
// the new destination directory with the remapped root UID/GID pair |
| 1010 | 1010 |
// as owner |
| 1011 |
- rootIDs, err := archiver.IDMappings.RootPair() |
|
| 1012 |
- if err != nil {
|
|
| 1013 |
- return err |
|
| 1014 |
- } |
|
| 1011 |
+ rootIDs := archiver.IDMappings.RootPair() |
|
| 1015 | 1012 |
// Create dst, copy src's content into it |
| 1016 | 1013 |
logrus.Debugf("Creating dest directory: %s", dst)
|
| 1017 | 1014 |
if err := idtools.MkdirAllAndChownNew(dst, 0755, rootIDs); err != nil {
|
| ... | ... |
@@ -47,10 +47,7 @@ func untarHandler(tarArchive io.Reader, dest string, options *archive.TarOptions |
| 47 | 47 |
} |
| 48 | 48 |
|
| 49 | 49 |
idMappings := idtools.NewIDMappingsFromMaps(options.UIDMaps, options.GIDMaps) |
| 50 |
- rootIDs, err := idMappings.RootPair() |
|
| 51 |
- if err != nil {
|
|
| 52 |
- return err |
|
| 53 |
- } |
|
| 50 |
+ rootIDs := idMappings.RootPair() |
|
| 54 | 51 |
|
| 55 | 52 |
dest = filepath.Clean(dest) |
| 56 | 53 |
if _, err := os.Stat(dest); os.IsNotExist(err) {
|
| ... | ... |
@@ -158,19 +158,19 @@ func NewIDMappingsFromMaps(uids []IDMap, gids []IDMap) *IDMappings {
|
| 158 | 158 |
return &IDMappings{uids: uids, gids: gids}
|
| 159 | 159 |
} |
| 160 | 160 |
|
| 161 |
-// RootPair returns a uid and gid pair for the root user |
|
| 162 |
-func (i *IDMappings) RootPair() (IDPair, error) {
|
|
| 163 |
- uid, gid, err := GetRootUIDGID(i.uids, i.gids) |
|
| 164 |
- return IDPair{UID: uid, GID: gid}, err
|
|
| 161 |
+// RootPair returns a uid and gid pair for the root user. The error is ignored |
|
| 162 |
+// because a root user always exists, and the defaults are correct when the uid |
|
| 163 |
+// and gid maps are empty. |
|
| 164 |
+func (i *IDMappings) RootPair() IDPair {
|
|
| 165 |
+ uid, gid, _ := GetRootUIDGID(i.uids, i.gids) |
|
| 166 |
+ return IDPair{UID: uid, GID: gid}
|
|
| 165 | 167 |
} |
| 166 | 168 |
|
| 167 | 169 |
// ToHost returns the host UID and GID for the container uid, gid. |
| 168 | 170 |
// Remapping is only performed if the ids aren't already the remapped root ids |
| 169 | 171 |
func (i *IDMappings) ToHost(pair IDPair) (IDPair, error) {
|
| 170 |
- target, err := i.RootPair() |
|
| 171 |
- if err != nil {
|
|
| 172 |
- return IDPair{}, err
|
|
| 173 |
- } |
|
| 172 |
+ var err error |
|
| 173 |
+ target := i.RootPair() |
|
| 174 | 174 |
|
| 175 | 175 |
if pair.UID != target.UID {
|
| 176 | 176 |
target.UID, err = toHost(pair.UID, i.uids) |