跳到正文
Skillpedia
部署与云(DevOps)35k · #7684

auditing-terraform-infrastructure-for-security

它能做什么

这个工具可以在你把基础设施代码(Terraform)部署到云端之前,检查其中是否存在安全配置问题。它能帮你找出访问权限过宽、数据未加密或资源被公开暴露等问题。

适用场景

  • ✓当你想把安全检查集成到自动化部署流程(CI/CD)中时。
  • ✓在将 Terraform 代码应用到环境之前,检查它是否遵循安全最佳实践。
  • ✓当你想创建自动化规则,确保基础设施在部署时保持安全配置时。

技能链接

https://github.com/mukul975/Anthropic-Cybersecurity-Skills/blob/main/skills/auditing-terraform-infrastructure-for-security/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/mukul975/Anthropic-Cybersecurity-Skills/blob/main/skills/auditing-terraform-infrastructure-for-security/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“帮我扫描 Terraform 代码中的安全问题,并告诉我哪些地方需要修复。”

每周 5 个新技能,1 分钟读完。

工作原理

这个工具会调用其他程序(Checkov、tfsec、Terrascan 和 OPA)来分析你的 Terraform 代码。它们会查找已知的不安全配置模式,并将其与你可以自定义的安全规则进行比对。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

Auditing Terraform Infrastructure for Security

When to Use

  • When integrating security scanning into CI/CD pipelines for Terraform deployments
  • When reviewing Terraform plans and modules for security best practices before applying
  • When building policy-as-code guardrails for cloud infrastructure provisioning
  • When auditing existing Terraform state files to identify deployed misconfigurations
  • When enforcing organizational security standards across multiple Terraform projects

Do not use for runtime security monitoring (use CSPM tools), for application security testing (use SAST/DAST tools), or for cloud configuration drift detection (use AWS Config or Azure Policy after deployment).

Prerequisites

  • Checkov installed (pip install checkov)
  • tfsec installed (brew install tfsec or binary from GitHub)
  • Terrascan installed (brew install terrascan)
  • Terraform v1.0+ for plan generation
  • OPA (Open Policy Agent) for custom policy enforcement
  • Git repository with Terraform code to audit

Workflow

Step 1: Scan Terraform Code with Checkov

Run Checkov for comprehensive IaC security scanning with built-in and custom policies.

# Scan a Terraform directory
checkov -d ./terraform/ --framework terraform

# Scan with specific check categories
checkov -d ./terraform/ --check CKV_AWS_18,CKV_AWS_19,CKV_AWS_20,CKV_AWS_21

# Scan and output results in JSON
checkov -d ./terraform/ --output json > checkov-results.json

# Scan a Terraform plan file for more accurate analysis
terraform init && terraform plan -out=tfplan
terraform show -json tfplan > tfplan.json
checkov -f tfplan.json --framework terraform_plan

# Skip specific checks with justification
checkov -d ./terraform/ --skip-check CKV_AWS_145 \
  --bc-api-key $BRIDGECREW_API_KEY

# Scan Terraform modules
checkov -d ./modules/ --framework terraform --compact

# List all available checks
checkov --list --framework terraform | grep CKV_AWS

Step 2: Scan with tfsec for Terraform-Specific Issues

Use tfsec for Terraform-native security analysis with detailed remediation guidance.

# Scan a Terraform directory
tfsec ./terraform/

# Scan with minimum severity threshold
tfsec ./terraform/ --minimum-severity HIGH

# Output in JSON for CI/CD processing
tfsec ./terraform/ --format json > tfsec-results.json

# Scan with custom checks
tfsec ./terraform/ --custom-check-dir ./custom-checks/

# Exclude specific rules
tfsec ./terraform/ --exclude-downloaded-modules \
  --exclude aws-s3-enable-bucket-logging

# Scan and fail on specific severity
tfsec ./terraform/ --minimum-severity CRITICAL --soft-fail

# Generate SARIF output for GitHub Security tab
tfsec ./terraform/ --format sarif > tfsec.sarif

Step 3: Run Terrascan for Multi-Framework Compliance

Execute Terrascan for compliance checking against CIS, NIST, and SOC 2 frameworks.

# Scan Terraform against CIS AWS benchmark
terrascan scan -t aws -i terraform -d ./terraform/ \
  --policy-type aws --verbose

# Scan against specific compliance frameworks
terrascan scan -t aws -i terraform -d ./terraform/ \
  --policy-type aws \
  --categories "Compliance Validation"

# Output in JSON
terrascan scan -t aws -i terraform -d ./terraform/ \
  --output json > terrascan-results.json

# Scan a Terraform plan
terrascan scan -t aws -i terraform \
  --iac-file tfplan.json \
  --iac-type tfplan

# List available policies
terrascan scan --list-policies -t aws

Step 4: Create Custom OPA Policies for Organization Standards

Write Rego policies for organization-specific security requirements.

# policy/aws_s3_encryption.rego
package terraform.aws.s3

deny[msg] {
    resource := input.resource.aws_s3_bucket[name]
    not resource.server_side_encryption_configuration
    msg := sprintf("S3 bucket '%s' must have server-side encryption enabled", [name])
}

# policy/aws_iam_no_wildcards.rego
package terraform.aws.iam

deny[msg] {
    resource := input.resource.aws_iam_policy[name]
    statement := resource.policy.Statement[_]
    statement.Action == "*"
    statement.Effect == "Allow"
    msg := sprintf("IAM policy '%s' must not use wildcard (*) actions", [name])
}

deny[msg] {
    resource := input.resource.aws_iam_policy[name]
    statement := resource.policy.Statement[_]
    statement.Resource == "*"
    statement.Effect == "Allow"
    contains(statement.Action[_], "*")
    msg := sprintf("IAM policy '%s' has overly permissive actions on wildcard resources", [name])
}


…
常见问题

什么是 Terraform?

Terraform 是一款工具,让你可以用代码文件来描述和管理云基础设施(比如服务器、数据库),而不必在图形界面里一步步点击操作。

什么是“安全配置错误”?

指的是在搭建基础设施时出现的错误或疏忽,可能让你的系统暴露在攻击之下,例如让数据库任何人都能从互联网上访问。

我可以用它来监控已经运行中的基础设施吗?

不可以。这个工具是用来在部署之前检查代码的。如果要监控正在运行的系统,你需要使用其他专门的工具。

详情

作者的原始描述

Auditing Terraform infrastructure-as-code for security misconfigurations using Checkov, tfsec, Terrascan, and OPA/Rego policies to detect overly permissive IAM policies, public resource exposure, missing encryption, and insecure defaults before cloud deployment. '

repo: mukul975/Anthropic-Cybersecurity-Skills

热度

GitHub 星标
35k
排名
#7684
许可证
Apache-2.0
更新时间
2026/8/31

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能