joemunene-by/ghostcloud
GitHub: joemunene-by/ghostcloud
ghostcloud 是一款多云 CSPM 工具,通过离线扫描 AWS、GCP、Azure 的标准化 JSON 资源快照来检测安全错误配置,并支持 CI/CD 流水线集成以在部署前拦截风险。
Stars: 0 | Forks: 0
ghostcloud
多云安全态势管理 (CSPM) 和错误配置扫描工具,适用于 AWS、GCP 和 Azure。ghostcloud 会根据安全最佳实践检查来评估云资源配置, 报告带有严重程度和修复指南的错误配置,并可用于拦截 CI pipeline。 ghostcloud 是优先离线的。它扫描标准化的资源快照(纯 JSON),而不是调用实时的云 API,因此它可以在零云凭证的情况下确定性地运行,并且非常容易进行测试、演示和嵌入到 CI 中。包含了一个依赖注入的收集器接口,供以后希望从实时账户生成快照的团队使用。 ## 仅限授权使用 ghostcloud 是一款防御性工具。仅对您拥有或被明确授权评估的云账户和资源快照使用它。您有责任遵守所有适用的法律、合同和提供商服务条款。 ## 安装说明 需要 Python 3.11 或更高版本。 ``` git clone https://github.com/joemunene-by/ghostcloud.git cd ghostcloud python -m venv .venv source .venv/bin/activate pip install -e ".[dev]" ``` 这将安装 `ghostcloud` 命令。 ## 快速开始 列出所有可用的检查: ``` ghostcloud checks ``` 扫描内置的多云示例: ``` ghostcloud scan --input examples/all_providers.json --provider all ``` 示例输出: ``` ghostcloud findings Severity Check Provider Resource Title CRITICAL GC-AWS-EC2-001 aws sg-0a1b2c3d4e Security group exposes an admin port to the internet CRITICAL GC-AWS-IAM-002 aws arn:aws:iam:.. IAM policy grants wildcard action on all resources CRITICAL GC-AWS-S3-001 aws arn:aws:s3:.. S3 bucket allows public access CRITICAL GC-AZURE-NSG-001 azure /subscriptions/.. Network security group allows admin access from the internet CRITICAL GC-GCP-STORAGE-001 gcp //storage.. Cloud Storage bucket is publicly accessible HIGH GC-AWS-S3-002 aws arn:aws:s3:.. S3 bucket has no default encryption HIGH GC-GCP-IAM-001 gcp deploy@demo.. Service account granted primitive owner role MEDIUM GC-AWS-S3-003 aws arn:aws:s3:.. S3 bucket versioning is disabled MEDIUM GC-AZURE-DISK-001 azure /subscriptions/.. Managed disk is not encrypted 9 finding(s) (5 critical, 2 high, 2 medium) across 7 resource(s). ``` 为下游工具输出 JSON 或 SARIF: ``` ghostcloud scan --input examples/all_providers.json --format json --output report.json ghostcloud scan --input examples/all_providers.json --format sarif --output report.sarif ``` ## CLI 参考 ``` ghostcloud scan Scan a resource snapshot and report misconfigurations. ghostcloud checks List the available security checks. ghostcloud version Print the ghostcloud version. ``` `scan` 标志: | 标志 | 值 | 默认值 | 描述 | | --- | --- | --- | --- | | `--input`, `-i` | 路径 | 必需 | 资源快照 JSON 文件。 | | `--provider`, `-p` | `aws`, `gcp`, `azure`, `all` | `all` | 要扫描的 Provider 范围。 | | `--format`, `-f` | `console`, `json`, `sarif` | `console` | 输出格式。 | | `--min-severity` | `info`..`critical` | `info` | 仅报告达到或超过此严重程度的发现。 | | `--fail-on` | `info`..`critical` | 未设置 | 如果报告的任何发现达到或超过此严重程度,则以非零状态退出。 | | `--output`, `-o` | 路径 | stdout | 将报告写入文件。 | | `--verbose`, `-v` | 标志 | off | 在 stderr 上启用 debug 日志记录。 | 退出代码:`0` 正常(或发现低于 `--fail-on`),`1` 发现达到或超过 `--fail-on`,`2` 快照错误(缺失或格式错误的输入)。 ## 快照 schema 快照是一个 JSON 对象。每个 Provider 键映射到一个标准化资源列表。Provider 键是可选的;单个快照可以描述单个云。 ``` { "schema_version": 1, "aws": [ { "service": "s3", "type": "bucket", "id": "...", "region": "us-east-1", "config": { } } ], "gcp": [ { "service": "storage", "type": "bucket", "id": "...", "region": "us", "config": { } } ], "azure": [ { "service": "storage", "type": "storage_account", "id": "...", "region": "eastus", "config": { } } ] } ``` 每个资源具有: | 字段 | 必需 | 描述 | | --- | --- | --- | | `service` | 是 | 逻辑服务名称,例如 `s3`、`ec2`、`storage`。 | | `type` | 是 | 服务中的资源类型,例如 `bucket`、`security_group`。 | | `id` | 是 | 稳定标识符(ARN、self link、resource id 或 name)。 | | `region` | 否 | Region 或 location;对于全局资源可能为空。 | | `config` | 否 | 检查所检查的 Provider 特定配置块。 | `tests/fixtures/`(每个 Provider 都有一个存在漏洞和安全的示例)以及多云 `examples/all_providers.json` 下的测试用例展示了每个服务的 `config` 结构。例如,一个 AWS 安全组: ``` { "service": "ec2", "type": "security_group", "id": "sg-0a1b2c3d4e", "region": "us-east-1", "config": { "ingress_rules": [ { "from_port": 22, "to_port": 22, "cidrs": ["0.0.0.0/0"] } ] } } ``` ## 检查 | ID | Provider | 服务 | 严重程度 | 标题 | | --- | --- | --- | --- | --- | | GC-AWS-S3-001 | aws | s3 | CRITICAL | S3 bucket 允许公开访问 | | GC-AWS-S3-002 | aws | s3 | HIGH | S3 bucket 没有默认加密 | | GC-AWS-S3-003 | aws | s3 | MEDIUM | S3 bucket 版本控制被禁用 | | GC-AWS-EC2-001 | aws | ec2 | CRITICAL | 安全组向互联网开放了管理端口 | | GC-AWS-EBS-001 | aws | ec2 | MEDIUM | EBS 卷未加密 | | GC-AWS-IAM-001 | aws | iam | HIGH | 具有控制台访问权限的 IAM 用户没有 MFA | | GC-AWS-IAM-002 | aws | iam | CRITICAL | IAM policy 授予了对所有资源的通配符操作 | | GC-AWS-RDS-001 | aws | rds | HIGH | RDS 实例可公开访问 | | GC-AWS-RDS-002 | aws | rds | HIGH | RDS 实例存储未加密 | | GC-AWS-CLOUDTRAIL-001 | aws | cloudtrail | HIGH | CloudTrail 被禁用或不是多区域的 | | GC-GCP-STORAGE-001 | gcp | storage | CRITICAL | Cloud Storage bucket 可公开访问 | | GC-GCP-VPC-001 | gcp | compute | CRITICAL | 防火墙规则允许不受限制的 ingress | | GC-GCP-COMPUTE-001 | gcp | compute | HIGH | 实例具有可从互联网访问的 SSH 公网 IP | | GC-GCP-IAM-001 | gcp | iam | HIGH | Service account 被授予了基本的 owner 角色 | | GC-AZURE-STORAGE-001 | azure | storage | HIGH | 存储账户允许公开 blob 访问 | | GC-AZURE-NSG-001 | azure | network | CRITICAL | 网络安全组允许从互联网进行管理访问 | | GC-AZURE-DISK-001 | azure | compute | MEDIUM | 托管磁盘未加密 | ## CI 拦截 当发现达到选定的严重程度时,使用 `--fail-on` 阻止 pipeline。SARIF 输出可与代码扫描仪表板集成。 ``` - name: ghostcloud scan run: | pip install -e . ghostcloud scan --input snapshot.json --provider all --format sarif --output ghostcloud.sarif ghostcloud scan --input snapshot.json --provider all --fail-on high - name: Upload SARIF uses: github/codeql-action/upload-sarif@v3 with: sarif_file: ghostcloud.sarif ``` ## 架构 ``` src/ghostcloud/ models.py Severity, Resource, Finding data model snapshot.py Snapshot schema parsing and validation scanner.py Runs checks with per-check isolation, severity filtering report.py Console table, JSON, and SARIF 2.1.0 renderers cli.py Typer CLI (scan, checks, version) checks/ base.py Check base class and provider-keyed Registry aws.py AWS checks gcp.py GCP checks azure.py Azure checks collectors/ Optional live-collector interface (no cloud SDKs required) ``` 检查会声明元数据(id、Provider、服务、严重程度、描述、修复)并实现 `evaluate(resource)`,当资源配置错误时返回一个 `Finding`,否则返回 `None`。扫描程序会隔离每项检查,这样抛出异常的检查将被记录为扫描错误,而不会中止运行。 ## 开发 ``` pip install -e ".[dev]" ruff check . pytest ``` 测试套件是离线的,并在纯 `pytest` 下运行。每项检查都有一个存在漏洞的 fixture(必须触发)和一个安全的 fixture(必须保持静默),外加针对 SARIF 有效性、JSON 往返、严重程度阈值、退出代码和格式错误快照处理的测试。 ## 路线图 - 现有接口背后的适用于 AWS (boto3)、GCP 和 Azure 的实时收集器。 - 更多检查:KMS 密钥轮换、公共 AMI 和快照、GuardDuty 启用、GCP Cloud SQL 公网 IP、Azure Key Vault 软删除和清除保护。 - 策略包和带有理由的单项检查抑制。 - 基线差异对比,以仅显示新引入的错误配置。 ## 许可证 MIT。参见 [许可证](LICENSE)。 ghostsuite 的一部分:十一款开源安全工具,一个幽灵。标签:CSPM, DevSecOps, Python, TinkerPop, 上游代理, 云配置审计, 图数据库, 多云, 安全合规, 无后门, 网络代理, 逆向工具