服务器租用 > 服务器相关 > linux > → 正文内容

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

发布时间:2022-12-25 11:42 整理发布:鸿网互联

CIS是什么?

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

Docker Bench Security

Docker Bench for Security是一个开源的脚本。它是基于CIS Docker Benchmark v1.3.1规范的,用于自动化巡检在生产环境中运行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中的脚本选择检查的项,也可以通过命令行选项排除不需要检查的项,下面看下支持的命令行选项.

命令选项

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_<section>_<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

关注微信公众号·云原生生态圈 查看更多精彩好文

您可能感兴趣的文章: