cloudon-one/git-security-scanner-public

GitHub: cloudon-one/git-security-scanner-public

集成 Gitleaks 与 Trivy 的全能 GitHub Action,用于在 CI/CD 流水线中自动化扫描代码密钥、依赖漏洞及基础设施错误配置。

Stars: 3 | Forks: 0

# Git 安全扫描器 - GitHub Action [![GitHub Marketplace](https://img.shields.io/badge/Marketplace-Git%20Security%20Scanner-blue?logo=github)](https://github.com/marketplace/actions/git-security-scanner) [![Release](https://img.shields.io/github/v/release/cloudon-one/git-security-scanner-public)](https://github.com/cloudon-one/git-security-scanner-public/releases/tag/2.3) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![Docker](https://img.shields.io/badge/Docker-ghcr.io-blue?logo=docker)](https://github.com/cloudon-one/git-security-scanner-public/pkgs/container/git-security-scanner) **针对 GitHub 仓库的全面安全扫描** - 在您的 CI/CD 流水线中检测密钥、漏洞和错误配置。 ## 功能特性 - **密钥检测** - 使用 Gitleaks 发现 API 密钥、密码和令牌 - **漏洞扫描** - 使用 Trivy 识别 CVE 和安全问题 - **OSV 扫描** - 检测开源依赖项中的已知漏洞 - **错误配置检测** - 发现 IaC 和 Kubernetes 安全问题 - **多种报告格式** - 支持 JSON、HTML 以及用于 GitHub Security 标签页的 SARIF - **PR 集成** - 在 pull requests 上自动添加安全评论 - **质量门禁** - 发现关键安全问题时使构建失败 - **多架构支持** - 支持 AMD64 和 ARM64 runner ## 快速开始 添加到您的工作流(`.github/workflows/security.yml`): ``` name: Security Scan on: [push, pull_request] permissions: contents: read security-events: write pull-requests: write packages: read jobs: security: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 with: fetch-depth: 0 - name: Run Security Scan uses: cloudon-one/git-security-scanner-public@2.3 with: github_token: ${{ secrets.GITHUB_TOKEN }} fail_on_critical: true scan_type: all create_pr_comment: true - name: Upload scan artifacts if: always() uses: actions/upload-artifact@v4 with: name: security-scan-results-${{ github.run_number }} path: /tmp/security-scan-results/ retention-days: 30 ``` ## 配置 ### 输入 | 输入 | 必填 | 默认值 | 描述 | |-------|----------|---------|-------------| | `github_token` | 否 | `${{ github.token }}` | 用于 API 访问的 GitHub 令牌 | | `fail_on_critical` | 否 | `true` | 发现关键问题时使构建失败 | | `scan_type` | 否 | `all` | 扫描类型:`all`、`gitleaks` 或 `trivy` | | `repository_path` | 否 | `.` | 要扫描的仓库路径 | | `upload_sarif` | 否 | `true` | 上传 SARIF 到 GitHub Security 标签页 | | `create_pr_comment` | 否 | `true` | 使用结果创建 PR 评论 | | `scanner_version` | 否 | `main` | 要使用的 Docker 镜像标签 | ### 输出 | 输出 | 描述 | |--------|-------------| | `risk_level` | 整体风险:`CRITICAL`、`HIGH`、`MEDIUM`、`LOW`、`INFO` | | `critical_count` | 关键问题数量 | | `high_count` | 高严重性问题数量 | | `medium_count` | 中严重性问题数量 | | `low_count` | 低严重性问题数量 | | `secrets_found` | 检测到的密钥数量 | | `vulnerabilities_found` | 发现的漏洞数量 | | `misconfigurations_found` | 检测到的错误配置数量 | | `report_url` | 详细安全报告的链接 | ## 使用示例 ### 基础安全检查 ``` - uses: cloudon-one/git-security-scanner-public@2.3 with: fail_on_critical: true create_pr_comment: true ``` ### 带有结果处理的高级配置 ``` - uses: cloudon-one/git-security-scanner-public@2.3 id: security with: scan_type: all fail_on_critical: false repository_path: ./src - name: Process Results if: always() run: | echo "Risk Level: ${{ steps.security.outputs.risk_level }}" echo "Secrets: ${{ steps.security.outputs.secrets_found }}" echo "Vulnerabilities: ${{ steps.security.outputs.vulnerabilities_found }}" echo "Misconfigurations: ${{ steps.security.outputs.misconfigurations_found }}" ``` ### 定期每周安全审计 ``` name: Weekly Security Audit on: schedule: - cron: '0 2 * * 1' # Mondays at 2 AM workflow_dispatch: permissions: contents: read security-events: write packages: read jobs: audit: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 with: fetch-depth: 0 - uses: cloudon-one/git-security-scanner-public@2.3 with: fail_on_critical: false ``` ### 仅 Gitleaks 扫描(密钥检测) ``` - uses: cloudon-one/git-security-scanner-public@2.3 with: scan_type: gitleaks fail_on_critical: true ``` ### 仅 Trivy 扫描(漏洞和错误配置) ``` - uses: cloudon-one/git-security-scanner-public@2.3 with: scan_type: trivy fail_on_critical: false ``` ## 从源代码构建 ### 前置条件 - 支持 BuildKit 的 Docker - GitHub Token(用于 GHCR 访问) ### 构建 Docker 镜像 ``` docker build --platform linux/amd64 -t git-security-scanner . ``` ### 运行本地扫描 ``` # 扫描当前目录 docker run --rm \ -v $(pwd):/scan_target:ro \ -v $(pwd)/reports:/reports \ git-security-scanner all # 使用特定扫描类型进行扫描 docker run --rm \ -v $(pwd):/scan_target:ro \ -v $(pwd)/reports:/reports \ git-security-scanner gitleaks ``` ## 架构 ``` git-security-scanner-public/ ├── action.yml # GitHub Action composite definition ├── Dockerfile # Multi-stage container build (Alpine 3.23) ├── git-audit-script.py # Main Python orchestration script ├── run_scans.sh # Shell entrypoint wrapper ├── gitleaks.toml # Secret detection rules configuration ├── Makefile # Build automation └── .github/workflows/ ├── build-scanner-image.yml # Docker image CI/CD └── repository-security-scan.yml # Self-scan workflow ``` ## 安全工具 (2.3) | 工具 | 版本 | 用途 | |------|---------|---------| | [Gitleaks](https://github.com/gitleaks/gitleaks) | v8.30.1 | Git 历史记录和代码中的密钥检测 | | [Trivy](https://github.com/aquasecurity/trivy) | v0.69.3 | 漏洞和错误配置扫描 | | [OSV-Scanner](https://github.com/google/osv-scanner) | v2.2.1 | 开源依赖漏洞检测 | | [Helm](https://helm.sh/) | v3.20.1 | Kubernetes 清单模板渲染 | **基础镜像**:Alpine Linux 3.23 搭配 Python 3.12 ## 更新日志 ### 2.3 (2026-04-08) - 更新 Gitleaks v8.28.0 → v8.30.1 - 更新 Trivy v0.65.0 → v0.69.3 - 新增 OSV-Scanner v2.2.1 用于依赖漏洞检测 - 更新 Helm v3.18.6 → v3.20.1 - 更新 Alpine Linux 3.19 → 3.23 - 为所有安全工具下载添加 SHA256 校验和验证(AMD64 + ARM64) - 修复 JSON 报告指标提取路径 - 移除生产代码中的调试打印语句 - 提升跨仓库 GHCR 访问的 Docker 镜像拉取可靠性 - 多架构支持(AMD64 和 ARM64) ### v2 (2025-11-22) - 新增多架构 Docker 构建 - 新增 Makefile 和 Dockerfile 校验和验证 - 新增单元测试 - 重构主 Python 脚本 ### v1.1.1 (2025-08-27) - 初始公开发布,集成 Gitleaks 和 Trivy ## 贡献 请参阅 [CONTRIBUTING.md](CONTRIBUTING.md) 了解开发指南。 ## 支持 - **Issues**:[报告错误](https://github.com/cloudon-one/git-security-scanner-public/issues) - **Discussions**:[提出问题](https://github.com/cloudon-one/git-security-scanner-public/discussions) ## 许可证 MIT License - 请参阅 [LICENSE](LICENSE) 文件。 由 [CloudOn One](https://github.com/cloudon-one) 制作
标签:Cutter, DevSecOps, GitHub Action, Gitleaks, Git Secrets, Hakrawler, Kubernetes 安全, OSV, SARIF, Vercel, Web截图, 上游代理, 安全扫描, 容器安全, 时序注入, 模型鲁棒性, 自动化工单, 请求拦截, 质量门禁, 逆向工具