|
144 | 144 | desc 'Verify that the \'docker.service\' file ownership and group-ownership are correctly set to \'root\'' |
145 | 145 | ref 'https://docs.docker.com/engine/admin/systemd/' |
146 | 146 |
|
147 | | - describe file(command('systemctl show -p FragmentPath docker.service').stdout.split('=')[1].delete("\n")) do |
| 147 | + describe file(docker.path) do |
148 | 148 | it { should exist } |
149 | 149 | it { should be_file } |
150 | 150 | it { should be_owned_by 'root' } |
|
158 | 158 | desc 'Verify that the \'docker.service\' file permissions are correctly set to \'644\' or more restrictive' |
159 | 159 | ref 'https://docs.docker.com/engine/admin/systemd/' |
160 | 160 |
|
161 | | - describe file(command('systemctl show -p FragmentPath docker.service').stdout.split('=')[1].delete("\n")) do |
| 161 | + describe file(docker.path) do |
162 | 162 | it { should exist } |
163 | 163 | it { should be_file } |
164 | 164 | it { should be_readable.by('owner') } |
|
179 | 179 | ref 'https://github.com/YungSang/fedora-atomic-packer/blob/master/oem/docker.socket' |
180 | 180 | ref 'https://daviddaeschler.com/2014/12/14/centos-7rhel-7-and-docker-containers-on-boot/' |
181 | 181 |
|
182 | | - describe file(command('systemctl show -p FragmentPath docker.socket').stdout.split('=')[1].delete("\n")) do |
| 182 | + describe file(docker.socket) do |
183 | 183 | it { should exist } |
184 | 184 | it { should be_file } |
185 | 185 | it { should be_owned_by 'root' } |
|
195 | 195 | ref 'https://github.com/YungSang/fedora-atomic-packer/blob/master/oem/docker.socket' |
196 | 196 | ref 'https://daviddaeschler.com/2014/12/14/centos-7rhel-7-and-docker-containers-on-boot/' |
197 | 197 |
|
198 | | - describe file(command('systemctl show -p FragmentPath docker.service').stdout.split('=')[1].delete("\n")) do |
| 198 | + describe file(docker.path) do |
199 | 199 | it { should exist } |
200 | 200 | it { should be_file } |
201 | 201 | it { should be_readable.by('owner') } |
|
502 | 502 | ref 'https://github.com/docker/docker/issues/7906' |
503 | 503 | ref 'https://www.altiscale.com/blog/making-docker-work-yarn/' |
504 | 504 |
|
505 | | - ids = command('docker ps --format "{{.ID}}"').stdout.split |
506 | | - ids.each do |id| |
507 | | - raw = command("docker inspect #{id}").stdout |
508 | | - info = json('').parse(raw) |
509 | | - describe info[0] do |
| 505 | + docker.ps.each do |id| |
| 506 | + describe docker.inspect(id) do |
510 | 507 | its(%w(Config User)) { should eq attrs['CONTAINER_USER'] } |
511 | 508 | its(%w(Config User)) { should_not eq nil } |
512 | 509 | end |
|
550 | 547 | ref 'http://man7.org/linux/man-pages/man7/capabilities.7.html' |
551 | 548 | ref 'https://github.com/docker/docker/blob/master/oci/defaults_linux.go#L64-L79' |
552 | 549 |
|
553 | | - ids = command('docker ps --format "{{.ID}}"').stdout.split |
554 | | - ids.each do |id| |
555 | | - raw = command("docker inspect #{id}").stdout |
556 | | - info = json('').parse(raw) |
557 | | - describe info[0] do |
| 550 | + docker.ps.each do |id| |
| 551 | + describe docker.inspect(id) do |
558 | 552 | its(%w(HostConfig CapDrop)) { should include(/all/) } |
559 | 553 | its(%w(HostConfig CapDrop)) { should_not eq nil } |
560 | 554 | its(%w(HostConfig CapAdd)) { should eq attrs['CONTAINER_CAPADD'] } |
|
568 | 562 | desc 'Using the --privileged flag gives all Linux Kernel Capabilities to the container thus overwriting the --cap-add and --cap-drop flags. Ensure that it is not used.' |
569 | 563 | ref 'https://docs.docker.com/engine/reference/commandline/cli/' |
570 | 564 |
|
571 | | - ids = command('docker ps --format "{{.ID}}"').stdout.split |
572 | | - ids.each do |id| |
573 | | - raw = command("docker inspect #{id}").stdout |
574 | | - info = json('').parse(raw) |
575 | | - describe info[0] do |
| 565 | + docker.ps.each do |id| |
| 566 | + describe docker.inspect(id) do |
576 | 567 | its(%w(HostConfig Privileged)) { should eq false } |
577 | 568 | its(%w(HostConfig Privileged)) { should_not eq true } |
578 | 569 | end |
|
585 | 576 | desc 'Sensitive host system directories such as \'/, /boot, /dev, /etc, /lib, /proc, /sys, /usr\' should not be allowed to be mounted as container volumes especially in read-write mode.' |
586 | 577 | ref 'https://docs.docker.com/engine/userguide/containers/dockervolumes/' |
587 | 578 |
|
588 | | - ids = command('docker ps --format "{{.ID}}"').stdout.split |
589 | | - ids.each do |id| |
590 | | - raw = command("docker inspect #{id}").stdout |
591 | | - info = json('').parse(raw) |
592 | | - info[0]['Mounts'].each do |mounts| |
| 579 | + docker.ps.each do |id| |
| 580 | + info = docker.inspect(id) |
| 581 | + info['Mounts'].each do |mounts| |
593 | 582 | describe mounts['Source'] do |
594 | 583 | it { should_not eq '/' } |
595 | 584 | it { should_not match(/\/boot/) } |
|
610 | 599 | desc 'SSH server should not be running within the container. You should SSH into the Docker host, and use nsenter tool to enter a container from a remote host.' |
611 | 600 | ref 'https://blog.docker.com/2014/06/why-you-dont-need-to-run-sshd-in-docker/' |
612 | 601 |
|
613 | | - ids = command('docker ps --format "{{.ID}}"').stdout.split |
614 | | - ids.each do |id| |
| 602 | + docker.ps.each do |id| |
615 | 603 | execute_command = 'docker exec ' << id << ' ps -e' |
616 | 604 | describe command(execute_command) do |
617 | 605 | its('stdout') { should_not match(/ssh/) } |
|
626 | 614 | ref 'https://docs.docker.com/engine/userguide/networking/default_network/binding/' |
627 | 615 | ref 'https://www.adayinthelifeof.nl/2012/03/12/why-putting-ssh-on-another-port-than-22-is-bad-idea/' |
628 | 616 |
|
629 | | - ids = command('docker ps --format "{{.ID}}"').stdout.split |
630 | | - ids.each do |id| |
631 | | - raw = command("docker inspect #{id}").stdout |
632 | | - info = json('').parse(raw) |
633 | | - ports = info[0]['NetworkSettings']['Ports'].keys |
| 617 | + docker.ps.each do |id| |
| 618 | + info = docker.inspect(id) |
| 619 | + ports = info['NetworkSettings']['Ports'].keys |
634 | 620 | ports.each do |item| |
635 | | - info[0]['NetworkSettings']['Ports'][item].each do |hostport| |
| 621 | + info['NetworkSettings']['Ports'][item].each do |hostport| |
636 | 622 | describe hostport['HostPort'].to_i.between?(1, 1024) do |
637 | 623 | it { should eq false } |
638 | 624 | end |
|
655 | 641 | ref 'https://docs.docker.com/engine/userguide/networking/dockernetworks/' |
656 | 642 | ref 'https://github.com/docker/docker/issues/6401' |
657 | 643 |
|
658 | | - ids = command('docker ps --format "{{.ID}}"').stdout.split |
659 | | - ids.each do |id| |
660 | | - raw = command("docker inspect #{id}").stdout |
661 | | - info = json('').parse(raw) |
662 | | - describe info[0] do |
| 644 | + docker.ps.each do |id| |
| 645 | + describe docker.inspect(id) do |
663 | 646 | its(%w(HostConfig NetworkMode)) { should_not eq 'host' } |
664 | 647 | end |
665 | 648 | end |
|
673 | 656 | ref 'https://docs.docker.com/engine/reference/commandline/cli/#run' |
674 | 657 | ref 'https://docs.docker.com/v1.8/articles/runmetrics/' |
675 | 658 |
|
676 | | - ids = command('docker ps --format "{{.ID}}"').stdout.split |
677 | | - ids.each do |id| |
678 | | - raw = command("docker inspect #{id}").stdout |
679 | | - info = json('').parse(raw) |
680 | | - describe info[0] do |
| 659 | + docker.ps.each do |id| |
| 660 | + describe docker.inspect(id) do |
681 | 661 | its(%w(HostConfig Memory)) { should_not eq 0 } |
682 | 662 | end |
683 | 663 | end |
|
691 | 671 | ref 'https://docs.docker.com/engine/reference/commandline/cli/#run' |
692 | 672 | ref 'https://docs.docker.com/v1.8/articles/runmetrics/' |
693 | 673 |
|
694 | | - ids = command('docker ps --format "{{.ID}}"').stdout.split |
695 | | - ids.each do |id| |
696 | | - raw = command("docker inspect #{id}").stdout |
697 | | - info = json('').parse(raw) |
698 | | - describe info[0] do |
| 674 | + docker.ps.each do |id| |
| 675 | + describe docker.inspect(id) do |
699 | 676 | its(%w(HostConfig CpuShares)) { should_not eq 0 } |
700 | 677 | its(%w(HostConfig CpuShares)) { should_not eq 1024 } |
701 | 678 | end |
|
708 | 685 | desc 'The container\'s root file system should be treated as a \'golden image\' and any writes to the root filesystem should be avoided. You should explicitly define a container volume for writing.' |
709 | 686 | ref 'https://docs.docker.com/engine/reference/commandline/cli/#run' |
710 | 687 |
|
711 | | - ids = command('docker ps --format "{{.ID}}"').stdout.split |
712 | | - ids.each do |id| |
713 | | - raw = command("docker inspect #{id}").stdout |
714 | | - info = json('').parse(raw) |
715 | | - describe info[0] do |
| 688 | + docker.ps.each do |id| |
| 689 | + describe docker.inspect(id) do |
716 | 690 | its(%w(HostConfig ReadonlyRootfs)) { should eq true } |
717 | 691 | end |
718 | 692 | end |
|
724 | 698 | desc 'By default, Docker containers can make connections to the outside world, but the outside world cannot connect to containers. Each outgoing connection will appear to originate from one of the host machine\'s own IP addresses. Only allow container services to be contacted through a specific external interface on the host machine.' |
725 | 699 | ref 'https://docs.docker.com/engine/userguide/networking/default_network/binding/' |
726 | 700 |
|
727 | | - ids = command('docker ps --format "{{.ID}}"').stdout.split |
728 | | - ids.each do |id| |
729 | | - raw = command("docker inspect #{id}").stdout |
730 | | - info = json('').parse(raw) |
731 | | - ports = info[0]['NetworkSettings']['Ports'].keys |
| 701 | + docker.ps.each do |id| |
| 702 | + info = docker.inspect(id) |
| 703 | + ports = info['NetworkSettings']['Ports'].keys |
732 | 704 | ports.each do |item| |
733 | | - info[0]['NetworkSettings']['Ports'][item].each do |hostip| |
| 705 | + info['NetworkSettings']['Ports'][item].each do |hostip| |
734 | 706 | describe hostip['HostIp'] do |
735 | 707 | it { should_not eq '0.0.0.0' } |
736 | 708 | end |
|
745 | 717 | desc 'Using the \'--restart\' flag in \'docker run\' command you can specify a restart policy for how a container should or should not be restarted on exit. You should choose the \'on-failure\' restart policy and limit the restart attempts to 5.' |
746 | 718 | ref 'https://docs.docker.com/engine/reference/commandline/cli/#restart-policies' |
747 | 719 |
|
748 | | - ids = command('docker ps --format "{{.ID}}"').stdout.split |
749 | | - ids.each do |id| |
750 | | - raw = command("docker inspect #{id}").stdout |
751 | | - info = json('').parse(raw) |
752 | | - only_if { info[0]['HostConfig']['RestartPolicy']['Name'] != 'no' } |
753 | | - describe info[0] do |
| 720 | + docker.ps.each do |id| |
| 721 | + info = docker.inspect(id) |
| 722 | + only_if { info['HostConfig']['RestartPolicy']['Name'] != 'no' } |
| 723 | + describe info do |
754 | 724 | its(%w(HostConfig RestartPolicy Name)) { should eq 'on-failure' } |
755 | 725 | end |
756 | | - describe info[0] do |
| 726 | + describe info do |
757 | 727 | its(%w(HostConfig RestartPolicy MaximumRetryCount)) { should eq 5 } |
758 | 728 | end |
759 | 729 | end |
|
766 | 736 | ref 'https://docs.docker.com/engine/reference/run/#pid-settings' |
767 | 737 | ref 'http://man7.org/linux/man-pages/man7/pid_namespaces.7.html' |
768 | 738 |
|
769 | | - ids = command('docker ps --format "{{.ID}}"').stdout.split |
770 | | - ids.each do |id| |
771 | | - raw = command("docker inspect #{id}").stdout |
772 | | - info = json('').parse(raw) |
773 | | - describe info[0] do |
| 739 | + docker.ps.each do |id| |
| 740 | + describe docker.inspect(id) do |
774 | 741 | its(%w(HostConfig PidMode)) { should_not eq 'host' } |
775 | 742 | end |
776 | 743 | end |
|
783 | 750 | ref 'https://docs.docker.com/engine/reference/run/#ipc-settings' |
784 | 751 | ref 'http://man7.org/linux/man-pages/man7/pid_namespaces.7.html' |
785 | 752 |
|
786 | | - ids = command('docker ps --format "{{.ID}}"').stdout.split |
787 | | - ids.each do |id| |
788 | | - raw = command("docker inspect #{id}").stdout |
789 | | - info = json('').parse(raw) |
790 | | - describe info[0] do |
| 753 | + docker.ps.each do |id| |
| 754 | + describe docker.inspect(id) do |
791 | 755 | its(%w(HostConfig IpcMode)) { should_not eq 'host' } |
792 | 756 | end |
793 | 757 | end |
|
799 | 763 | desc 'Host devices can be directly exposed to containers at runtime. Do not directly expose host devices to containers especially for containers that are not trusted.' |
800 | 764 | ref 'https://docs.docker.com/engine/reference/commandline/cli/#run' |
801 | 765 |
|
802 | | - ids = command('docker ps --format "{{.ID}}"').stdout.split |
803 | | - ids.each do |id| |
804 | | - raw = command("docker inspect #{id}").stdout |
805 | | - info = json('').parse(raw) |
806 | | - describe info[0] do |
| 766 | + docker.ps.each do |id| |
| 767 | + describe docker.inspect(id) do |
807 | 768 | its(%w(HostConfig Devices)) { should be_empty } |
808 | 769 | end |
809 | 770 | end |
|
815 | 776 | desc 'The default ulimit is set at the Docker daemon level. However, you may override the default ulimit setting, if needed, during container runtime.' |
816 | 777 | ref 'https://docs.docker.com/engine/reference/commandline/cli/#setting-ulimits-in-a-container' |
817 | 778 |
|
818 | | - ids = command('docker ps --format "{{.ID}}"').stdout.split |
819 | | - ids.each do |id| |
820 | | - raw = command("docker inspect #{id}").stdout |
821 | | - info = json('').parse(raw) |
822 | | - describe info[0] do |
| 779 | + docker.ps.each do |id| |
| 780 | + describe docker.inspect(id) do |
823 | 781 | its(%w(HostConfig Ulimits)) { should eq nil } |
824 | 782 | end |
825 | 783 | end |
|
833 | 791 | ref 'https://docs.docker.com/engine/reference/run/' |
834 | 792 | ref 'https://www.kernel.org/doc/Documentation/filesystems/sharedsubtree.txt' |
835 | 793 |
|
836 | | - ids = command('docker ps --format "{{.ID}}"').stdout.split |
837 | | - ids.each do |id| |
| 794 | + docker.ps.each do |id| |
838 | 795 | raw = command("docker inspect --format '{{range $mnt := .Mounts}} {{json $mnt.Propagation}} {{end}}' #{id}").stdout |
839 | 796 | describe raw.delete("\n").delete('\"').delete(' ') do |
840 | 797 | it { should_not eq 'shared' } |
|
849 | 806 | ref 'https://docs.docker.com/engine/reference/run/' |
850 | 807 | ref 'http://man7.org/linux/man-pages/man7/pid_namespaces.7.html' |
851 | 808 |
|
852 | | - ids = command('docker ps --format "{{.ID}}"').stdout.split |
853 | | - ids.each do |id| |
854 | | - raw = command("docker inspect #{id}").stdout |
855 | | - info = json('').parse(raw) |
856 | | - describe info[0] do |
| 809 | + docker.ps.each do |id| |
| 810 | + describe docker.inspect(id) do |
857 | 811 | its(%w(HostConfig UTSMode)) { should_not eq 'host' } |
858 | 812 | end |
859 | 813 | end |
|
870 | 824 | ref 'https://www.kernel.org/doc/Documentation/prctl/seccomp_filter.txt' |
871 | 825 | ref 'https://github.com/docker/docker/pull/17034' |
872 | 826 |
|
873 | | - ids = command('docker ps --format "{{.ID}}"').stdout.split |
874 | | - ids.each do |id| |
875 | | - raw = command("docker inspect #{id}").stdout |
876 | | - info = json('').parse(raw) |
877 | | - describe info[0] do |
| 827 | + docker.ps.each do |id| |
| 828 | + describe docker.inspect(id) do |
878 | 829 | its(%w(HostConfig SecurityOpt)) { should include(/seccomp/) } |
879 | 830 | its(%w(HostConfig SecurityOpt)) { should_not include(/seccomp[=|:]unconfined/) } |
880 | 831 | end |
|
888 | 839 | ref 'https://docs.docker.com/engine/reference/run/#specifying-custom-cgroups' |
889 | 840 | ref 'https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Resource_Management_Guide/ch01.html' |
890 | 841 |
|
891 | | - ids = command('docker ps --format "{{.ID}}"').stdout.split |
892 | | - ids.each do |id| |
893 | | - raw = command("docker inspect #{id}").stdout |
894 | | - info = json('').parse(raw) |
895 | | - describe info[0] do |
| 842 | + docker.ps.each do |id| |
| 843 | + describe docker.inspect(id) do |
896 | 844 | its(%w(HostConfig CgroupParent)) { should be_empty } |
897 | 845 | end |
898 | 846 | end |
|
908 | 856 | ref 'https://lwn.net/Articles/475678/' |
909 | 857 | ref 'https://lwn.net/Articles/475362/' |
910 | 858 |
|
911 | | - ids = command('docker ps --format "{{.ID}}"').stdout.split |
912 | | - ids.each do |id| |
913 | | - raw = command("docker inspect #{id}").stdout |
914 | | - info = json('').parse(raw) |
915 | | - describe info[0] do |
| 859 | + docker.ps.each do |id| |
| 860 | + describe docker.inspect(id) do |
916 | 861 | its(%w(HostConfig SecurityOpt)) { should include(/no-new-privileges/) } |
917 | 862 | end |
918 | 863 | end |
|
0 commit comments