2017年8月13日 星期日

Unprivileged container mapping

REF: https://pve.proxmox.com/wiki/Unprivileged_LXC_containers

Let's see an example, we want to make uid 1005 accessible in an unprivileged container.
First, we have to change the container UID mapping in the file /etc/pve/lxc/1234.conf:
# uid map: from uid 0 map 1005 uids (in the ct) to the range starting 100000 (on the host), so 0..1004 (ct) → 100000..101004 (host)
lxc.id_map = u 0 100000 1005
lxc.id_map = g 0 100000 1005
# we map 1 uid starting from uid 1005 onto 1005, so 1005 → 1005
lxc.id_map = u 1005 1005 1
lxc.id_map = g 1005 1005 1
# we map the rest of 65535 from 1006 upto 101006, so 1006..65535 → 101006..165535
lxc.id_map = u 1006 101006 64530
lxc.id_map = g 1006 101006 64530
Then we have to allow lxc to actually do the mapping on the host. Since lxc creates the CT using root, we have to allow root to use these uids in the container.
First the file /etc/subuid (we allow 1 piece of uid starting from 1005):
root:1005:1
then /etc/subgid:
root:1005:1

You can start or restart the container here, it should start and see /shared mapped from the host directory /mnt/bindmounts/shared, all uids will be mapped to 65534:65534 except 1005, which would be seen (and written) as 1005:1005.

沒有留言:

張貼留言