2015-05-11 06:08:28 +02:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
logit "\n"
|
|
|
|
info "4 - Container Images and Build Files"
|
|
|
|
|
|
|
|
# 4.1
|
|
|
|
check_4_1="4.1 - Create a user for the container"
|
|
|
|
|
|
|
|
# If container_users is empty, there are no running containers
|
2015-05-15 05:26:32 +02:00
|
|
|
if [ -z "$containers" ]; then
|
2015-05-11 06:08:28 +02:00
|
|
|
info "$check_4_1"
|
|
|
|
info " * No containers running"
|
|
|
|
else
|
|
|
|
# We have some containers running, set failure flag to 0. Check for Users.
|
|
|
|
fail=0
|
|
|
|
# Make the loop separator be a new-line in POSIX compliant fashion
|
|
|
|
set -f; IFS=$'
|
|
|
|
'
|
2015-05-14 04:22:39 +02:00
|
|
|
for c in $containers; do
|
|
|
|
user=`docker inspect --format 'User={{.Config.User}}' $c`
|
2015-05-11 06:08:28 +02:00
|
|
|
|
2015-05-15 05:26:32 +02:00
|
|
|
if [ "$user" = "User=" -o "$user" = "User=[]" -o "$user" = "User=<no value>" ]; then
|
2015-05-11 06:08:28 +02:00
|
|
|
# If it's the first container, fail the test
|
|
|
|
if [ $fail -eq 0 ]; then
|
|
|
|
warn "$check_4_1"
|
2015-05-14 04:22:39 +02:00
|
|
|
warn " * Running as root: $c"
|
2015-05-11 06:08:28 +02:00
|
|
|
fail=1
|
|
|
|
else
|
2015-05-14 04:22:39 +02:00
|
|
|
warn " * Running as root: $c"
|
2015-05-11 06:08:28 +02:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
# We went through all the containers and found none running as root
|
|
|
|
if [ $fail -eq 0 ]; then
|
|
|
|
pass "$check_4_1"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
# Make the loop separator go back to space
|
|
|
|
set +f; unset IFS
|