关于 artifact-sbom-publisher
用于配置构建与发布工作流的技能,可发布带有软件供应链元数据的制品。内容涵盖 SBOM 生成、漏洞扫描、来源证明、元数据和证明声明。
主要功能
- 01发布构建制品
- 02生成 SPDX 和 CycloneDX SBOM
- 03扫描 SBOM 漏洞
- 04生成 SLSA 来源证明
- 05制品元数据与证明声明
适用场景
- 01为软件版本附加 SBOM
- 02发布前扫描 SBOM
- 03记录构建来源与制品元数据
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ patricio0312rev/ skills --skill artifact-sbom-publisher安装后在 Claude Code 中输入/artifact-sbom-publisher确认已加载。
详细介绍
构件与 SBOM 发布器
生成并发布带有供应链安全元数据的构件。
构建构件
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: "20"
- run: npm ci
- run: npm run build
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: dist-${{ github.sha }}
path: |
dist/
!dist/**/*.map
retention-days: 30
if-no-files-found: error
生成 SBOM(CycloneDX)
sbom:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Generate SBOM
uses: CycloneDX/gh-node-module-generatebom@master
with:
path: ./
output: ./sbom.json
- name: Upload SBOM
uses: actions/upload-artifact@v4
with:
name: sbom-${{ github.sha }}
path: sbom.json
使用 Syft 生成 SBOM
- name: Generate SBOM with Syft
run: |
curl -sSfL https://raw.githubusercontent.com/anchore/syft/main/install.sh | sh -s -- -b /usr/local/bin
syft . -o spdx-json > sbom-spdx.json
syft . -o cyclonedx-json > sbom-cyclonedx.json
- name: Upload SBOMs
uses: actions/upload-artifact@v4
with:
name: sboms
path: |
sbom-spdx.json
sbom-cyclonedx.json
Docker 镜像 SBOM
- name: Build image
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: myapp:${{ github.sha }}
sbom: true
provenance: true
- name: Generate SBOM for image
run: |
syft myapp:${{ github.sha }} -o spdx-json > image-sbom.json
- name: Scan SBOM for vulnerabilities
uses: anchore/scan-action@v3
with:
sbom: image-sbom.json
fail-build: true
severity-cutoff: high
构建溯源信息(SLSA)
provenance:
runs-on: ubuntu-latest
permissions:
actions: read
id-token: write
contents: write
steps:
- uses: actions/checkout@v4
- name: Build
run: npm run build
- name: Generate provenance
uses: actions/attest-build-provenance@v1
with:
subject-path: "dist/**"
构件元数据
- name: Create artifact metadata
run: |
cat > artifact-metadata.json << EOF
{
"version": "${{ github.ref_name }}",
"commit": "${{ github.sha }}",
"branch": "${{ github.ref }}",
"build_time": "$(date -u +%Y-%m-%dT%H:%M:%SZ)",
"builder": "GitHub Actions",
"workflow": "${{ github.workflow }}",
"run_id": "${{ github.run_id }}",
"actor": "${{ github.actor }}"
}
EOF
- name: Upload metadata
uses: actions/upload-artifact@v4
with:
name: metadata
path: artifact-metadata.json
打包与发布
release:
runs-on: ubuntu-latest
needs: [build, sbom]
if: github.event_name == 'release'
steps:
- name: Download artifacts
uses: actions/download-artifact@v4
with:
path: artifacts/
- name: Create release package
run: |
cd artifacts
tar -czf ../release.tar.gz dist-* sbom-* metadata/
- name: Upload to release
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: ./release.tar.gz
asset_name: release-${{ github.ref_name }}.tar.gz
asset_content_type: application/gzip
漏洞扫描
- name: Scan SBOM for vulnerabilities
uses: aquasecurity/trivy-action@master
with:
scan-type: "sbom"
format: "sarif"
output: "trivy-results.sarif"
sbom-sources: "sbom.json"
- name: Upload scan results
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: "trivy-results.sarif"
构件证明
- name: Attest artifact
uses: actions/attest@v1
with:
subject-path: "dist/myapp.tar.gz"
predicate-type: "https://slsa.dev/provenance/v1"
predicate: |
{
"buildType": "https://github.com/actions/workflow",
"builder": {
"id": "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
},
"metadata": {
"buildInvocationId": "${{ github.run_id }}",
"completeness": {
"parameters": true,
"environment": false,
"materials": true
}
}
}
最佳实践
- 生成 SBOM:适用于所有版本
- 多种格式:SPDX 和 CycloneDX
- 扫描漏洞:发布前进行
- 签署构件:以便验证
- 包含溯源信息:SLSA 证明
- 保留策略:构件保留 30 天
- 元数据:版本、提交、时间戳
- 自动化:纳入每次构建
输出检查清单
- 已上传构建构件
- 已生成 SBOM(SPDX 或 CycloneDX)
- 已配置漏洞扫描
- 已生成构建溯源信息
- 已包含构件元数据
- 已自动化发布打包
- 证明/签署(可选)
- 已设置保留策略
评论
支持 Markdown