本文档正在积极开发中,尚未最终定稿。
Skip to content

8.2 自动化工作流

架构

BAUER GROUP 的 CRA 自动化分布在两个仓库中:

  • CRA 专用工作流和操作位于 SEC-CRACompliance(本仓库)
  • 通用操作(VEX 生成、SBOM 认证)位于 automation-templates

消费者仓库(您的产品)只需一行 uses: 即可调用 CRA 发布工作流。

┌──────────────────────────────────────────┐
│            Consumer Repo (Product)        │
│                                          │
│  uses: bauer-group/SEC-CRACompliance/    │
│        .github/workflows/cra-release.yml │
└──────────────────┬───────────────────────┘

    ┌──────────────┼──────────────┐
    ▼              ▼              ▼
┌─────────┐  ┌──────────┐  ┌────────────┐
│ CRA-Repo│  │ CRA-Repo │  │ Automation │
│ Actions │  │ Actions  │  │ Templates  │
├─────────┤  ├──────────┤  ├────────────┤
│ SBOM    │  │Compliance│  │ VEX        │
│ Sign    │  │ Report   │  │ Attestation│
│ Scan    │  │          │  │            │
│ Hub     │  │          │  │            │
└─────────┘  └──────────┘  └────────────┘
CRA-specific  CRA-specific    Generic

可复用工作流

cra-release.yml — 发布制品

主要工作流。为每次发布生成、签名和存档所有 CRA 制品。

使用方法(零配置):

yaml
jobs:
  cra:
    uses: bauer-group/SEC-CRACompliance/.github/workflows/cra-release.yml@main
    permissions:
      contents: write
      id-token: write
      attestations: write
      security-events: write

使用方法(自定义):

yaml
jobs:
  cra:
    uses: bauer-group/SEC-CRACompliance/.github/workflows/cra-release.yml@main
    with:
      run-validation: true
      validation-command: 'npm run ci'
      sign-sbom: true
      attest-sbom: true
      generate-vex: true
      generate-compliance-report: true
      support-period-years: 5
      fail-on-critical: true
    permissions:
      contents: write
      id-token: write
      attestations: write
      security-events: write

流水线流程:

步骤操作制品CRA 参考
1SBOM 生成sbom.cdx.jsonAnnex I, 第II部分, 编号 1
2SBOM 签名 (Cosign).sig + .certAnnex I, 第II部分, 编号 7
3SBOM 认证GitHub AttestationAnnex I, 第II部分, 编号 7
4漏洞扫描vulnerability-report.jsonAnnex I, 第II部分, 编号 1
5VEX 生成vex.openvex.jsonAnnex I II.2
6合规报告.json + .mdAnnex VII
7SARIF 上传GitHub Security 标签页Annex I, 第I部分, 编号 2(a)
8发布附件发布中的所有制品Art. 13

零配置

所有新功能(认证、VEX、合规报告)默认启用。现有消费者无需更改工作流即可自动获取。

cra-scan.yml — 定期漏洞扫描

用于持续 CVE 监控(Annex I, 第I部分, 编号 2(a))。通过 cron 计划每日运行。

yaml
on:
  schedule:
    - cron: '0 6 * * *'

jobs:
  scan:
    uses: bauer-group/SEC-CRACompliance/.github/workflows/cra-scan.yml@main
    with:
      severity-threshold: MEDIUM
      fail-on-critical: false
      create-issue: true
    permissions:
      contents: read
      security-events: write
      issues: write

功能:

  • 多引擎扫描(Trivy + Grype + OSV-Scanner)
  • 针对 CRITICAL 发现自动创建 GitHub Issue
  • SARIF 上传到 GitHub Security 标签页
  • 可配置的严重性阈值

cra-report.yml — Hub API 报告

将合规数据发送到软件安全中心 API 进行集中跟踪。

yaml
jobs:
  report:
    uses: bauer-group/SEC-CRACompliance/.github/workflows/cra-report.yml@main
    with:
      send-sbom: true
      send-vulnerabilities: true
      send-release-info: true

完整的消费者工作流

复制粘贴

将此工作流复制到您的产品仓库中,保存为 .github/workflows/cra.yml。涵盖发布合规、每周扫描和中心报告 — 全部采用合理的默认值。

最小配置(零配置)

可在任何仓库中开箱即用。所有功能均以默认值启用。

yaml
# .github/workflows/cra.yml
name: CRA Compliance

on:
  release:
    types: [published]
  schedule:
    - cron: '0 6 * * 1'  # 每周一 06:00 UTC
  workflow_dispatch:

permissions:
  contents: write
  id-token: write
  attestations: write
  security-events: write
  issues: write

jobs:
  # 发布时:完整的 CRA 流水线
  cra-release:
    if: github.event_name == 'release'
    uses: bauer-group/SEC-CRACompliance/.github/workflows/cra-release.yml@main
    permissions:
      contents: write
      id-token: write
      attestations: write
      security-events: write

  # 每周:CVE 扫描
  cra-scan:
    if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch'
    uses: bauer-group/SEC-CRACompliance/.github/workflows/cra-scan.yml@main
    permissions:
      contents: read
      security-events: write
      issues: write

