Skip to content
This repository was archived by the owner on Oct 13, 2023. It is now read-only.

Commit 6aba415

Browse files
authored
Merge pull request #40562 from thaJeztah/19.03_backport_39353_subgid_subuid
[19.03] backport Fix docker crash when creating namespaces with UID in /etc/subuid and /etc/subgid Upstream-commit: 89f296a53479edc1e937e0e5e3e7db4c27b6df60 Component: engine
2 parents a6e499a + af7196a commit 6aba415

1 file changed

Lines changed: 23 additions & 2 deletions

File tree

components/engine/daemon/daemon_unix.go

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1176,11 +1176,32 @@ func setupRemappedRoot(config *config.Config) (*idtools.IdentityMapping, error)
11761176
// update remapped root setting now that we have resolved them to actual names
11771177
config.RemappedRoot = fmt.Sprintf("%s:%s", username, groupname)
11781178

1179+
// try with username:groupname, uid:groupname, username:gid, uid:gid,
1180+
// but keep the original error message (err)
11791181
mappings, err := idtools.NewIdentityMapping(username, groupname)
1180-
if err != nil {
1182+
if err == nil {
1183+
return mappings, nil
1184+
}
1185+
user, lookupErr := idtools.LookupUser(username)
1186+
if lookupErr != nil {
11811187
return nil, errors.Wrap(err, "Can't create ID mappings")
11821188
}
1183-
return mappings, nil
1189+
logrus.Infof("Can't create ID mappings with username:groupname %s:%s, try uid:groupname %d:%s", username, groupname, user.Uid, groupname)
1190+
mappings, lookupErr = idtools.NewIdentityMapping(fmt.Sprintf("%d", user.Uid), groupname)
1191+
if lookupErr == nil {
1192+
return mappings, nil
1193+
}
1194+
logrus.Infof("Can't create ID mappings with uid:groupname %d:%s, try username:gid %s:%d", user.Uid, groupname, username, user.Gid)
1195+
mappings, lookupErr = idtools.NewIdentityMapping(username, fmt.Sprintf("%d", user.Gid))
1196+
if lookupErr == nil {
1197+
return mappings, nil
1198+
}
1199+
logrus.Infof("Can't create ID mappings with username:gid %s:%d, try uid:gid %d:%d", username, user.Gid, user.Uid, user.Gid)
1200+
mappings, lookupErr = idtools.NewIdentityMapping(fmt.Sprintf("%d", user.Uid), fmt.Sprintf("%d", user.Gid))
1201+
if lookupErr == nil {
1202+
return mappings, nil
1203+
}
1204+
return nil, errors.Wrap(err, "Can't create ID mappings")
11841205
}
11851206
return &idtools.IdentityMapping{}, nil
11861207
}

0 commit comments

Comments
 (0)