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

Commit af7196a

Browse files
yongtangthaJeztah
authored andcommitted
Fix docker crash when creating namespaces with UID in /etc/subuid and /etc/subgid
This fix tries to address the issue raised in 39353 where docker crash when creating namespaces with UID in /etc/subuid and /etc/subgid. The issue was that, mapping to `/etc/sub[u,g]id` in docker does not allow numeric ID. This fix fixes the issue by probing other combinations (uid:groupname, username:gid, uid:gid) when normal username:groupname fails. This fix fixes 39353. Signed-off-by: Yong Tang <yong.tang.github@outlook.com> (cherry picked from commit f09dc2f4fc68c0e622797404763b757739b79aaa) Signed-off-by: Sebastiaan van Stijn <github@gone.nl> Upstream-commit: dcae74c44a58b403be4f3e623c30e02aaea8f9be Component: engine
1 parent d9f362f commit af7196a

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)