完整配置(所有参数)

适用于有特定需求的产品 — Node.js 验证、Class I 分类、Grype 扫描等。

yaml
# .github/workflows/cra.yml
name: CRA Compliance

on:
  release:
    types: [published]
  schedule:
    - cron: '0 6 * * 1'
  workflow_dispatch:

permissions:
  contents: write
  id-token: write
  attestations: write
  security-events: write
  issues: write

jobs:
  # ── 发布:完整的 CRA 流水线 ──
  cra-release:
    if: github.event_name == 'release'
    uses: bauer-group/SEC-CRACompliance/.github/workflows/cra-release.yml@main
    with:
      # 验证
      run-validation: true              # 在生成 CRA 制品前运行 lint/build
      node-version: '24'                # 用于验证的 Node.js 版本
      validation-command: 'npm run ci'  # 您的验证命令

      # SBOM 与扫描
      scan-target: '.'                  # 目录、镜像引用或 SBOM 路径
      scan-type: 'auto'                 # auto | fs | image | sbom
      sign-sbom: true                   # Cosign 无密钥签名
      fail-on-critical: true            # CRITICAL CVE 时阻止发布
      enable-grype: true                # 额外的 Grype 扫描
      enable-osv: true                  # 额外的 OSV-Scanner

      # 认证与 VEX
      attest-sbom: true                 # GitHub 原生 SBOM 认证
      generate-vex: true                # OpenVEX 文档
      vex-overrides: 'security/vex-overrides.json'  # 手动分类文件

      # 合规报告
      generate-compliance-report: true
      support-period-years: 5           # Art. 13(8):至少 5 年

      # EU 符合性声明
      generate-eu-doc: true             # Annex V JSON
      render-pdfs: true                 # JSON → PDF 渲染
      classification: 'important-class-1'  # standard | important-class-1 | important-class-2 | critical
      conformity-module: 'module-a'     # module-a | module-b-c | module-h | eucc
      manufacturer-name: 'BAUER GROUP GmbH'

      # 发布
      upload-to-release: true           # 将所有制品附加到 GitHub Release
      retention-days: 90                # 制品保留期
    permissions:
      contents: write
      id-token: write
      attestations: write
      security-events: write

  # ── 每周:CVE 扫描 ──
  cra-scan:
    if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch'
    uses: bauer-group/SEC-CRACompliance/.github/workflows/cra-scan.yml@main
    with:
      severity-threshold: 'MEDIUM'      # UNKNOWN | LOW | MEDIUM | HIGH | CRITICAL
      fail-on-critical: false           # 不让定期扫描失败
      create-issue: true                # 为 CRITICAL CVE 创建 GitHub Issue
      enable-grype: true
      enable-osv: true
    permissions:
      contents: read
      security-events: write
      issues: write

  # ── 发布后:报告到 Hub ──
  cra-report:
    if: github.event_name == 'release'
    needs: [cra-release]
    uses: bauer-group/SEC-CRACompliance/.github/workflows/cra-report.yml@main
    with:
      dry-run: true                     # Hub 投入运行后设为 false
    permissions:
      contents: read
      id-token: write

Docker / Container Image

适用于构建容器镜像的产品 — 扫描镜像而非文件系统。

yaml
jobs:
  cra-release:
    if: github.event_name == 'release'
    uses: bauer-group/SEC-CRACompliance/.github/workflows/cra-release.yml@main
    with:
      scan-target: 'ghcr.io/bauer-group/my-app:${{ github.ref_name }}'
      scan-type: 'image'
      classification: 'important-class-2'
    permissions:
      contents: write
      id-token: write
      attestations: write
      security-events: write

产品配置文件(推荐)

无需在工作流中传递所有参数,而是在仓库根目录创建一个 cra-product.jsoncra-eu-doc 操作会自动读取它:

json
{
  "$schema": "https://cra.docs.bauer-group.com/schemas/cra-product/v1.0.0",
  "product": {
    "name": "API-Gateway",
    "description": "REST API Gateway for BAUER GROUP services",
    "classification": "important-class-1",
    "conformityModule": "module-a"
  },
  "manufacturer": {
    "name": "BAUER GROUP GmbH",
    "address": "Street, City, Country"
  },
  "support": {
    "periodYears": 5,
    "until": "2031-12-31"
  },
  "contacts": {
    "securityEmail": "disclosure@bauer-group.com",
    "productOwner": "team@bauer-group.com"
  }
}

参数参考

cra-release.yml

