/cybersecurity-skills-zh:implementing-infrastructure-as-code-security-scanningfrom cybersecurity-skills-zh
Scans IaC templates (Terraform, CloudFormation, Kubernetes, Helm) for misconfigurations using Checkov, tfsec, and KICS. Integrates scanning into CI/CD pipelines to block insecure cloud resources before deployment.
Ships in cybersecurity-skills-zh. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them; scripts run unread.
不适用于扫描应用源代码(使用 SAST)、监控已部署基础设施的配置漂移(使用云安全态势管理工具)或容器镜像漏洞扫描(使用 Trivy)。
pip install checkov)或已安装 tfsec# 扫描目录中的所有 Terraform 文件
checkov -d ./terraform/ --framework terraform --output cli --output json --output-file-path ./results
# 扫描特定文件
checkov -f main.tf --output json
# 扫描 Terraform 计划(对动态值更准确)
terraform init && terraform plan -out=tfplan
terraform show -json tfplan > tfplan.json
checkov -f tfplan.json --framework terraform_plan
# 仅运行特定检查
checkov -d ./terraform/ --check CKV_AWS_18,CKV_AWS_19,CKV_AWS_20
# 跳过特定检查
checkov -d ./terraform/ --skip-check CKV_AWS_145,CKV2_AWS_6
# .github/workflows/iac-security.yml
name: IaC Security Scan
on:
pull_request:
paths:
- 'terraform/**'
- 'cloudformation/**'
- 'k8s/**'
jobs:
checkov:
name: Checkov IaC Scan
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run Checkov
uses: bridgecrewio/checkov-action@v12
with:
directory: terraform/
framework: terraform
output_format: cli,sarif
output_file_path: console,checkov.sarif
soft_fail: false
skip_check: CKV_AWS_145
- name: Upload SARIF
if: always()
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: checkov.sarif
category: checkov-iac
tfsec:
name: tfsec Scan
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run tfsec
uses: aquasecurity/[email protected]
with:
working_directory: terraform/
sarif_file: tfsec.sarif
soft_fail: false
- name: Upload SARIF
if: always()
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: tfsec.sarif
category: tfsec
# custom_checks/s3_versioning.py
from checkov.terraform.checks.resource.base_resource_check import BaseResourceCheck
from checkov.common.models.enums import CheckResult, CheckCategories
class S3BucketVersioning(BaseResourceCheck):
def __init__(self):
name = "Ensure S3 bucket has versioning enabled"
id = "CKV_CUSTOM_1"
supported_resources = ["aws_s3_bucket"]
categories = [CheckCategories.GENERAL_SECURITY]
super().__init__(name=name, id=id, categories=categories,
supported_resources=supported_resources)
def scan_resource_conf(self, conf):
versioning = conf.get("versioning", [{}])
if isinstance(versioning, list) and len(versioning) > 0:
if versioning[0].get("enabled", [False])[0]:
return CheckResult.PASSED
return CheckResult.FAILED
check = S3BucketVersioning()
# .checkov.yaml
branch: main
compact: true
directory:
- terraform/
- cloudformation/
framework:
- terraform
- cloudformation
- kubernetes
output:
- cli
- sarif
skip-check:
- CKV_AWS_145 # 使用 CMK 的 S3 默认加密(SSE-S3 可接受)
- CKV2_AWS_6 # S3 存储桶请求日志记录(由 CloudTrail 处理)
soft-fail: false
# 扫描 Kubernetes 清单
checkov -d ./k8s/ --framework kubernetes
# 扫描 Helm charts(先渲染模板)
checkov -d ./charts/myapp/ --framework helm
# 使用 KICS 扫描(Keeping Infrastructure as Code Secure)
docker run -v $(pwd)/k8s:/path checkmarx/kics:latest scan \
--path /path \
--output-path /path/results \
--type Kubernetes \
--report-formats json,sarif
| 术语 | 定义 |
|---|---|
| IaC 扫描 | 对基础设施代码模板进行自动化分析,以在部署前检测安全配置错误 |
| 策略即代码 | 以可执行代码定义的安全策略,可进行版本控制、测试和自动化执行 |
| CKV 检查 ID | Checkov 每个安全检查的唯一标识符(例如,CKV_AWS_18 表示 S3 公共访问) |
| Terraform 计划扫描 | 扫描已解析的 Terraform 计划 JSON,包含计算值和模块展开 |
| 基于图的扫描 | Checkov 分析资源之间关系的能力,而非仅单个资源配置 |
| 配置漂移检测 | 识别 IaC 定义与实际已部署基础设施状态之间的差异 |
| 自定义策略 | 用 Python 或 YAML 编写的组织特定安全检查,用于执行内部标准 |
背景:某开发团队反复创建没有适当访问控制的 S3 存储桶。最近一次事件通过公共存储桶暴露了客户数据。
方法:
aws_s3_bucket_public_access_block 资源soft_fail: false 以在 S3 安全检查失败时阻止 PR 合并注意事项:仅扫描 .tf 文件会遗漏动态计算值。使用 Terraform 计划扫描可获得更高准确性。Checkov 的资源关系检查(CKV2 前缀)需要图分析模式。
IaC 安全扫描报告
==========================
框架:Terraform
目录:terraform/
扫描日期:2026-02-23
Checkov 结果:
通过:187
失败:12
跳过:3
未知:0
失败检查:
CKV_AWS_18 [高危] S3 存储桶具有公共读 ACL
资源:aws_s3_bucket.data_lake
文件:terraform/storage.tf:15-28
CKV_AWS_24 [高危] CloudWatch 日志组未加密
资源:aws_cloudwatch_log_group.app
文件:terraform/monitoring.tf:3-8
CKV_AWS_79 [中危] 已启用实例元数据服务 v1
资源:aws_instance.web
文件:terraform/compute.tf:12-30
质量门禁:失败(2 个高危发现)
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
Terraform, CloudFormation, Kubernetes, Helm, GitHub Actions, AWS, Azure, GCP
npx claudepluginhub killvxk/cybersecurity-skills-zh --plugin cybersecurity-skills-zh735 skills in this plugin
/acquiring-disk-image-with-dd-and-dcfldd使用 dd 和 dcfldd 创建取证级逐位磁盘镜像,通过哈希验证保持证据完整性。/analyzing-active-directory-acl-abuse使用 ldap3 检测 Active Directory 中危险的 ACL 配置错误,识别 GenericAll、WriteDACL 和 WriteOwner 等滥用路径/analyzing-android-malware-with-apktool使用 apktool 进行反编译、jadx 恢复 Java 源码、androguard 进行权限分析,对 Android APK 恶意软件样本执行静态分析,包括清单检查和可疑 API 调用检测。/analyzing-api-gateway-access-logs解析 API 网关访问日志(AWS API Gateway、Kong、Nginx),检测 BOLA/IDOR 攻击、速率限制绕过、凭据扫描和注入尝试。使用 pandas 进行请求模式的统计分析和异常检测。适用于调查 API 滥用或构建 API 专项威胁检测规则。
/analyzing-apt-group-with-mitre-navigator使用 MITRE ATT&CK Navigator 分析高级持续性威胁(APT)组织的技术手法,创建对手 TTP 的分层热力图,用于检测差距分析和威胁导向防御。/analyzing-azure-activity-logs-for-threats通过 azure-monitor-query 查询 Azure Monitor 活动日志和登录日志,检测可疑管理操作、不可能的地理旅行(Impossible Travel)、权限提升和资源修改。为 Azure 环境的威胁狩猎构建 KQL 查询。适用于调查可疑的 Azure 租户活动或构建云 SIEM 检测规则。
Other plugins' skills for the same job