CIS[1]即Center for Internet Security (CIS) 为安全基准计划提供了定义明确、公正、基于一致性的行业最佳实践来帮助组织评估和增强其安全性。

 遵循CIS Docker Benchmarks规范的开源巡检脚本 开源 巡检 脚本 第1张

本文转载自微信公众号「云原生生态圈」,作者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. 1_host_configuration.sh
  2. 2_docker_daemon_configuration.sh
  3. 3_docker_daemon_configuration_files.sh
  4. 4_container_images.sh
  5. 5_container_runtime.sh
  6. 6_docker_security_operations.sh
  7. 7_docker_swarm_configuration.sh
  8. 8_docker_enterprise_configuration.sh
  9. 99_community_checks.sh

在docker-bench-security中可以通过修改functions中的脚本选择检查的项,也可以通过命令行选项排除不需要检查的项,下面看下支持的命令行选项.

3命令选项

docker-bench-security

  1. -b可选Donotprintcolors不打印颜色
  2. -h可选Printthishelpmessage打印帮助信息
  3. -lFILE可选LogoutputinFILE,insidecontainerifrunusingdocker日志输出文件,如果使用docker运行,在容器内部
  4. -uUSERS可选Commadelimitedlistoftrusteddockeruser(s)以逗号分隔的受信任docker用户列表
  5. -cCHECK可选Commadelimitedlistofspecificcheck(s)id以逗号分隔的指定检查id列表
  6. -eCHECK可选Commadelimitedlistofspecificcheck(s)idtoexclude要排除的以逗号分隔的检查id列表
  7. -iINCLUDE可选Commadelimitedlistofpatternswithinacontainerorimagenametocheck以逗号分隔的容器或图像名称中的模式列表
  8. -xEXCLUDE可选Commadelimitedlistofpatternswithinacontainerorimagenametoexcludefromcheck容器或图像名称中要排除的以逗号分隔的模式列表
  9. -nLIMIT可选InJSONoutput,whenreportinglistsofitems(containers,images,etc.),limitthenumberofreporteditemstoLIMIT.Default0(nolimit).
  10. 在JSON输出中,当报告项目列表(容器,图像等)时,限制报告项目的数量为LIMIT。默认0(无限制)。
  11. -pPRINT可选Disabletheprintingofremediationmeasures.Default:printremediationmeasures.禁用打印补救措施。默认值:打印补救措施。

每个CIS巡检项在脚本中是以check_<section>_<number>格式命名的. 如果要排除某项检查可以使用

  1. shdocker-bench-security.sh-echeck_2_2#表示检查所有,除了check_2_2(2.2Ensurethelogginglevelissetto'info')

也可以只检查某项

  1. shdocker-bench-security.sh-ccheck_2_2

使用很简单。

在使用的时候可以通过--help查看支持的命令行选项,我在使用的时候发现docker镜像中支持的与git仓库中写的不一致,当然你可以自己打一个镜像。

构建镜像

  1. gitclonehttps://github.com/docker/docker-bench-security.git
  2. cddocker-bench-security
  3. dockerbuild--no-cache-tdocker-bench-security.

下面是在Mac上执行一次巡检的Demo.

Docker Desktop for Mac

  1. dockerrun--rm--nethost--pidhost--usernshost--cap-addaudit_control\
  2. -eDOCKER_CONTENT_TRUST=$DOCKER_CONTENT_TRUST\
  3. -v/var/lib:/var/lib:ro\
  4. -v/var/run/docker.sock:/var/run/docker.sock:ro\
  5. -v`pwd`:/usr/local/bin/log/\
  6. --labeldocker_bench_security\
  7. docker/docker-bench-security-tdevops.v1
  8. #------------------------------------------------------------------------------
  9. #DockerBenchforSecurityv1.3.4
  10. #
  11. #Docker,Inc.(c)2015-
  12. #
  13. #Checksfordozensofcommonbest-practicesarounddeployingDockercontainersinproduction.
  14. #InspiredbytheCISDockerCommunityEditionBenchmarkv1.1.0.
  15. #------------------------------------------------------------------------------
  16. InitializingThuSep204:55:59UTC2021
  17. Lookingforimagedevops.v1
  18. [INFO]1-HostConfiguration
  19. [WARN]1.1-Ensureaseparatepartitionforcontainershasbeencreated
  20. [NOTE]1.2-EnsurethecontainerhosthasbeenHardened
  21. ....[省略省略过多内容]
  22. [PASS]7.10-Ensuremanagementplanetraffichasbeenseparatedfromdataplanetraffic(Swarmmodenotenabled)
  23. [INFO]Checks:105
  24. [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规范的开源巡检脚本

发表评论

您需要后才能发表评论