遵循CIS Docker Benchmarks規(guī)范的開(kāi)源巡檢腳本
本文轉(zhuǎn)載自微信公眾號(hào)「云原生生態(tài)圈」,作者M(jìn)arionxue。轉(zhuǎn)載本文請(qǐng)聯(lián)系云原生生態(tài)圈公眾號(hào)。
1CIS是什么?
CIS[1]即Center for Internet Security (CIS) 為安全基準(zhǔn)計(jì)劃提供了定義明確、公正、基于一致性的行業(yè)最佳實(shí)踐來(lái)幫助組織評(píng)估和增強(qiáng)其安全性
2Docker Bench Security
Docker Bench for Security[2]是一個(gè)開(kāi)源的腳本。它是基于CIS Docker Benchmark v1.3.1[3]規(guī)范的,用于自動(dòng)化巡檢在生產(chǎn)環(huán)境中運(yùn)行Docker容器的數(shù)十種常見(jiàn)的最佳實(shí)踐的腳本。
通過(guò)調(diào)用tests目錄的以下腳本進(jìn)行巡檢, 具體的巡檢的內(nèi)容可以參考的腳本的內(nèi)容。
- 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中可以通過(guò)修改functions中的腳本選擇檢查的項(xiàng),也可以通過(guò)命令行選項(xiàng)排除不需要檢查的項(xiàng),下面看下支持的命令行選項(xiàng).
3命令選項(xiàng)
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運(yùn)行,在容器內(nèi)部
- -u USERS 可選 Comma delimited list of trusted docker user(s) 以逗號(hào)分隔的受信任docker用戶列表
- -c CHECK 可選 Comma delimited list of specific check(s) id 以逗號(hào)分隔的指定檢查id列表
- -e CHECK 可選 Comma delimited list of specific check(s) id to exclude 要排除的以逗號(hào)分隔的檢查id列表
- -i INCLUDE 可選 Comma delimited list of patterns within a container or image name to check 以逗號(hào)分隔的容器或圖像名稱中的模式列表
- -x EXCLUDE 可選 Comma delimited list of patterns within a container or image name to exclude from check 容器或圖像名稱中要排除的以逗號(hào)分隔的模式列表
- -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輸出中,當(dāng)報(bào)告項(xiàng)目列表(容器,圖像等)時(shí),限制報(bào)告項(xiàng)目的數(shù)量為L(zhǎng)IMIT。默認(rèn)0(無(wú)限制)。
- -p PRINT 可選 Disable the printing of remediation measures. Default: print remediation measures. 禁用打印補(bǔ)救措施。默認(rèn)值:打印補(bǔ)救措施。
每個(gè)CIS巡檢項(xiàng)在腳本中是以check_<section>_<number>格式命名的. 如果要排除某項(xiàng)檢查可以使用
也可以只檢查某項(xiàng) 使用很簡(jiǎn)單。 在使用的時(shí)候可以通過(guò)--help查看支持的命令行選項(xiàng),我在使用的時(shí)候發(fā)現(xiàn)docker鏡像中支持的與git倉(cāng)庫(kù)中寫(xiě)的不一致,當(dāng)然你可以自己打一個(gè)鏡像。 下面是在Mac上執(zhí)行一次巡檢的Demo. 參考資料 [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/構(gòu)建鏡像
Docker Desktop for Mac




























