Commit d6523915 by Wolfgang Bumiller

tests: lxc-test-apparmor-mount: show a log on error

parent 023d07ee
...@@ -45,6 +45,7 @@ DONE=0 ...@@ -45,6 +45,7 @@ DONE=0
KNOWN_RELEASES="precise trusty xenial yakkety zesty" KNOWN_RELEASES="precise trusty xenial yakkety zesty"
MOUNTSR=/sys/kernel/security/apparmor/features/mount MOUNTSR=/sys/kernel/security/apparmor/features/mount
dnam=`mktemp -d` dnam=`mktemp -d`
logfile=`mktemp`
cname=`basename $dnam` cname=`basename $dnam`
cleanup() { cleanup() {
run_cmd lxc-destroy -f -n $cname || true run_cmd lxc-destroy -f -n $cname || true
...@@ -56,12 +57,21 @@ cleanup() { ...@@ -56,12 +57,21 @@ cleanup() {
rm -Rf $HDIR /run/user/$(id -u $TUSER) rm -Rf $HDIR /run/user/$(id -u $TUSER)
deluser $TUSER deluser $TUSER
if [ $DONE -eq 0 ]; then if [ $DONE -eq 0 ]; then
echo 'Failed container log:' >&2
cat "$logfile" >&2
echo 'End log' >&2
rm -f "$logfile"
echo "FAIL" echo "FAIL"
exit 1 exit 1
fi fi
rm -f "$logfile"
echo "PASS" echo "PASS"
} }
clear_log() {
truncate -s0 "$logfile"
}
trap cleanup exit trap cleanup exit
# Only run on a normally configured ubuntu lxc system # Only run on a normally configured ubuntu lxc system
...@@ -74,6 +84,8 @@ if [ "$(id -u)" != "0" ]; then ...@@ -74,6 +84,8 @@ if [ "$(id -u)" != "0" ]; then
exit 1 exit 1
fi fi
chmod 0666 "$logfile"
# This would be much simpler if we could run it as # This would be much simpler if we could run it as
# root. However, in order to not have the bind mount # root. However, in order to not have the bind mount
# of an empty directory over the securitfs 'mount' directory # of an empty directory over the securitfs 'mount' directory
...@@ -160,7 +172,7 @@ fi ...@@ -160,7 +172,7 @@ fi
run_cmd lxc-create -t download -n $cname -- -d ubuntu -r $release -a $ARCH run_cmd lxc-create -t download -n $cname -- -d ubuntu -r $release -a $ARCH
echo "test default confined container" echo "test default confined container"
run_cmd lxc-start -n $cname -d run_cmd lxc-start -n $cname -d -lDEBUG -o "$logfile"
run_cmd lxc-wait -n $cname -s RUNNING run_cmd lxc-wait -n $cname -s RUNNING
pid=`run_cmd lxc-info -p -H -n $cname` pid=`run_cmd lxc-info -p -H -n $cname`
profile=`cat /proc/$pid/attr/current` profile=`cat /proc/$pid/attr/current`
...@@ -169,10 +181,11 @@ if [ "x$profile" != "x${default_profile}" ]; then ...@@ -169,10 +181,11 @@ if [ "x$profile" != "x${default_profile}" ]; then
exit 1 exit 1
fi fi
run_cmd lxc-stop -n $cname -k run_cmd lxc-stop -n $cname -k
clear_log
echo "test regular unconfined container" echo "test regular unconfined container"
echo "lxc.apparmor.profile = unconfined" >> $HDIR/.local/share/lxc/$cname/config echo "lxc.apparmor.profile = unconfined" >> $HDIR/.local/share/lxc/$cname/config
run_cmd lxc-start -n $cname -d run_cmd lxc-start -n $cname -d -lDEBUG -o "$logfile"
run_cmd lxc-wait -n $cname -s RUNNING run_cmd lxc-wait -n $cname -s RUNNING
pid=`run_cmd lxc-info -p -H -n $cname` pid=`run_cmd lxc-info -p -H -n $cname`
profile=`cat /proc/$pid/attr/current` profile=`cat /proc/$pid/attr/current`
...@@ -181,6 +194,7 @@ if [ "x$profile" != "xunconfined" ]; then ...@@ -181,6 +194,7 @@ if [ "x$profile" != "xunconfined" ]; then
exit 1 exit 1
fi fi
run_cmd lxc-stop -n $cname -k run_cmd lxc-stop -n $cname -k
clear_log
echo "masking $MOUNTSR" echo "masking $MOUNTSR"
mount --bind $dnam $MOUNTSR mount --bind $dnam $MOUNTSR
...@@ -198,7 +212,7 @@ fi ...@@ -198,7 +212,7 @@ fi
echo "test regular unconfined container" echo "test regular unconfined container"
echo "lxc.apparmor.profile = unconfined" >> $HDIR/.local/share/lxc/$cname/config echo "lxc.apparmor.profile = unconfined" >> $HDIR/.local/share/lxc/$cname/config
run_cmd lxc-start -n $cname -d run_cmd lxc-start -n $cname -d -lDEBUG -o "$logfile"
run_cmd lxc-wait -n $cname -s RUNNING run_cmd lxc-wait -n $cname -s RUNNING
pid=`run_cmd lxc-info -p -H -n $cname` pid=`run_cmd lxc-info -p -H -n $cname`
if [ "$pid" = "-1" ]; then if [ "$pid" = "-1" ]; then
...@@ -211,11 +225,12 @@ if [ "x$profile" != "xunconfined" ]; then ...@@ -211,11 +225,12 @@ if [ "x$profile" != "xunconfined" ]; then
exit 1 exit 1
fi fi
run_cmd lxc-stop -n $cname -k run_cmd lxc-stop -n $cname -k
clear_log
echo "testing override" echo "testing override"
sed -i '/apparmor.profile/d' $HDIR/.local/share/lxc/$cname/config sed -i '/apparmor.profile/d' $HDIR/.local/share/lxc/$cname/config
echo "lxc.apparmor.allow_incomplete = 1" >> $HDIR/.local/share/lxc/$cname/config echo "lxc.apparmor.allow_incomplete = 1" >> $HDIR/.local/share/lxc/$cname/config
run_cmd lxc-start -n $cname -d run_cmd lxc-start -n $cname -d -lDEBUG -o "$logfile"
run_cmd lxc-wait -n $cname -s RUNNING run_cmd lxc-wait -n $cname -s RUNNING
pid=`run_cmd lxc-info -p -H -n $cname` pid=`run_cmd lxc-info -p -H -n $cname`
if [ "$pid" = "-1" ]; then if [ "$pid" = "-1" ]; then
...@@ -228,5 +243,6 @@ if [ "x$profile" != "x${default_profile}" ]; then ...@@ -228,5 +243,6 @@ if [ "x$profile" != "x${default_profile}" ]; then
exit 1 exit 1
fi fi
run_cmd lxc-stop -n $cname -k run_cmd lxc-stop -n $cname -k
clear_log
DONE=1 DONE=1
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment