3.2 依赖项监控
概述
依赖项监控 (Dependency Monitoring) 持续监控我们所有仓库中的依赖项,并在安全更新可用时自动创建拉取请求 (Pull Request)。
工具
GitHub Dependabot
Dependabot 在所有仓库中启用,负责处理:
- 安全更新: 针对已知漏洞自动创建 PR
- 版本更新: 针对可用更新定期创建 PR(可配置)
- 告警: 针对新 CVE 的 GitHub Security Alerts
配置 (.github/dependabot.yml):
yaml
version: 2
updates:
# 示例:NPM
- package-ecosystem: "npm"
directory: "/"
schedule:
interval: "weekly"
open-pull-requests-limit: 10
labels:
- "dependencies"
- "security"
# 示例:Docker
- package-ecosystem: "docker"
directory: "/"
schedule:
interval: "weekly"
labels:
- "dependencies"
- "docker"
# 示例:GitHub Actions
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
labels:
- "dependencies"
- "ci"Dependabot 自动合并
对于非关键更新(来自受信任软件包的补丁更新),使用现有的自动合并工作流 (docker-maintenance-dependabot.yml):
- Dependabot 创建 PR
- CI 流水线运行(测试、安全扫描)
- 成功后:自动批准
- 自动合并 (squash)
重要提示
自动合并 仅 针对补丁更新和受信任的生态系统启用。主版本和次版本更新需要手动审查。
GitHub Security Alerts
GitHub Security Alerts 在所有仓库中启用:
- 自动通知依赖项中的新 CVE
- 映射到特定的清单文件
- 严重程度分类(Critical、High、Medium、Low)
- 通过 Dependabot Security Updates 提供修复建议
Trivy 容器扫描
对于容器镜像,在 CI/CD 中额外使用 Trivy:
yaml
# 每次构建时自动扫描
- name: Trivy Vulnerability Scan
uses: aquasecurity/trivy-action@master
with:
image-ref: ${{ env.IMAGE }}
severity: CRITICAL,HIGH
exit-code: 1 # 发现问题时构建失败Docker 基础镜像监控
现有工作流 modules-docker-base-image-monitor.yml 监控基础镜像:
- 检测新的基础镜像版本
- 更新可用时自动创建 PR
- 确保操作系统软件包保持最新
监控矩阵
| 生态系统 | 工具 | 频率 | 自动合并 |
|---|---|---|---|
| NPM | Dependabot | 每周 | 补丁更新 |
| NuGet | Dependabot | 每周 | 补丁更新 |
| pip/Poetry | Dependabot | 每周 | 补丁更新 |
| Docker | Dependabot + 基础镜像监控 | 每周 | 补丁更新 |
| GitHub Actions | Dependabot | 每周 | 次版本/补丁 |
| Go Modules | Dependabot | 每周 | 补丁更新 |
| Composer (PHP) | Dependabot | 每周 | 补丁更新 |
升级处理流程
Dependabot/Trivy 检测到 CVE
|
+-- 低/中等严重程度
| +-- 创建 PR -> 在下一个冲刺中审查
|
+-- 高严重程度
| +-- 创建 PR -> 24 小时内审查 -> 补丁发布
|
+-- 严重 (Critical)
+-- 创建 PR -> 立即处理
+-- Teams 通知安全负责人
+-- 检查:是否正在被积极利用?
| +-- 是 -> ENISA 报告流程(24 小时)
| +-- 否 -> 48 小时内修补
+-- 热修复发布