遵循CIS Docker Benchmarks规范的开源巡检脚本(内附CIS Docker Benchmarks PDF下载)

1CIS是什么?

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

2Docker Bench Security

Docker Bench for Security[2]是一个开源的脚本。它是基于CIS Docker Benchmark v1.3.1[3]规范的,用于自动化巡检在生产环境中运行Docker容器的数十种常见的最佳实践的脚本。

公众号内回复 cis-docker ,获取CIS出品的CIS_Docker_Benchmark_v1.3.1_PDF

通过调用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       可选   Do not print colors 不打印颜色
-h     可选   Print this help message 打印帮助信息
-l FILE  可选   Log output in FILE, inside container if run using docker 日志输出文件,如果使用docker运行,在容器内部
-u USERS 可选   Comma delimited list of trusted docker user(s) 以逗号分隔的受信任docker用户列表
-c CHECK 可选   Comma delimited list of specific check(s) id 以逗号分隔的指定检查id列表
-e CHECK 可选   Comma delimited list of specific check(s) id to exclude 要排除的以逗号分隔的检查id列表
-i INCLUDE 可选 Comma delimited list of patterns within a container or image name to check 以逗号分隔的容器或图像名称中的模式列表
-x EXCLUDE 可选 Comma delimited list of patterns within a container or image name to exclude from check 容器或图像名称中要排除的以逗号分隔的模式列表
-n LIMIT   可选 In JSON output, when reporting lists of items (containers, images, etc.), limit the number of reported items to LIMIT. Default 0 (no limit).
 在JSON输出中,当报告项目列表(容器,图像等)时,限制报告项目的数量为LIMIT。默认0(无限制)。
-p PRINT   可选 Disable the printing of remediation measures. Default: print remediation measures. 禁用打印补救措施。默认值:打印补救措施。

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

sh docker-bench-security.sh -e check_2_2 # 表示检查所有,除了check_2_2(2.2 Ensure the logging level is set to 'info')

也可以只检查某项

sh docker-bench-security.sh -c check_2_2

使用很简单。

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

构建镜像

git clone https://github.com/docker/docker-bench-security.git
cd docker-bench-security
docker build --no-cache -t docker-bench-security .

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

Docker Desktop for Mac

docker run --rm --net host --pid host --userns host --cap-add audit_control \
    -e DOCKER_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/ \
    --label docker_bench_security \
    docker/docker-bench-security -t devops.v1
# ------------------------------------------------------------------------------
# Docker Bench for Security v1.3.4
#
# Docker, Inc. (c) 2015-
#
# Checks for dozens of common best-practices around deploying Docker containers in production.
# Inspired by the CIS Docker Community Edition Benchmark v1.1.0.
# ------------------------------------------------------------------------------

Initializing Thu Sep  2 04:55:59 UTC 2021

Looking for image devops.v1

[INFO] 1 - Host Configuration
[WARN] 1.1  - Ensure a separate partition for containers has been created
[NOTE] 1.2  - Ensure the container host has been Hardened
....[省略省略过多内容]
[PASS] 7.10  - Ensure management plane traffic has been separated from data plane traffic (Swarm mode not enabled)

