环境与配置管理60 条

gitleaks 用法

开源密钥扫描工具:支持全历史检测、规则可扩展、输出脱敏;常用于 CI 流水线与本地 pre-commit。

CI/CD 与发布速查开发更新于 2026-10-12
命令gitleaks detect(历史/目录)、gitleaks protect(暂存区)
配置.gitleaks.toml 自定义规则与 allowlist(抑制误报)
输出JSON/SARIF,便于接入报告与门禁

CI 使用

CI 使用
gitleaks detect --source . --report-format sarif --report-path gitleaks.sarif --redact
gitleaks protect --staged --redact
历史扫描发现条目要区分「真实凭据 / 示例占位符」:allowlist 精确到路径与规则。

易错点

  • allowlist 写太宽(整目录忽略):真问题被一起忽略,精确到规则与文件
  • 只跑增量不跑历史:一次性历史扫描补齐后并入常态

数据来源与参考

  • gitleaks 文档(GitHub)
​‌‌​​‌​​​‌‌​‌‌‌‌​‌‌​​​‌‌​‌‌‌​​‌‌​​‌​‌‌‌​​‌‌‌​​​‌​‌‌​‌​​‌​‌‌‌​​​‌​‌‌​‌​​‌​‌‌​​​‌‌​‌‌‌​‌​​​‌‌​‌‌‌‌​​‌​‌‌‌​​‌‌​​​‌‌​‌‌​‌‌‌‌​‌‌​‌‌​‌