…lines 1–16 unchanged (16 lines)
17 fi
18 # Make the loop separator be a new-line in POSIX compliant fashion
19 set -f; IFS=$'
20 '
21}
22
23check_5_1() {
24 local id="5.1"
25 local desc="Ensure swarm mode is not Enabled, if not needed (Automated)"
26 local remediation="If swarm mode has been enabled on a system in error, you should run the command: docker swarm leave"
27 local remediationImpact="Disabling swarm mode will impact the operation of Docker Enterprise components if these are in use."
28 local check="$id - $desc"
29 starttestjson "$id" "$desc"
30
31 if docker info 2>/dev/null | grep -e "Swarm:*\sinactive\s*" >/dev/null 2>&1; then
32 pass -s "$check"
33 logcheckresult "PASS"
34 return
35 fi
36 warn -s "$check"
37 logcheckresult "WARN"
38}
39
40check_5_2() {
41 if [ -z "$containers" ]; then
42 return
43 fi
44
45 local id="5.2"
46 local desc="Ensure that, if applicable, an AppArmor Profile is enabled (Automated)"
47 local remediation="If AppArmor is applicable for your Linux OS, you should enable it. Alternatively, Docker's default AppArmor policy can be used."
48 local remediationImpact="The container will have the security controls defined in the AppArmor profile. It should be noted that if the AppArmor profile is misconfigured, this may cause issues with the operation of the container."
49 local check="$id - $desc"
50 starttestjson "$id" "$desc"
51
…lines 52–77 unchanged (26 lines)
78
79check_5_3() {
80 if [ -z "$containers" ]; then
81 return
82 fi
83
84 local id="5.3"
85 local desc="Ensure that, if applicable, SELinux security options are set (Automated)"
86 local remediation="Set the SELinux State. Set the SELinux Policy. Create or import a SELinux policy template for Docker containers. Start Docker in daemon mode with SELinux enabled. Start your Docker container using the security options."
87 local remediationImpact="Any restrictions defined in the SELinux policy will be applied to your containers. It should be noted that if your SELinux policy is misconfigured, this may have an impact on the correct operation of the affected containers."
88 local check="$id - $desc"
89 starttestjson "$id" "$desc"
90
…lines 91–116 unchanged (26 lines)
117
118check_5_4() {
119 if [ -z "$containers" ]; then
120 return
121 fi
122
123 local id="5.4"
124 local desc="Ensure that Linux kernel capabilities are restricted within containers (Automated)"
125 local remediation="You could remove all the currently configured capabilities and then restore only the ones you specifically use: docker run --cap-drop=all --cap-add={<Capability 1>,<Capability 2>} <Run arguments> <Container Image Name or ID> <Command>"
126 local remediationImpact="Restrictions on processes within a container are based on which Linux capabilities are in force. Removal of the NET_RAW capability prevents the container from creating raw sockets which is good security practice under most circumstances, but may affect some networking utilities."
127 local check="$id - $desc"
128 starttestjson "$id" "$desc"
129
…lines 130–159 unchanged (30 lines)
160
161check_5_5() {
162 if [ -z "$containers" ]; then
163 return
164 fi
165
166 local id="5.5"
167 local desc="Ensure that privileged containers are not used (Automated)"
168 local remediation="You should not run containers with the --privileged flag."
169 local remediationImpact="If you start a container without the --privileged flag, it will not have excessive default capabilities."
170 local check="$id - $desc"
171 starttestjson "$id" "$desc"
172
…lines 173–198 unchanged (26 lines)
199
200check_5_6() {
201 if [ -z "$containers" ]; then
202 return
203 fi
204
205 local id="5.6"
206 local desc="Ensure sensitive host system directories are not mounted on containers (Automated)"
207 local remediation="You should not mount directories which are security sensitive on the host within containers, especially in read-write mode."
208 local remediationImpact="None."
209 local check="$id - $desc"
210 starttestjson "$id" "$desc"
211
…lines 212–256 unchanged (45 lines)
257
258check_5_7() {
259 if [ -z "$containers" ]; then
260 return
261 fi
262
263 local id="5.7"
264 local desc="Ensure sshd is not run within containers (Automated)"
265 local remediation="Uninstall the SSH daemon from the container and use docker exec to enter a container on the remote host."
266 local remediationImpact="None."
267 local check="$id - $desc"
268 starttestjson "$id" "$desc"
269
…lines 270–284 unchanged (15 lines)
285 warn " * Container running sshd: $c"
286 ssh_exec_containers="$ssh_exec_containers $c"
287 fi
288 fi
289
290 exec_check=$(docker exec "$c" ps -el 2>/dev/null)
291 if [ $? -eq 265 ]; then
292 if [ $printcheck -eq 0 ]; then
293 warn -s "$check"
294 printcheck=1
295 fi
296 warn " * Docker exec fails: $c"
297 ssh_exec_containers="$ssh_exec_containers $c"
…lines 298–309 unchanged (12 lines)
310
311check_5_8() {
312 if [ -z "$containers" ]; then
313 return
314 fi
315
316 local id="5.8"
317 local desc="Ensure privileged ports are not mapped within containers (Automated)"
318 local remediation="You should not map container ports to privileged host ports when starting a container. You should also, ensure that there is no such container to host privileged port mapping declarations in the Dockerfile."
319 local remediationImpact="None."
320 local check="$id - $desc"
321 starttestjson "$id" "$desc"
322
323 fail=0
324 privileged_port_containers=""
325 for c in $containers; do
326 # Port format is private port -> ip: public port
327 ports=$(docker port "$c" | awk '{print $0}' | cut -d ':' -f2)
328
329 # iterate through port range (line delimited)
330 for port in $ports; do
331 if [ -n "$port" ] && [ "$port" -lt 1025 ]; then
332 # If it's the first container, fail the test
333 if [ $fail -eq 0 ]; then
334 warn -s "$check"
335 warn " * Privileged Port in use: $port in $c"
336 privileged_port_containers="$privileged_port_containers $c:$port"
337 fail=1
…lines 338–352 unchanged (15 lines)
353
354check_5_9() {
355 if [ -z "$containers" ]; then
356 return
357 fi
358
359 local id="5.9"
360 local desc="Ensure that only needed ports are open on the container (Manual)"
361 local remediation="You should ensure that the Dockerfile for each container image only exposes needed ports."
362 local remediationImpact="None."
363 local check="$id - $desc"
364 starttestjson "$id" "$desc"
365
…lines 366–389 unchanged (24 lines)
390 logcheckresult "PASS"
391 return
392 fi
393 logcheckresult "WARN" "Containers with open ports" "$open_port_containers"
394}
395
396check_5_10() {
397 if [ -z "$containers" ]; then
398 return
399 fi
400
401 local id="5.10"
402 local desc="Ensure that the host's network namespace is not shared (Automated)"
403 local remediation="You should not pass the --net=host option when starting any container."
404 local remediationImpact="None."
405 local check="$id - $desc"
406 starttestjson "$id" "$desc"
407
…lines 408–433 unchanged (26 lines)
434
435check_5_11() {
436 if [ -z "$containers" ]; then
437 return
438 fi
439
440 local id="5.11"
441 local desc="Ensure that the memory usage for containers is limited (Automated)"
442 local remediation="You should run the container with only as much memory as it requires by using the --memory argument."
443 local remediationImpact="If correct memory limits are not set on each container, one process can expand its usage and cause other containers to run out of resources."
444 local check="$id - $desc"
445 starttestjson "$id" "$desc"
446
…lines 447–475 unchanged (29 lines)
476
477check_5_12() {
478 if [ -z "$containers" ]; then
479 return
480 fi
481
482 local id="5.12"
483 local desc="Ensure that CPU priority is set appropriately on containers (Automated)"
484 local remediation="You should manage the CPU runtime between your containers dependent on their priority within your organization. To do so start the container using the --cpu-shares argument."
485 local remediationImpact="If you do not correctly assign CPU thresholds, the container process may run out of resources and become unresponsive. If CPU resources on the host are not constrainted, CPU shares do not place any restrictions on individual resources."
486 local check="$id - $desc"
487 starttestjson "$id" "$desc"
488
…lines 489–520 unchanged (32 lines)
521
522check_5_13() {
523 if [ -z "$containers" ]; then
524 return
525 fi
526
527 local id="5.13"
528 local desc="Ensure that the container's root filesystem is mounted as read only (Automated)"
529 local remediation="You should add a --read-only flag at a container's runtime to enforce the container's root filesystem being mounted as read only."
530 local remediationImpact="Enabling --read-only at container runtime may break some container OS packages if a data writing strategy is not defined. You should define what the container's data should and should not persist at runtime in order to decide which strategy to use."
531 local check="$id - $desc"
532 starttestjson "$id" "$desc"
533
…lines 534–559 unchanged (26 lines)
560
561check_5_14() {
562 if [ -z "$containers" ]; then
563 return
564 fi
565
566 local id="5.14"
567 local desc="Ensure that incoming container traffic is bound to a specific host interface (Automated)"
568 local remediation="You should bind the container port to a specific host interface on the desired host port. Example: docker run --detach --publish 10.2.3.4:49153:80 nginx In this example, the container port 80 is bound to the host port on 49153 and would accept incoming connection only from the 10.2.3.4 external interface."
569 local remediationImpact="None."
570 local check="$id - $desc"
571 starttestjson "$id" "$desc"
572
…lines 573–598 unchanged (26 lines)
599
600check_5_15() {
601 if [ -z "$containers" ]; then
602 return
603 fi
604
605 local id="5.15"
606 local desc="Ensure that the 'on-failure' container restart policy is set to '5' (Automated)"
607 local remediation="If you wish a container to be automatically restarted, a sample command is docker run --detach --restart=on-failure:5 nginx"
608 local remediationImpact="If this option is set, a container will only attempt to restart itself 5 times."
609 local check="$id - $desc"
610 starttestjson "$id" "$desc"
611
…lines 612–651 unchanged (40 lines)
652
653check_5_16() {
654 if [ -z "$containers" ]; then
655 return
656 fi
657
658 local id="5.16"
659 local desc="Ensure that the host's process namespace is not shared (Automated)"
660 local remediation="You should not start a container with the --pid=host argument."
661 local remediationImpact="Container processes cannot see processes on the host system."
662 local check="$id - $desc"
663 starttestjson "$id" "$desc"
664
…lines 665–690 unchanged (26 lines)
691
692check_5_17() {
693 if [ -z "$containers" ]; then
694 return
695 fi
696
697 local id="5.17"
698 local desc="Ensure that the host's IPC namespace is not shared (Automated)"
699 local remediation="You should not start a container with the --ipc=host argument."
700 local remediationImpact="Shared memory segments are used in order to accelerate interprocess communications, commonly in high-performance applications. If this type of application is containerized into multiple containers, you might need to share the IPC namespace of the containers in order to achieve high performance. Under these circumstances, you should still only share container specific IPC namespaces and not the host IPC namespace."
701 local check="$id - $desc"
702 starttestjson "$id" "$desc"
703
…lines 704–729 unchanged (26 lines)
730
731check_5_18() {
732 if [ -z "$containers" ]; then
733 return
734 fi
735
736 local id="5.18"
737 local desc="Ensure that host devices are not directly exposed to containers (Manual)"
738 local remediation="You should not directly expose host devices to containers. If you do need to expose host devices to containers, you should use granular permissions as appropriate to your organization."
739 local remediationImpact="You would not be able to use host devices directly within containers."
740 local check="$id - $desc"
741 starttestjson "$id" "$desc"
742
…lines 743–768 unchanged (26 lines)
769
770check_5_19() {
771 if [ -z "$containers" ]; then
772 return
773 fi
774
775 local id="5.19"
776 local desc="Ensure that the default ulimit is overwritten at runtime if needed (Manual)"
777 local remediation="You should only override the default ulimit settings if needed in a specific case."
778 local remediationImpact="If ulimits are not set correctly, overutilization by individual containers could make the host system unusable."
779 local check="$id - $desc"
780 starttestjson "$id" "$desc"
781
…lines 782–807 unchanged (26 lines)
808
809check_5_20() {
810 if [ -z "$containers" ]; then
811 return
812 fi
813
814 local id="5.20"
815 local desc="Ensure mount propagation mode is not set to shared (Automated)"
816 local remediation="Do not mount volumes in shared mode propagation."
817 local remediationImpact="None."
818 local check="$id - $desc"
819 starttestjson "$id" "$desc"
820
…lines 821–845 unchanged (25 lines)
846
847check_5_21() {
848 if [ -z "$containers" ]; then
849 return
850 fi
851
852 local id="5.21"
853 local desc="Ensure that the host's UTS namespace is not shared (Automated)"
854 local remediation="You should not start a container with the --uts=host argument."
855 local remediationImpact="None."
856 local check="$id - $desc"
857 starttestjson "$id" "$desc"
858
…lines 859–884 unchanged (26 lines)
885
886check_5_22() {
887 if [ -z "$containers" ]; then
888 return
889 fi
890
891 local id="5.22"
892 local desc="Ensure the default seccomp profile is not Disabled (Automated)"
893 local remediation="By default, seccomp profiles are enabled. You do not need to do anything unless you want to modify and use a modified seccomp profile."
894 local remediationImpact="With Docker 1.10 and greater, the default seccomp profile blocks syscalls, regardless of -- cap-add passed to the container."
895 local check="$id - $desc"
896 starttestjson "$id" "$desc"
897
…lines 898–922 unchanged (25 lines)
923
924check_5_23() {
925 if [ -z "$containers" ]; then
926 return
927 fi
928
929 local id="5.23"
930 local desc="Ensure that docker exec commands are not used with the privileged option (Automated)"
931 local remediation="You should not use the --privileged option in docker exec commands."
932 local remediationImpact="If you need enhanced capabilities within a container, then run it with all the permissions it requires. These should be specified individually."
933 local check="$id - $desc"
934 starttestjson "$id" "$desc"
935
936 note -c "$check"
937 logcheckresult "NOTE"
938}
939
940check_5_24() {
941 if [ -z "$containers" ]; then
942 return
943 fi
944
945 local id="5.24"
946 local desc="Ensure that docker exec commands are not used with the user=root option (Manual)"
947 local remediation="You should not use the --user=root option in docker exec commands."
948 local remediationImpact="None."
949 local check="$id - $desc"
950 starttestjson "$id" "$desc"
951
952 note -c "$check"
953 logcheckresult "NOTE"
954}
955
956check_5_25() {
957 if [ -z "$containers" ]; then
958 return
959 fi
960
961 local id="5.25"
962 local desc="Ensure that cgroup usage is confirmed (Automated)"
963 local remediation="You should not use the --cgroup-parent option within the docker run command unless strictly required."
964 local remediationImpact="None."
965 local check="$id - $desc"
966 starttestjson "$id" "$desc"
967
…lines 968–992 unchanged (25 lines)
993}
994
995check_5_26() {
996 if [ -z "$containers" ]; then
997 return
998 fi
999 local id="5.26"
1000 local desc="Ensure that the container is restricted from acquiring additional privileges (Automated)"
1001 local remediation="You should start your container with the options: docker run --rm -it --security-opt=no-new-privileges ubuntu bash"
1002 local remediationImpact="The no_new_priv option prevents LSMs like SELinux from allowing processes to acquire new privileges."
1003 local check="$id - $desc"
1004 starttestjson "$id" "$desc"
1005
…lines 1006–1038 unchanged (33 lines)
1039
1040check_5_27() {
1041 if [ -z "$containers" ]; then
1042 return
1043 fi
1044
1045 local id="5.27"
1046 local desc="Ensure that container health is checked at runtime (Automated)"
1047 local remediation="You should run the container using the --health-cmd parameter."
1048 local remediationImpact="None."
1049 local check="$id - $desc"
1050 starttestjson "$id" "$desc"
1051
…lines 1052–1073 unchanged (22 lines)
1074
1075check_5_28() {
1076 if [ -z "$containers" ]; then
1077 return
1078 fi
1079
1080 local id="5.28"
1081 local desc="Ensure that Docker commands always make use of the latest version of their image (Manual)"
1082 local remediation="You should use proper version pinning mechanisms (the <latest> tag which is assigned by default is still vulnerable to caching attacks) to avoid extracting cached older versions. Version pinning mechanisms should be used for base images, packages, and entire images. You can customize version pinning rules according to your requirements."
1083 local remediationImpact="None."
1084 local check="$id - $desc"
1085 starttestjson "$id" "$desc"
1086
1087 info -c "$check"
1088 logcheckresult "INFO"
1089}
1090
1091check_5_29() {
1092 if [ -z "$containers" ]; then
1093 return
1094 fi
1095
1096 local id="5.29"
1097 local desc="Ensure that the PIDs cgroup limit is used (Automated)"
1098 local remediation="Use --pids-limit flag with an appropriate value when launching the container."
1099 local remediationImpact="Set the PIDs limit value as appropriate. Incorrect values might leave containers unusable."
1100 local check="$id - $desc"
1101 starttestjson "$id" "$desc"
1102
…lines 1103–1128 unchanged (26 lines)
1129
1130check_5_30() {
1131 if [ -z "$containers" ]; then
1132 return
1133 fi
1134
1135 local id="5.30"
1136 local desc="Ensure that Docker's default bridge 'docker0' is not used (Manual)"
1137 local remediation="You should follow the Docker documentation and set up a user-defined network. All the containers should be run in this network."
1138 local remediationImpact="User-defined networks need to be configured and managed in line with organizational security policy."
1139 local check="$id - $desc"
1140 starttestjson "$id" "$desc"
1141
…lines 1142–1177 unchanged (36 lines)
1178
1179check_5_31() {
1180 if [ -z "$containers" ]; then
1181 return
1182 fi
1183
1184 local id="5.31"
1185 local desc="Ensure that the host's user namespaces are not shared (Automated)"
1186 local remediation="You should not share user namespaces between host and containers."
1187 local remediationImpact="None."
1188 local check="$id - $desc"
1189 starttestjson "$id" "$desc"
1190
…lines 1191–1209 unchanged (19 lines)
1210 logcheckresult "PASS"
1211 return
1212 fi
1213 logcheckresult "WARN" "Containers sharing host user namespace" "$hostns_shared_containers"
1214}
1215
1216check_5_32() {
1217 if [ -z "$containers" ]; then
1218 return
1219 fi
1220
1221 local id="5.32"
1222 local desc="Ensure that the Docker socket is not mounted inside any containers (Automated)"
1223 local remediation="You should ensure that no containers mount docker.sock as a volume."
1224 local remediationImpact="None."
1225 local check="$id - $desc"
1226 starttestjson "$id" "$desc"
1227
…lines 1228–1256 unchanged (29 lines)