hubertwojcik/cloud-defense-in-depth

GitHub: hubertwojcik/cloud-defense-in-depth

一个用于跨多安全层检测和修复云环境配置错误的深度防御框架。

Stars: 0 | Forks: 0

# 云深度防御框架 一个用于跨多个安全层检测和修复云环境配置错误的深度防御框架。该项目演示了如何通过结合基础设施即代码策略执行、云安全态势管理工具、CI/CD安全门禁和运行时监控,形成分层控制,从而在AWS环境中减少配置错误的爆炸半径。 ## 架构 该框架由四个连续的防御层组成: ``` ┌─────────────────────────────────────────────────────────────┐ │ Layer 1 — PREVENTION │ │ Checkov · tfsec · OPA/Rego │ │ Blocks misconfigs in Terraform code before deployment │ ├─────────────────────────────────────────────────────────────┤ │ Layer 2 — DETECTION (CI/CD) │ │ Prowler · Trivy · GitHub Security tab (SARIF) │ │ Scans IaC and live AWS environment, surfaces findings │ ├─────────────────────────────────────────────────────────────┤ │ Layer 3 — RUNTIME MONITORING │ │ AWS Security Hub · EventBridge · SNS │ │ Aggregates findings at runtime, alerts on HIGH/CRITICAL │ ├─────────────────────────────────────────────────────────────┤ │ Layer 4 — REMEDIATION │ │ Scenario runbooks · before/after Terraform · IAM guidance │ │ Actionable fix guidance for each misconfiguration type │ └─────────────────────────────────────────────────────────────┘ ``` ## 技术栈 | 类别 | 工具 | |---|---| | 基础设施 / IaC | Terraform | | 策略执行 | OPA (Open Policy Agent), Checkov, tfsec | | CSPM / 扫描 | Prowler, Trivy | | 运行时监控 | AWS Security Hub, EventBridge, SNS | | CI/CD | GitHub Actions | | 云平台 | AWS(主要) | | 报告 | SARIF, GitHub Security 选项卡 | ## 仓库结构 ``` . ├── terraform/ # Base AWS demo environment │ └── security_hub.tf # AWS Security Hub provisioning ├── opa/ # OPA/Rego policies and unit tests │ └── tests/ ├── scenarios/ # Misconfiguration test cases │ ├── s3-public-access/ │ ├── iam-wildcard/ │ └── open-security-group/ ├── .github/ │ └── workflows/ │ └── security-gates.yml # CI/CD scanning pipeline └── docs/ ├── architecture.md ├── policies.md ├── runtime-monitoring.md ├── security-tab.md ├── remediation-runbooks.md └── lessons-learned.md ``` ## 配置错误场景 每个场景都位于 `scenarios/` 目录中,包含故意配置错误的Terraform代码、逐层分析哪些工具能捕获该错误,以及修复操作手册。 | 场景 | 风险 | 捕获工具 | |---|---|---| | S3 公开访问 | 数据泄露 | OPA, Checkov, tfsec, Prowler, Security Hub | | 过度授权的 IAM 角色 | 权限提升 | OPA, Checkov, tfsec | | 开放的安全组 (0.0.0.0/0) | 未授权访问 | OPA, Checkov, tfsec, Prowler | ## CI/CD 安全门禁 GitHub Actions 工作流 (`.github/workflows/security-gates.yml`) 在每次推送和拉取请求时运行: ``` push / pull_request │ ├── checkov → SARIF → GitHub Security tab ├── tfsec → SARIF → GitHub Security tab ├── opa → policy evaluation ├── trivy → SARIF → GitHub Security tab └── prowler → SARIF + HTML artifact ``` 任何违规操作都会阻止合并。 ## 里程碑 | # | 里程碑 | 描述 | |---|---|---| | 1 | 基础与架构 | 仓库结构、Terraform 基础、架构文档、CI 骨架 | | 2 | 预防层 | 将 Checkov, tfsec, OPA 集成到 CI/CD 中 | | 3 | 检测层 | 在 Security 选项卡中整合 Prowler, Trivy, SARIF | | 4 | 运行时监控 | AWS Security Hub, EventBridge 告警 | | 5 | 场景与修复 | 配置错误测试用例和操作手册 | ## 入门指南 ### 前置条件 - [Terraform](https://developer.hashicorp.com/terraform/install) >= 1.5 - [AWS CLI](https://aws.amazon.com/cli/) 已配置适当凭据 - [Checkov](https://www.checkov.io/) — `pip install checkov` - [tfsec](https://aquasecurity.github.io/tfsec/) — `brew install tfsec` - [OPA](https://www.openpolicyagent.org/) — `brew install opa` - [Prowler](https://docs.prowler.com/) — `pip install prowler` - [Trivy](https://aquasecurity.github.io/trivy/) — `brew install trivy` ### 本地运行扫描器 ``` # Checkov checkov -d terraform/ # tfsec tfsec terraform/ # OPA opa test opa/tests/ # Trivy trivy config terraform/ ``` ### 部署演示环境 ``` cd terraform/ terraform init terraform plan terraform apply ``` ## 许可证 MIT
标签:AWS, AWS Security Hub, CI/CD安全, DPI, ECS, EventBridge, Groq API, IaC安全, Llama, OPA, Prowler, Rego, SARIF, SNS, Terraform, tfsec, Vagrant, 云安全框架, 修复, 图计算, 安全层, 检测安全, 深度防御, 知识图谱, 网络安全, 运行时监控, 配置修复, 配置错误检测, 隐私保护, 靶场, 预防安全