[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/

云原生生态圈 · 往期推荐

云原生生态圈之玩转容器系列文章

云原生生态圈之运维架构专辑文章

云原生生态圈之DevOps理论与实践系列文章

云原生生态圈之Kubernetes理论与实践系列文章

云原生生态圈之Go语言系列文章   技术源于生活系列视频

戳“阅读原文”一起来充电吧! 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Docker 通用安全配置指南。 Conventions ......................................................................................................................... 9 Scoring Information ........................................................................................................................................ 9 Profile Definitions ......................................................................................................................................... 10 Acknowledgements ...................................................................................................................................... 11 Recommendations ............................................................................................................................................. 12 1 Host Configuration .................................................................................................................................... 12 1.1 Ensure a separate partition for containers has been created (Scored) .................. 12 1.2 Ensure the container host has been Hardened (Not Scored) ...................................... 14 1.3 Ensure Docker is up to date (Not Scored) .......................................................................... 16 1.4 Ensure only trusted users are allowed to control Docker daemon (Scored) ........ 18 1.5 Ensure auditing is configured for the docker daemon (Scored) ................................ 20 1.6 Ensure auditing is configured for Docker files and directories - /var/lib/docker (Scored) ................................................................................................................................................... 22 1.7 Ensure auditing is configured for Docker files and directories - /etc/docker (Scored) ................................................................................................................................................... 24 1.8 Ensure auditing is configured for Docker files and directories - docker.service (Scored) ................................................................................................................................................... 26 1.9 Ensure auditing is configured for Docker files and directories - docker.socket (Scored) ................................................................................................................................................... 28 1.10 Ensure auditing is configured for Docker files and directories - /etc/default/docker (Scored) ......................................................................................................... 30 1.11 Ensure auditing is configured for Docker files and directories - /etc/docker/daemon.json (Scored) ............................................................................................. 32 1.12 Ensure auditing is configured for Docker files and directories - /usr/bin/docker-containerd (Scored) ........................................................................................ 34
文件清单: CIS Google Kubernetes Engine (GKE) Benchmark v1.0.0.pdf CIS_Aliyun_Linux_2_Benchmark_v1.0.0.pdf CIS_Amazon_Linux_2_Benchmark_v1.0.0.pdf CIS_Amazon_Linux_2_STIG_Benchmark_v1.0.0.pdf CIS_Amazon_Web_Services_Foundations_Benchmark_v1.2.0.pdf CIS_Amazon_Web_Services_Three-tier_Web_Architecture_Benchmark_v1.0.0.pdf CIS_Apache_HTTP_Server_2.4_Benchmark_v1.5.0.pdf CIS_Apache_Tomcat_9_Benchmark_v1.0.0.pdf CIS_Apple_iOS_12_Benchmark_v1.0.0.pdf CIS_Apple_iOS_13_and_iPadOS_13_Benchmark_v1.0.0.pdf CIS_CentOS_Linux_6_Benchmark_v2.1.0.pdf CIS_CentOS_Linux_8_Benchmark_v1.0.0.pdf CIS_Debian_Linux_10_Benchmark_v1.0.0.pdf CIS_Debian_Linux_8_Benchmark_v2.0.1.pdf CIS_Debian_Linux_9_Benchmark_v1.0.1.pdf CIS_Distribution_Independent_Linux_Benchmark_v2.0.0.pdf CIS_Docker_1.13.0_Benchmark_v1.0.0.pdf CIS_Docker_Benchmark_v1.2.0.pdf CIS_Docker_Community_Edition_Benchmark_v1.1.0.pdf CIS_Fedora_28_Family_Linux_Benchmark_v1.0.0.pdf CIS_Google_Android_Benchmark_v1.3.0.pdf CIS_Google_Chrome_Benchmark_v2.0.0.pdf CIS_Google_Cloud_Platform_Foundation_Benchmark_v1.1.0.pdf CIS_Kubernetes_Benchmark_v1.5.1.pdf CIS_Microsoft_Exchange_Server_2016_Benchmark_v1.0.0.pdf CIS_Microsoft_IIS_10_Benchmark_v1.1.1.pdf CIS_Microsoft_SQL_Server_2019_Benchmark_v1.0.0.pdf CIS_Microsoft_Windows_10_Enterprise_Release_1909_Benchmark_v1.8.1.pdf CIS_Microsoft_Windows_7_Workstation_Benchmark_v3.1.0.pdf CIS_Microsoft_Windows_8.1_Workstation_Benchmark_v2.3.0.pdf CIS_Microsoft_Windows_Server_2012_R2_Benchmark_v2.3.0.pdf CIS_Microsoft_Windows_Server_2019_RTM_Release_1809_Benchmark_v1.0.1.pdf CIS_MongoDB_3.4_Benchmark_v1.0.0.pdf CIS_MongoDB_3.6_Benchmark_v1.0.0.pdf CIS_NGINX_Benchmark_v1.0.0.pdf CIS_Oracle_MySQL_Community_Server_5.7_Benchmark_v1.0.0.pdf CIS_Oracle_MySQL_Enterprise_Edition_5.6_Benchmark_v1.1.0.pdf CIS_Oracle_Solaris_11.4_Benchmark_v1.0.0.pdf CIS_PostgreSQL_12_Benchmark_v1.0.0.pdf CIS_Red_Hat_Enterprise_Linux_7_Benchmark_v2.2.0.pdf CIS_Red_Hat_Enterprise_Linux_8_Benchmark_v1.0.0.pdf CIS_Security_Metrics-Quick_Start_Guide_v1.0.0.pdf CIS_Security_Metrics_v1.1.0.pdf CIS_SUSE_Linux_Enterprise_12_Benchmark_v2.1.0.pdf CIS_Ubuntu_Linux_16.04_LTS_Benchmark_v1.1.0.pdf CIS_Ubuntu_Linux_18.04_LTS_Benchmark_v2.0.1.pdf CIS_VMware_ESXi_6.5_Benchmark_v1.0.0.pdf CIS_VMware_ESXi_6.7_Benchmark_v1.0.0.pdf
Docker 1.13 安全配置 ............................................................................................................................................. 11 1 Host Configuration .................................................................................................................................... 11 1.1 Create a separate partition for containers (Scored) ....................................................... 11 1.2 Harden the container host (Not Scored) ............................................................................. 13 1.3 Keep Docker up to date (Not Scored) ................................................................................... 15 1.4 Only allow trusted users to control Docker daemon (Scored) ................................... 16 1.5 Audit docker daemon (Scored) ............................................................................................... 18 1.6 Audit Docker files and directories - /var/lib/docker (Scored) .................................. 20 1.7 Audit Docker files and directories - /etc/docker (Scored) .......................................... 22 1.8 Audit Docker files and directories - docker.service (Scored) ..................................... 24 1.9 Audit Docker files and directories - docker.socket (Scored) ....................................... 26 1.10 Audit Docker files and directories - /etc/default/docker (Scored) ....................... 28 1.11 Audit Docker files and directories - /etc/docker/daemon.json (Scored) ........... 30 1.12 Audit Docker files and directories - /usr/bin/docker-containerd (Scored) ...... 32 1.13 Audit Docker files and directories - /usr/bin/docker-runc (Scored) ................... 34 2 Docker daemon configuration .............................................................................................................. 36 2.1 Restrict network traffic between containers (Scored) .................................................. 36 2.2 Set the logging level (Scored) .................................................................................................. 38 2.3 Allow Docker to make changes to iptables (Scored) ...................................................... 39 2.4 Do not use insecure registries (Scored) .............................................................................. 41

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值