cozyGarage/sentielflow
GitHub: cozyGarage/sentielflow
一款集成于 CI/CD 流水线中的全链路安全门禁工具,集中检测密钥泄露、IaC 配置风险、依赖漏洞及策略违规问题。
Stars: 0 | Forks: 0
# SentinelFlow
[](https://github.com/cozyGarage/sentielflow/actions/workflows/security-scan.yml)
**CI/CD 安全门禁**
SentinelFlow 是一款安全扫描工具,可集成到 CI/CD pipeline 中,用于检测泄露的 secret、不安全的基础设施配置、存在漏洞的依赖项以及违规策略。
## 功能
- **Secret 扫描**:检测泄露的 API key、token、密码和凭证(包括 git 历史记录)
- **基础设施即代码**:扫描 Terraform、Kubernetes 和 Dockerfile 配置
- **依赖分析**:通过 OSV API 检查存在漏洞的依赖项
- **SAST**:针对常见语言的 OWASP 导向静态分析模式
- **容器扫描**:集成 Trivy 进行镜像漏洞扫描
- **许可证策略**:标记具有禁用许可证(GPL、AGPL 等)的依赖项
- **策略执行**:基于 OPA 的策略即代码验证
- **SBOM 生成**:输出 CycloneDX SBOM 以提升供应链可见性
- **多种报告格式**:支持 Text、Markdown、SARIF、JSON 和 HTML 输出
## 快速开始
### 安装
```
# 从源码构建
git clone https://github.com/cozygarage/sentinelflow
cd sentinelflow
go build -o sentinelflow ./cmd/sentinelflow
# 或者使用 Make(Windows:sentinelflow.exe)
make build
```
### 基本用法
```
# 初始化配置
sentinelflow init
# 运行所有 scanner
sentinelflow scan --all
# 扫描特定类型
sentinelflow scan --secrets --iac
# 为 GitHub 生成 SARIF 报告
sentinelflow scan --all --format sarif -o report.sarif
# 为 PR 评论生成 Markdown 报告
sentinelflow scan --all --format markdown -o report.md
```
## 配置
在项目根目录下创建一个 `.sentinelflow.yaml` 文件(或运行 `sentinelflow init`):
```
version: "1.0"
scanners:
secrets:
enabled: true
allowlist:
- "test/**"
- "**/*_test.go"
entropy_threshold: 4.5
iac:
enabled: true
frameworks:
- terraform
- kubernetes
- dockerfile
dependencies:
enabled: true
ecosystems:
- auto
severity: medium
ai:
enabled: false # Not yet implemented
policies:
enabled: true
fail_on:
severity: high
secrets: true
policy_violations: true
```
请参阅 [配置参考](docs/configuration.md) 了解所有选项。
## CI/CD 集成
### GitHub Actions
```
name: Security Scan
on: [pull_request]
jobs:
security:
runs-on: ubuntu-latest
permissions:
contents: read
security-events: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: cozyGarage/sentielflow/.github/actions/sentinelflow@main
with:
scan-all: 'true'
fail-on: high
format: sarif
output: report.sarif
- uses: github/codeql-action/upload-sarif@v3
if: always()
with:
sarif_file: report.sarif
```
### GitLab CI
```
sentinelflow:
image: golang:1.25
script:
- go build -o sentinelflow ./cmd/sentinelflow
- ./sentinelflow scan --all --format sarif -o gl-security-report.sarif
artifacts:
reports:
sast: gl-security-report.sarif
```
请参阅 [CI/CD 集成](docs/cicd-integration.md) 获取更多示例。
## 架构
SentinelFlow 采用面向 pipeline 的设计:中央扫描引擎负责调度 adapter、聚合发现的问题,并为 GitHub Security 标签页输出 SARIF。
```
flowchart LR
subgraph Input
SRC[Source tree]
CFG[.sentinelflow.yaml]
end
subgraph Engine
SE[Scan Engine]
AD1[Secrets]
AD2[IaC]
AD3[Dependencies OSV]
AD4[SAST]
AD5[Policy OPA]
AD6[License]
end
subgraph Output
SARIF[SARIF report]
GH[GitHub Security tab]
MD[Markdown PR comment]
end
SRC --> SE
CFG --> SE
SE --> AD1 & AD2 & AD3 & AD4 & AD5 & AD6
AD1 & AD2 & AD3 & AD4 & AD5 & AD6 --> SE
SE --> SARIF --> GH
SE --> MD
```
| 层级 | 职责 |
| --- | --- |
| **扫描引擎** | 文件发现、并发扫描器调度、结果聚合 |
| **Adapter** | Secret、IaC、依赖项 (OSV)、SAST、许可证、OPA 策略 |
| **报告器** | SARIF、JSON、Markdown、HTML — SARIF 上传可与 GitHub Advanced Security 集成 |
请参阅 [ARCHITECTURE.md](ARCHITECTURE.md) 和 [docs/architecture.md](docs/architecture.md) 获取更详细的图表。
## 合规性与 Pipeline 集成
SentinelFlow 被设计为适合受监管环境的**安全左移门禁**。它能清晰地映射到常见的控制主题,并且不会存储或窃取发现的 secret。
| 控制主题 | SentinelFlow 功能 | 框架对应关系 |
| --- | --- | --- |
| **Secret 与凭证规范** | 正则表达式 + 熵值扫描,CI 中发现 secret 即失败 | PCI-DSS Req. 3 & 8(保护存储的凭证;识别用户) |
| **安全配置** | 针对 Terraform、Kubernetes、Dockerfile 的 IaC 扫描 | PCI-DSS Req. 2(安全配置);DORA ICT 风险管理 |
| **依赖项与供应链风险** | Lockfile 解析 + OSV 漏洞查询 | DORA Art. 6(ICT 风险管理);PCI-DSS Req. 6(安全开发) |
| **策略即代码执行** | OPA/Rego 门禁(例如禁止特权容器、要求使用 HTTPS) | DORA 运营弹性测试;内部变更控制策略 |
| **审计轨迹** | 将 SARIF 产物上传至 GitHub Security;在 CI 中生成 SBOM | 为审计和事件响应提供证据收集证明 |
**Pipeline 集成模式:** 在每次 pull request 时运行 `sentinelflow scan --all --format sarif`,将 SARIF 上传至平台的安全标签页,并在超出严重性阈值时阻止合并。内置的 [`.github/workflows/security-scan.yml`](.github/workflows/security-scan.yml) workflow 实现了此端到端流程(扫描 → 上传 SARIF → 评论 PR → SBOM 作业)。
## 扫描器
| 扫描器 | 标志 | 描述 |
| --- | --- | --- |
| **Secret** | `--secrets` | 正则表达式、熵值、git 历史记录 |
| **IaC** | `--iac` | Terraform、Kubernetes、Dockerfile |
| **依赖项** | `--deps` | OSV 漏洞查询 |
| **SAST** | `--sast` | OWASP 导向的静态模式 |
| **容器** | `--container` | Trivy 镜像扫描 |
| **许可证** | `--license` | 禁用许可证检测 |
| **策略** | (配置) | OPA/Rego 策略执行 |
## CLI 命令
| 命令 | 描述 |
| --- | --- |
| `sentinelflow scan` | 运行安全扫描器 |
| `sentinelflow init` | 创建默认配置 |
| `sentinelflow sbom` | 生成 CycloneDX SBOM |
| `sentinelflow policy list` | 列出内置策略 |
| `sentinelflow policy validate` | 验证 Rego 策略语法 |
| `sentinelflow policy test` | 针对输入的 JSON 测试策略 |
| `sentinelflow policy generate` | 创建新的策略模板 |
| `sentinelflow hook install` | 安装 pre-commit hook |
| `sentinelflow version` | 打印版本信息 |
## 文档
- [使用指南](docs/usage.md)
- [配置参考](docs/configuration.md)
- [扫描器文档](docs/scanners.md)
- [CI/CD 集成](docs/cicd-integration.md)
- [编写自定义策略](docs/policies.md)
- [架构](docs/architecture.md)
## 开发
```
# 运行测试
go test ./...
# 运行集成测试
go test -tags=integration ./test/...
# 构建
go build -o sentinelflow ./cmd/sentinelflow
# 本地运行
./sentinelflow scan --all --verbose
```
## 安全性
- **不存储 secret**:从不存储或传输发现的 secret
- **本地处理**:默认情况下所有扫描均在本地进行
- **最小权限**:CI 集成仅需代码的读取权限
## 贡献
欢迎踊跃贡献。请参阅 [CONTRIBUTING.md](CONTRIBUTING.md) 了解指南。
## 致谢
基于以下工具构建:
- [Cobra](https://github.com/spf13/cobra) — CLI 框架
- [Viper](https://github.com/spf13/viper) — 配置管理
- [OPA](https://www.openpolicyagent.org/) — 策略引擎
- [go-sarif](https://github.com/owenrumney/go-sarif) — SARIF 支持
标签:AI应用开发, CI/CD安全, DevSecOps, EVTX分析, Go语言, IaC扫描, Llama, LLM防护, OPA策略, StruQ, 上游代理, 日志审计, 秘密检测, 程序破解, 错误基检测, 静态代码分析