mirror of
https://github.com/containers/podman.git
synced 2025-06-28 22:53:21 +08:00
utils: do not generate duplicate range
do not generate a duplicated range when --userns=keep-id:uid=0 or --userns=keep-id:gid=0 are used. Closes: https://github.com/containers/podman/issues/22078 Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
This commit is contained in:
@ -195,7 +195,7 @@ func getRootlessKeepIDMapping(uid, gid int, uids, gids []idtools.IDMap) (*stypes
|
||||
|
||||
options.UIDMap, options.GIDMap = nil, nil
|
||||
|
||||
if len(uids) > 0 {
|
||||
if len(uids) > 0 && uid != 0 {
|
||||
options.UIDMap = append(options.UIDMap, idtools.IDMap{ContainerID: 0, HostID: 1, Size: min(uid, maxUID)})
|
||||
}
|
||||
options.UIDMap = append(options.UIDMap, idtools.IDMap{ContainerID: uid, HostID: 0, Size: 1})
|
||||
@ -203,7 +203,7 @@ func getRootlessKeepIDMapping(uid, gid int, uids, gids []idtools.IDMap) (*stypes
|
||||
options.UIDMap = append(options.UIDMap, idtools.IDMap{ContainerID: uid + 1, HostID: uid + 1, Size: maxUID - uid})
|
||||
}
|
||||
|
||||
if len(gids) > 0 {
|
||||
if len(gids) > 0 && gid != 0 {
|
||||
options.GIDMap = append(options.GIDMap, idtools.IDMap{ContainerID: 0, HostID: 1, Size: min(gid, maxGID)})
|
||||
}
|
||||
options.GIDMap = append(options.GIDMap, idtools.IDMap{ContainerID: gid, HostID: 0, Size: 1})
|
||||
|
@ -612,6 +612,20 @@ func TestGetRootlessKeepIDMapping(t *testing.T) {
|
||||
expectedUID: 1000,
|
||||
expectedGID: 1000,
|
||||
},
|
||||
{
|
||||
uid: 0,
|
||||
gid: 0,
|
||||
uids: []idtools.IDMap{{ContainerID: 0, HostID: 100000, Size: 65536}},
|
||||
gids: []idtools.IDMap{{ContainerID: 0, HostID: 100000, Size: 65536}},
|
||||
expectedOptions: &stypes.IDMappingOptions{
|
||||
HostUIDMapping: false,
|
||||
HostGIDMapping: false,
|
||||
UIDMap: []idtools.IDMap{{ContainerID: 0, HostID: 0, Size: 1}, {ContainerID: 1, HostID: 1, Size: 65536}},
|
||||
GIDMap: []idtools.IDMap{{ContainerID: 0, HostID: 0, Size: 1}, {ContainerID: 1, HostID: 1, Size: 65536}},
|
||||
},
|
||||
expectedUID: 0,
|
||||
expectedGID: 0,
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
|
Reference in New Issue
Block a user