解决 Trivy 报错 DB update failed GitHub rate limit 数据库更新限流修复
排查 CI 流水线运行 Trivy 镜像漏洞扫描报 FATAL: failed to download vulnerability DB: rate limit exceeded,分析 GitHub Token 与私有镜像源。
问题现象
CI/CD 流水线中运行 Trivy 镜像安全扫描时突发崩溃:
FATAL Failed to download vulnerability DB: database download error: OCI repository error: 429 Too Many Requests
触发根因
- Trivy 默认从 GitHub Container Registry (ghcr.io) 下载最新的 CVE 漏洞库(
trivy-db); - 共享 CI Runner 的出口公网 IP 在短时间内触发了 GitHub 的匿名匿名下载速率限制(Rate Limit)。
解决步骤
注入 GitHub Personal Access Token 提升限流配额
在执行命令前配置环境变量:
export GITHUB_TOKEN="${{ secrets.GH_PAT_TOKEN }}"
trivy image --download-db-only
搭建或改用内部私有容器镜像代理仓库(推荐企业落地实践)
在内网 Harbor 代理缓存漏洞库并指定源:
trivy image --db-repository registry.internal/aquasecurity/trivy-db:2 my-app:latest
对于隔离环境开启离线扫描模式
使用 --skip-db-update 跳过自动下载。
验证确认
重新运行安全流水线:
漏洞库秒级命中拉取,CVE 检测报告正常输出且无任何 429 报错。