参数类型默认值说明
run-validationbooleanfalse生成 CRA 制品前运行 lint/build
node-versionstring'24'Node.js 版本(当 run-validation: true
validation-commandstring'npm run lint'验证命令
scan-targetstring'.'目录、镜像引用或 SBOM 文件路径
scan-typestring'auto'autofsimagesbom
sbom-filenamestring'sbom.cdx.json'SBOM 输出文件名
sign-sbombooleantrue使用 Cosign 签名 SBOM(无密钥)
fail-on-criticalbooleanfalse发现 CRITICAL 漏洞时失败
enable-grypebooleanfalse将 Grype 作为额外扫描器运行
enable-osvbooleantrue运行 OSV-Scanner
attest-sbombooleantrue创建 GitHub SBOM 认证
generate-vexbooleantrue生成 OpenVEX 文档
vex-overridesstring'security/vex-overrides.json'VEX 分类覆盖文件路径
generate-compliance-reportbooleantrue生成 JSON + Markdown 报告
support-period-yearsnumber5支持期限(Art. 13(8))
generate-eu-docbooleantrue生成 EU 符合性声明
render-pdfsbooleantrueJSON → PDF 渲染
classificationstring'standard'CRA 类别:standardimportant-class-1important-class-2critical
conformity-modulestring'module-a'模块:module-amodule-b-cmodule-heucc
manufacturer-namestring'BAUER GROUP GmbH'制造商法定名称
upload-to-releasebooleantrue将制品附加到 GitHub Release
retention-daysnumber90制品保留天数

cra-scan.yml

参数类型默认值说明
scan-targetstring'.'扫描目标
scan-typestring'auto'扫描类型
severity-thresholdstring'MEDIUM'报告的最低严重性
fail-on-criticalbooleanfalse发现 CRITICAL 时失败
create-issuebooleantrue为 CRITICAL 创建 GitHub Issue
enable-grypebooleanfalse额外的 Grype 扫描
enable-osvbooleantrue额外的 OSV-Scanner

所需权限

工作流权限原因
cra-releasecontents: write上传发布资产
cra-releaseid-token: writeCosign 无密钥签名 (OIDC)
cra-releaseattestations: writeGitHub SBOM 认证
cra-releasesecurity-events: writeSARIF 上传到 Security 标签页
cra-scancontents: read读取仓库进行扫描
cra-scansecurity-events: writeSARIF 上传
cra-scanissues: write创建 CVE Issue
cra-reportcontents: read读取 SBOM + 扫描结果
cra-reportid-token: writeAPI 身份验证

发布制品

完整配置的 CRA 发布会产生:

制品格式用途CRA 参考
sbom.cdx.jsonCycloneDX JSON软件物料清单Annex I, 第II部分, 编号 1
sbom.cdx.json.sigCosign 签名SBOM 完整性(便携)Annex I, 第II部分, 编号 7
sbom.cdx.json.certX.509 证书签名身份Annex I, 第II部分, 编号 7
GitHub AttestationSigstoreSBOM 来源(GitHub 原生)Annex I, 第II部分, 编号 7
vulnerability-report.jsonTrivy JSON已知漏洞Annex I, 第II部分, 编号 1
vex.openvex.jsonOpenVEX v0.2.0漏洞可利用性Annex I II.2
cra-compliance-report.jsonCustom Schema v1.0.0机器可读合规状态Annex VII
cra-compliance-report.mdMarkdown人类可读合规状态Annex VII
eu-doc.jsonEU DoC Schema v1.0.0机器可读 EU 符合性声明Art. 28, Annex V
EU-Declaration-*.pdfPDF可打印 EU 符合性声明Art. 28, Annex V
CRA-Compliance-Report-*.pdfPDF可打印合规报告Annex VII

验证

下载后请验证 SBOM 的真实性:

bash
# Cosign
cosign verify-blob --signature sbom.cdx.json.sig --certificate sbom.cdx.json.cert sbom.cdx.json

# GitHub Attestation
gh attestation verify sbom.cdx.json --repo owner/repo

VEX 分类

VEX 文档会为所有发现的 CVE 自动生成 under_investigation 声明。进行分类:

  1. 在您的产品仓库中创建 security/vex-overrides.json
  2. 为每个 CVE 添加手动决策
json
{
  "@context": "https://openvex.dev/ns/v0.2.0",
  "statements": [
    {
      "vulnerability": { "@id": "CVE-2024-1234" },
      "products": [{ "@id": "pkg:github/your-org/your-repo" }],
      "status": "not_affected",
      "justification": "vulnerable_code_not_in_execute_path",
      "impact_statement": "Dependency imported but affected function never called."
    }
  ]
}
状态使用场景
not_affected漏洞存在,但在您的产品中不可利用
affected漏洞可利用 — 需要修复
fixed漏洞已修复
under_investigation评估待定(自动生成的默认值)

合规评分

合规报告给出满分 100 的评分:

类别满分标准
SBOM20已生成 (10) + 已签名 (5) + 已认证 (5)
签名15Cosign 验证 (10) + 认证存在 (5)
漏洞200 关键 (15) + 0 高危 (5)
VEX10已生成 (5) + 手动覆盖存在 (5)
安全策略15SECURITY.md (10) + CVD 流程已定义 (5)
支持期限10已在配置中定义 (10)
CRA 条款覆盖10已满足的映射条款百分比

CLI 工具

使用 cra-check CLI 进行本地验证或检查任何 GitHub 仓库。

文档基于 CC BY-NC 4.0 许可 · 代码基于 MIT 许可