Chebis26/devsecops-pipeline

GitHub: Chebis26/devsecops-pipeline

一个企业级 DevSecOps 流水线项目,通过 GitHub Actions 和 Terraform 在 CI/CD 全流程中集成 SAST/DAST、容器扫描、机密检测和策略即代码等安全门禁,实现安全左移与自动化合规验证。

Stars: 1 | Forks: 0

# 企业级 DevSecOps Pipeline [![GitHub Actions](https://img.shields.io/badge/CI-GitHub_Actions-2088FF?logo=github-actions)](https://github.com/features/actions) [![Terraform](https://img.shields.io/badge/IaC-Terraform-623CE4?logo=terraform)](https://www.terraform.io/) [![安全](https://img.shields.io/badge/Security-Shift_Left-red)](docs/SECURITY.md) [![许可证](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE) 一个生产级的 DevSecOps pipeline,在软件交付生命周期的每个阶段都集成了安全防护。实现了安全左移,涵盖自动化的 SAST、DAST、容器扫描、机密检测、基础设施扫描以及 policy-as-code 实施。 ## 执行摘要 将安全视为事后补充,在生产环境中修复的成本是开发阶段的 30 倍。此 pipeline 在整个 CI/CD 流程中集成了安全门禁,在为开发者提供快速反馈的同时,强制执行严格的合规性检查,确保生产部署前的安全。 ## Pipeline 架构 ``` ┌────────────────────────────────────────────────────────────────────────┐ │ Developer Pushes Code │ └──────────────────────────────┬─────────────────────────────────────────┘ │ ┌────────────────────▼─────────────────────┐ │ PR / Commit Gates │ │ │ │ ① Secret Scanning (Gitleaks + TruffleHog)│ │ ② SAST (Semgrep + CodeQL) │ │ ③ Dependency Audit (Safety + OWASP) │ │ ④ IaC Scan (tfsec + Checkov) │ │ ⑤ License Compliance │ └────────────────────┬─────────────────────┘ │ All gates pass ┌────────────────────▼─────────────────────┐ │ Build & Package │ │ │ │ ⑥ Docker Build (multi-stage, rootless) │ │ ⑦ Container Scan (Trivy + Grype) │ │ ⑧ SBOM Generation (Syft) │ │ ⑨ Image Signing (cosign) │ │ ⑩ Push to ECR (signed + verified) │ └────────────────────┬─────────────────────┘ │ ┌────────────────────▼─────────────────────┐ │ Deploy to Staging │ │ │ │ ⑪ Terraform Plan + OPA policy check │ │ ⑫ Terraform Apply │ │ ⑬ DAST (OWASP ZAP API scan) │ │ ⑭ Integration Tests │ └────────────────────┬─────────────────────┘ │ Manual approval gate ┌────────────────────▼─────────────────────┐ │ Production Deployment │ │ │ │ ⑮ Verify image signature │ │ ⑯ Blue/Green deploy via CodeDeploy │ │ ⑰ Smoke tests + canary validation │ │ ⑱ CloudWatch alarms armed │ └──────────────────────────────────────────┘ ``` ## 按阶段划分的安全控制 | 阶段 | 工具 | 门禁类型 | 是否阻止部署? | |-------|------|-----------|----------------| | Commit | Gitleaks | 机密扫描 | 是 | | Commit | Semgrep | SAST | 是 (critical) | | Commit | Safety | CVE 审计 | 是 (critical) | | Commit | tfsec | IaC 扫描 | 是 | | Build | Trivy | 容器 CVE | 是 (critical/high) | | Build | Syft | SBOM | 否 (artifact) | | Build | cosign | 镜像签名 | 是 (prod) | | Staging | OWASP ZAP | DAST | 是 (high) | | Staging | OPA | Policy-as-code | 是 | | Prod | cosign verify | 签名校验 | 是 | ## 仓库结构 ``` devsecops-pipeline/ ├── .github/workflows/ │ ├── pr-security-gates.yml # PR checks: secrets, SAST, deps │ ├── build-and-scan.yml # Container build, scan, sign, push │ ├── deploy-staging.yml # IaC + DAST in staging │ ├── deploy-prod.yml # Production blue/green deploy │ └── scheduled-scans.yml # Nightly full dependency audit ├── terraform/ │ ├── modules/ecr/ # ECR with scan-on-push, immutable tags │ └── modules/codepipeline/ # AWS CodePipeline alternative ├── docker/ │ └── app/Dockerfile # Hardened multi-stage Dockerfile ├── policies/ │ ├── opa/ # Open Policy Agent rules │ └── checkov/ # Custom Checkov policies ├── scripts/ │ ├── python/sbom_report.py # SBOM vulnerability reporter │ └── bash/scan_image.sh # Local pre-push container scan └── tests/ ├── integration/ # API integration tests └── security/ # Security regression tests ``` ## 快速开始 ### 在本地运行安全检查 ``` # 安装 pre-commit hooks pip install pre-commit pre-commit install # 手动运行所有检查 pre-commit run --all-files # 扫描 container image ./scripts/bash/scan_image.sh myapp:latest # 检查 IaC tfsec terraform/ checkov -d terraform/ ``` ### Pipeline 所需的 Secrets | Secret | 用途 | |--------|---------| | `AWS_ROLE_ARN` | 用于 AWS 访问的 OIDC role | | `ECR_REGISTRY` | ECR registry URL | | `COSIGN_PRIVATE_KEY` | 镜像签名密钥 | | `COSIGN_PASSWORD` | 密钥口令 | | `SLACK_WEBHOOK_URL` | 部署通知 | ## Policy-as-Code OPA 策略强制执行以下规则: - 生产环境中禁止使用 `latest` 镜像标签 - 所有镜像必须具有经过验证的 cosign 签名 - Terraform 资源必须包含必需的标签 - 禁止公开的 S3 bucket 或对 0.0.0.0/0 开放的安全组 - ECR 镜像不得包含 critical CVE ## SBOM 与供应链安全 每次构建都会生成 CycloneDX 格式的软件物料清单 (SBOM),使用 cosign 进行签名,并与镜像一起存储在 ECR 中。这使得以下功能成为可能: - 针对特定部署版本的 CVE 追踪 - 许可证合规性审计 - 供应链证明 ## 许可证 MIT 许可证 — 详见 [LICENSE](LICENSE)
标签:AI应用开发, CCS 2025, DAST, DevSecOps, ECS, GitHub Actions, LLM防护, SAST, Terraform, 上游代理, 安全扫描, 恶意软件分析, 时序注入, 盲注攻击, 自动笔记, 请求拦截, 逆向工具