Merge branch 'master' of github.com:konstruktoid/docker-bench-security into issue_25

* 'master' of github.com:konstruktoid/docker-bench-security:
  Fix test 5.14 to not always pass when multiple ports are published.
  change to docker repository
  make readme codeblocks prettier
  Add first version of CONTRIBUTING.md
  Issue , remove -U, -u
  use official alpine image as the base
  Make the main script an executable for if I want to run it on my host

Signed-off-by: Thomas Sjögren <konstruktoid@users.noreply.github.com>

Conflicts:
	README.md
This commit is contained in:
Thomas Sjögren 2015-06-15 22:01:36 +02:00
commit eca8471c71
7 changed files with 87 additions and 35 deletions

View file

@ -5,7 +5,7 @@ info "2 - Docker Daemon Configuration"
# 2.1
check_2_1="2.1 - Do not use lxc execution driver"
pgrep -U root -u root -lf docker | grep lxc >/dev/null 2>&1
pgrep -lf docker | grep lxc >/dev/null 2>&1
if [ $? -eq 0 ]; then
warn "$check_2_1"
else
@ -14,7 +14,7 @@ fi
# 2.2
check_2_2="2.2 - Restrict network traffic between containers"
pgrep -U root -u root -lf docker | grep "icc=false" >/dev/null 2>&1
pgrep -lf docker | grep "icc=false" >/dev/null 2>&1
if [ $? -eq 0 ]; then
pass "$check_2_2"
else
@ -23,7 +23,7 @@ fi
# 2.3
check_2_3="2.3 - Set the logging level"
pgrep -U root -u root -lf docker | grep "log-level=\"debug\"" >/dev/null 2>&1
pgrep -lf docker | grep "log-level=\"debug\"" >/dev/null 2>&1
if [ $? -eq 0 ]; then
warn "$check_2_3"
else
@ -32,7 +32,7 @@ fi
# 2.4
check_2_4="2.4 - Allow Docker to make changes to iptables"
pgrep -U root -u root -lf docker | grep "iptables=false" >/dev/null 2>&1
pgrep -lf docker | grep "iptables=false" >/dev/null 2>&1
if [ $? -eq 0 ]; then
warn "$check_2_4"
else
@ -41,7 +41,7 @@ fi
# 2.5
check_2_5="2.5 - Do not use insecure registries"
pgrep -U root -u root -lf docker | grep "insecure-registry" >/dev/null 2>&1
pgrep -lf docker | grep "insecure-registry" >/dev/null 2>&1
if [ $? -eq 0 ]; then
warn "$check_2_5"
else
@ -50,7 +50,7 @@ fi
# 2.6
check_2_6="2.6 - Setup a local registry mirror"
pgrep -U root -u root -lf docker | grep "registry-mirror" >/dev/null 2>&1
pgrep -lf docker | grep "registry-mirror" >/dev/null 2>&1
if [ $? -eq 0 ]; then
pass "$check_2_6"
else
@ -69,7 +69,7 @@ fi
# 2.8
check_2_8="2.8 - Do not bind Docker to another IP/Port or a Unix socket"
pgrep -U root -u root -lf docker | grep "\-H" >/dev/null 2>&1
pgrep -lf docker | grep "\-H" >/dev/null 2>&1
if [ $? -eq 0 ]; then
info "$check_2_8"
info " * Docker daemon running with -H"
@ -79,9 +79,9 @@ fi
# 2.9
check_2_9="2.9 - Configure TLS authentication for Docker daemon"
pgrep -U root -u root -lf docker | grep "tcp://" >/dev/null 2>&1
pgrep -lf docker | grep "tcp://" >/dev/null 2>&1
if [ $? -eq 0 ]; then
pgrep -U root -u root -lf docker | grep "tlsverify" | grep "tlskey" >/dev/null 2>&1
pgrep -lf docker | grep "tlsverify" | grep "tlskey" >/dev/null 2>&1
if [ $? -eq 0 ]; then
pass "$check_2_9"
info " * Docker daemon currently listening on TCP"
@ -96,7 +96,7 @@ fi
# 2.10
check_2_10="2.10 - Set default ulimit as appropriate"
pgrep -U root -u root -lf docker | grep "default-ulimit" >/dev/null 2>&1
pgrep -lf docker | grep "default-ulimit" >/dev/null 2>&1
if [ $? -eq 0 ]; then
pass "$check_2_10"
else

View file

@ -201,18 +201,21 @@ else
fail=0
for c in $containers; do
port=$(docker port "$c" | awk '{print $1}' | cut -d '/' -f1)
ports=$(docker port "$c" | awk '{print $1}' | cut -d '/' -f1)
if [ ! -z "$port" ] && [ "$port" -lt 1025 ]; then
# If it's the first container, fail the test
if [ $fail -eq 0 ]; then
warn "$check_5_8"
warn " * Privileged Port in use: $port in $c"
fail=1
else
warn " * Privileged Port in use: $port in $c"
# iterate through port range (line delimited)
for port in $ports; do
if [ ! -z "$port" ] && [ "0$port" -lt 1025 ]; then
# If it's the first container, fail the test
if [ $fail -eq 0 ]; then
warn "$check_5_8"
warn " * Privileged Port in use: $port in $c"
fail=1
else
warn " * Privileged Port in use: $port in $c"
fi
fi
fi
done
done
# We went through all the containers and found no privileged ports
if [ $fail -eq 0 ]; then
@ -316,17 +319,18 @@ else
fail=0
for c in $containers; do
ip=$(docker port "$c" | awk '{print $3}' | cut -d ':' -f1)
if [ "$ip" = "0.0.0.0" ]; then
# If it's the first container, fail the test
if [ $fail -eq 0 ]; then
warn "$check_5_14"
warn " * Port being bound to wildcard IP: $ip in $c"
fail=1
else
warn " * Port being bound to wildcard IP: $ip in $c"
for ip in $(docker port "$c" | awk '{print $3}' | cut -d ':' -f1); do
if [ "$ip" = "0.0.0.0" ]; then
# If it's the first container, fail the test
if [ $fail -eq 0 ]; then
warn "$check_5_14"
warn " * Port being bound to wildcard IP: $ip in $c"
fail=1
else
warn " * Port being bound to wildcard IP: $ip in $c"
fi
fi
fi
done
done
# We went through all the containers and found no ports bound to 0.0.0.0
if [ $fail -eq 0 ]; then

View file

@ -40,8 +40,8 @@ images=$(docker images -q | wc -l | awk '{print $1}')
active_images=0
for c in $(docker inspect -f "{{.Image}}" $(docker ps -qa)); do
if [[ $(docker images --no-trunc -a | grep $c) ]]; then
((active_images++))
if docker images --no-trunc -a | grep $c > /dev/null ; then
active_images=$(( active_images += 1 ))
fi
done
@ -53,7 +53,7 @@ else
info " * There are currently: $images images"
fi
if [[ "$active_images" -lt "$((images / 2))" ]]; then
if [ "$active_images" -lt "$((images / 2))" ]; then
warn " * Only $active_images out of $images are in use"
fi