cleancloud-io/cleancloud
GitHub: cleancloud-io/cleancloud
面向 AWS 和 Azure 的云资源浪费扫描器,可在 CI/CD 中检测孤立资源并预估月度浪费。
Stars: 81 | Forks: 4
# CleanCloud



[](https://github.com/cleancloud-io/cleancloud/actions/workflows/security-scan.yml)

**云浪费的 Trivy。一款查找孤立资源并在 CI 中执行卫生策略的扫描器。**
就像针对 Terraform 的 `tfsec` 或针对容器的 `trivy` 一样 —— CleanCloud 扫描您的云环境并报告浪费资金的内容。运行一次进行快速审计,安排定期运行,或将其接入 CI/CD 以在违反策略时使构建失败。
- **20 条高信号检测规则:** 孤立卷、空闲数据库、空负载均衡器等
- **预估每月浪费:** 针对每项发现及总计
- **CI 原生执行(可选):** `--fail-on-confidence HIGH` 或 `--fail-on-cost 100` 作为您的流水线关卡
- **多种输出格式:** 人类可读、JSON、CSV 和 markdown(可粘贴到 GitHub PR 或 Slack)
- **设计上只读:** 无删除、无标签更改、无任何变更 —— 永远
- **无代理。无遥测。无 SaaS。** 在您的环境中运行,数据永不流出
**使用案例:**
- 一次性云浪费审计 —— 在 CloudShell 中运行,60 秒内查看结果
- 定期卫生扫描 —— cron 作业或每周 CI 运行以捕捉配置漂移
- CI/CD 执行关卡 —— 当浪费超过阈值时使构建失败
```
Found 6 hygiene issues:
1. [AWS] Unattached EBS Volume — $40/month
2. [AWS] Idle NAT Gateway — $32.40/month
3. [AWS] Unattached Elastic IP — $0/month
...
Estimated monthly waste: ~$147
Regions scanned: us-east-1, us-west-2, eu-west-1
```
## 用户评价
## 快速开始
```
pipx install cleancloud
pipx ensurepath # adds cleancloud to PATH — restart your shell after this
cleancloud demo # see sample findings without any cloud credentials
```
当您准备好扫描真实环境时:
```
cleancloud scan --provider aws --all-regions
cleancloud scan --provider azure
```
### 无需安装 —— 在您的云 Shell 中试用
拥有 AWS 或 Azure 账户?无需本地设置,几秒钟内运行真实扫描。
**AWS — [AWS CloudShell](https://console.aws.amazon.com/cloudshell):**
```
pip install --upgrade cleancloud
cleancloud doctor --provider aws # check what permissions your session has
cleancloud scan --provider aws --all-regions
```
**Azure — [Azure Cloud Shell](https://shell.azure.com):**
```
pip install --upgrade --user cleancloud
export PATH="$HOME/.local/bin:$PATH"
cleancloud doctor --provider azure # check what permissions your session has
cleancloud scan --provider azure
```
两个 Shell 都使用您的门户会话进行身份验证 —— 无需单独的凭证。
权限因账户而异;
`doctor` 会在扫描前准确告诉您哪些功能可用。如果缺少权限,CleanCloud 将跳过这些规则并报告跳过了什么。
## 运行效果
```
Found 6 hygiene issues:
1. [AWS] Unattached EBS Volume
Risk : Low
Confidence : High
Resource : aws.ebs.volume → vol-0a1b2c3d4e5f67890
Region : us-east-1
Rule : aws.ebs.volume.unattached
Reason : Volume has been unattached for 47 days
Details:
- size_gb: 500
- state: available
- tags: {"Project": "legacy-api", "Owner": "platform"}
2. [AWS] Idle NAT Gateway
Risk : Medium
Confidence : Medium
Resource : aws.ec2.nat_gateway → nat-0abcdef1234567890
Region : us-west-2
Rule : aws.ec2.nat_gateway.idle
Reason : No traffic detected for 21 days
Details:
- name: staging-nat
- total_bytes_out: 0
- estimated_monthly_cost_usd: 32.40
3. [AWS] Unattached Elastic IP
Risk : Low
Confidence : High
Resource : aws.ec2.elastic_ip → eipalloc-0a1b2c3d4e5f6
Region : eu-west-1
Rule : aws.ec2.elastic_ip.unattached
Reason : Elastic IP not associated with any instance or ENI (age: 92 days)
--- Scan Summary ---
Total findings: 6
By risk: low: 5 medium: 1
By confidence: high: 2 medium: 4
Minimum estimated waste: ~$147/month
(4 of 6 findings costed)
Regions scanned: us-east-1, us-west-2, eu-west-1 (auto-detected)
```
还没有云账户?`cleancloud demo` 无需任何凭证即可显示示例输出。
### 可共享的 Markdown 报告
```
cleancloud scan --provider aws --all-regions --output markdown
```
打印分组摘要,您可以直接将其粘贴到 GitHub PR 评论、Slack 消息或 Issue 中:
```
## CleanCloud 扫描结果
**Provider:** AWS
**Regions:** us-east-1, us-west-2, eu-west-1
**Scanned:** 2026-03-07
**Estimated monthly waste:** ~$147
**Total findings:** 6
| Finding | Count | Est. Monthly Cost |
|---------|------:|------------------:|
| Unattached EBS Volume | 2 | ~$115 |
| Idle NAT Gateway | 1 | ~$32 |
| Unattached Elastic IP | 1 | ~$0 |
| Detached ENI | 1 | — |
| CloudWatch Log Group: Infinite Retention | 1 | — |
**Confidence:** high: 3 · medium: 3
> Generated by [CleanCloud](https://github.com/cleancloud-io/cleancloud) — read-only cloud hygiene scanner for AWS and Azure.
```
使用 `--output-file results.md` 保存到文件。如果不使用 `--output-file`,则会打印到 stdout。
包含 `doctor`、JSON、CSV 和 markdown 的完整输出示例:[`docs/example-outputs.md`](docs/example-outputs.md)
## CleanCloud 检测内容
跨 AWS 和 Azure 的 20 条规则 —— 保守、高信号,旨在避免 IaC 环境中的误报。
**AWS:**
- 未挂载的 EBS 卷 (HIGH)
- 旧的 EBS 快照
- 无限保留的 CloudWatch Logs
- 未挂载的弹性 IP (HIGH)
- 分离的 ENI
- 未标记的资源
- 旧的 AMI
- 空闲的 NAT Gateway
- 空闲的 RDS 实例 (HIGH)
- 空闲的负载均衡器 (HIGH)
**Azure:**
- 未挂载的托管磁盘
- 旧的快照
- 未使用的公共 IP (HIGH)
- 空负载均衡器 (HIGH)
- 空 App Gateway (HIGH)
- 空 App Service Plan (HIGH)
- 空闲的 VNet Gateway
- 已停止(未释放)的 VM (HIGH)
- 空闲的 SQL 数据库 (HIGH)
- 未标记的资源
没有置信度标记的规则为 MEDIUM —— 它们使用基于时间的启发式方法或多个信号。从 `--fail-on-confidence HIGH` 开始以捕捉明显的浪费,然后随着团队验证逐步收紧。
**完整的规则详情、信号和证据:** [`docs/rules.md`](docs/rules.md)
## CI/CD 执行
扫描默认退出代码为 `0`。选择加入执行:
| Flag | 行为 | 退出代码 |
|------|----------|-----------|
| *(无)* | 仅报告,从不失败 | `0` |
| `--fail-on-confidence HIGH` | 在 HIGH 置信度发现时失败 | `2` |
| `--fail-on-confidence MEDIUM` | 在 MEDIUM 或更高置信度时失败 | `2` |
| `--fail-on-cost 50` | 如果预估每月浪费 >= $50 则失败 | `2` |
| `--fail-on-findings` | 有任何发现则失败 | `2` |
### GitHub Actions — AWS (OIDC)
```
- uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::${{ vars.AWS_ACCOUNT_ID }}:role/CleanCloudCIReadOnly
aws-region: us-east-1
- run: pip install cleancloud
- run: |
cleancloud scan --provider aws --all-regions \
--fail-on-confidence HIGH \
--output json --output-file scan.json
```
### GitHub Actions — Azure (Workload Identity)
```
- uses: azure/login@v2
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- run: pip install cleancloud
- run: |
cleancloud scan --provider azure \
--fail-on-confidence MEDIUM \
--output json --output-file scan.json
```
**完整 CI/CD 指南:** [`docs/ci.md`](docs/ci.md) — OIDC 设置、执行模式、输出格式。
设置指南:[AWS](docs/aws.md) · [Azure](docs/azure.md)
## 路线图
- 额外的 AWS 规则(S3 生命周期、已停止的 EC2 实例)
- `cleancloud.yaml` 中的策略即代码(配置中的 `fail_on_confidence`、`fail_on_cost`)
- 规则过滤(`--rules` 标志)
- 多账户扫描(AWS Organizations)
## 文档
- [`docs/rules.md`](docs/rules.md) — 检测规则、信号和证据
- [`docs/aws.md`](docs/aws.md) — AWS IAM 策略和 OIDC 设置
- [`docs/azure.md`](docs/azure.md) — Azure RBAC 和 Workload Identity 设置
- [`docs/ci.md`](docs/ci.md) — CI/CD 集成指南
- [`docs/example-outputs.md`](docs/example-outputs.md) — 完整输出示例
- [`SECURITY.md`](SECURITY.md) — 安全策略和威胁模型
- [`docs/infosec-readiness.md`](docs/infosec-readiness.md) — IAM Proof Pack、威胁模型
**发现了 Bug?** [提交 Issue](https://github.com/cleancloud-io/cleancloud/issues)
**功能请求?** [发起讨论](https://github.com/cleancloud-io/cleancloud/discussions)
**有问题?** suresh@getcleancloud.com
[MIT 许可证](LICENSE)
安装故障排除
**macOS:** `brew install pipx && pipx install cleancloud` **Linux:** `sudo apt install pipx && pipx install cleancloud` **Windows:** `python3 -m pip install --user pipx && python3 -m pipx ensurepath && pipx install cleancloud` **Command not found: cleancloud** — 运行 `pipx ensurepath` 然后重启您的 shell。 **externally-managed-environment error** — 使用 `pipx` 代替 `pip`。 **从之前的 pip 安装升级** — 先将其移除以避免遮蔽: ``` pip uninstall cleancloud && pipx install cleancloud && pipx ensurepath ``` **安装后版本错误** — 运行 `which cleancloud`;可能是旧的 pip 安装遮蔽了 pipx。 **最低推荐版本:v1.6.3** — 早期版本存在设置摩擦。运行 `cleancloud --version` 进行检查。标签:AWS, Azure, DPI, EBS卷, FinOps, Linux安全, LNA, NAT网关, Orphaned Resources, Python, 云卫生, 云浪费, 基础设施审计, 安全合规, 左移策略, 开源, 弹性IP, 成本优化, 文档结构分析, 无后门, 漏洞利用检测, 环境监测, 知识图谱, 策略即代码, 网络代理, 聊天机器人安全, 资源扫描, 逆向工具, 闲置资源