From: Bogdan Purcareata Date: Mon, 20 Oct 2014 19:56:53 +0000 (-0400) Subject: busybox template: support for unprivileged containers X-Git-Tag: lxc-1.0.7~45 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c3c0a8b7e5bcce5c23102cabebb63bd40be5effd;p=thirdparty%2Flxc.git busybox template: support for unprivileged containers Apply the changes found in templates/lxc-download to the busybox template as well. Change ownership of the config and fstab files to the unprivileged user, and the ownership of the rootfs to root in the new user namespace. Eliminate the "unsupported for userns" flag. Signed-off-by: Bogdan Purcareata Acked-by: Serge E. Hallyn --- diff --git a/templates/lxc-busybox.in b/templates/lxc-busybox.in index 246e743f0..ca2dd4348 100644 --- a/templates/lxc-busybox.in +++ b/templates/lxc-busybox.in @@ -20,15 +20,8 @@ # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -# Detect use under userns (unsupported) -for arg in "$@"; do - [ "$arg" = "--" ] && break - if [ "$arg" = "--mapped-uid" -o "$arg" = "--mapped-gid" ]; then - echo "This template can't be used for unprivileged containers." 1>&2 - echo "You may want to try the \"download\" template instead." 1>&2 - exit 1 - fi -done +LXC_MAPPED_UID= +LXC_MAPPED_GID= # Make sure the usual locations are in PATH export PATH=$PATH:/usr/sbin:/usr/bin:/sbin:/bin @@ -310,6 +303,21 @@ EOF echo "lxc.mount.auto = proc:mixed sys" >>$path/config } +remap_userns() +{ + path=$1 + + if [ -n "$LXC_MAPPED_UID" ] && [ "$LXC_MAPPED_UID" != "-1" ]; then + chown $LXC_MAPPED_UID $path/config $path/fstab >/dev/null 2>&1 + chown -R root $path/rootfs >/dev/null 2>&1 + fi + + if [ -n "$LXC_MAPPED_GID" ] && [ "$LXC_MAPPED_GID" != "-1" ]; then + chgrp $LXC_MAPPED_GID $path/config $path/fstab >/dev/null 2>&1 + chgrp -R root $path/rootfs >/dev/null 2>&1 + fi +} + usage() { cat <