本文へスキップ
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に貼り付けるだけ。AIがスキルを読んで指示に従います。

貼り付け用メッセージ

このスキルを使って手伝ってください:https://github.com/mukul975/Anthropic-Cybersecurity-Skills/blob/main/skills/auditing-terraform-infrastructure-for-security/SKILL.md このリンクのSKILL.mdファイルを読んで、私の作業でその指示に従ってください。
こういうスキルを、AIが自分で見つけてくれたら?無料のSkillpedia MCPをインストール。1行で、作業の前に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

ログイン して投票しましょう。

コメント

  • …

このリポジトリの他のスキル

似ているスキル