nirbhays/shieldiac
GitHub: nirbhays/shieldiac
ShieldIaC 是一款集成 AI 修复建议的静态分析工具,用于在部署前扫描 Terraform、Kubernetes 等基础设施代码的安全配置错误及合规性。
Stars: 1 | Forks: 0
ShieldIaC
在基础设施代码进入生产环境之前,捕获其中的安全配置错误。
为什么选择 ShieldIaC? •
演示 •
支持的格式 •
合规框架 •
快速开始 •
功能亮点 •
对比 •
架构 •
贡献
## 为什么选择 ShieldIaC?
基础设施代码中的安全配置错误是导致云泄露的首要原因。大多数团队都是在部署*之后*才发现这些问题 —— 那时损失已经造成。
|
### 没有 ShieldIaC
- 先部署,再被入侵,仓促修补
- 安全审查是人工且不一致的
- 合规审计是痛苦的、事后补救的工作
- 无法跨代码库了解安全态势
- 开发人员需要等待数天才能获得安全团队的反馈
|
### 拥有 ShieldIaC
- 扫描每个 PR,解释每个发现,AI 建议每个修复
- 每次推送自动运行 100+ 条规则
- 跨 9 个框架的持续合规映射
- 带有趋势跟踪的实时安全评分
- 开发人员获得即时、可操作的反馈
|
## 演示
当 ShieldIaC 在您的基础设施代码中发现安全问题时,其 PR 评论看起来是这样的:
```
===================================================================
ShieldIaC Security Scan Results
Scan ID: shld-a8f3c901 | Security Score: D (52/100)
3 CRITICAL | 2 HIGH | 1 MEDIUM | 0 LOW
===================================================================
CRITICAL SHLD-S3-001 S3 bucket without server-side encryption
---------------------------------------------------------------
File: infra/storage.tf (line 14)
Resource: aws_s3_bucket.user_uploads
Framework: CIS AWS 2.1.1 | SOC 2 CC6.1 | HIPAA 164.312(a)(1)
AI Fix Suggestion:
resource "aws_s3_bucket_server_side_encryption_configuration" "user_uploads" {
bucket = aws_s3_bucket.user_uploads.id
rule {
apply_server_side_encryption_by_default {
sse_algorithm = "aws:kms"
}
}
}
---
HIGH SHLD-EC2-001 Security group allows unrestricted ingress (0.0.0.0/0)
--------------------------------------------------------------------------
File: infra/network.tf (line 38)
Resource: aws_security_group.web_sg (port 22)
Framework: CIS AWS 4.1 | PCI-DSS 1.3.1 | NIST AC-4
AI Fix Suggestion:
ingress {
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["10.0.0.0/8"] # Restrict to internal VPN range
description = "SSH from corporate VPN only"
}
---
MEDIUM SHLD-RDS-003 RDS instance without automated backups enabled
--------------------------------------------------------------------
File: infra/database.tf (line 22)
Resource: aws_db_instance.primary
Framework: CIS AWS 2.3.1 | SOC 2 A1.2 | ISO 27001 A.12.3
AI Fix Suggestion:
resource "aws_db_instance" "primary" {
...
backup_retention_period = 7
backup_window = "03:00-04:00"
copy_tags_to_snapshot = true
}
===================================================================
View full report: https://github.com/nirbhays/shieldiac
PDF compliance report: https://github.com/nirbhays/shieldiac
===================================================================
```
每个发现都包含严重级别、确切的文件位置、合规框架映射,以及一个您可以直接应用的 AI 生成的修复方案。
## 支持的格式
ShieldIaC 从单一平台扫描四种主要的 IaC 格式。只需放入以下任何文件类型,扫描就会自动开始。
Terraform
.tf .tf.json
50+ 规则
AWS S3, IAM, EC2, RDS, VPC
GCP Compute, IAM, Storage
HCL 和 JSON 格式
|
Kubernetes
.yaml .yml
25+ 规则
Pods, Deployments, RBAC
NetworkPolicy, Resources
Security contexts
|
Dockerfile
Dockerfile
20 规则
基础镜像, USER 指令
Secret 暴露, 软件包
健康检查, 端口
|
CloudFormation
.yaml .json
10+ 规则
S3, EC2, RDS, VPC
映射到 Terraform 规则
一次编写,双重扫描
|
## 合规框架
每条规则都映射到一个或多个合规控制项。ShieldIaC 开箱即支持 **9 个行业框架**。

CIS Foundations
AWS, GCP, and Kubernetes benchmarks
|

SOC 2 Type II
Trust Services Criteria
|

HIPAA
Health data protection safeguards
|

PCI-DSS v4.0
Payment card data security
|

NIST 800-53
Federal information systems
|

