名称: ggshield-scanner
描述: 在硬编码的密钥(API 密钥、凭证、令牌)泄露到 git 之前,检测 500 多种类型。封装了 GitGuardian 的 ggshield CLI。
主页: https://github.com/GitGuardian/ggshield-skill
元数据:
clawdbot:
requires:
bins: ["ggshield"]
env: ["GITGUARDIAN_API_KEY"]
ggshield 是一款 CLI 工具,用于检测代码库中的硬编码密钥。此 Moltbot 技能为您的 AI 助手带来了密钥扫描能力。
密钥是绝不应提交到版本控制的敏感凭证:
- AWS 访问密钥、GCP 服务账户、Azure 凭证
- API 令牌(GitHub、Slack、Stripe 等)
- 数据库密码和连接字符串
- 私有加密密钥和证书
- OAuth 令牌和刷新令牌
- PayPal/Stripe API 密钥
- 邮件服务器凭证
单个泄露的密钥可能导致:
- 🔓 基础设施被攻破
- 💸 产生巨额云账单(攻击者滥用您的 AWS 账户)
- 📊 客户数据泄露(违反 GDPR/CCPA)
- 🚨 触发安全事件和审计
ggshield 能在这些密钥到达您的仓库之前将其捕获。
scan-repo扫描整个 git 仓库以查找密钥(包括历史记录)。
@clawd scan-repo /path/to/my/project
输出示例(无问题):
🔍 正在扫描仓库...
✅ 仓库干净:已扫描 1,234 个文件,未发现密钥
输出示例(检测到问题):
❌ 发现 2 个密钥:
- config/prod.py:42 处的 AWS 访问密钥 ID
- .env.backup:8 处的 Slack API 令牌
使用 'ggshield secret ignore --last-found' 忽略,或将其移除。
scan-file扫描单个文件以查找密钥。
@clawd scan-file /path/to/config.py
scan-staged仅扫描已暂存的 git 更改(适用于提交前检查)。
@clawd scan-staged
此命令仅对您 git add 过的更改运行(速度很快!)。
install-hooks将 ggshield 安装为 git 提交前钩子。
@clawd install-hooks
安装后,每次提交都会自动扫描:
$ git commit -m "添加配置"
🔍 正在运行 ggshield 提交前钩子...
❌ 检测到密钥!提交被阻止。
请移除密钥后重试。
scan-docker扫描 Docker 镜像各层中的密钥。
@clawd scan-docker my-app:latest
ggshield CLI:通过 pip 安装
bash
pip install ggshield>=1.15.0
GitGuardian API 密钥:密钥检测所必需
bash
export GITGUARDIAN_API_KEY="your-api-key-here"
Python 3.8+:ggshield 所需
clawdhub install ggshield-scanner
现在该技能已在您的 Moltbot 工作区中可用。
启动一个新的 Moltbot 会话以加载此技能:
moltbot start
# 或通过消息:@clawd list-skills
开发者:@clawd scan-repo .
Moltbot:✅ 仓库干净。可以推送!
开发者:git push
开发者:@clawd scan-repo ~/my-old-project
Moltbot:❌ 在历史记录中发现 5 个密钥!
- config/secrets.json 中的 AWS 密钥
- docker-compose.yml 中的数据库密码
- .env.example 中的 Slack webhook
Moltbot:建议:立即轮换这些凭证。
考虑使用 git-filter-repo 将其从历史记录中移除。
开发者:@clawd install-hooks
Moltbot:✅ 已安装提交前钩子
开发者:echo "SECRET_TOKEN=xyz" > config.py
开发者:git add config.py
开发者:git commit -m "添加配置"
Moltbot:❌ 提交前钩子检测到密钥!
开发者:rm config.py && git reset
开发者:(将配置添加到 .gitignore 和环境变量中)
开发者:git commit -m "添加配置" # 现在可以了!
开发者:@clawd scan-docker my-api:v1.2.3
Moltbot:✅ Docker 镜像干净
这些是技能运行所必需的:
| 变量 | 值 | 设置位置 |
|---|---|---|
GITGUARDIAN_API_KEY |
来自 https://dashboard.gitguardian.com 的 API 密钥 | ~/.bashrc 或 ~/.zshrc |
GITGUARDIAN_ENDPOINT |
https://api.gitguardian.com (默认,可选) |
通常不需要 |
创建 ~/.gitguardian/.gitguardian.yml 以进行持久化设置:
verbose: false
output-format: json
exit-code: true
详情请见:https://docs.gitguardian.com/ggshield-docs/
✅ 仅发送元数据:
❌ 绝不发送:
参考:GitGuardian 企业客户可以使用本地扫描,无需将数据发送到任何地方。
ggshield 使用以下方法:
ggshield 未安装或不在您的 PATH 中。
修复:
pip install ggshield
which ggshield # 应返回一个路径
环境变量未设置。
修复:
export GITGUARDIAN_API_KEY="your-key"
# 如需持久化,添加到 ~/.bashrc 或 ~/.zshrc:
echo 'export GITGUARDIAN_API_KEY="your-key"' >> ~/.bashrc
source ~/.bashrc
API 密钥无效或已过期。
修复:
# 测试 API 密钥
ggshield auth status
# 如果无效,请在 https://dashboard.gitguardian.com → API Tokens 重新生成
# 然后:export GITGUARDIAN_API_KEY="new-key"
扫描 50GB 的单体仓库需要时间。ggshield 正在执行大量工作。
变通方案:
# 仅扫描暂存的更改(更快):
@clawd scan-staged
# 或指定子目录:
@clawd scan-file ./app/config.py
有时 ggshield 会标记一个并非密钥的字符串(例如,测试密钥):
# 忽略最后发现的密钥
ggshield secret ignore --last-found
# 忽略文件中的所有密钥
ggshield secret ignore --path ./config-example.py
这将创建包含忽略规则的 .gitguardian/config.json。
您可以将密钥扫描添加到 GitHub Actions / GitLab CI:
# .github/workflows/secret-scan.yml
名称: 密钥扫描
on: [push]
jobs:
scan:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: pip install ggshield
- run: ggshield secret scan repo .
env:
GITGUARDIAN_API_KEY: ${{ secrets.GITGUARDIAN_API_KEY }}
如果您的公司使用 GitGuardian 企业版,您可以在不将数据发送到云端的情况下进行扫描:
export GITGUARDIAN_ENDPOINT="https://your-instance.gitguardian.com"
export GITGUARDIAN_API_KEY="your-enterprise-key"
MIT 许可证 - 详见 LICENSE 文件
版本:1.0.0
最后更新:2026 年 1 月
维护者:GitGuardian