]> git.ipfire.org Git - thirdparty/util-linux.git/commit
unshare: Add options to map blocks of user/group IDs
authorSean Anderson <seanga2@gmail.com>
Wed, 24 Nov 2021 18:26:16 +0000 (13:26 -0500)
committerKarel Zak <kzak@redhat.com>
Wed, 1 Dec 2021 12:35:59 +0000 (13:35 +0100)
commitff5dc96ebf2bf83150ba1fa73f4498ed2210c29c
treea80798c4ea123e549ec23d4233d957a08be559bc
parent783bb52a96e901133662fe93f8671c982db3934a
unshare: Add options to map blocks of user/group IDs

This adds the ability to map multiple user/group IDs when creating a new
user namespace. Regular processes cannot map any user other than the
effective user, so we need to use the setuid helpers newuidmap and
newgidmap, provided by shadow. Typically, users will be assigned blocks
of user/group IDs in /etc/sub{u,g}id, although it is also possible to
use NSS. There is a second advantage in using these helpers: because we
never write to /proc/self/gid_map, we don't have to disable setgroups.

Because the process of mapping IDs is almost identical, whether we are
mapping user IDs or group IDs, we put both in a common "map_range"
structure. These are read in by (ab)using string_to_idarray. In addition
to any map created with --map-users, we still need to handle a map of
size one created with --map-user. This makes constructing the helpers'
command line the trickiest part of the whole process. newuidmap/
newgidmap check to see if any ranges overlap before creating a mapping.
To avoid failing, we carve out a hole in the mapping for the singular
map. In the worst case, we may have three separate maps.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
sys-utils/unshare.c