2015-05-11 06:08:28 +02:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
logit "\n"
|
|
|
|
info "6 - Docker Security Operations"
|
|
|
|
|
|
|
|
# 6.5
|
|
|
|
check_6_5="6.5 - Use a centralized and remote log collection service"
|
|
|
|
|
|
|
|
# If containers 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_6_5"
|
|
|
|
info " * No containers running"
|
|
|
|
else
|
|
|
|
fail=0
|
|
|
|
set -f; IFS=$'
|
|
|
|
'
|
2015-05-14 04:22:39 +02:00
|
|
|
for c in $containers; do
|
2015-12-22 19:46:32 +01:00
|
|
|
docker inspect --format '{{ .Volumes }}' "$c" 2>/dev/null 1>&2
|
|
|
|
|
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
volumes=$(docker inspect --format '{{ .Volumes }}' "$c")
|
|
|
|
else
|
|
|
|
volumes=$(docker inspect --format '{{ .Config.Volumes }}' "$c")
|
|
|
|
fi
|
2015-05-14 04:22:39 +02:00
|
|
|
|
2015-05-15 05:26:32 +02:00
|
|
|
if [ "$volumes" = "map[]" ]; then
|
2015-05-11 06:08:28 +02:00
|
|
|
# If it's the first container, fail the test
|
|
|
|
if [ $fail -eq 0 ]; then
|
|
|
|
info "$check_6_5"
|
2015-05-14 04:22:39 +02:00
|
|
|
info " * Container has no volumes, ensure centralized logging is enabled : $c"
|
2015-05-11 06:08:28 +02:00
|
|
|
fail=1
|
|
|
|
else
|
2015-05-14 04:22:39 +02:00
|
|
|
info " * Container has no volumes, ensure centralized logging is enabled : $c"
|
2015-05-11 06:08:28 +02:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
# Only alert if there are no volumes. If there are volumes, can't know if they
|
|
|
|
# are used for logs
|
|
|
|
fi
|
|
|
|
# Make the loop separator go back to space
|
|
|
|
set +f; unset IFS
|
|
|
|
|
|
|
|
# 6.6
|
|
|
|
check_6_6="6.6 - Avoid image sprawl"
|
2015-08-10 16:27:32 +02:00
|
|
|
images=$(docker images -q | sort -u | wc -l | awk '{print $1}')
|
2015-06-01 22:37:28 +02:00
|
|
|
active_images=0
|
|
|
|
|
|
|
|
for c in $(docker inspect -f "{{.Image}}" $(docker ps -qa)); do
|
2015-06-21 23:03:34 +02:00
|
|
|
if docker images --no-trunc -a | grep "$c" > /dev/null ; then
|
2015-06-09 04:15:41 +02:00
|
|
|
active_images=$(( active_images += 1 ))
|
2015-06-01 22:37:28 +02:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2015-05-29 13:42:34 +02:00
|
|
|
if [ "$images" -gt 100 ]; then
|
2015-05-11 06:08:28 +02:00
|
|
|
warn "$check_6_6"
|
|
|
|
warn " * There are currently: $images images"
|
|
|
|
else
|
|
|
|
info "$check_6_6"
|
|
|
|
info " * There are currently: $images images"
|
|
|
|
fi
|
|
|
|
|
2015-06-09 04:15:41 +02:00
|
|
|
if [ "$active_images" -lt "$((images / 2))" ]; then
|
2015-06-01 22:37:28 +02:00
|
|
|
warn " * Only $active_images out of $images are in use"
|
|
|
|
fi
|
|
|
|
|
2015-05-11 06:08:28 +02:00
|
|
|
# 6.7
|
|
|
|
check_6_7="6.7 - Avoid container sprawl"
|
2015-05-29 13:42:34 +02:00
|
|
|
total_containers=$(docker info 2>/dev/null | grep "Containers" | awk '{print $2}')
|
|
|
|
running_containers=$(docker ps -q | wc -l | awk '{print $1}')
|
2015-06-21 23:03:34 +02:00
|
|
|
diff="$((total_containers - running_containers))"
|
2015-05-29 13:42:34 +02:00
|
|
|
if [ "$diff" -gt 25 ]; then
|
2015-05-11 06:08:28 +02:00
|
|
|
warn "$check_6_7"
|
|
|
|
warn " * There are currently a total of $total_containers containers, with only $running_containers of them currently running"
|
|
|
|
else
|
|
|
|
info "$check_6_7"
|
|
|
|
info " * There are currently a total of $total_containers containers, with $running_containers of them currently running"
|
|
|
|
fi
|