]> git.proxmox.com Git - pve-container.git/commit
lxc start: warn in case of conflicting lxc.idmap entries
authorFriedrich Weber <f.weber@proxmox.com>
Mon, 15 May 2023 13:08:23 +0000 (15:08 +0200)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Thu, 25 May 2023 07:10:56 +0000 (09:10 +0200)
commitd17fe04161d252b85227ba2401e1e7ce03e842ff
treee7a0e4b0d9a0eb42c7e58cc8128463bdffcf6fb6
parent971f85f2519d7f2ddb3a3dd9a3a715b5e575b6ca
lxc start: warn in case of conflicting lxc.idmap entries

Users can customize the mapping between host and container uids/gids
by providing `lxc.idmap` entries in the container config. The syntax
is described in lxc.container.conf(5). One source of errors are
conflicting entries for one or more uid/gids. An example:

    ...
    lxc.idmap: u 0 100000 65536
    lxc.idmap: u 1000 1000 10
    ...

Assuming `root:1000:10` is correctly added to /etc/subuid, starting
the container fails with an error that is hard to interpret:

    lxc_map_ids: 3701 newuidmap failed to write mapping
    "newuidmap: write to uid_map failed: Invalid argument":
    newuidmap 67993 0 100000 65536 1000 1000 10

In order to simplify troubleshooting, validate the mapping before
starting the container and print a warning if a conflict is detected.
For the above mapping:

    lxc.idmap: invalid map entry 'u 1000 1000 10':
    container uid 1000 is also mapped by entry 'u 0 100000 65536'

The warning appears in the task log and in the output of `pct start`.

The validation subroutine considers uid and gid mappings separately.
For each of the two types, it makes one pass to detect container id
conflicts and one pass to detect host id conflicts. The subroutine
dies with the first detected conflict.

A failed validation only prints a warning instead of erroring out, to
make sure buggy (or outdated) validation logic does not prevent
containers from starting.

Note that validation does not take /etc/sub{uid,gid} into account,
which, if misconfigured, could still prevent the container from
starting with an error like

    "newuidmap: uid range [1000-1010) -> [1000-1010) not allowed"

If needed, validating /etc/sub{uid,gid} could be added in the future.

Signed-off-by: Friedrich Weber <f.weber@proxmox.com>
src/PVE/LXC.pm
src/test/Makefile
src/test/idmap-test.pm [new file with mode: 0644]
src/test/run_idmap_tests.pl [new file with mode: 0755]