drifthoundhq/drifthound

GitHub: drifthoundhq/drifthound

一个用于集中收集和追踪 Terraform 基础设施偏差报告的 Rails 平台,提供历史记录、可视化仪表板和实时告警功能。

Stars: 29 | Forks: 2

DriftHound

A Watchdog for Your Infrastructure State.

logo

![Ruby](https://img.shields.io/badge/dynamic/regex?url=https://raw.githubusercontent.com/drifthoundhq/drifthound/main/.ruby-version&search=ruby-(.*)&label=Ruby&logo=ruby&logoColor=red&color=CC342D&style=for-the-badge) ![Build](https://img.shields.io/github/actions/workflow/status/drifthoundhq/drifthound/ci.yml?branch=main&style=for-the-badge&logo=github&label=Build) ![GitHub release (latest SemVer)](https://img.shields.io/github/v/release/drifthoundhq/drifthound?style=for-the-badge&color=blue) [![Demo](https://img.shields.io/badge/Demo-Try%20It-10b981?style=for-the-badge&logo=rocket&logoColor=white)](https://demo.drifthound.io) [![License](https://img.shields.io/badge/License-AGPL--3.0-orange?style=for-the-badge)](https://opensource.org/licenses/AGPL-3.0)

## 什么是 DriftHound? DriftHound 是一个 Rails WebApp,通过 API 接收 Terraform 偏差报告,并提供跨项目的基础设施偏差可见性。 在线演示站点:https://demo.drifthound.io ## 功能特性 - **偏差报告 API**:通过经过身份验证的 API 接收 Terraform 偏差检查结果 - **历史数据**:存储并追踪每个项目的偏差检查历史 - **项目状态**:显示项目状态(OK / Drift / Error / Unknown) - **Web 仪表板**:一目了然地查看所有项目及其偏差状态 - **图表仪表板**:带有交互式图表的可视化分析,用于偏差监控 - **Slack 通知**:检测到偏差或解决偏差时发送实时警报 ## 系统要求 - Ruby 3.x - PostgreSQL - Rails 8.0+ ## 本地开发 ### 非 Docker 环境 1. **安装依赖** ``` bundle install ``` 2. **启动数据库** ``` docker compose up postgres -d ``` 3. **数据库设置** ``` bin/rails db:create db:migrate db:seed ``` 1. **启动服务器** ``` bin/rails server ``` #### 运行测试 1. 创建测试数据库 ``` make prepare-test-db ``` 2. 单元测试 ``` make run-tests ``` ### Docker 环境 **配置数据库并启动应用** ``` make docker-db-setup ``` 这将启动服务,然后创建、迁移并填充数据库。 同时在填充步骤中自动创建 API token。 ## CLI 使用 DriftHound 提供了一个 CLI 工具,用于在 CI/CD 流水线中自动执行偏差检查。 ### 快速安装 ``` sudo curl -L https://raw.githubusercontent.com/drifthoundhq/drifthound/main/bin/drifthound-cli -o /usr/local/bin/drifthound && sudo chmod +x /usr/local/bin/drifthound ``` ### 使用示例 ``` drifthound --tool=terraform \ --project=my-project \ --environment=production \ --token=YOUR_API_TOKEN \ --api-url=http://localhost:3000 \ --dir=./terraform ``` 📖 详细的 CLI 文档、Docker 使用方法和 CI/CD 集成示例请参阅 [docs/cli-usage.md](docs/cli-usage.md)。 ## API 使用 你可以直接向 API 提交偏差检查结果: ``` curl -X POST \ http://localhost:3000/api/v1/projects/my-project/environments/my-env/checks \ -H "Authorization: Bearer YOUR_API_TOKEN" \ -H "Content-Type: application/json" \ -d '{ "status": "drift", "add_count": 2, "change_count": 1, "destroy_count": 0, "duration": 8.2, "raw_output": "Plan: 2 to add, 1 to change, 0 to destroy." }' ``` **生成 API Token:** 1. 在 `/login` 以管理员身份登录 2. 点击导航栏中的 **API Tokens** 3. 创建新 token 并复制(仅显示一次!) 📖 完整的 API 文档,包括高级功能和示例,请参阅 [docs/api-usage.md](docs/api-usage.md)。 ## GitHub Actions 集成 使用官方 DriftHound GitHub Action 在你的 GitHub workflows 中自动执行偏差检测。 🔄 **GitHub Action**:[https://github.com/drifthoundhq/drifthound-action](https://github.com/drifthoundhq/drifthound-action) ## 部署 DriftHound 可以使用 Docker 和 Kubernetes 部署到生产环境。 ### Docker 镜像 预构建的 Docker 镜像可在 GitHub Container Registry 中获取: ``` docker pull ghcr.io/drifthoundhq/drifthound:latest ``` ### Kubernetes 部署 可以使用 Helm Chart 将 DriftHound 部署到 Kubernetes 集群: 📦 **Helm Chart 仓库**:[https://github.com/drifthoundhq/helm-chart/](https://github.com/drifthoundhq/helm-chart/) 有关部署说明和配置选项,请参阅 Helm Chart 文档。 ## 文档 - **[配置指南](docs/configuration.md)** - 环境变量、数据库设置、Slack 配置和部署示例 - **[CLI 指南](docs/cli-usage.md)** - 详细的 CLI 文档、Docker 使用方法和 CI/CD 集成示例 - **[API 参考](docs/api-usage.md)** - 完整的 API 文档、高级功能和集成示例 - **[Slack 通知](docs/slack-notifications.md)** - 配置 Slack 偏差检测警报 ## 架构 ``` flowchart LR A["CI/CD (Terraform)"] --> B["DriftHound API"] B --> C["PostgreSQL (Storage)"] ``` ## 许可证 AGPL-3.0
标签:API集成, DriftHound, EC2, ECS, IaC, PostgreSQL, Ruby on Rails, Slack通知, Terraform, 互联网扫描, 内存转储, 历史记录, 可观测性, 可视化仪表盘, 子域名突变, 开源, 开源安全, 批量扫描, 持续监控, 测试用例, 漂移检测, 请求拦截