Unprivileged Containers


• In an unprivileged container, if anyone gets the root privilege in the container, they can't do anything with root power on the host machine
• Limitations: can't mount devices to unprivileged container

sudo apt-get install lxc uidmap
sudo lxc-checkconfig
sudo adduser lxcuser
# Allocate subgid and subuid to lxcuser
sudo usermod --add-subuids 100000-165536 lxcuser
sudo usermod --add-subgids 100000-165536 lxcuser
sudo chmod +x /home/lxcuser

# create ~/.config/lxc/default.conf
lxc.network.type = veth
lxc.network.link = lxcbr0
lxc.network.flags = up
lxc.network.hwaddr = 00:16:3e:xx:xx:xx
lxc.id_map = u 0 100000 65536 # OR adjust for autocreated values in /etc/subuid
lxc.id_map = g 0 100000 65536 # same as above for /etc/subgid

logout

# Create /etc/lxc/lxc-usernet
# USERNAME TYPE BRIDGE COUNT
lxcuser veth lxcbr0 10                  # max of 10 containers

grep lxcuser /etc/sub* 2>/dev/null      # verify subgid & subuid assigned

# Log out/restart, log in as lxcuser

# Download the special image/rootfs:
lxc-create -t download -n unprivileged -- -d ubuntu -r trusty -a amd64
## download is a special type

# start the container
lxc-start -n unprivileged -d

# list container IP
lxc-ls --fancy

# ssh in and enjoy (login/pass: ubuntu/ubuntu)


Further Readings


https://stgraber.org/2013/12/20/lxc-1-0-blog-post-series/
• View “download” available: Image server for LXC and LXD










Index