yazz-Sh/devsecops-secure-cicd-pipeline

GitHub: yazz-Sh/devsecops-secure-cicd-pipeline

该项目通过将 SAST、密钥检测、依赖扫描和容器安全等自动化安全检查集成到 GitHub Actions 中,演示了一套面向 Node.js Web 应用的完整安全 CI/CD 流水线。

Stars: 0 | Forks: 0

# Web 应用程序的安全 CI/CD Pipeline ![Security CI Pipeline](https://static.pigsec.cn/wp-content/uploads/repos/cas/8a/8adef3c537edbce4abb10f50f0578d72677cfae8d66a886ffa314959c515fc90.svg) ## 项目概述 本项目是一个实践性的 DevSecOps 实验室,重点是将安全检查直接集成到 CI/CD pipeline 中。 其目标是通过自动化测试、容器化、静态分析、secret 检测、漏洞扫描、Docker 镜像扫描以及基础的动态应用程序安全测试,来保护一个简单的 Node.js Web 应用程序。 本项目演示了如何将安全“左移”并集成到软件交付工作流中,而不是将其作为最后的手动步骤。 ## 技术栈 | 类别 | 工具 | |---|---| | 应用程序 | Node.js, Express.js, Helmet | | 容器化 | Docker, Docker Compose | | CI/CD | GitHub Actions | | 测试 | Node.js Test Runner, Supertest | | SAST | Semgrep | | Secret 检测 | Gitleaks | | 漏洞扫描 | Trivy | | DAST | OWASP ZAP Baseline Scan | ## 应用程序 Endpoint | 方法 | Endpoint | 描述 | |---|---|---| | GET | `/` | 主 API 响应 | | GET | `/health` | 健康检查 endpoint | | GET | `/users` | 演示用户 endpoint | | POST | `/login` | 演示登录 endpoint | ## CI/CD Pipeline GitHub Actions 工作流在每次推送到 `main` 分支以及发起 pull request 时自动运行。 Pipeline 阶段: 1. 安装依赖项 2. 运行自动化 API 测试 3. 运行 Semgrep SAST 扫描 4. 运行 Gitleaks secret 检测 5. 运行 Trivy 文件系统漏洞扫描 6. 构建 Docker 镜像 7. 运行 Trivy Docker 镜像漏洞扫描 8. 启动应用程序容器 9. 运行 OWASP ZAP baseline DAST 扫描 10. 将所有安全报告作为 GitHub Actions artifact 上传 ## 已实施的安全控制 | 安全控制 | 工具 | 目的 | |---|---|---| | 静态代码分析 | Semgrep | 检测不安全的编码模式 | | Secret 检测 | Gitleaks | 检测暴露的 secret、API key、token 和凭证 | | 文件系统漏洞扫描 | Trivy | 检测依赖项和文件系统漏洞 | | Docker 镜像漏洞扫描 | Trivy | 检测容器镜像内部的漏洞 | | 动态应用程序安全测试 | OWASP ZAP | 从外部视角测试运行中的应用程序 | ## 生成的安全报告 每次工作流运行都会生成以下报告并作为 artifact 上传: | 报告 | 工具 | 格式 | |---|---|---| | SAST 报告 | Semgrep | JSON | | Secret 检测报告 | Gitleaks | JSON | | 文件系统漏洞报告 | Trivy | JSON | | Docker 镜像漏洞报告 | Trivy | JSON | | DAST baseline 报告 | OWASP ZAP | HTML + JSON | ## 截图 ### GitHub Actions Pipeline 成功 ![GitHub Actions Pipeline 成功](https://raw.githubusercontent.com/yazz-Sh/devsecops-secure-cicd-pipeline/main/screenshots/github-actions-success.png) ### 生成的安全报告 ![Pipeline Artifact](https://raw.githubusercontent.com/yazz-Sh/devsecops-secure-cicd-pipeline/main/screenshots/pipeline-artifacts.png) ### Docker 容器运行中 ![Docker 容器运行中](https://raw.githubusercontent.com/yazz-Sh/devsecops-secure-cicd-pipeline/main/screenshots/docker-container-running.png) ### 健康 Endpoint ![健康 Endpoint](https://static.pigsec.cn/wp-content/uploads/repos/cas/f0/f0b51aa11e12091627022e88480cb40fe7ae926472830ca9422a7f312c2ee99f.png) ## 在本地运行 ``` cd app npm install npm start ``` 应用程序 URL: ``` http://localhost:3000 ``` 健康检查: ``` http://localhost:3000/health ``` ## 使用 Docker 运行 ``` docker compose up --build ``` 停止容器: ``` docker compose down ``` ## 项目结构 ``` devsecops-secure-cicd-pipeline/ ├── app/ │ ├── package.json │ ├── package-lock.json │ ├── server.js │ └── server.test.js ├── .github/ │ └── workflows/ │ └── security-pipeline.yml ├── screenshots/ │ ├── github-actions-success.png │ ├── pipeline-artifacts.png │ ├── docker-container-running.png │ └── health-endpoint.png ├── reports/ ├── Dockerfile ├── docker-compose.yml ├── .gitignore ├── LICENSE └── README.md ``` ## 我学到了什么 通过这个项目,我实践了: - 构建基础的 Node.js API - 编写自动化 API 测试 - 使用 Docker 对应用程序进行容器化 - 创建 GitHub Actions CI/CD pipeline - 使用 Semgrep 运行 SAST - 使用 Gitleaks 检测已提交的 secret - 使用 Trivy 扫描依赖项和 Docker 镜像 - 使用 OWASP ZAP 运行基础的 DAST 扫描 - 将安全报告作为 GitHub Actions artifact 上传 ## 下一步改进 计划改进: - 为高危和严重漏洞添加安全门控 - 检测到 secret 时使 pipeline 失败 - 将 SARIF 报告添加到 GitHub Security 标签页 - 添加 SBOM 生成 - 添加 Kubernetes 部署清单 - 添加基础设施即代码扫描 - 添加带有安全检查的云部署 ## 展示的技能 DevSecOps | CI/CD 安全 | 应用程序安全 | Docker 安全 | 漏洞扫描 | Secret 检测 | SAST | DAST | GitHub Actions
标签:DevSecOps, Docker, GitHub Actions, GNU通用公共许可证, MITM代理, Node.js, URL发现, 上游代理, 安全检测, 安全防御评估, 版权保护, 自动笔记, 自定义脚本, 请求拦截, 错误基检测, 静态代码分析