ISO 27001
Information security management
|

GDPR
EU data protection regulation
|

AWS Well-Architected
Security pillar best practices
|

GCP Security
Google Cloud security foundations
|
## 快速开始
只需三步即可运行 ShieldIaC。无需配置文件。无需安装 CLI 工具。连接并运行即可。
### 第 1 步 -- 安装 GitHub App
在您的代码仓库中安装 [ShieldIaC GitHub App](https://github.com/apps/shieldiac)。授予代码读取权限以及拉取请求和检查的写入权限。
### 第 2 步 -- 推送 IaC 代码
推送一个包含任何受支持 IaC 文件(`.tf`、`.yaml`、`Dockerfile` 或 CloudFormation 模板)的提交或打开一个 Pull Request。ShieldIaC 会自动检测文件类型。
### 第 3 步 -- 获取您的安全报告
几秒钟内,ShieldIaC 就会在您的 PR 上发布详细评论,其中包括:
- 按严重性分组(CRITICAL / HIGH / MEDIUM / LOW)的发现
- 针对严重和高危发现的 AI 生成修复建议
- 带有合规框架映射的安全评分(A 至 F)
- 指向 ShieldIaC 仪表板上完整报告的链接
就是这样。后续的每个 PR 都会自动扫描。
## 功能亮点
|
### AI 修复建议
对于每个 CRITICAL 和 HIGH 级别的发现,ShieldIaC 使用 GPT-4.1-mini 生成针对您的特定配置量身定制的 **生产就绪代码修复**。修复方案具有上下文感知能力 —— 它们读取周围代码以生成您可以直接应用的建议。结果会缓存 24 小时以降低成本。
|
### 安全评分
每次扫描都会产生一个 **0 到 100 的安全评分** 和字母等级(A 至 F)。评分按严重性加权:CRITICAL 发现扣 15 分,HIGH 扣 8 分,MEDIUM 扣 3 分,LOW 扣 1 分。按文件数量归一化,以便在代码库之间进行公平比较。随时间跟踪趋势 —— 改善、下降或稳定。
|
|
### PDF 合规报告
单击即可生成 **可供审计的 PDF 报告**。每份报告包括执行摘要、每个框架的控制状态(通过 / 失败 / 部分)、带有修复步骤的详细发现,以及专为审计人员审查设计的专业格式。导出用于 SOC 2、HIPAA、PCI-DSS 等。
|
### Web 仪表板
一个功能齐全的仪表板,用于 **跟踪所有代码库的安全态势**。查看组织级概览、带有趋势图的按代码库扫描历史、带有严重性和框架过滤器的发现细节数据,以及显示框架级通过率的合规仪表板。使用 Next.js 14 构建。
|
## 对比
ShieldIaC 与流行的 IaC 安全工具的对比:
| 功能 | ShieldIaC | Checkov | tfsec | Snyk IaC |
|---------|:---------:|:-------:|:-----:|:--------:|
| **带有发现的 PR 评论** | 是 | 部分 (CI) | 部分 (CI) | 是 |
| **AI 驱动的修复建议** | 是 (GPT-4.1-mini) | 否 | 否 | 否 |
| **安全评分 (A-F)** | 是 | 否 | 否 | 否 |
| **Terraform 扫描** | 50+ 规则 | 1000+ | 200+ | 300+ |
| **Kubernetes 扫描** | 25+ 规则 | 200+ | N/A | 100+ |
| **Dockerfile 扫描** | 20 规则 | 30+ | N/A | 20+ |
| **CloudFormation 扫描** | 10+ 规则 | 400+ | N/A | 200+ |
| **合规映射 (9 个框架)** | 是 | 是 | 部分 | 是 |
| **PDF 合规报告** | 是 | 否 | 否 | 付费 |
| **Web 仪表板** | 是 | 付费 (Prisma) | 否 | 付费 |
| **自托管选项** | 是 | 是 | 是 | 否 |
| **设置复杂性** | 零配置 (GitHub App) | CI 流水线设置 | CI 流水线设置 | App 安装 |
| **定价** | 有免费版 | 开源 / 付费 | 开源 | 有免费版 / 付费 |
## 架构
```
ShieldIaC Scanning Pipeline
============================================================================
Developer GitHub ShieldIaC AI Engine
--------- ------ --------- ---------
| | | |
| git push / | | |
| open PR | | |
|--------------->| | |
| | webhook event | |
| |---------------->| |
| | | |
| | | Verify HMAC-SHA256 |
| | | signature |
| | | |
| | | Detect IaC files |
| | | (.tf .yaml |
| | | Dockerfile .json) |
| | | |
| | fetch files | |
| |<----------------| |
| |---------------->| |
| | | |
| | | +-----------------+|
| | | | Scanning Engine ||
| | | | ||
| | | | Terraform 50+ ||
| | | | Kubernetes 25+ ||
| | | | Dockerfile 20 ||
| | | | CloudForm. 10+ ||
| | | +-----------------+|
| | | |
| | | CRITICAL/HIGH |
| | | findings? |
| | |-------------------->|
| | | AI fix |
| | |<--------------------|
| | | (GPT-4.1-mini) |
| | | |
| | | Calculate score |
| | | Map compliance |
| | | Generate report |
| | | |
| | PR comment + | |
| | check run | |
| |<----------------| |
| | | |
| view results | | store in |
|<---------------| | PostgreSQL + Redis |
| | | |
Infrastructure:
+-----------------+ +------------+ +------------+ +-----------+
| Cloud Run | | PostgreSQL | | Redis | | Vercel |
| (Python/FastAPI)| | (Supabase) | | (Upstash) | | (Next.js) |
| Backend API | | Scan data | | Job queue | | Dashboard |
+-----------------+ +------------+ +------------+ +-----------+
```
### 流水线步骤
| 步骤 | 描述 |
|------|-------------|
| **1. Webhook** | GitHub 向 Cloud Run 端点发送 `push` 或 `pull_request` 事件 |
| **2. 验证** | HMAC-SHA256 签名验证确保 webhook 真实有效 |
| **3. 检测** | 文件类型检测器识别变更集中的 IaC 文件(`.tf`、`.yaml`、`Dockerfile`、`.json`) |
| **4. 获取** | 通过 GitHub API 从代码仓库下载变更的 IaC 文件 |
| **5. 解析** | 使用适当的解析器(HCL、YAML、Dockerfile 指令解析器)解析每个文件 |
| **6. 扫描** | 根据规则注册表中所有匹配的规则评估已解析的资源 |
| **7. AI 修复** | 对于 CRITICAL 和 HIGH 级别的发现,GPT-4.1-mini 生成具有上下文感知能力的代码修复 |
| **8. 评分** | 使用按严重性加权的公式计算安全评分(0-100),并按文件数量归一化 |
| **9. 合规** | 将发现映射到 CIS、SOC 2、HIPAA、PCI-DSS、NIST、ISO 27001 和 GDPR 控制项 |
| **10. 报告** | 在 PR 上发布格式化的 Markdown 评论;结果存储在 PostgreSQL 中供仪表板使用 |
### 技术栈
| 组件 | 技术 | 用途 |
|-----------|------------|---------|
| Backend | Python / FastAPI on Cloud Run | Webhook 处理、扫描、API |
| Frontend | Next.js 14 on Vercel | 安全仪表板和报告 |
| Database | PostgreSQL (Supabase) | 扫描结果、用户数据、审计跟踪 |
| Queue | Redis (Upstash) | 异步扫描作业处理 |
| AI | OpenAI GPT-4.1-mini | 修复建议(约 $0.006/次扫描) |
| Auth | Clerk (GitHub OAuth) | 用户身份验证 |
| Payments | Stripe Billing | 订阅管理 |
## 项目结构
```
shieldiac/
├── backend/ # Python/FastAPI backend
│ ├── api/ # API route handlers
│ ├── models/ # Pydantic data models
│ │ ├── scan.py # Scan request/result models
│ │ ├── finding.py # Finding response models
│ │ ├── rule.py # Rule & custom rule models
│ │ ├── compliance.py # Compliance framework models
│ │ ├── billing.py # Subscription & billing models
│ │ └── github.py # GitHub webhook models
│ ├── rules/ # Security rule definitions
│ │ ├── base.py # BaseRule class + RuleRegistry
│ │ ├── loader.py # Dynamic rule discovery
│ │ ├── terraform/ # 50+ Terraform rules (AWS + GCP)
│ │ ├── kubernetes/ # 25+ Kubernetes rules
│ │ └── docker/ # 20 Dockerfile rules
│ ├── services/ # Business logic
│ │ ├── scanner_engine.py # Main scan orchestrator
│ │ ├── terraform_scanner.py # HCL/JSON parser + scanner
│ │ ├── kubernetes_scanner.py # K8s manifest scanner
│ │ ├── dockerfile_scanner.py # Dockerfile instruction scanner
│ │ ├── cloudformation_scanner.py
│ │ ├── ai_fix_generator.py # GPT-4.1-mini integration
│ │ ├── github_service.py # GitHub API (comments, checks)
│ │ ├── scoring_engine.py # Security score calculation
│ │ ├── compliance_mapper.py # Finding-to-framework mapping
│ │ ├── billing_service.py # Stripe integration
│ │ ├── queue_service.py # Redis job queue
│ │ └── report_generator.py # PDF compliance reports
│ ├── utils/ # Parsing utilities
│ ├── main.py # FastAPI application entry
│ ├── config.py # Pydantic settings
│ └── requirements.txt # Python dependencies
├── frontend/ # Next.js 14 dashboard
│ └── src/
│ ├── app/ # App Router pages
│ └── components/ # React components
├── database/ # SQL schemas & migrations
├── infra/ # Terraform deployment IaC
├── tests/ # Test suite & fixtures
├── docs/ # Documentation
└── .github/workflows/ # CI/CD pipelines
```
## 定价
| 方案 | 价格 | 扫描次数/月 | 代码库数量 | 核心功能 |
|------|-------|-------------|-------|--------------|
| **Free** | $0 | 50 | 3 | 核心规则,PR 评论,安全评分 |
| **Pro** | $49/月 | 无限制 | 10 | 所有规则,AI 修复,仪表板,Slack 告警 |
| **Business** | $199/月 | 无限制 | 无限制 | 自定义规则 (OPA/Rego),PDF 报告,RBAC |
| **Enterprise** | $499/月 | 无限制 | 无限制 | SSO/SAML,自托管扫描器,SLA,审计日志 |
## 贡献
我们欢迎贡献 —— 特别是新的安全规则。完整指南请参阅 [docs/CONTRIBUTING.md](docs/CONTRIBUTING.md)。
### 添加新规则
添加规则是一个三步过程:创建一个类,定义元数据,并注册它。注册表会自动发现新规则。
```
from backend.rules.base import (
BaseRule, Severity, ResourceType,
registry, ComplianceMapping, ComplianceFramework
)
@registry.register
class S3BucketLoggingRule(BaseRule):
id = "SHLD-S3-010"
description = "S3 bucket does not have access logging enabled"
severity = Severity.MEDIUM
resource_type = ResourceType.TERRAFORM
remediation = "Enable access logging by adding a logging configuration block"
compliance = [
ComplianceMapping(ComplianceFramework.CIS_AWS, "2.1.3", "Ensure S3 access logging"),
ComplianceMapping(ComplianceFramework.SOC2, "CC7.2", "System monitoring"),
]
tags = ["logging", "s3", "monitoring"]
def evaluate(self, resource, context):
findings = []
if not resource.get("logging"):
findings.append(self.make_finding(
resource_name=resource.get("name", "unknown"),
file_path=context.file_path,
))
return findings
```
将文件放入 `backend/rules/terraform/`,ShieldIaC 会在下一次扫描时自动加载它。无需更改配置。
### 开发环境设置
```
# 克隆 repository
git clone https://github.com/your-org/shieldiac.git
cd shieldiac
# 设置环境变量
cp .env.example .env
# 使用 GitHub App 凭证和(可选)的 OpenAI API key 编辑 .env
# 启动 infrastructure services
docker-compose up -d # PostgreSQL + Redis
# 启动 backend
cd backend
pip install -r requirements.txt
uvicorn main:app --reload --port 8000
# 启动 frontend(在单独的 terminal 中)
cd frontend
npm install
npm run dev
# Dashboard 位于 http://localhost:3000
```
## 文档
| 文档 | 描述 |
|----------|-------------|
| [架构](docs/ARCHITECTURE.md) | 系统设计、扫描流水线、数据流 |
| [API 参考](docs/API.md) | 端点文档 |
| [部署指南](docs/DEPLOYMENT.md) | 生产环境部署演练 |
| [安全](docs/SECURITY.md) | 安全模型和数据处理 |
| [贡献](docs/CONTRIBUTING.md) | 如何贡献和添加新规则 |
## 许可证
MIT License。详情请参阅 [LICENSE](LICENSE)。
## 致谢
- [Checkov](https://www.checkov.io/) 和 [tfsec](https://github.com/aquasecurity/tfsec) 在规则模式和扫描方法方面提供了灵感。
- [CIS Benchmarks](https://www.cisecurity.org/) 提供了合规框架定义。
- [OWASP](https://owasp.org/) 提供了安全最佳实践。
专为相信安全应属于 PR 而非事后复盘的 DevSecOps 团队构建。
网站 •
文档 •
Issues •
a href="https://discord.gg/shieldiac">Discord
标签:AI修复, Ansible, CloudFormation, DevSecOps, ECS, IaC安全, SAST, Terraform, 上游代理, 云安全监控, 代码审查, 合规框架, 安全左移, 安全扫描, 搜索引擎查询, 时序注入, 测试用例, 漏洞修复, 盲注攻击, 结构化查询, 网络安全培训, 自动化安全, 请求拦截, 逆向工具, 静态分析