2015-05-11 06:08:28 +02:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
logit "\n"
|
2017-01-23 17:06:10 +01:00
|
|
|
info "5 - Container Runtime"
|
2015-05-11 06:08:28 +02:00
|
|
|
|
|
|
|
# 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 " * No containers running, skipping Section 5"
|
|
|
|
else
|
|
|
|
# Make the loop separator be a new-line in POSIX compliant fashion
|
|
|
|
set -f; IFS=$'
|
|
|
|
'
|
|
|
|
# 5.1
|
2017-07-07 11:16:49 +02:00
|
|
|
check_5_1="5.1 - Ensure AppArmor Profile is Enabled"
|
2015-05-11 06:08:28 +02:00
|
|
|
|
|
|
|
fail=0
|
2015-05-14 04:22:39 +02:00
|
|
|
for c in $containers; do
|
2015-05-29 13:42:34 +02:00
|
|
|
policy=$(docker inspect --format 'AppArmorProfile={{ .AppArmorProfile }}' "$c")
|
2015-05-11 06:08:28 +02:00
|
|
|
|
2015-05-15 05:26:32 +02:00
|
|
|
if [ "$policy" = "AppArmorProfile=" -o "$policy" = "AppArmorProfile=[]" -o "$policy" = "AppArmorProfile=<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_5_1"
|
2015-05-14 04:22:39 +02:00
|
|
|
warn " * No AppArmorProfile Found: $c"
|
2017-10-13 10:25:23 +02:00
|
|
|
logjson "5.1" "WARN: $c"
|
2015-05-11 06:08:28 +02:00
|
|
|
fail=1
|
|
|
|
else
|
2015-05-14 04:22:39 +02:00
|
|
|
warn " * No AppArmorProfile Found: $c"
|
2017-10-13 10:25:23 +02:00
|
|
|
logjson "5.1" "WARN: $c"
|
2015-05-11 06:08:28 +02:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
# We went through all the containers and found none without AppArmor
|
|
|
|
if [ $fail -eq 0 ]; then
|
|
|
|
pass "$check_5_1"
|
2017-10-13 10:25:23 +02:00
|
|
|
logjson "5.1" "PASS"
|
2015-05-11 06:08:28 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
# 5.2
|
2017-07-07 11:16:49 +02:00
|
|
|
check_5_2="5.2 - Ensure SELinux security options are set, if applicable"
|
2015-05-11 06:08:28 +02:00
|
|
|
|
|
|
|
fail=0
|
2015-05-14 04:22:39 +02:00
|
|
|
for c in $containers; do
|
2015-05-29 13:42:34 +02:00
|
|
|
policy=$(docker inspect --format 'SecurityOpt={{ .HostConfig.SecurityOpt }}' "$c")
|
2015-05-11 06:08:28 +02:00
|
|
|
|
2015-05-15 05:26:32 +02:00
|
|
|
if [ "$policy" = "SecurityOpt=" -o "$policy" = "SecurityOpt=[]" -o "$policy" = "SecurityOpt=<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_5_2"
|
2015-05-14 04:22:39 +02:00
|
|
|
warn " * No SecurityOptions Found: $c"
|
2017-10-13 10:25:23 +02:00
|
|
|
logjson "5.2" "WARN: $c"
|
2015-05-11 06:08:28 +02:00
|
|
|
fail=1
|
|
|
|
else
|
2015-05-14 04:22:39 +02:00
|
|
|
warn " * No SecurityOptions Found: $c"
|
2017-10-13 10:25:23 +02:00
|
|
|
logjson "5.2" "WARN: $c"
|
2015-05-11 06:08:28 +02:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
# We went through all the containers and found none without SELinux
|
|
|
|
if [ $fail -eq 0 ]; then
|
|
|
|
pass "$check_5_2"
|
2017-10-13 10:25:23 +02:00
|
|
|
logjson "5.2" "PASS"
|
2015-05-11 06:08:28 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
# 5.3
|
2017-07-07 11:16:49 +02:00
|
|
|
check_5_3="5.3 - Ensure Linux Kernel Capabilities are restricted within containers"
|
2015-05-11 06:08:28 +02:00
|
|
|
|
|
|
|
fail=0
|
2015-05-14 04:22:39 +02:00
|
|
|
for c in $containers; do
|
2017-01-25 12:07:14 +01:00
|
|
|
container_caps=$(docker inspect --format 'CapAdd={{ .HostConfig.CapAdd}}' "$c")
|
|
|
|
caps=$(echo "$container_caps" | tr "[:lower:]" "[:upper:]" | \
|
|
|
|
sed 's/CAPADD/CapAdd/' | \
|
|
|
|
sed -r "s/AUDIT_WRITE|CHOWN|DAC_OVERRIDE|FOWNER|FSETID|KILL|MKNOD|NET_BIND_SERVICE|NET_RAW|SETFCAP|SETGID|SETPCAP|SETUID|SYS_CHROOT|\s//g")
|
2015-05-11 06:08:28 +02:00
|
|
|
|
2015-08-13 21:46:21 +02:00
|
|
|
if [ "$caps" != 'CapAdd=' -a "$caps" != 'CapAdd=[]' -a "$caps" != 'CapAdd=<no value>' -a "$caps" != 'CapAdd=<nil>' ]; then
|
2015-05-11 06:08:28 +02:00
|
|
|
# If it's the first container, fail the test
|
|
|
|
if [ $fail -eq 0 ]; then
|
2016-04-15 00:12:00 +02:00
|
|
|
warn "$check_5_3"
|
2015-05-14 04:22:39 +02:00
|
|
|
warn " * Capabilities added: $caps to $c"
|
2017-10-13 10:25:23 +02:00
|
|
|
logjson "5.3" "WARN: $c"
|
2015-05-11 06:08:28 +02:00
|
|
|
fail=1
|
|
|
|
else
|
2015-05-14 04:22:39 +02:00
|
|
|
warn " * Capabilities added: $caps to $c"
|
2017-10-13 10:25:23 +02:00
|
|
|
logjson "5.3" "WARN: $c"
|
2015-05-11 06:08:28 +02:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
# We went through all the containers and found none with extra capabilities
|
|
|
|
if [ $fail -eq 0 ]; then
|
2016-04-15 00:12:00 +02:00
|
|
|
pass "$check_5_3"
|
2017-10-13 10:25:23 +02:00
|
|
|
logjson "5.3" "PASS"
|
2015-05-11 06:08:28 +02:00
|
|
|
fi
|
|
|
|
|
2016-04-15 00:12:00 +02:00
|
|
|
# 5.4
|
2017-07-07 11:16:49 +02:00
|
|
|
check_5_4="5.4 - Ensure privileged containers are not used"
|
2015-05-11 06:08:28 +02:00
|
|
|
|
|
|
|
fail=0
|
2015-05-14 04:22:39 +02:00
|
|
|
for c in $containers; do
|
2015-05-29 13:42:34 +02:00
|
|
|
privileged=$(docker inspect --format '{{ .HostConfig.Privileged }}' "$c")
|
2015-05-11 06:08:28 +02:00
|
|
|
|
2015-05-15 05:26:32 +02:00
|
|
|
if [ "$privileged" = "true" ]; then
|
2015-05-11 06:08:28 +02:00
|
|
|
# If it's the first container, fail the test
|
|
|
|
if [ $fail -eq 0 ]; then
|
2016-04-15 00:12:00 +02:00
|
|
|
warn "$check_5_4"
|
2015-05-14 04:22:39 +02:00
|
|
|
warn " * Container running in Privileged mode: $c"
|
2017-10-13 10:25:23 +02:00
|
|
|
logjson "5.4" "WARN: $c"
|
2015-05-11 06:08:28 +02:00
|
|
|
fail=1
|
|
|
|
else
|
2015-05-14 04:22:39 +02:00
|
|
|
warn " * Container running in Privileged mode: $c"
|
2017-10-13 10:25:23 +02:00
|
|
|
logjson "5.4" "WARN: $c"
|
2015-05-11 06:08:28 +02:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
# We went through all the containers and found no privileged containers
|
|
|
|
if [ $fail -eq 0 ]; then
|
2016-04-15 00:12:00 +02:00
|
|
|
pass "$check_5_4"
|
2017-10-13 10:25:23 +02:00
|
|
|
logjson "5.4" "PASS"
|
2015-05-11 06:08:28 +02:00
|
|
|
fi
|
|
|
|
|
2016-04-15 00:12:00 +02:00
|
|
|
# 5.5
|
2017-07-07 11:16:49 +02:00
|
|
|
check_5_5="5.5 - Ensure sensitive host system directories are not mounted on containers"
|
2015-05-11 06:08:28 +02:00
|
|
|
|
2015-05-14 04:22:39 +02:00
|
|
|
# List of sensitive directories to test for. Script uses new-lines as a separator.
|
|
|
|
# Note the lack of identation. It needs it for the substring comparison.
|
2017-02-13 11:36:16 +01:00
|
|
|
sensitive_dirs='/
|
|
|
|
/boot
|
2015-05-14 04:22:39 +02:00
|
|
|
/dev
|
|
|
|
/etc
|
|
|
|
/lib
|
|
|
|
/proc
|
|
|
|
/sys
|
|
|
|
/usr'
|
2015-05-11 06:08:28 +02:00
|
|
|
fail=0
|
2015-05-14 04:22:39 +02:00
|
|
|
for c in $containers; do
|
2017-01-24 15:26:19 +01:00
|
|
|
if docker inspect --format '{{ .VolumesRW }}' "$c" 2>/dev/null 1>&2; then
|
2015-12-22 19:46:32 +01:00
|
|
|
volumes=$(docker inspect --format '{{ .VolumesRW }}' "$c")
|
|
|
|
else
|
|
|
|
volumes=$(docker inspect --format '{{ .Mounts }}' "$c")
|
|
|
|
fi
|
2015-05-11 06:08:28 +02:00
|
|
|
# Go over each directory in sensitive dir and see if they exist in the volumes
|
|
|
|
for v in $sensitive_dirs; do
|
2015-05-14 04:22:39 +02:00
|
|
|
sensitive=0
|
2017-02-10 15:35:06 +01:00
|
|
|
if echo "$volumes" | grep -e "{.*\s$v\s.*true\s}" 2>/tmp/null 1>&2; then
|
|
|
|
sensitive=1
|
|
|
|
fi
|
2015-05-14 04:22:39 +02:00
|
|
|
if [ $sensitive -eq 1 ]; then
|
|
|
|
# If it's the first container, fail the test
|
|
|
|
if [ $fail -eq 0 ]; then
|
2016-04-15 00:12:00 +02:00
|
|
|
warn "$check_5_5"
|
2015-05-14 04:22:39 +02:00
|
|
|
warn " * Sensitive directory $v mounted in: $c"
|
2017-10-13 10:25:23 +02:00
|
|
|
logjson "5.5" "WARN: $v in $c"
|
2015-05-14 04:22:39 +02:00
|
|
|
fail=1
|
|
|
|
else
|
|
|
|
warn " * Sensitive directory $v mounted in: $c"
|
2017-10-13 10:25:23 +02:00
|
|
|
logjson "5.5" "WARN: $v in $c"
|
2015-05-14 04:22:39 +02:00
|
|
|
fi
|
2015-05-11 06:08:28 +02:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
done
|
|
|
|
# We went through all the containers and found none with sensitive mounts
|
|
|
|
if [ $fail -eq 0 ]; then
|
2016-04-15 00:12:00 +02:00
|
|
|
pass "$check_5_5"
|
2017-10-13 10:25:23 +02:00
|
|
|
logjson "5.5" "PASS"
|
2015-05-11 06:08:28 +02:00
|
|
|
fi
|
|
|
|
|
2016-04-15 00:12:00 +02:00
|
|
|
# 5.6
|
2017-07-07 11:16:49 +02:00
|
|
|
check_5_6="5.6 - Ensure ssh is not run within containers"
|
2015-05-11 06:08:28 +02:00
|
|
|
|
|
|
|
fail=0
|
2015-08-13 22:06:03 +02:00
|
|
|
printcheck=0
|
2015-05-14 04:22:39 +02:00
|
|
|
for c in $containers; do
|
|
|
|
|
2015-05-29 13:42:34 +02:00
|
|
|
processes=$(docker exec "$c" ps -el 2>/dev/null | grep -c sshd | awk '{print $1}')
|
2015-06-21 23:11:23 +02:00
|
|
|
if [ "$processes" -ge 1 ]; then
|
2015-05-11 06:08:28 +02:00
|
|
|
# If it's the first container, fail the test
|
|
|
|
if [ $fail -eq 0 ]; then
|
2016-04-15 00:12:00 +02:00
|
|
|
warn "$check_5_6"
|
2015-05-14 04:22:39 +02:00
|
|
|
warn " * Container running sshd: $c"
|
2017-10-13 10:25:23 +02:00
|
|
|
logjson "5.6" "WARN: $c"
|
2015-05-11 06:08:28 +02:00
|
|
|
fail=1
|
2015-08-13 22:06:03 +02:00
|
|
|
printcheck=1
|
2015-05-11 06:08:28 +02:00
|
|
|
else
|
2015-05-14 04:22:39 +02:00
|
|
|
warn " * Container running sshd: $c"
|
2017-10-13 10:25:23 +02:00
|
|
|
logjson "5.6" "WARN: $c"
|
2015-05-11 06:08:28 +02:00
|
|
|
fi
|
|
|
|
fi
|
2015-08-13 22:06:03 +02:00
|
|
|
|
|
|
|
exec_check=$(docker exec "$c" ps -el 2>/dev/null)
|
|
|
|
if [ $? -eq 255 ]; then
|
|
|
|
if [ $printcheck -eq 0 ]; then
|
2016-04-15 00:12:00 +02:00
|
|
|
warn "$check_5_6"
|
2017-10-13 10:25:23 +02:00
|
|
|
logjson "5.6" "WARN"
|
2015-08-13 22:06:03 +02:00
|
|
|
printcheck=1
|
|
|
|
fi
|
|
|
|
warn " * Docker exec fails: $c"
|
2017-10-13 10:25:23 +02:00
|
|
|
logjson "5.6" "WARN: $c"
|
2015-08-13 22:06:03 +02:00
|
|
|
fail=1
|
|
|
|
fi
|
|
|
|
|
2015-05-11 06:08:28 +02:00
|
|
|
done
|
|
|
|
# We went through all the containers and found none with sshd
|
|
|
|
if [ $fail -eq 0 ]; then
|
2016-04-15 00:12:00 +02:00
|
|
|
pass "$check_5_6"
|
2015-05-11 06:08:28 +02:00
|
|
|
fi
|
|
|
|
|
2016-04-15 00:12:00 +02:00
|
|
|
# 5.7
|
2017-07-07 11:16:49 +02:00
|
|
|
check_5_7="5.7 - Ensure privileged ports are not mapped within containers"
|
2015-05-11 06:08:28 +02:00
|
|
|
|
|
|
|
fail=0
|
|
|
|
for c in $containers; do
|
2015-06-18 12:21:57 +02:00
|
|
|
# Port format is private port -> ip: public port
|
|
|
|
ports=$(docker port "$c" | awk '{print $0}' | cut -d ':' -f2)
|
2015-05-14 04:22:39 +02:00
|
|
|
|
2015-06-09 04:15:41 +02:00
|
|
|
# iterate through port range (line delimited)
|
|
|
|
for port in $ports; do
|
2017-07-07 11:16:49 +02:00
|
|
|
if [ ! -z "$port" ] && [ "$port" -lt 1024 ]; then
|
2015-06-09 04:15:41 +02:00
|
|
|
# If it's the first container, fail the test
|
|
|
|
if [ $fail -eq 0 ]; then
|
2016-04-15 00:12:00 +02:00
|
|
|
warn "$check_5_7"
|
2015-06-09 04:15:41 +02:00
|
|
|
warn " * Privileged Port in use: $port in $c"
|
2017-10-13 10:25:23 +02:00
|
|
|
logjson "5.7" "WARN: $port in $c"
|
2015-06-09 04:15:41 +02:00
|
|
|
fail=1
|
|
|
|
else
|
|
|
|
warn " * Privileged Port in use: $port in $c"
|
2017-10-13 10:25:23 +02:00
|
|
|
logjson "5.7" "WARN: $port in $c"
|
2015-06-09 04:15:41 +02:00
|
|
|
fi
|
2015-05-11 06:08:28 +02:00
|
|
|
fi
|
2015-06-09 04:15:41 +02:00
|
|
|
done
|
2015-05-11 06:08:28 +02:00
|
|
|
done
|
|
|
|
# We went through all the containers and found no privileged ports
|
|
|
|
if [ $fail -eq 0 ]; then
|
2016-04-15 00:12:00 +02:00
|
|
|
pass "$check_5_7"
|
2017-10-13 10:25:23 +02:00
|
|
|
logjson "5.7" "PASS"
|
2015-05-11 06:08:28 +02:00
|
|
|
fi
|
|
|
|
|
2017-01-23 17:06:10 +01:00
|
|
|
# 5.8
|
2017-07-07 11:16:49 +02:00
|
|
|
check_5_8="5.8 - Ensure only needed ports are open on the container"
|
2017-03-23 11:29:58 +01:00
|
|
|
note "$check_5_8"
|
2017-10-13 10:25:23 +02:00
|
|
|
logjson "5.8" "NOTE"
|
2017-01-23 17:06:10 +01:00
|
|
|
|
2016-04-15 00:12:00 +02:00
|
|
|
# 5.9
|
2017-07-07 11:16:49 +02:00
|
|
|
check_5_9="5.9 - Ensure the host's network namespace is not shared"
|
2015-05-11 06:08:28 +02:00
|
|
|
|
|
|
|
fail=0
|
2015-05-14 04:22:39 +02:00
|
|
|
for c in $containers; do
|
2015-05-29 13:42:34 +02:00
|
|
|
mode=$(docker inspect --format 'NetworkMode={{ .HostConfig.NetworkMode }}' "$c")
|
2015-05-14 04:22:39 +02:00
|
|
|
|
2015-05-15 05:26:32 +02:00
|
|
|
if [ "$mode" = "NetworkMode=host" ]; then
|
2015-05-11 06:08:28 +02:00
|
|
|
# If it's the first container, fail the test
|
|
|
|
if [ $fail -eq 0 ]; then
|
2016-04-15 00:12:00 +02:00
|
|
|
warn "$check_5_9"
|
2015-05-14 04:22:39 +02:00
|
|
|
warn " * Container running with networking mode 'host': $c"
|
2017-10-13 10:25:23 +02:00
|
|
|
logjson "5.9" "WARN: $c"
|
2015-05-11 06:08:28 +02:00
|
|
|
fail=1
|
|
|
|
else
|
2015-05-14 04:22:39 +02:00
|
|
|
warn " * Container running with networking mode 'host': $c"
|
2017-10-13 10:25:23 +02:00
|
|
|
logjson "5.9" "WARN: $c"
|
2015-05-11 06:08:28 +02:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
# We went through all the containers and found no Network Mode host
|
|
|
|
if [ $fail -eq 0 ]; then
|
2016-04-15 00:12:00 +02:00
|
|
|
pass "$check_5_9"
|
2017-10-13 10:25:23 +02:00
|
|
|
logjson "5.9" "PASS"
|
2015-05-11 06:08:28 +02:00
|
|
|
fi
|
|
|
|
|
2016-04-15 00:12:00 +02:00
|
|
|
# 5.10
|
2017-07-07 11:16:49 +02:00
|
|
|
check_5_10="5.10 - Ensure memory usage for container is limited"
|
2015-05-11 06:08:28 +02:00
|
|
|
|
|
|
|
fail=0
|
2015-05-14 04:22:39 +02:00
|
|
|
for c in $containers; do
|
2017-01-27 10:59:57 +01:00
|
|
|
if docker inspect --format '{{ .Config.Memory }}' "$c" 2> /dev/null 1>&2; then
|
2015-12-22 19:46:32 +01:00
|
|
|
memory=$(docker inspect --format '{{ .Config.Memory }}' "$c")
|
|
|
|
else
|
|
|
|
memory=$(docker inspect --format '{{ .HostConfig.Memory }}' "$c")
|
|
|
|
fi
|
2015-05-14 04:22:39 +02:00
|
|
|
|
2015-05-29 13:42:34 +02:00
|
|
|
if [ "$memory" = "0" ]; then
|
2015-05-11 06:08:28 +02:00
|
|
|
# If it's the first container, fail the test
|
|
|
|
if [ $fail -eq 0 ]; then
|
2016-04-15 00:12:00 +02:00
|
|
|
warn "$check_5_10"
|
2015-05-14 04:22:39 +02:00
|
|
|
warn " * Container running without memory restrictions: $c"
|
2017-10-13 10:25:23 +02:00
|
|
|
logjson "5.10" "WARN: $c"
|
2015-05-11 06:08:28 +02:00
|
|
|
fail=1
|
|
|
|
else
|
2015-05-14 04:22:39 +02:00
|
|
|
warn " * Container running without memory restrictions: $c"
|
2017-10-13 10:25:23 +02:00
|
|
|
logjson "5.10" "WARN: $c"
|
2015-05-11 06:08:28 +02:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
# We went through all the containers and found no lack of Memory restrictions
|
|
|
|
if [ $fail -eq 0 ]; then
|
2016-04-15 00:12:00 +02:00
|
|
|
pass "$check_5_10"
|
2017-10-13 10:25:23 +02:00
|
|
|
logjson "5.10" "PASS"
|
2015-05-11 06:08:28 +02:00
|
|
|
fi
|
|
|
|
|
2016-04-15 00:12:00 +02:00
|
|
|
# 5.11
|
2017-07-07 11:16:49 +02:00
|
|
|
check_5_11="5.11 - Ensure CPU priority is set appropriately on the container"
|
2015-05-11 06:08:28 +02:00
|
|
|
|
|
|
|
fail=0
|
2015-05-14 04:22:39 +02:00
|
|
|
for c in $containers; do
|
2017-01-27 10:59:57 +01:00
|
|
|
if docker inspect --format '{{ .Config.CpuShares }}' "$c" 2> /dev/null 1>&2; then
|
2015-12-22 19:46:32 +01:00
|
|
|
shares=$(docker inspect --format '{{ .Config.CpuShares }}' "$c")
|
|
|
|
else
|
|
|
|
shares=$(docker inspect --format '{{ .HostConfig.CpuShares }}' "$c")
|
|
|
|
fi
|
2015-05-14 04:22:39 +02:00
|
|
|
|
2015-05-15 05:26:32 +02:00
|
|
|
if [ "$shares" = "0" ]; then
|
2015-05-11 06:08:28 +02:00
|
|
|
# If it's the first container, fail the test
|
|
|
|
if [ $fail -eq 0 ]; then
|
2016-04-15 00:12:00 +02:00
|
|
|
warn "$check_5_11"
|
2015-05-14 04:22:39 +02:00
|
|
|
warn " * Container running without CPU restrictions: $c"
|
2017-10-13 10:25:23 +02:00
|
|
|
logjson "5.11" "WARN: $c"
|
2015-05-11 06:08:28 +02:00
|
|
|
fail=1
|
|
|
|
else
|
2015-05-14 04:22:39 +02:00
|
|
|
warn " * Container running without CPU restrictions: $c"
|
2017-10-13 10:25:23 +02:00
|
|
|
logjson "5.11" "WARN: $c"
|
2015-05-11 06:08:28 +02:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
# We went through all the containers and found no lack of CPUShare restrictions
|
|
|
|
if [ $fail -eq 0 ]; then
|
2016-04-15 00:12:00 +02:00
|
|
|
pass "$check_5_11"
|
2017-10-13 10:25:23 +02:00
|
|
|
logjson "5.11" "PASS"
|
2015-05-11 06:08:28 +02:00
|
|
|
fi
|
|
|
|
|
2016-04-15 00:12:00 +02:00
|
|
|
# 5.12
|
2017-07-07 11:16:49 +02:00
|
|
|
check_5_12="5.12 - Ensure the container's root filesystem is mounted as read only"
|
2015-05-11 06:08:28 +02:00
|
|
|
|
|
|
|
fail=0
|
2015-05-14 04:22:39 +02:00
|
|
|
for c in $containers; do
|
2015-05-29 13:42:34 +02:00
|
|
|
read_status=$(docker inspect --format '{{ .HostConfig.ReadonlyRootfs }}' "$c")
|
2015-05-14 04:22:39 +02:00
|
|
|
|
2015-05-15 05:26:32 +02:00
|
|
|
if [ "$read_status" = "false" ]; then
|
2015-05-11 06:08:28 +02:00
|
|
|
# If it's the first container, fail the test
|
|
|
|
if [ $fail -eq 0 ]; then
|
2016-04-15 00:12:00 +02:00
|
|
|
warn "$check_5_12"
|
2015-05-14 04:22:39 +02:00
|
|
|
warn " * Container running with root FS mounted R/W: $c"
|
2017-10-13 10:25:23 +02:00
|
|
|
logjson "5.12" "WARN: $c"
|
2015-05-11 06:08:28 +02:00
|
|
|
fail=1
|
|
|
|
else
|
2015-05-14 04:22:39 +02:00
|
|
|
warn " * Container running with root FS mounted R/W: $c"
|
2017-10-13 10:25:23 +02:00
|
|
|
logjson "5.12" "WARN: $c"
|
2015-05-11 06:08:28 +02:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
# We went through all the containers and found no R/W FS mounts
|
|
|
|
if [ $fail -eq 0 ]; then
|
2016-04-15 00:12:00 +02:00
|
|
|
pass "$check_5_12"
|
2017-10-13 10:25:23 +02:00
|
|
|
logjson "5.12" "PASS"
|
2015-05-11 06:08:28 +02:00
|
|
|
fi
|
|
|
|
|
2016-04-15 00:12:00 +02:00
|
|
|
# 5.13
|
2017-07-07 11:16:49 +02:00
|
|
|
check_5_13="5.13 - Ensure incoming container traffic is binded to a specific host interface"
|
2015-05-11 06:08:28 +02:00
|
|
|
|
|
|
|
fail=0
|
|
|
|
for c in $containers; do
|
2015-06-15 20:26:13 +02:00
|
|
|
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
|
2016-04-15 00:12:00 +02:00
|
|
|
warn "$check_5_13"
|
2015-06-15 20:26:13 +02:00
|
|
|
warn " * Port being bound to wildcard IP: $ip in $c"
|
2017-10-13 10:25:23 +02:00
|
|
|
logjson "5.13" "WARN: $ip in $c"
|
2015-06-15 20:26:13 +02:00
|
|
|
fail=1
|
|
|
|
else
|
|
|
|
warn " * Port being bound to wildcard IP: $ip in $c"
|
2017-10-13 10:25:23 +02:00
|
|
|
logjson "5.13" "WARN: $ip in $c"
|
2015-06-15 20:26:13 +02:00
|
|
|
fi
|
2015-05-11 06:08:28 +02:00
|
|
|
fi
|
2015-06-15 20:26:13 +02:00
|
|
|
done
|
2015-05-11 06:08:28 +02:00
|
|
|
done
|
|
|
|
# We went through all the containers and found no ports bound to 0.0.0.0
|
|
|
|
if [ $fail -eq 0 ]; then
|
2016-04-15 00:12:00 +02:00
|
|
|
pass "$check_5_13"
|
2017-10-13 10:25:23 +02:00
|
|
|
logjson "5.13" "PASS"
|
2015-05-11 06:08:28 +02:00
|
|
|
fi
|
|
|
|
|
2016-04-15 00:12:00 +02:00
|
|
|
# 5.14
|
2017-07-07 11:16:49 +02:00
|
|
|
check_5_14="5.14 - Ensure 'on-failure' container restart policy is set to '5'"
|
2015-05-11 06:08:28 +02:00
|
|
|
|
|
|
|
fail=0
|
2015-05-14 04:22:39 +02:00
|
|
|
for c in $containers; do
|
2016-04-15 00:12:00 +02:00
|
|
|
policy=$(docker inspect --format MaximumRetryCount='{{ .HostConfig.RestartPolicy.MaximumRetryCount }}' "$c")
|
2015-05-11 06:08:28 +02:00
|
|
|
|
2016-04-15 00:12:00 +02:00
|
|
|
if [ "$policy" != "MaximumRetryCount=5" ]; then
|
2015-05-11 06:08:28 +02:00
|
|
|
# If it's the first container, fail the test
|
|
|
|
if [ $fail -eq 0 ]; then
|
2016-04-15 00:12:00 +02:00
|
|
|
warn "$check_5_14"
|
|
|
|
warn " * MaximumRetryCount is not set to 5: $c"
|
2017-10-13 10:25:23 +02:00
|
|
|
logjson "5.14" "WARN: $c"
|
2015-05-11 06:08:28 +02:00
|
|
|
fail=1
|
|
|
|
else
|
2016-04-15 00:12:00 +02:00
|
|
|
warn " * MaximumRetryCount is not set to 5: $c"
|
2017-10-13 10:25:23 +02:00
|
|
|
logjson "5.14" "WARN: $c"
|
2015-05-11 06:08:28 +02:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
2016-04-15 00:12:00 +02:00
|
|
|
# We went through all the containers and they all had MaximumRetryCount=5
|
2015-05-11 06:08:28 +02:00
|
|
|
if [ $fail -eq 0 ]; then
|
2016-04-15 00:12:00 +02:00
|
|
|
pass "$check_5_14"
|
2017-10-13 10:25:23 +02:00
|
|
|
logjson "5.14" "PASS"
|
2015-05-11 06:08:28 +02:00
|
|
|
fi
|
|
|
|
|
2016-04-15 00:12:00 +02:00
|
|
|
# 5.15
|
2017-07-07 11:16:49 +02:00
|
|
|
check_5_15="5.15 - Ensure the host's process namespace is not shared"
|
2015-05-11 06:08:28 +02:00
|
|
|
|
|
|
|
fail=0
|
2015-05-14 04:22:39 +02:00
|
|
|
for c in $containers; do
|
2015-05-29 13:42:34 +02:00
|
|
|
mode=$(docker inspect --format 'PidMode={{.HostConfig.PidMode }}' "$c")
|
2015-05-14 04:22:39 +02:00
|
|
|
|
2015-05-15 05:26:32 +02:00
|
|
|
if [ "$mode" = "PidMode=host" ]; then
|
2015-05-11 06:08:28 +02:00
|
|
|
# If it's the first container, fail the test
|
|
|
|
if [ $fail -eq 0 ]; then
|
2016-04-15 00:12:00 +02:00
|
|
|
warn "$check_5_15"
|
2015-05-14 04:22:39 +02:00
|
|
|
warn " * Host PID namespace being shared with: $c"
|
2017-10-13 10:25:23 +02:00
|
|
|
logjson "5.15" "WARN: $c"
|
2015-05-11 06:08:28 +02:00
|
|
|
fail=1
|
|
|
|
else
|
2015-05-14 04:22:39 +02:00
|
|
|
warn " * Host PID namespace being shared with: $c"
|
2017-10-13 10:25:23 +02:00
|
|
|
logjson "5.15" "WARN: $c"
|
2015-05-11 06:08:28 +02:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
# We went through all the containers and found none with PidMode as host
|
|
|
|
if [ $fail -eq 0 ]; then
|
2016-04-15 00:12:00 +02:00
|
|
|
pass "$check_5_15"
|
2017-10-13 10:25:23 +02:00
|
|
|
logjson "5.15" "PASS"
|
2015-05-11 06:08:28 +02:00
|
|
|
fi
|
|
|
|
|
2016-04-15 00:12:00 +02:00
|
|
|
# 5.16
|
2017-07-07 11:16:49 +02:00
|
|
|
check_5_16="5.16 - Ensure the host's IPC namespace is not shared"
|
2015-05-11 06:08:28 +02:00
|
|
|
|
|
|
|
fail=0
|
2015-05-14 04:22:39 +02:00
|
|
|
for c in $containers; do
|
2015-05-29 13:42:34 +02:00
|
|
|
mode=$(docker inspect --format 'IpcMode={{.HostConfig.IpcMode }}' "$c")
|
2015-05-14 04:22:39 +02:00
|
|
|
|
2015-05-15 05:26:32 +02:00
|
|
|
if [ "$mode" = "IpcMode=host" ]; then
|
2015-05-11 06:08:28 +02:00
|
|
|
# If it's the first container, fail the test
|
|
|
|
if [ $fail -eq 0 ]; then
|
2016-04-15 00:12:00 +02:00
|
|
|
warn "$check_5_16"
|
2015-05-14 04:22:39 +02:00
|
|
|
warn " * Host IPC namespace being shared with: $c"
|
2017-10-13 10:25:23 +02:00
|
|
|
logjson "5.16" "WARN: $c"
|
2015-05-11 06:08:28 +02:00
|
|
|
fail=1
|
|
|
|
else
|
2015-05-14 04:22:39 +02:00
|
|
|
warn " * Host IPC namespace being shared with: $c"
|
2017-10-13 10:25:23 +02:00
|
|
|
logjson "5.16" "WARN: $c"
|
2015-05-11 06:08:28 +02:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
# We went through all the containers and found none with IPCMode as host
|
|
|
|
if [ $fail -eq 0 ]; then
|
2016-04-15 00:12:00 +02:00
|
|
|
pass "$check_5_16"
|
2017-10-13 10:25:23 +02:00
|
|
|
logjson "5.16" "PASS"
|
2015-05-11 06:08:28 +02:00
|
|
|
fi
|
|
|
|
|
2016-04-15 00:12:00 +02:00
|
|
|
# 5.17
|
2017-07-07 11:16:49 +02:00
|
|
|
check_5_17="5.17 - Ensure host devices are not directly exposed to containers"
|
2015-05-11 06:08:28 +02:00
|
|
|
|
|
|
|
fail=0
|
2015-05-14 04:22:39 +02:00
|
|
|
for c in $containers; do
|
2015-05-29 13:42:34 +02:00
|
|
|
devices=$(docker inspect --format 'Devices={{ .HostConfig.Devices }}' "$c")
|
2015-05-14 04:22:39 +02:00
|
|
|
|
2015-05-15 05:26:32 +02:00
|
|
|
if [ "$devices" != "Devices=" -a "$devices" != "Devices=[]" -a "$devices" != "Devices=<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
|
2016-04-15 00:12:00 +02:00
|
|
|
info "$check_5_17"
|
2015-05-14 04:22:39 +02:00
|
|
|
info " * Container has devices exposed directly: $c"
|
2017-10-13 10:25:23 +02:00
|
|
|
logjson "5.17" "INFO: $c"
|
2015-05-11 06:08:28 +02:00
|
|
|
fail=1
|
|
|
|
else
|
2015-05-14 04:22:39 +02:00
|
|
|
info " * Container has devices exposed directly: $c"
|
2017-10-13 10:25:23 +02:00
|
|
|
logjson "5.17" "INFO: $c"
|
2015-05-11 06:08:28 +02:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
# We went through all the containers and found none with devices
|
|
|
|
if [ $fail -eq 0 ]; then
|
2016-04-15 00:12:00 +02:00
|
|
|
pass "$check_5_17"
|
2017-10-13 10:25:23 +02:00
|
|
|
logjson "5.17" "PASS"
|
2015-05-11 06:08:28 +02:00
|
|
|
fi
|
|
|
|
|
2016-04-15 00:12:00 +02:00
|
|
|
# 5.18
|
2017-07-07 11:16:49 +02:00
|
|
|
check_5_18="5.18 - Ensure the default ulimit is overwritten at runtime, only if needed"
|
2015-05-11 06:08:28 +02:00
|
|
|
|
|
|
|
fail=0
|
2015-05-14 04:22:39 +02:00
|
|
|
for c in $containers; do
|
2015-05-29 13:42:34 +02:00
|
|
|
ulimits=$(docker inspect --format 'Ulimits={{ .HostConfig.Ulimits }}' "$c")
|
2015-05-14 04:22:39 +02:00
|
|
|
|
2015-05-15 05:26:32 +02:00
|
|
|
if [ "$ulimits" = "Ulimits=" -o "$ulimits" = "Ulimits=[]" -o "$ulimits" = "Ulimits=<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
|
2016-04-15 00:12:00 +02:00
|
|
|
info "$check_5_18"
|
2015-05-14 04:22:39 +02:00
|
|
|
info " * Container no default ulimit override: $c"
|
2017-10-13 10:25:23 +02:00
|
|
|
logjson "5.18" "INFO: $c"
|
2015-05-11 06:08:28 +02:00
|
|
|
fail=1
|
|
|
|
else
|
2015-05-14 04:22:39 +02:00
|
|
|
info " * Container no default ulimit override: $c"
|
2017-10-13 10:25:23 +02:00
|
|
|
logjson "5.18" "INFO: $c"
|
2015-05-11 06:08:28 +02:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
# We went through all the containers and found none without Ulimits
|
|
|
|
if [ $fail -eq 0 ]; then
|
2016-04-15 00:12:00 +02:00
|
|
|
pass "$check_5_18"
|
2017-10-13 10:25:23 +02:00
|
|
|
logjson "5.18" "PASS"
|
2016-04-15 00:12:00 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
# 5.19
|
2017-07-07 11:16:49 +02:00
|
|
|
check_5_19="5.19 - Ensure mount propagation mode is not set to shared"
|
2016-04-15 00:12:00 +02:00
|
|
|
|
|
|
|
fail=0
|
|
|
|
for c in $containers; do
|
2017-01-27 11:00:25 +01:00
|
|
|
if docker inspect --format 'Propagation={{range $mnt := .Mounts}} {{json $mnt.Propagation}} {{end}}' "$c" | \
|
|
|
|
grep shared 2>/dev/null 1>&2; then
|
2016-04-15 00:12:00 +02:00
|
|
|
# If it's the first container, fail the test
|
|
|
|
if [ $fail -eq 0 ]; then
|
|
|
|
warn "$check_5_19"
|
|
|
|
warn " * Mount propagation mode is shared: $c"
|
2017-10-13 10:25:23 +02:00
|
|
|
logjson "5.19" "WARN: $c"
|
2016-04-15 00:12:00 +02:00
|
|
|
fail=1
|
|
|
|
else
|
|
|
|
warn " * Mount propagation mode is shared: $c"
|
2017-10-13 10:25:23 +02:00
|
|
|
logjson "5.19" "WARN: $c"
|
2016-04-15 00:12:00 +02:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
# We went through all the containers and found none with shared propagation mode
|
|
|
|
if [ $fail -eq 0 ]; then
|
2015-05-11 06:08:28 +02:00
|
|
|
pass "$check_5_19"
|
2017-10-13 10:25:23 +02:00
|
|
|
logjson "5.19" "PASS"
|
2015-05-11 06:08:28 +02:00
|
|
|
fi
|
2016-04-15 00:12:00 +02:00
|
|
|
|
|
|
|
# 5.20
|
2017-07-07 11:16:49 +02:00
|
|
|
check_5_20="5.20 - Ensure the host's UTS namespace is not shared"
|
2016-04-15 00:12:00 +02:00
|
|
|
|
|
|
|
fail=0
|
|
|
|
for c in $containers; do
|
|
|
|
mode=$(docker inspect --format 'UTSMode={{.HostConfig.UTSMode }}' "$c")
|
|
|
|
|
|
|
|
if [ "$mode" = "UTSMode=host" ]; then
|
|
|
|
# If it's the first container, fail the test
|
|
|
|
if [ $fail -eq 0 ]; then
|
|
|
|
warn "$check_5_20"
|
|
|
|
warn " * Host UTS namespace being shared with: $c"
|
2017-10-13 10:25:23 +02:00
|
|
|
logjson "5.20" "WARN: $c"
|
2016-04-15 00:12:00 +02:00
|
|
|
fail=1
|
|
|
|
else
|
|
|
|
warn " * Host UTS namespace being shared with: $c"
|
2017-10-13 10:25:23 +02:00
|
|
|
logjson "5.20" "WARN: $c"
|
2016-04-15 00:12:00 +02:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
# We went through all the containers and found none with UTSMode as host
|
|
|
|
if [ $fail -eq 0 ]; then
|
|
|
|
pass "$check_5_20"
|
2017-10-13 10:25:23 +02:00
|
|
|
logjson "5.20" "PASS"
|
2016-04-15 00:12:00 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
# 5.21
|
2017-07-07 11:16:49 +02:00
|
|
|
check_5_21="5.21 - Ensure the default seccomp profile is not Disabled"
|
2016-04-15 00:12:00 +02:00
|
|
|
|
|
|
|
fail=0
|
|
|
|
for c in $containers; do
|
2018-01-12 11:36:14 +01:00
|
|
|
if docker inspect --format 'SecurityOpt={{.HostConfig.SecurityOpt }}' "$c" | \
|
|
|
|
grep -E 'seccomp:unconfined|seccomp=unconfined' 2>/dev/null 1>&2; then
|
2016-04-15 00:12:00 +02:00
|
|
|
# If it's the first container, fail the test
|
|
|
|
if [ $fail -eq 0 ]; then
|
|
|
|
warn "$check_5_21"
|
|
|
|
warn " * Default seccomp profile disabled: $c"
|
2017-10-13 10:25:23 +02:00
|
|
|
logjson "5.21" "WARN: $c"
|
2016-04-15 00:12:00 +02:00
|
|
|
fail=1
|
|
|
|
else
|
|
|
|
warn " * Default seccomp profile disabled: $c"
|
2017-10-13 10:25:23 +02:00
|
|
|
logjson "5.21" "WARN: $c"
|
2016-04-15 00:12:00 +02:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
2016-12-20 16:01:58 +01:00
|
|
|
# We went through all the containers and found none with default secomp profile disabled
|
2016-04-15 00:12:00 +02:00
|
|
|
if [ $fail -eq 0 ]; then
|
|
|
|
pass "$check_5_21"
|
2017-10-13 10:25:23 +02:00
|
|
|
logjson "5.21" "PASS"
|
2016-04-15 00:12:00 +02:00
|
|
|
fi
|
|
|
|
|
2017-01-23 17:06:10 +01:00
|
|
|
# 5.22
|
2017-07-07 11:16:49 +02:00
|
|
|
check_5_22="5.22 - Ensure docker exec commands are not used with privileged option"
|
2017-03-23 11:29:58 +01:00
|
|
|
note "$check_5_22"
|
2017-10-13 10:25:23 +02:00
|
|
|
logjson "5.22" "NOTE"
|
2017-01-23 17:06:10 +01:00
|
|
|
|
|
|
|
# 5.23
|
2017-07-07 11:16:49 +02:00
|
|
|
check_5_23="5.23 - Ensure docker exec commands are not used with user option"
|
2017-03-23 11:29:58 +01:00
|
|
|
note "$check_5_23"
|
2017-10-13 10:25:23 +02:00
|
|
|
logjson "5.23" "NOTE"
|
2016-04-15 00:12:00 +02:00
|
|
|
|
|
|
|
# 5.24
|
2017-07-07 11:16:49 +02:00
|
|
|
check_5_24="5.24 - Ensure cgroup usage is confirmed"
|
2016-04-15 00:12:00 +02:00
|
|
|
|
|
|
|
fail=0
|
|
|
|
for c in $containers; do
|
|
|
|
mode=$(docker inspect --format 'CgroupParent={{.HostConfig.CgroupParent }}x' "$c")
|
|
|
|
|
|
|
|
if [ "$mode" != "CgroupParent=x" ]; then
|
|
|
|
# If it's the first container, fail the test
|
|
|
|
if [ $fail -eq 0 ]; then
|
2017-01-24 15:26:19 +01:00
|
|
|
warn "$check_5_24"
|
|
|
|
warn " * Confirm cgroup usage: $c"
|
2017-10-13 10:25:23 +02:00
|
|
|
logjson "5.24" "WARN: $c"
|
2016-04-15 00:12:00 +02:00
|
|
|
fail=1
|
|
|
|
else
|
2017-01-24 15:26:19 +01:00
|
|
|
warn " * Confirm cgroup usage: $c"
|
2017-10-13 10:25:23 +02:00
|
|
|
logjson "5.24" "WARN: $c"
|
2016-04-15 00:12:00 +02:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
# We went through all the containers and found none with UTSMode as host
|
|
|
|
if [ $fail -eq 0 ]; then
|
|
|
|
pass "$check_5_24"
|
2017-10-13 10:25:23 +02:00
|
|
|
logjson "5.24" "PASS"
|
2016-04-15 00:12:00 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
# 5.25
|
2017-07-07 11:16:49 +02:00
|
|
|
check_5_25="5.25 - Ensure the container is restricted from acquiring additional privileges"
|
2016-04-15 00:12:00 +02:00
|
|
|
|
|
|
|
fail=0
|
|
|
|
for c in $containers; do
|
2017-01-27 11:00:36 +01:00
|
|
|
if ! docker inspect --format 'SecurityOpt={{.HostConfig.SecurityOpt }}' "$c" | grep 'no-new-privileges' 2>/dev/null 1>&2; then
|
2016-04-15 00:12:00 +02:00
|
|
|
# If it's the first container, fail the test
|
|
|
|
if [ $fail -eq 0 ]; then
|
|
|
|
warn "$check_5_25"
|
|
|
|
warn " * Privileges not restricted: $c"
|
2017-10-13 10:25:23 +02:00
|
|
|
logjson "5.25" "WARN: $c"
|
2016-04-15 00:12:00 +02:00
|
|
|
fail=1
|
|
|
|
else
|
|
|
|
warn " * Privileges not restricted: $c"
|
2017-10-13 10:25:23 +02:00
|
|
|
logjson "5.25" "WARN: $c"
|
2016-04-15 00:12:00 +02:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
2016-12-20 16:01:58 +01:00
|
|
|
# We went through all the containers and found none with capability to acquire additional privileges
|
2016-04-15 00:12:00 +02:00
|
|
|
if [ $fail -eq 0 ]; then
|
|
|
|
pass "$check_5_25"
|
2017-10-13 10:25:23 +02:00
|
|
|
logjson "5.25" "PASS"
|
2016-04-15 00:12:00 +02:00
|
|
|
fi
|
2016-12-20 16:01:58 +01:00
|
|
|
|
|
|
|
# 5.26
|
2017-07-07 11:16:49 +02:00
|
|
|
check_5_26="5.26 - Ensure container health is checked at runtime"
|
2016-12-20 16:01:58 +01:00
|
|
|
|
|
|
|
fail=0
|
|
|
|
for c in $containers; do
|
2017-01-24 15:26:19 +01:00
|
|
|
if ! docker inspect --format '{{ .Id }}: Health={{ .State.Health.Status }}' "$c" 2>/dev/null 1>&2; then
|
2016-12-20 16:01:58 +01:00
|
|
|
if [ $fail -eq 0 ]; then
|
|
|
|
warn "$check_5_26"
|
2017-01-23 16:16:02 +01:00
|
|
|
warn " * Health check not set: $c"
|
2017-10-13 10:25:23 +02:00
|
|
|
logjson "5.26" "WARN: $c"
|
2016-12-20 16:01:58 +01:00
|
|
|
fail=1
|
|
|
|
else
|
2017-01-23 16:16:02 +01:00
|
|
|
warn " * Health check not set: $c"
|
2017-10-13 10:25:23 +02:00
|
|
|
logjson "5.26" "WARN: $c"
|
2016-12-20 16:01:58 +01:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
if [ $fail -eq 0 ]; then
|
|
|
|
pass "$check_5_26"
|
2017-10-13 10:25:23 +02:00
|
|
|
logjson "5.26" "PASS"
|
2016-12-20 16:01:58 +01:00
|
|
|
fi
|
|
|
|
|
2017-01-23 17:06:10 +01:00
|
|
|
# 5.27
|
|
|
|
check_5_27="5.27 - Ensure docker commands always get the latest version of the image"
|
|
|
|
info "$check_5_27"
|
2017-10-13 10:25:23 +02:00
|
|
|
logjson "5.27" "INFO"
|
2017-01-23 17:06:10 +01:00
|
|
|
|
2016-12-20 16:01:58 +01:00
|
|
|
# 5.28
|
2017-07-07 11:16:49 +02:00
|
|
|
check_5_28="5.28 - Ensure PIDs cgroup limit is used"
|
2016-12-20 16:01:58 +01:00
|
|
|
|
|
|
|
fail=0
|
|
|
|
for c in $containers; do
|
2017-01-23 12:52:31 +01:00
|
|
|
pidslimit=$(docker inspect --format '{{.HostConfig.PidsLimit }}' "$c")
|
2016-12-20 16:01:58 +01:00
|
|
|
|
2017-01-24 15:26:19 +01:00
|
|
|
if [ "$pidslimit" -le 0 ]; then
|
2016-12-20 16:01:58 +01:00
|
|
|
# If it's the first container, fail the test
|
|
|
|
if [ $fail -eq 0 ]; then
|
|
|
|
warn "$check_5_28"
|
2017-01-23 17:06:10 +01:00
|
|
|
warn " * PIDs limit not set: $c"
|
2017-10-13 10:25:23 +02:00
|
|
|
logjson "5.28" "WARN: $c"
|
2016-12-20 16:01:58 +01:00
|
|
|
fail=1
|
|
|
|
else
|
2017-01-23 17:06:10 +01:00
|
|
|
warn " * PIDs limit not set: $c"
|
2017-10-13 10:25:23 +02:00
|
|
|
logjson "5.28" "WARN: $c"
|
2016-12-20 16:01:58 +01:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
# We went through all the containers and found all with PIDs limit
|
|
|
|
if [ $fail -eq 0 ]; then
|
|
|
|
pass "$check_5_28"
|
2017-10-13 10:25:23 +02:00
|
|
|
logjson "5.28" "PASS"
|
2016-12-20 16:01:58 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
# 5.29
|
2017-07-07 11:16:49 +02:00
|
|
|
check_5_29="5.29 - Ensure Docker's default bridge docker0 is not used"
|
2016-12-20 16:01:58 +01:00
|
|
|
|
|
|
|
fail=0
|
2017-01-23 12:52:31 +01:00
|
|
|
networks=$(docker network ls -q 2>/dev/null)
|
2016-12-20 16:01:58 +01:00
|
|
|
for net in $networks; do
|
2017-01-24 15:26:19 +01:00
|
|
|
if docker network inspect --format '{{ .Options }}' "$net" 2>/dev/null | grep "com.docker.network.bridge.name:docker0" >/dev/null 2>&1; then
|
|
|
|
docker0Containers=$(docker network inspect --format='{{ range $k, $v := .Containers }} {{ $k }} {{ end }}' "$net" | \
|
|
|
|
sed -e 's/^ //' -e 's/ /\n/g' 2>/dev/null)
|
2016-12-20 16:01:58 +01:00
|
|
|
if [ -n "$docker0Containers" ]; then
|
|
|
|
if [ $fail -eq 0 ]; then
|
2017-01-23 17:06:10 +01:00
|
|
|
info "$check_5_29"
|
2017-10-13 10:25:23 +02:00
|
|
|
logjson "5.29" "INFO"
|
2016-12-20 16:01:58 +01:00
|
|
|
fail=1
|
|
|
|
fi
|
|
|
|
for c in $docker0Containers; do
|
2017-01-24 15:26:19 +01:00
|
|
|
cName=$(docker inspect --format '{{.Name}}' "$c" 2>/dev/null | sed 's/\///g')
|
|
|
|
info " * Container in docker0 network: $cName"
|
2017-10-13 10:25:23 +02:00
|
|
|
logjson "5.29" "INFO: $c"
|
2016-12-20 16:01:58 +01:00
|
|
|
done
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
# We went through all the containers and found none in docker0 network
|
|
|
|
if [ $fail -eq 0 ]; then
|
|
|
|
pass "$check_5_29"
|
2017-10-13 10:25:23 +02:00
|
|
|
logjson "5.29" "PASS"
|
2016-12-20 16:01:58 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
# 5.30
|
2017-07-07 11:16:49 +02:00
|
|
|
check_5_30="5.30 - Ensure the host's user namespaces is not shared"
|
2016-12-20 16:01:58 +01:00
|
|
|
|
|
|
|
fail=0
|
|
|
|
for c in $containers; do
|
2017-01-24 15:26:19 +01:00
|
|
|
if docker inspect --format '{{ .HostConfig.UsernsMode }}' "$c" 2>/dev/null | grep -i 'host' >/dev/null 2>&1; then
|
2016-12-20 16:01:58 +01:00
|
|
|
# If it's the first container, fail the test
|
|
|
|
if [ $fail -eq 0 ]; then
|
|
|
|
warn "$check_5_30"
|
|
|
|
warn " * Namespace shared: $c"
|
2017-10-13 10:25:23 +02:00
|
|
|
logjson "5.30" "WARN: $c"
|
2016-12-20 16:01:58 +01:00
|
|
|
fail=1
|
|
|
|
else
|
|
|
|
warn " * Namespace shared: $c"
|
2017-10-13 10:25:23 +02:00
|
|
|
logjson "5.30" "WARN: $c"
|
2016-12-20 16:01:58 +01:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
# We went through all the containers and found none with host's user namespace shared
|
|
|
|
if [ $fail -eq 0 ]; then
|
|
|
|
pass "$check_5_30"
|
2017-10-13 10:25:23 +02:00
|
|
|
logjson "5.30" "PASS"
|
2016-12-20 16:01:58 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
# 5.31
|
2017-07-07 11:16:49 +02:00
|
|
|
check_5_31="5.31 - Ensure the Docker socket is not mounted inside any containers"
|
2016-12-20 16:01:58 +01:00
|
|
|
|
|
|
|
fail=0
|
|
|
|
for c in $containers; do
|
2017-01-24 15:26:19 +01:00
|
|
|
if docker inspect --format '{{ .Mounts }}' "$c" 2>/dev/null | grep 'docker.sock' >/dev/null 2>&1; then
|
2016-12-20 16:01:58 +01:00
|
|
|
# If it's the first container, fail the test
|
|
|
|
if [ $fail -eq 0 ]; then
|
|
|
|
warn "$check_5_31"
|
2017-01-23 12:40:32 +01:00
|
|
|
warn " * Docker socket shared: $c"
|
2017-10-13 10:25:23 +02:00
|
|
|
logjson "5.31" "WARN: $c"
|
2016-12-20 16:01:58 +01:00
|
|
|
fail=1
|
|
|
|
else
|
2017-01-23 12:40:32 +01:00
|
|
|
warn " * Docker socket shared: $c"
|
2017-10-13 10:25:23 +02:00
|
|
|
logjson "5.31" "WARN: $c"
|
2016-12-20 16:01:58 +01:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
# We went through all the containers and found none with docker.sock shared
|
|
|
|
if [ $fail -eq 0 ]; then
|
|
|
|
pass "$check_5_31"
|
2017-10-13 10:25:23 +02:00
|
|
|
logjson "5.31" "PASS"
|
2016-12-20 16:01:58 +01:00
|
|
|
fi
|
2015-05-11 06:08:28 +02:00
|
|
|
fi
|