已合并
feat: Added gitleaks for sensitive information detection #4843
wujinyuan1创建于 26 天前
feat: Added gitleaks for sensitive information detection #4843
已合并
wujinyuan1创建于 26 天前
wujinyuan1
26 天前

What this PR does / why we need it?

  1. 引入gitleaks二进制离线扫描工具
  2. 新增pre-commit/.gitleaks.toml配置,继承官方全部检测规则
  3. 配置pre-commit钩子,提交前自动扫描密钥硬编码风险。

Does this PR introduce any user-facing change?

无.

How was this patch tested?

PR流水线pre-commit检测新增敏感信息检测.

likedislike
Pull Request已成功合入, 合并人@ascend-robot
(感谢 wujinyuan1 的贡献)
Wwujinyuan1
26 天前 创建了 pull request,commit ebecd117
atomgit-bot
atomgit-bot
26 天前 评论:

变更摘要

本次 PR 引入了 gitleaks 离线二进制敏感信息扫描工具,通过在 .pre-commit-config.yaml 中新增本地 Hook 与独立的 pre-commit/.gitleaks.toml 配置文件,实现在 pre-commit 阶段自动检测代码中硬编码的密钥、凭证等敏感信息,防止其被提交到仓库。

主要改动

  • 新增 pre-commit 本地 Hook:在 .pre-commit-config.yaml 中添加 gitleaks-offline-scan Hook,使用本地二进制 ./gitleakssystem 语言运行,并通过 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.0redact = truemaxMatchLength = 2048scanGitHistory = false 等全局扫描基础参数。
  • 提供扩展配置注释示例:在 .gitleaks.toml 中以注释形式内置了禁用指定内置规则(disabledRules)、新增自定义业务检测规则([[rules]])、全局白名单路径与停用词、以及代码行内 # gitleaks:allow 局部放行等用法的完整示例,方便后续按需启用。
likedislike
atomgit-bot
atomgit-bot
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

⛔ 需要修改

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

/approve

likedislike
ascend-robotascend-robot成员
25 天前 添加了label:approvedlgtm
ascend-robotascend-robot成员
25 天前 合入了pull request
ascend-robot
ascend-robot成员
25 天前 评论:

Pull Request 已合并或已关闭。

If you want to solve this problem, you can click here to do it in the FAQs.

likedislike
ascend-robot
ascend-robot成员
25 天前 评论:

Pull Request 已合并或已关闭。

If you want to solve this problem, you can click here to do it in the FAQs.

likedislike