ScanGuard 是一个团队级的综合安全扫描工具集,提供容器镜像安全扫描和代码质量扫描功能,支持多语言、多团队、灵活配置。
本项目包含两个主要功能模块:
ScanGuard/ ├── README.md # 项目主文档 ├── docs/ # 文档目录 │ ├── TEAM_GUIDE.md # 团队使用指南 │ ├── CHANGELOG.md # 更新日志 │ ├── EXAMPLES.md # 使用示例 │ ├── QUICK_REFERENCE.md # 快速参考 │ ├── SCAN_CAPABILITIES.md # 扫描能力说明 │ └── ... # 其他文档 ├── configs/ # 配置模板目录 │ ├── README.md # 配置文件说明 │ ├── strict.conf # 严格模式配置 │ ├── standard.conf # 标准模式配置 │ ├── relaxed.conf # 宽松模式配置 │ ├── python.conf # Python 项目配置 │ ├── java.conf # Java 项目配置 │ ├── javascript.conf # JS/TS 项目配置 │ ├── exclusions-python.txt # Python 排除模板 │ ├── exclusions-java.txt # Java 排除模板 │ └── exclusions-javascript.txt # JS 排除模板 ├── integrations/ # CI/CD 集成目录 ⭐ │ ├── README.md # 集成指南 │ ├── QUICK_START.md # 快速开始 │ ├── image-scan/ # 镜像扫描集成配置 │ │ ├── gitlab-ci.yml # GitLab CI 配置 │ │ ├── github-actions.yml # GitHub Actions 配置 │ │ ├── jenkins-pipeline.groovy # Jenkins Pipeline │ │ └── cnb.yml # CNB 平台配置 ⭐ │ ├── code-scan/ # 代码扫描集成配置 │ │ ├── gitlab-ci.yml # GitLab CI 配置 │ │ ├── github-actions.yml # GitHub Actions 配置 │ │ ├── jenkins-pipeline.groovy # Jenkins Pipeline │ │ └── cnb.yml # CNB 平台配置 ⭐ │ ├── CNB_GUIDE.md # CNB 平台集成指南 ⭐ │ └── scripts/ # 可执行脚本 │ ├── image-scan.sh # 镜像扫描一键脚本 │ └── code-scan.sh # 代码扫描一键脚本 ├── image-scan/ # 镜像扫描模块 │ ├── scan.sh # 镜像扫描脚本 │ ├── generate_report.py # 报告生成脚本 │ ├── README.md # 镜像扫描使用说明 │ └── tests/ # 单元测试 │ ├── test_generate_report.py # 报告生成测试 │ ├── test_data.py # 测试数据 │ └── README.md # 测试说明 └── code-scan/ # 代码扫描模块 ├── docker-compose.yml # SonarQube 服务配置 ├── scan.sh # 代码扫描脚本 ├── generate_report.py # 报告生成脚本 ├── sonar-rules.conf # 规则配置文件 ├── exclusions.txt # 扫描排除规则 ├── README.md # 代码扫描使用说明 └── CONFIG_GUIDE.md # 配置详细指南
如果你是第一次使用 ScanGuard,或者需要为团队配置扫描工具,请查看:
📖 团队使用指南 - 详细的团队使用和配置说明
扫描 Docker 镜像的安全漏洞:
cd image-scan
./scan.sh <镜像名称> [阻断级别] [企业微信Webhook Key]
示例:
# 基本扫描(使用默认 HIGH 级别)
./scan.sh nginx:latest
# 指定阻断级别
./scan.sh nginx:latest CRITICAL
# 扫描并发送企业微信通知(使用 webhook key)
./scan.sh nginx:latest HIGH "your-webhook-key-here"
# 或使用环境变量(推荐)
export WECHAT_KEY="your-webhook-key-here"
./scan.sh nginx:latest HIGH
更多详情请查看 image-scan/README.md
根据项目类型选择合适的配置:
# Python 项目
cp configs/python.conf <项目目录>/sonar-rules.conf
cp configs/exclusions-python.txt <项目目录>/exclusions.txt
# Java 项目
cp configs/java.conf <项目目录>/sonar-rules.conf
cp configs/exclusions-java.txt <项目目录>/exclusions.txt
# JavaScript/TypeScript 项目
cp configs/javascript.conf <项目目录>/sonar-rules.conf
cp configs/exclusions-javascript.txt <项目目录>/exclusions.txt
# 或者按严格程度选择
cp configs/standard.conf <项目目录>/sonar-rules.conf # 标准模式(推荐)
cp configs/strict.conf <项目目录>/sonar-rules.conf # 严格模式
cp configs/relaxed.conf <项目目录>/sonar-rules.conf # 宽松模式
cd code-scan
docker-compose up -d
等待服务启动后,访问 http://localhost:9000 进行初始配置。
cd code-scan
./scan.sh <SonarQube_Token> [项目Key] [输出文件] [企业微信Key]
示例:
export SONAR_TOKEN=sqa_xxxxx
export SONAR_PROJECT=my-project
cd code-scan
./scan.sh
更多详情请查看:
export WECHAT_KEY="your-key"./scan.sh <image> [level] [key]cp configs/python.conf sonar-rules.conf
cp configs/exclusions-python.txt exclusions.txt
# 根据需要调整配置
cp configs/javascript.conf sonar-rules.conf
cp configs/exclusions-javascript.txt exclusions.txt
cp configs/java.conf sonar-rules.conf
cp configs/exclusions-java.txt exclusions.txt
# 使用宽松模式,逐步改进
cp configs/relaxed.conf sonar-rules.conf
更多使用场景请查看 TEAM_GUIDE.md
| 项目类型 | 推荐配置 | 说明 |
|---|---|---|
| 新项目 | strict.conf 或 standard.conf | 从高标准开始 |
| 成熟项目 | standard.conf ⭐ | 平衡质量和效率 |
| 遗留代码 | relaxed.conf | 逐步改进 |
| Python 项目 | python.conf | 语言特定优化 |
| Java 项目 | java.conf | 企业级 Java |
| 前端项目 | javascript.conf | 现代前端框架 |
详细配置说明请查看:
镜像扫描模块包含完整的单元测试:
cd image-scan/tests
python3 -m unittest discover -s . -p "test_*.py" -v
测试覆盖:
更多详情请查看 image-scan/tests/README.md
| 文档 | 说明 |
|---|---|
| README.md | 项目主文档(当前) |
| integrations/README.md | CI/CD 集成指南 ⭐ |
| integrations/QUICK_START.md | 快速集成指南 ⚡ |
| integrations/CNB_GUIDE.md | CNB 平台集成指南 ⭐ |
| docs/TEAM_GUIDE.md | 团队使用指南 |
| docs/CHANGELOG.md | 更新日志 |
| docs/EXAMPLES.md | 使用示例 |
| docs/QUICK_REFERENCE.md | 快速参考 |
| docs/SCAN_CAPABILITIES.md | 扫描能力说明 |
| configs/README.md | 配置模板说明 |
| code-scan/README.md | 代码扫描使用说明 |
| code-scan/CONFIG_GUIDE.md | 配置详细指南 |
| image-scan/README.md | 镜像扫描使用说明 |
| image-scan/tests/README.md | 测试说明 |
无需下载项目,直接使用远程脚本:
# 镜像扫描
curl -sL https://cnb.cool/fagougou/ScanGuard/-/git/raw/main/integrations/scripts/image-scan.sh | \
bash -s -- <镜像名称> [阻断级别] [webhook_key]
# 代码扫描
curl -sL https://cnb.cool/fagougou/ScanGuard/-/git/raw/main/integrations/scripts/code-scan.sh | \
bash -s -- <token> <project> [output] [wechat_key] [scan_dir] [sonar_host]
我们为各种 CI/CD 平台提供了开箱即用的配置:
如果你需要下载项目到本地使用,请查看 TEAM_GUIDE.md
A: 参考 configs/README.md 中的选择指南。
A: 参考 code-scan/CONFIG_GUIDE.md 中的自定义配置章节。
A: 可以在 exclusions.txt 中排除文件,或使用代码注释抑制(如 # NOSONAR)。
A: 从 standard.conf 开始,添加各语言的规则配置。参考 配置详细指南。
欢迎提交 Issue 和 Pull Request 来改进本项目。
本项目采用 MIT 许可证。
如有问题或建议,请通过 Issue 反馈。
维护团队:ScanGuard 项目组
最后更新:2025年12月