2015-05-11 06:08:28 +02:00
|
|
|
#!/bin/sh
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# CIS Docker 1.6 Benchmark v1.0.0 checker
|
|
|
|
#
|
|
|
|
# Docker, Inc. (c) 2015
|
|
|
|
#
|
|
|
|
# Provides automated tests for the CIS Docker 1.6 Benchmark:
|
|
|
|
# https://benchmarks.cisecurity.org/tools2/docker/CIS_Docker_1.6_Benchmark_v1.0.0.pdf
|
|
|
|
#
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
# Load dependencies
|
|
|
|
. ./output_lib.sh
|
|
|
|
. ./helper_lib.sh
|
|
|
|
|
|
|
|
# Setup the paths
|
|
|
|
this_path=$(abspath $0) ## Path of this file including filenamel
|
|
|
|
dir_name=`dirname ${this_path}` ## Dir where this file is
|
|
|
|
myname=`basename ${this_path}` ## file name of this script.
|
|
|
|
logger="${myname}.log"
|
|
|
|
|
2015-05-31 01:40:23 +02:00
|
|
|
export PATH=/bin:/sbin:/usr/bin:/usr/local/bin:/usr/sbin/
|
2015-05-11 06:08:28 +02:00
|
|
|
|
|
|
|
# Check for required program(s)
|
|
|
|
req_progs='docker netstat grep awk'
|
|
|
|
for p in $req_progs; do
|
|
|
|
command -v $p >/dev/null 2>&1 || { printf "$p command not found.\n"; exit 1; }
|
|
|
|
done
|
|
|
|
|
|
|
|
# Ensure we can connect to docker daemon
|
|
|
|
`docker ps -q >/dev/null 2>&1`
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
printf "Error connecting to docker daemon (does docker ps work?)\n"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
usage () {
|
|
|
|
printf "
|
|
|
|
usage: $myname [options]
|
|
|
|
|
|
|
|
-h optional Print this help message\n"
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
yell "# ------------------------------------------------------------------------------
|
|
|
|
# CIS Docker 1.6 Benchmark v1.0.0 checker
|
|
|
|
#
|
|
|
|
# Docker, Inc. (c) 2015
|
|
|
|
#
|
|
|
|
# Provides automated tests for the CIS Docker 1.6 Benchmark:
|
|
|
|
# https://benchmarks.cisecurity.org/tools2/docker/CIS_Docker_1.6_Benchmark_v1.0.0.pdf
|
|
|
|
# ------------------------------------------------------------------------------"
|
|
|
|
|
|
|
|
logit "Initializing `date`\n"
|
|
|
|
|
|
|
|
# Warn if not root
|
|
|
|
ID=`id -u`
|
2015-05-15 05:26:32 +02:00
|
|
|
if [ "x$ID" != "x0" ]; then
|
2015-05-11 06:08:28 +02:00
|
|
|
warn "Some tests might require root to run"
|
|
|
|
sleep 3
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Get the flags
|
|
|
|
while getopts :hlfi: args
|
|
|
|
do
|
|
|
|
case $args in
|
|
|
|
h) usage ;;
|
|
|
|
l) logger="$OPTARG" ;;
|
|
|
|
*) usage ;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
# Load all the tests from tests/ and run them
|
|
|
|
main () {
|
2015-05-14 02:08:12 +02:00
|
|
|
# List all running containers
|
|
|
|
containers=`docker ps -q`
|
2015-05-26 05:18:22 +02:00
|
|
|
# If there is a container with label docker-bench, memorize it:
|
2015-05-14 02:08:12 +02:00
|
|
|
benchcont="nil"
|
|
|
|
for c in $containers; do
|
|
|
|
labels=`docker inspect --format '{{ .Config.Labels }}' $c`
|
2015-05-26 05:18:22 +02:00
|
|
|
contains "$labels" "docker-bench" && benchcont="$c"
|
2015-05-14 02:08:12 +02:00
|
|
|
done
|
2015-05-26 05:18:22 +02:00
|
|
|
# List all running containers except docker-bench
|
2015-05-14 02:08:12 +02:00
|
|
|
containers=`docker ps -q | grep -v $benchcont`
|
2015-05-14 04:22:39 +02:00
|
|
|
|
2015-05-11 06:08:28 +02:00
|
|
|
for test in tests/*.sh
|
|
|
|
do
|
|
|
|
. ./$test
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
main "$@"
|