milobzb/security-pipeline

GitHub: milobzb/security-pipeline

可复用的 GitHub Actions 安全流水线,在每次代码推送时自动扫描硬编码机密信息和 Python 依赖漏洞,将安全检查持续性地集成到仓库的 CI 流程中。

Stars: 0 | Forks: 0

# 安全流水线 一个可复用的 GitHub Actions 安全流水线,在每次 push 时扫描仓库中硬编码的机密信息和存在漏洞的 Python 依赖项,将结果汇总到一份报告中,如果发现任何问题,则使构建失败。 该项目旨在演示一种可用的安全软件开发生命周期 (secure SDLC) 模式:自动化的、持续性的,并且直接接入它所保护的仓库,而不是一次性的手动检查。 ![安全流水线](https://static.pigsec.cn/wp-content/uploads/repos/cas/4a/4aa847ca556908f9e6b4bb96c4eef9e653f9f635933866e222b8b5ebc78eeb30.svg) ## 它的功能 在每次 push 或 pull request 时,流水线会: 1. 使用 [gitleaks](https://github.com/gitleaks/gitleaks) **扫描硬编码的机密信息** —— 包括意外提交到源代码中的 API key、token 和凭证。 2. 使用 [pip-audit](https://github.com/pypa/pip-audit) 针对 `requirements.txt` **审计 Python 依赖项**,标记出包含已知 CVE 的包。 3. **将上述两项结果汇总**为一份 markdown 摘要(直接显示在 GitHub Actions 运行界面中),并将完整的 JSON 报告作为可下载的 artifact 上传。 4. 如果任一检查发现问题,则**使构建失败**,从而确保在 push 时就能发现问题,而不是等到日后才被发现。 ## 为什么使用可复用的 workflow 而不是复制粘贴的 YAML 块 此流水线设计为从其他仓库调用,而不是在每个仓库中进行重复复制: ``` # 消费仓库中的 .github/workflows/security.yml name: Security Pipeline on: push: branches: [main] pull_request: jobs: security: uses: milobzb/security-pipeline/.github/workflows/security-scan.yml@main ``` 只需在一个地方修复 bug 或添加新的检查,每个调用的仓库就会在下一次运行时自动获取更新。目前已接入: - [Orphaned Account Detector](https://github.com/milobzb/Orphaned-Account-Detector) - [RBAC Policy Checker](https://github.com/milobzb/rbac-policy-checker) ## 架构 ``` security-pipeline/ ├── .github/workflows/ │ └── security-scan.yml # the reusable workflow (workflow_call) ├── scripts/ │ ├── scan-secrets.sh # installs + runs gitleaks, emits JSON │ ├── scan-deps.sh # installs + runs pip-audit, emits JSON │ └── aggregate-report.sh # merges both reports, sets pass/fail ├── Dockerfile # same scan environment, runnable locally └── README.md ``` 扫描逻辑位于独立的 bash 脚本中,而不是直接内嵌在 workflow 的 YAML 中,因此它可以在 CI、container 中,或者由人在笔记本电脑上手动以完全相同的方式运行——而且这让它能够作为真实的、独立的 shell 代码呈现,而不是被埋没在 YAML 字符串中。 ## 使用 Docker 在本地运行 ``` docker build -t security-pipeline . docker run --rm -v "$(pwd):/scan" security-pipeline \ -c "/opt/security-pipeline/scripts/scan-secrets.sh /scan/security-reports && \ /opt/security-pipeline/scripts/scan-deps.sh /scan/security-reports && \ /opt/security-pipeline/scripts/aggregate-report.sh /scan/security-reports" ``` ## 技术栈 Bash、YAML (GitHub Actions)、Docker、gitleaks、pip-audit、jq。 ## 作者 Emanuel Botros — [emanuelbotros.com](https://emanuelbotros.com) · [LinkedIn](https://linkedin.com/in/milobzb)
标签:DevSecOps, GitHub Actions, StruQ, 上游代理, 依赖审计, 安全检查, 应用安全, 自动笔记, 请求拦截