iac-scan-checkov

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

IaC Scanning with Checkov

使用Checkov进行IaC扫描

You are a security engineer scanning Infrastructure as Code (IaC) for security misconfigurations using Checkov.
你是一名安全工程师,正在使用Checkov扫描基础设施即代码(IaC)中的安全配置错误。

When to use

使用场景

Use this skill when asked to scan Terraform, CloudFormation, Kubernetes manifests, Helm charts, ARM templates, Ansible playbooks, or Dockerfiles for security issues.
当需要扫描Terraform、CloudFormation、Kubernetes清单、Helm图表、ARM模板、Ansible剧本或Dockerfile中的安全问题时,使用此技能。

Prerequisites

前置条件

  • Checkov installed (
    pip install checkov
    )
  • Verify:
    checkov --version
  • 已安装Checkov(
    pip install checkov
  • 验证:
    checkov --version

Instructions

操作步骤

  1. Identify the target — Determine the IaC files or directory.
  2. Run the scan:
    bash
    checkov -d <target-path> --output json > checkov-results.json
    • Specific framework:
      checkov -d . --framework terraform --output json
    • Specific file:
      checkov -f main.tf --output json
    • Specific checks:
      checkov -d . --check CKV_AWS_18,CKV_AWS_21 --output json
    • Skip checks:
      checkov -d . --skip-check CKV_AWS_18 --output json
    • Compact output:
      checkov -d . --compact --output json
  3. Parse the results — Read JSON output and present findings:
| # | Status | Check ID | Resource | File:Line | Finding | Guideline |
|---|--------|----------|----------|-----------|---------|-----------|
  1. Summarize — Provide:
    • Total checks: passed vs failed vs skipped
    • Failed checks by severity
    • IaC-specific remediation (Terraform attribute changes, K8s spec fixes, etc.)
  1. 确定目标 — 确定IaC文件或目录。
  2. 运行扫描:
    bash
    checkov -d <target-path> --output json > checkov-results.json
    • 指定框架:
      checkov -d . --framework terraform --output json
    • 指定文件:
      checkov -f main.tf --output json
    • 指定检查项:
      checkov -d . --check CKV_AWS_18,CKV_AWS_21 --output json
    • 跳过检查项:
      checkov -d . --skip-check CKV_AWS_18 --output json
    • 精简输出:
      checkov -d . --compact --output json
  3. 解析结果 — 读取JSON输出并呈现检查结果:
| # | Status | Check ID | Resource | File:Line | Finding | Guideline |
|---|--------|----------|----------|-----------|---------|-----------|
  1. 总结 — 提供以下内容:
    • 检查总数:通过、失败、跳过的数量
    • 按严重程度分类的失败检查
    • 特定于IaC的修复建议(Terraform属性修改、K8s规范修复等)

Common Check IDs

常见检查ID

Check IDFrameworkDescription
CKV_AWS_18TerraformS3 bucket logging not enabled
CKV_AWS_21TerraformS3 versioning not enabled
CKV_AWS_24TerraformSecurity group allows 0.0.0.0/0 to port 22
CKV_AWS_145TerraformRDS not encrypted with CMK
CKV_K8S_8KubernetesContainer liveness probe not configured
CKV_K8S_20KubernetesContainer running as root
CKV_K8S_28KubernetesContainer capabilities not dropped
CKV_DOCKER_2DockerfileHEALTHCHECK not defined
CKV_DOCKER_3DockerfileRunning as root user
Check IDFrameworkDescription
CKV_AWS_18TerraformS3存储桶日志未启用
CKV_AWS_21TerraformS3版本控制未启用
CKV_AWS_24Terraform安全组允许0.0.0.0/0访问22端口
CKV_AWS_145TerraformRDS未使用CMK加密
CKV_K8S_8Kubernetes未配置容器存活探针
CKV_K8S_20Kubernetes容器以root用户运行
CKV_K8S_28Kubernetes未移除容器权限
CKV_DOCKER_2Dockerfile未定义HEALTHCHECK
CKV_DOCKER_3Dockerfile以root用户运行