sunnyoncloud9/devsecops-pipeline

GitHub: sunnyoncloud9/devsecops-pipeline

基于 GitHub Actions 的 DevSecOps 流水线项目,将 SAST、SCA、密钥扫描、容器和 IaC 扫描整合到 CI/CD 流程中,通过自动化安全门禁在不安全代码进入生产前将其拦截。

Stars: 0 | Forks: 0

# 🛡️ DevSecOps Pipeline [![DevSecOps Pipeline](https://static.pigsec.cn/wp-content/uploads/repos/cas/a7/a7765e5f213bea1ed6d685c1c859a11ca9accbe786b6f3bdfc659126f3a5ad14.svg)](https://github.com/sunnyoncloud9/devsecops-pipeline/actions/workflows/devsecops.yml) [![Python 3.11+](https://img.shields.io/badge/python-3.11+-blue.svg)](https://www.python.org/) [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE) ## 📌 概述 本项目实现了一个生产级的 **DevSecOps pipeline**,在软件交付生命周期的每个阶段都嵌入了安全措施。每次提交都会自动扫描易受攻击的代码、存在漏洞的依赖项、泄露的机密信息、不安全的容器镜像以及配置错误的基础设施——如果发现严重问题,构建将被**阻止**。 其目标是展示**安全左移**:在问题进入生产环境之前,在 CI 阶段就将其捕获。 ## 📸 Pipeline 运行展示 ### 所有扫描阶段通过 ![Security Gate Logs](https://raw.githubusercontent.com/sunnyoncloud9/devsecops-pipeline/main/images/gate-logs.png) ### Pipeline 运行概览 ![Pipeline Failure](https://static.pigsec.cn/wp-content/uploads/repos/cas/7f/7f28391e7574c0d90a69a5314b50e3957d6d9824e735094675d3331c82c09aa2.png) ## 🔧 Pipeline 阶段 | 阶段 | 工具 | 负责检测的内容 | |-------|------|-----------------| | **SAST** | Bandit, Semgrep | 不安全的代码模式、注入漏洞 | | **SCA** | pip-audit, Safety | 存在漏洞的依赖项 (CVE) | | **机密扫描** | Gitleaks, detect-secrets | 硬编码的 API key、token、密码 | | **容器扫描** | Trivy | 镜像中存在漏洞的 OS 包 | | **IaC 扫描** | Checkov | 配置错误的 Terraform 资源 | | **安全门禁** | 自定义 Python 脚本 | 汇总结果,执行策略 | ## 🏗️ 架构 ``` Developer pushes code │ ▼ ┌─────────────────────────────────────────────┐ │ GitHub Actions Pipeline │ │ │ │ SAST ──┐ │ │ SCA ───┤ │ │ Secrets┤──→ Security Gate ──→ Pass / Fail │ │ Docker ┤ │ │ IaC ───┘ │ └─────────────────────────────────────────────┘ ``` ## 🚦 安全门禁策略 该门禁 (`scripts/security_gate.py`) 强制执行以下策略: - **严重 (CRITICAL) 级别发现:** 允许 `0` 个 —— 任何严重级别的发现都会导致构建失败 - **高 (HIGH) 级别发现:** 最多容忍 `5` 个 —— 超过此数量将导致构建失败 ``` if critical > 0: print("❌ Critical vulnerabilities found") sys.exit(1) if high > 5: print("❌ Too many high vulnerabilities") sys.exit(1) print("✅ Security gate passed") ``` ## 💥 失败场景示例 一名开发者引入了存在漏洞的依赖项: 1. 代码通过 SAST ✅ 2. 依赖项扫描检测到 CVE ✅ 3. 安全门禁评估所有发现的问题 4. 构建**失败** —— 不安全的代码在部署前被阻止 ❌ ## 🔐 示例应用中的安全实践 - 从环境变量中加载机密信息 —— 绝不硬编码 - 非 root 容器用户 —— 最小权限原则 - 锁定基础镜像 —— 使用 `python:3.11-slim`,而非 `latest` - 生产级 WSGI 服务器 —— 使用 gunicorn,而非 Flask 开发服务器 - 所有 endpoint 均进行输入验证 - Terraform 中配置 S3 加密、版本控制和阻止公共访问 - 最小权限安全组 —— 仅限 HTTPS ## 📁 项目结构 ``` devsecops-pipeline/ ├── .github/workflows/ │ └── devsecops.yml # Full pipeline definition ├── sample-app/ │ ├── app.py # Hardened Flask app │ ├── requirements.txt │ └── Dockerfile # Non-root hardened container ├── iac/ │ └── main.tf # Secure-by-default Terraform ├── scripts/ │ ├── security_gate.py # Aggregates results, enforces policy │ └── report.py # Generates PDF security report ├── tests/ │ └── test_security_gate.py # Unit tests ├── images/ │ ├── failure.png │ └── gate-logs.png └── README.md ``` ## 🚀 本地运行 ``` # 运行 security gate python scripts/security_gate.py ./reports # 生成 PDF 报告 python scripts/report.py ./reports # 运行单元测试 python -m unittest discover tests/ # 构建并运行示例应用 docker build -t sample-app ./sample-app docker run -p 5000:5000 sample-app ``` ## 🗺️ 路线图 - [ ] DAST 阶段(对运行中的应用进行动态扫描) - [ ] SBOM 生成 (CycloneDX) - [ ] 签名容器镜像 (cosign) - [ ] 使用 OIDC 将门禁部署到 AWS - [ ] 门禁失败时发送 Slack 通知 ## 👤 作者 **Sunny Bhardwaj** - GitHub: [@sunnyoncloud9](https://github.com/sunnyoncloud9) - LinkedIn: [linkedin.com/in/bhardwajsunny](https://www.linkedin.com/in/bhardwajsunny/) ## 📜 许可证 MIT 许可证 —— 详情请参阅 [LICENSE](LICENSE)。
标签:请求拦截, 逆向工具