CIS[1]即Center for Internet Security (CIS) 为安全基准计划提供了定义明确、公正、基于一致性的行业最佳实践来帮助组织评估和增强其安全性。
本文转载自微信公众号「云原生生态圈」,作者Marionxue。转载本文请联系云原生生态圈公众号。
1CIS是什么?
CIS[1]即Center for Internet Security (CIS) 为安全基准计划提供了定义明确、公正、基于一致性的行业最佳实践来帮助组织评估和增强其安全性
2Docker Bench Security
Docker Bench for Security[2]是一个开源的脚本。它是基于CIS Docker Benchmark v1.3.1[3]规范的,用于自动化巡检在生产环境中运行Docker容器的数十种常见的最佳实践的脚本。
通过调用tests目录的以下脚本进行巡检, 具体的巡检的内容可以参考的脚本的内容。
- 1_host_configuration.sh
- 2_docker_daemon_configuration.sh
- 3_docker_daemon_configuration_files.sh
- 4_container_images.sh
- 5_container_runtime.sh
- 6_docker_security_operations.sh
- 7_docker_swarm_configuration.sh
- 8_docker_enterprise_configuration.sh
- 99_community_checks.sh
在docker-bench-security中可以通过修改functions中的脚本选择检查的项,也可以通过命令行选项排除不需要检查的项,下面看下支持的命令行选项.
3命令选项
docker-bench-security
- -b可选Donotprintcolors不打印颜色
- -h可选Printthishelpmessage打印帮助信息
- -lFILE可选LogoutputinFILE,insidecontainerifrunusingdocker日志输出文件,如果使用docker运行,在容器内部
- -uUSERS可选Commadelimitedlistoftrusteddockeruser(s)以逗号分隔的受信任docker用户列表
- -cCHECK可选Commadelimitedlistofspecificcheck(s)id以逗号分隔的指定检查id列表
- -eCHECK可选Commadelimitedlistofspecificcheck(s)idtoexclude要排除的以逗号分隔的检查id列表
- -iINCLUDE可选Commadelimitedlistofpatternswithinacontainerorimagenametocheck以逗号分隔的容器或图像名称中的模式列表
- -xEXCLUDE可选Commadelimitedlistofpatternswithinacontainerorimagenametoexcludefromcheck容器或图像名称中要排除的以逗号分隔的模式列表
- -nLIMIT可选InJSONoutput,whenreportinglistsofitems(containers,images,etc.),limitthenumberofreporteditemstoLIMIT.Default0(nolimit).
- 在JSON输出中,当报告项目列表(容器,图像等)时,限制报告项目的数量为LIMIT。默认0(无限制)。
- -pPRINT可选Disabletheprintingofremediationmeasures.Default:printremediationmeasures.禁用打印补救措施。默认值:打印补救措施。
每个CIS巡检项在脚本中是以check_<section>_<number>格式命名的. 如果要排除某项检查可以使用
- shdocker-bench-security.sh-echeck_2_2#表示检查所有,除了check_2_2(2.2Ensurethelogginglevelissetto'info')
也可以只检查某项
- shdocker-bench-security.sh-ccheck_2_2
使用很简单。
在使用的时候可以通过--help查看支持的命令行选项,我在使用的时候发现docker镜像中支持的与git仓库中写的不一致,当然你可以自己打一个镜像。
构建镜像
- gitclonehttps://github.com/docker/docker-bench-security.git
- cddocker-bench-security
- dockerbuild--no-cache-tdocker-bench-security.
下面是在Mac上执行一次巡检的Demo.
Docker Desktop for Mac
- dockerrun--rm--nethost--pidhost--usernshost--cap-addaudit_control\
- -eDOCKER_CONTENT_TRUST=$DOCKER_CONTENT_TRUST\
- -v/var/lib:/var/lib:ro\
- -v/var/run/docker.sock:/var/run/docker.sock:ro\
- -v`pwd`:/usr/local/bin/log/\
- --labeldocker_bench_security\
- docker/docker-bench-security-tdevops.v1
- #------------------------------------------------------------------------------
- #DockerBenchforSecurityv1.3.4
- #
- #Docker,Inc.(c)2015-
- #
- #Checksfordozensofcommonbest-practicesarounddeployingDockercontainersinproduction.
- #InspiredbytheCISDockerCommunityEditionBenchmarkv1.1.0.
- #------------------------------------------------------------------------------
- InitializingThuSep204:55:59UTC2021
- Lookingforimagedevops.v1
- [INFO]1-HostConfiguration
- [WARN]1.1-Ensureaseparatepartitionforcontainershasbeencreated
- [NOTE]1.2-EnsurethecontainerhosthasbeenHardened
- ....[省略省略过多内容]
- [PASS]7.10-Ensuremanagementplanetraffichasbeenseparatedfromdataplanetraffic(Swarmmodenotenabled)
- [INFO]Checks:105
- [INFO]Score:7
参考资料
[1]Center for Internet Security (CIS): https://www.cisecurity.org/
[2]Docker bench security: https://github.com/docker/docker-bench-security
[3]CIS Docker Benchmark: https://www.cisecurity.org/benchmark/docker/
知优网 » 遵循CIS Docker Benchmarks规范的开源巡检脚本