RewithSolo/security-ci-cd-pipeline

GitHub: RewithSolo/security-ci-cd-pipeline

基于 GitHub Actions 构建的 Go 微服务自动化 DevSecOps CI/CD 流水线,集成了 SAST、密钥扫描、IaC 校验、容器漏洞扫描和 Kubernetes manifest 验证等多层安全检查。

Stars: 0 | Forks: 0

# DevSecOps Pipeline | Security CI/CD 使用 GitHub Actions 为 Go 微服务构建的自动化 CI/CD pipeline。实现了静态安全分析、secret 扫描、Infrastructure-as-Code (IaC) 验证、container 漏洞扫描、artifact 发布以及离线 manifest 验证。 [![Security Pipeline](https://static.pigsec.cn/wp-content/uploads/repos/cas/9b/9b94682edfe233dd488aa34856cf9db4479fdeb3f544deca1f06309aa7c7e20a.svg)](https://github.com/RewithSolo/security-ci-cd-pipeline/actions) ![Go 版本](https://img.shields.io/badge/Go-1.24-00ADD8?style=flat&logo=go) ![Kubernetes](https://img.shields.io/badge/Kubernetes-1.30%2B-326CE5?style=flat&logo=kubernetes) ![Registry](https://img.shields.io/badge/GHCR-Distroless-blue?style=flat&logo=github) ## Pipeline 概述 ``` graph TD Push[Push / PR to main] --> SecretScan[1. Secret Scan: Gitleaks] SecretScan --> SAST[2. SAST: Semgrep] SecretScan --> IaC[3. IaC Scan: Checkov] SAST --> ContainerScan[4. Image Scan: Trivy] IaC --> ContainerScan ContainerScan --> CD[5. CD: Push to GHCR & Kubeconform] CD --> Alert[6. Telegram Notification] ``` ## 安全扫描与工具 | 阶段 | 工具 | 范围 / 目标 | 执行策略 | | :--- | :--- | :--- | :--- | | **Secrets** | Gitleaks | Git commit 历史 | 检测到暴露的 API key、token 或 private key 时失败 | | **SAST** | Semgrep | `app/` (Go 代码) | OWASP Top 10 及 Go 安全规则集 | | **IaC** | Checkov | `k8s/` (Manifests) | CIS Kubernetes 基准及 Pod 安全标准 | | **Container** | Trivy | 构建的 Docker 镜像 | 扫描 OS 及 Go 运行时的 CVE | | **Schema 验证** | Kubeconform | 更新的 K8s manifests | 严格的离线 K8s API schema 验证 | | **通知** | Telegram Action | Workflow 执行状态 | 向 SecOps 频道发送成功/失败状态 | ## 安全实现细节 ### 应用与 Container * **多阶段 Dockerfile:** 使用 `CGO_ENABLED=0` 构建静态二进制文件,并将其复制到 `gcr.io/distroless/static-debian12:nonroot` 中。 * **执行上下文:** 明确在 UID `65532` (`nonroot`) 下运行,移除 shell 二进制文件、package manager 和 root 访问权限。 ### Kubernetes 加固 (`k8s/`) * **Pod 安全上下文:** * `readOnlyRootFilesystem: true` * `runAsNonRoot: true` & `runAsUser: 65532` * `seccompProfile: { type: RuntimeDefault }` * **集群安全:** * `automountServiceAccountToken: false` (防止 API token 挂载) * 弃用权限:`capabilities.drop: ["ALL"]` * **资源管理:** 明确的 CPU/内存 `requests` 和 `limits`,以防止 noisy-neighbor / DoS 场景。 * **网络隔离:** 通过 `NetworkPolicy` 限制 Ingress (`k8s/networkpolicy.yaml`)。 ### Pipeline 安全(供应链) * **最小权限:** 全局 workflow 权限设置为 `contents: read`。`packages: write` 被严格限制在 CD 发布作业中。 * **并发处理:** 在新 commit 上取消正在进行的 pipeline 运行 (`cancel-in-progress: true`)。 ## 仓库结构 ``` . ├── .github/ │ └── workflows/ │ └── security-pipeline.yml # GitHub Actions workflow ├── app/ │ ├── main.go # Go microservice │ ├── go.mod # Module definition │ └── Dockerfile # Hardened multi-stage build ├── k8s/ │ ├── deployment.yaml # K8s Deployment manifest │ └── networkpolicy.yaml # Ingress NetworkPolicy └── README.md ``` ## 本地验证 在推送更改之前,在本地运行等效的安全检查: ``` # 1. 构建并扫描容器镜像 docker build -t security-demo-app:local ./app trivy image security-demo-app:local # 2. 运行 IaC 安全检查 checkov -d k8s/ --framework kubernetes # 3. 验证 Kubernetes manifest schema kubeconform -summary -strict k8s/ ``` ## 必需的 Secrets 在 **Settings -> Secrets and variables -> Actions** 中设置以下环境 secrets: * `TELEGRAM_TOKEN` — 来自 `@BotFather` 的 Bot API token * `TELEGRAM_TO` — 来自 `@userinfobot` 的聊天/用户 ID
标签:DevSecOps, EVTX分析, GitHub Actions, Go, Ruby工具, 上游代理, 子域名突变, 安全合规检查, 日志审计, 自动笔记, 请求拦截, 静态代码扫描(SAST)