已合并
feat: Added gitleaks for sensitive information detection #4843
wujinyuan1创建于 26 天前
feat: Added gitleaks for sensitive information detection #4843
已合并
Pull Request已成功合入, 合并人@ascend-robot
(感谢 wujinyuan1 的贡献)26 天前 创建了 pull request,commit ebecd117
atomgit-bot
26 天前 评论:
26 天前 评论:
变更摘要
本次 PR 引入了 gitleaks 离线二进制敏感信息扫描工具,通过在 .pre-commit-config.yaml 中新增本地 Hook 与独立的 pre-commit/.gitleaks.toml 配置文件,实现在 pre-commit 阶段自动检测代码中硬编码的密钥、凭证等敏感信息,防止其被提交到仓库。
主要改动
- 新增 pre-commit 本地 Hook:在
.pre-commit-config.yaml中添加gitleaks-offline-scanHook,使用本地二进制./gitleaks以system语言运行,并通过protect命令配合--verbose、--redact、--config=pre-commit/.gitleaks.toml参数,在pre-commit阶段执行敏感信息扫描。 - 新增 gitleaks 配置文件:创建
pre-commit/.gitleaks.toml,通过[extend] useDefault = true标准语法继承官方内置全套密钥检测规则(覆盖 AWS、Git、SSH、OBS 等常见凭证类型)。 - 配置全局白名单与扫描参数:通过
[[allowlists]]配置占位空正则paths = ["^$"]以满足语法校验,同时设定minEntropy = 3.0、redact = true、maxMatchLength = 2048、scanGitHistory = false等全局扫描基础参数。 - 提供扩展配置注释示例:在
.gitleaks.toml中以注释形式内置了禁用指定内置规则(disabledRules)、新增自定义业务检测规则([[rules]])、全局白名单路径与停用词、以及代码行内# gitleaks:allow局部放行等用法的完整示例,方便后续按需启用。


ascend-robot
26 天前 评论:
26 天前 评论:
atomgit-bot
26 天前 评论:
26 天前 评论:
代码审查
审查总结
本次审查覆盖了 2 个变更文件,逐文件结果如下:
| 文件 | 审查结果 |
|---|---|
.pre-commit-config.yaml |
发现 1 个问题(P1) |
pre-commit/.gitleaks.toml |
发现 1 个问题(P2) |
问题统计:
- P1: 1 个 —
./gitleaks二进制文件缺失,合并后 pre-commit 钩子将对所有提交者直接报错,阻断提交流程。 - P2: 1 个 —
minEntropy = 3.0远低于官方默认值 5.0,可能造成大量误报,频繁拦截合法代码提交。
整体风险评估: 中等风险。最关键的问题是 gitleaks 二进制文件未随 PR 一同提交,导致该功能实际上不可用且会破坏所有开发者的 pre-commit 体验。minEntropy 设置可能导致可用性问题(误报过多),但可在后续根据实际运行情况调整。
| 类型 | 数量 |
|---|---|
| 🔴 阻塞 | 1 |
| 🟡 建议 | 0 |
⛔ 需要修改


26 天前 添加了label:ascend-cla/yes
此处折叠了107条消息 查看更多
leizhenzhen23
25 天前 评论:
25 天前 评论:
/approve


25 天前 添加了label:approvedlgtm
25 天前 合入了pull request
ascend-robot
25 天前 评论:
25 天前 评论:
Pull Request 已合并或已关闭。
If you want to solve this problem, you can click here to do it in the FAQs.


ascend-robot
25 天前 评论:
25 天前 评论:
Pull Request 已合并或已关闭。
If you want to solve this problem, you can click here to do it in the FAQs.


What this PR does / why we need it?
Does this PR introduce any user-facing change?
无.
How was this patch tested?
PR流水线pre-commit检测新增敏感信息检测.