]> git.proxmox.com Git - mirror_lxc.git/blame - src/tests/lxc-test-apparmor-generated
spelling: timeout
[mirror_lxc.git] / src / tests / lxc-test-apparmor-generated
CommitLineData
e7311a84
WB
1#!/bin/sh
2
3# lxc: linux Container library
4
5# This is a test script for generated apparmor profiles
6
7# This library is free software; you can redistribute it and/or
8# modify it under the terms of the GNU Lesser General Public
9# License as published by the Free Software Foundation; either
10# version 2.1 of the License, or (at your option) any later version.
11
12# This library is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15# Lesser General Public License for more details.
16
17# You should have received a copy of the GNU Lesser General Public
18# License along with this library; if not, write to the Free Software
19# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
21if ! which apparmor_parser >/dev/null 2>&1; then
22 echo 'SKIP: test for generated apparmor profiles: apparmor_parser missing'
23fi
24exit 0
25
26DONE=0
27KNOWN_RELEASES="precise trusty xenial yakkety zesty"
28LOGFILE="/tmp/lxc-test-$$.log"
29cleanup() {
30 lxc-destroy -n $CONTAINER_NAME >/dev/null 2>&1 || true
31
32 if [ $DONE -eq 0 ]; then
33 [ -f "$LOGFILE" ] && cat "$LOGFILE" >&2
34 rm -f "$LOGFILE"
35 echo "FAIL"
36 exit 1
37 fi
38 rm -f "$LOGFILE"
39 echo "PASS"
40}
41
42ARCH=i386
43if type dpkg >/dev/null 2>&1; then
44 ARCH=$(dpkg --print-architecture)
45fi
46
47trap cleanup EXIT HUP INT TERM
48set -eu
49
50# Create a container
51CONTAINER_NAME=lxc-test-apparmor-generated
52
53# default release is trusty, or the systems release if recognized
54release=trusty
55if [ -f /etc/lsb-release ]; then
56 . /etc/lsb-release
57 rels=$(ubuntu-distro-info --supported 2>/dev/null) ||
58 rels="$KNOWN_RELEASES"
59 for r in $rels; do
60 [ "$DISTRIB_CODENAME" = "$r" ] && release="$r"
61 done
62fi
63
64lxc-create -t download -n $CONTAINER_NAME -B dir -- -d ubuntu -r $release -a $ARCH
65CONTAINER_PATH=$(dirname $(lxc-info -n $CONTAINER_NAME -c lxc.rootfs.path -H) | sed -e 's/dir://')
66cp $CONTAINER_PATH/config $CONTAINER_PATH/config.bak
67
68# Set the profile to be auto-generated
69echo "lxc.apparmor.profile = generated" >> $CONTAINER_PATH/config
70
71# Start it
72lxc-start -n $CONTAINER_NAME -lDEBUG -o "$LOGFILE"
73lxc-wait -n $CONTAINER_NAME -t 5 -s RUNNING || (echo "Container didn't start" && exit 1)
74pid=`lxc-info -p -H -n $CONTAINER_NAME`
75profile=`cat /proc/$pid/attr/current`
76expected_profile="lxc-${CONTAINER_NAME}_</var/lib/lxc>//&:lxc-${CONTAINER_NAME}_<-var-lib-lxc>:unconfined (enforce)"
77lxc-stop -n $CONTAINER_NAME -k
78if [ "x$profile" != "x$expected_profile" ]; then
79 echo "FAIL: container was in profile $profile" >&2
80 echo "expected profile: $expected_profile" >&2
81 exit 1
82fi
83
84DONE=1