Commit Graph

6 Commits

Author SHA1 Message Date
Kan Li c9bcfd8a5f Rework autons ID mapping generation.
This implements the algorithm proposed in
https://github.com/containers/storage/issues/852#issuecomment-798954173,
which is:
1. find available IDs from subuid/subgid file; by subtracting the used
   IDs (from other containers) as well as additional IDs, we get the IDs
   available to allocate;
2. target ID range is [0, requestedSize), subtract the additional IDs;
3. allocate IDs from range in step 1; the number to allocate is the
   number of IDs in step 2;
4. generate a mapping from IDs in step 3 to the ones in step 2.

Closes: https://github.com/containers/storage/issues/852

Signed-off-by: Kan Li <likan@google.com>
2021-04-03 13:22:23 -07:00
Kan Li d27c88d3ef Fix subtractAll bugs.
The logic of range subtraction [a,b)-[c,d) can be viewed as intersection
of [a,b) with (-inf, c) and [d, +inf), respectively. This makes the
logic simpler, that we no longer need to check 5 different cases.

It also fixes bugs that returns incorrect range.

Closes #763
Signed-off-by: Kan Li <likan@google.com>
2020-11-01 10:52:08 -08:00
Giuseppe Scrivano 4caae16a28
userns: make sure host id is not always 0
when it finds multiple available ranges, make sure the host id is
correctly initialized.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2020-08-06 16:34:57 +02:00
Giuseppe Scrivano 64570f6324
userns: fix host id calculation when ranges overlap
issue found while testing: https://github.com/cri-o/cri-o/pull/3944

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2020-08-03 14:57:43 +02:00
Giuseppe Scrivano ae6846d67a
userns: fix available range with explicit idmapping
when an explicit idmapping is specified, the host id must be taken
from the available range of IDs.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2020-07-12 15:44:53 +02:00
Giuseppe Scrivano 2cff5ddf93
userns: add support for auto
automatically pick an empty range and create an user namespace for the
container.

For root containers, it is necessary to specify an entry in
the /etc/subuid and /etc/subgid files to use for picking the range of
available IDs.  This is necessary to avoid collisions with IDs used
for rootless containers.  This setting is ignored for rootless
containers, since it is not possible to use arbitrary IDs, and the
initial set is always picked by the IDs assigned to the rootless
user.

When using auto userns, a container will use a range of IDs that is
not used by any other container user namespace, also those that are
not using auto userns, this is checked at creation time.
A successive container that doesn't use auto userns feature can still
collide with IDs used by an auto userns container.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2020-03-26 11:12:34 +01:00