遵循CIS Docker Benchmarks規(guī)范的開源巡檢腳本
本文轉載自微信公眾號「云原生生態(tài)圈」,作者Marionxue。轉載本文請聯(lián)系云原生生態(tài)圈公眾號。
1CIS是什么?
CIS[1]即Center for Internet Security (CIS) 為安全基準計劃提供了定義明確、公正、基于一致性的行業(yè)最佳實踐來幫助組織評估和增強其安全性
2Docker Bench Security
Docker Bench for Security[2]是一個開源的腳本。它是基于CIS Docker Benchmark v1.3.1[3]規(guī)范的,用于自動化巡檢在生產環(huán)境中運行Docker容器的數(shù)十種常見的最佳實踐的腳本。
通過調用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輸出中,當報告項目列表(容器,圖像等)時,限制報告項目的數(shù)量為LIMIT。默認0(無限制)。
- -p PRINT 可選 Disable the printing of remediation measures. Default: print remediation measures. 禁用打印補救措施。默認值:打印補救措施。
每個CIS巡檢項在腳本中是以check_<section>_<number>格式命名的. 如果要排除某項檢查可以使用
也可以只檢查某項 使用很簡單。 在使用的時候可以通過--help查看支持的命令行選項,我在使用的時候發(fā)現(xiàn)docker鏡像中支持的與git倉庫中寫的不一致,當然你可以自己打一個鏡像。 下面是在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/構建鏡像
Docker Desktop for Mac