lxc-test-unpriv revision 569c5fe10365bb93d8773a7bd390353bcaafd3c5
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar# lxc: linux Container library
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar# Serge Hallyn <serge.hallyn@ubuntu.com>
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar# This is a test script for unprivileged containers
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar# This library is free software; you can redistribute it and/or
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar# modify it under the terms of the GNU Lesser General Public
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar# License as published by the Free Software Foundation; either
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar# version 2.1 of the License, or (at your option) any later version.
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar# This library is distributed in the hope that it will be useful,
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar# but WITHOUT ANY WARRANTY; without even the implied warranty of
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar# Lesser General Public License for more details.
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar# You should have received a copy of the GNU Lesser General Public
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar# License along with this library; if not, write to the Free Software
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar# This test assumes an Ubuntu host
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar echo "ERROR: Must run as root."
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar# Test if we're using an overlayfs module that handles symlinks correctly. If
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar# not, we skip these tests since overlay clones will not work correctly.
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar mkdir "${MOUNTDIR}/lowerdir" "${MOUNTDIR}/upperdir" "${MOUNTDIR}/overlayfs"
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar mount -t overlayfs -o lowerdir="${MOUNTDIR}/lowerdir",upperdir="${MOUNTDIR}/upperdir" none "${MOUNTDIR}/overlayfs"
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar CORRECT_LINK_TARGET="${MOUNTDIR}/overlayfs/dummy_file"
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar DETECTED_LINK_TARGET=$(readlink -q /proc/$$/fd/9)
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar # This overlay module does not correctly handle symlinks, so skip the
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar if [ "${DETECTED_LINK_TARGET}" != "${CORRECT_LINK_TARGET}" ]; then
7014882c6a3672fd0e5d60200af8643ae53c5928Richard Lowewhich newuidmap >/dev/null 2>&1 || { echo "'newuidmap' command is missing" >&2; exit 1; }
7014882c6a3672fd0e5d60200af8643ae53c5928Richard LoweKNOWN_RELEASES="precise trusty xenial yakkety zesty"
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar run_cmd lxc-stop -n c2 -k || true
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar run_cmd lxc-stop -n c1 -k || true
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar sed -i '/lxcunpriv/d' /run/lxc/nics /etc/lxc/lxc-usernet
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar sed -i '/^lxcunpriv:/d' /etc/subuid /etc/subgid
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar if [ $DONE -eq 0 ]; then
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar env http_proxy=${http_proxy:-} https_proxy=${https_proxy:-} \
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar XDG_RUNTIME_DIR=/run/user/$(id -u $TUSER) $*
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikar# create a test user
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikarecho "$TUSER veth lxcbr0 2" >> /etc/lxc/lxc-usernet
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikarsed -i '/^lxcunpriv:/d' /etc/subuid /etc/subgid
c39526b769298791ff5b0b6c5e761f49aabaeb4ePramod Gunjikarusermod -v 910000-919999 -w 910000-919999 $TUSER
cd $HDIR