gfmcorrea/devsecops-gitlab-pipeline-security

GitHub: gfmcorrea/devsecops-gitlab-pipeline-security

一个基于 GitLab CI/CD 的 DevSecOps 教学与实践项目,演示如何将多种开源安全工具集成到流水线中并生成完整的证据与修复报告。

Stars: 0 | Forks: 0

# 基于 GitLab CI/CD 的 DevSecOps 安全流水线 ## 概述 我构建这个项目是为了使用 GitLab CI/CD 和开源安全工具来实践 DevSecOps 流水线安全。 目标是创建一个小型演示应用程序,向 CI/CD 流水线中添加安全检查,收集真实证据,并以清晰的方式记录结果。 该项目展示了我是如何将安全检查集成到以下流水线中的: ``` SAST secret scanning dependency scanning container image scanning security gate observation evidence-based reporting ``` 该项目使用了一个安全的本地/演示 Node.js 应用程序。它不会扫描外部目标、第三方系统、真实的公司代码或真实的生产数据。 ## 项目仓库 GitHub 仓库: ``` https://github.com/gfmcorrea/devsecops-gitlab-pipeline-security ``` GitLab CI/CD 项目: ``` https://gitlab.com/gfmcorrea/devsecops-gitlab-pipeline-security ``` ## 为什么我要构建这个项目 我构建这个项目是为了练习如何将安全工具添加到 CI/CD 工作流中。 我希望了解 DevSecOps 流水线从头到尾是如何运作的: ``` create a demo app add a GitLab CI/CD pipeline run security tools save scan reports as artifacts review findings document evidence explain remediation ``` 这个项目帮助我同时练习了技术性安全测试和文档编写。 ## 演示应用程序 演示应用程序是一个简单的 Node.js 和 Express 应用程序,位于: ``` app/ ``` 主要文件: ``` app/server.js app/package.json app/package-lock.json app/Dockerfile app/.dockerignore ``` 该应用程序包含用于安全验证的受控演示问题: ``` A demo-only insecure code pattern for SAST A fake API key for secret scanning Vulnerable dependencies for dependency scanning A Docker image for container scanning ``` 伪造的 secret 不是真实的,绝不能在生产环境中使用。 ## 实验环境 该项目的构建和测试使用了: ``` Ubuntu Git GitHub GitLab CI/CD Docker Node.js npm Semgrep Gitleaks npm audit Trivy Markdown ``` ## 使用的工具 Semgrep: ``` Used for static application security testing. ``` Gitleaks: ``` Used for secret scanning. ``` npm audit: ``` Used for dependency scanning. ``` Docker: ``` Used to build the demo application container image. ``` Trivy: ``` Used to scan the container image for known vulnerabilities. ``` GitLab CI/CD: ``` Used to automate the security pipeline. ``` ## 流水线阶段 GitLab CI/CD 流水线包含以下阶段: ``` setup sast secret_scan dependency_scan container_build container_scan report_summary ``` ## 流水线结果 流水线已在 GitLab CI/CD 中成功执行。 最终结果: ``` Status: Passed Jobs: 7 Branch: main Pipeline source: web ``` 已执行的作业: ``` setup: passed sast: passed secret_scan: passed dependency_scan: passed container_build: passed container_scan: passed report_summary: passed ``` 证据: ``` evidence/screenshots/pipeline/06-gitlab-all-jobs-passed.png evidence/tool-outputs/24-final-pipeline-summary.txt ``` ## 发现摘要 ### 发现 01 — SAST 不安全代码模式 状态: ``` Confirmed ``` 严重性: ``` Medium ``` 工具: ``` Semgrep ``` 摘要: ``` Semgrep detected user-controlled request data flowing into eval() in app/server.js. ``` 证据: ``` findings/01-sast-insecure-code-pattern.md evidence/reports/semgrep/ evidence/screenshots/sast/ ``` ### 发现 02 — Secret 检测伪造 Secret 状态: ``` Confirmed ``` 严重性: ``` Medium ``` 工具: ``` Gitleaks ``` 摘要: ``` Gitleaks detected a demo-only fake API key pattern in app/server.js. The output was redacted. ``` 证据: ``` findings/02-secret-detection-fake-secret.md evidence/reports/gitleaks/ evidence/screenshots/secret-scanning/ ``` ### 发现 03 — 易受攻击的依赖项 状态: ``` Confirmed ``` 严重性: ``` High ``` 工具: ``` npm audit ``` 摘要: ``` npm audit found 8 vulnerabilities in the demo application dependencies. ``` 观察摘要: ``` Low: 3 Moderate: 1 High: 4 Critical: 0 Total: 8 ``` 证据: ``` findings/03-vulnerable-dependency.md evidence/reports/dependency-check/ evidence/screenshots/dependency-scanning/ ``` ### 发现 04 — 容器镜像漏洞 状态: ``` Confirmed ``` 严重性: ``` Critical ``` 工具: ``` Trivy ``` 摘要: ``` Trivy found vulnerabilities in the demo container image. ``` 观察摘要: ``` Low: 1478 Medium: 3161 High: 1176 Critical: 197 Total: 6012 ``` 证据: ``` findings/04-container-image-vulnerabilities.md evidence/reports/trivy/ evidence/screenshots/container-scanning/ ``` ### 发现 05 — 安全门观察 状态: ``` Confirmed ``` 严重性: ``` Informational ``` 工具: ``` GitLab CI/CD ``` 摘要: ``` The pipeline used allow_failure for learning-focused security scan jobs. The jobs still generated evidence and artifacts for manual review. ``` 证据: ``` findings/05-security-gate-observation.md evidence/tool-outputs/24-final-pipeline-summary.txt evidence/tool-outputs/25-final-findings-summary.txt ``` ## 证据处理 我将证据保存在: ``` evidence/ ``` 主要证据文件夹: ``` evidence/reports/ evidence/screenshots/ evidence/tool-outputs/ ``` 在发布证据之前,我审查了输出内容,以避免暴露真实的 secret 或敏感数据。 Gitleaks 输出中使用了脱敏的 secret 值。 Trivy 报告包含漏洞描述和 CVE 信息。 导出的 Docker 镜像 tar 文件未提交到代码仓库中。 ## 如何在本地运行应用程序 进入应用程序文件夹: ``` cd app ``` 安装依赖项: ``` npm install ``` 运行应用程序: ``` npm start ``` 测试应用程序: ``` curl -i http://localhost:3000/ curl -i http://localhost:3000/health ``` ## 如何在本地运行 Docker 镜像 从项目根目录执行: ``` docker build -t devsecops-demo-app:local app ``` 运行容器: ``` docker run --rm -d --name devsecops-demo-app-test -p 3001:3000 devsecops-demo-app:local ``` 测试容器: ``` curl -i http://localhost:3001/ curl -i http://localhost:3001/health ``` 停止容器: ``` docker stop devsecops-demo-app-test ``` ## 如何运行流水线 流水线定义在: ``` .gitlab-ci.yml ``` 要在 GitLab 中运行它: ``` Open the GitLab project Go to Build > Pipelines Click New pipeline Select branch main Run the pipeline ``` 该流水线支持使用以下方式从 GitLab UI 进行手动运行: ``` - if: '$CI_PIPELINE_SOURCE == "web"' ``` ## 仓库结构 ``` devsecops-gitlab-pipeline-security/ ├── app ├── appendices ├── docs ├── evidence ├── findings ├── lessons-learned ├── methodology ├── pipeline ├── remediation ├── reports └── scope ``` ## 重要文件夹 app: ``` Demo Node.js application and Dockerfile. ``` pipeline: ``` Pipeline documentation and security scanning stages. ``` findings: ``` Confirmed findings and security observations. ``` evidence: ``` Screenshots, scan reports, CI artifacts, and tool outputs. ``` reports: ``` Final project report. ``` remediation: ``` Remediation guidance for the identified issues. ``` lessons-learned: ``` What I learned while building the project. ``` ## 展示的技能 该项目展示了对以下方面的实践经验: ``` GitLab CI/CD DevSecOps pipeline design SAST secret scanning dependency scanning container scanning Docker security artifacts security gates evidence-based reporting technical documentation Git and GitHub workflow ``` ## 经验教训 我学习了如何构建一个简单的安全流水线,并用真实的证据验证每一个步骤。 我还了解到,安全工具需要审查和调优。并非每一个发现都应自动中断流水线,特别是在早期采用阶段或在学习项目中。 最重要的教训是,DevSecOps 流水线不仅仅是运行工具。它还包括收集证据、审查结果、记录发现以及随着时间的推移不断改进工作流。 ## 道德免责声明 该项目是出于学习和作品集目的而创建的。 该应用程序是一个安全的本地演示应用。 本项目不包含: ``` real secrets real company code real customer data malware phishing persistence evasion destructive actions external target scanning third-party system testing ``` 所有测试均是针对为此项目创建的受控演示应用程序进行的。
标签:CI/CD流水线, DevSecOps, Docker, GitLab, MITM代理, 上游代理, 安全扫描, 安全防御评估, 时序注入, 自定义脚本, 请求拦截