From 7fd9509edeb53ac8e230641faa6d5862bc4572ac Mon Sep 17 00:00:00 2001 From: Toni Bergholm Date: Sat, 18 Jul 2026 12:27:46 +0300 Subject: [PATCH] ci(sbom): two-ecosystem CycloneDX SBOM artifacts + job-scoped audit token (OSTIF T-10, T-20) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - New sbom.yml (weekly + on lockfile change): cargo-cyclonedx binary SBOMs with --target all (so the Linux-only GTK stack incl. vendored glib is represented on any runner), the desktop frontend via npm sbom from the lockfile, uploaded as a 90-day artifact. Not a PR gate; release attachment waits on the deferred release pipeline (T-24). - .github/scripts/annotate_sbom_glib.py records the in-tree glib patch as CycloneDX pedigree (backport resolving RUSTSEC-2024-0429, diff URL → PROVENANCE.md) so version-keyed consumers don't misread the patched fork as unpatched upstream (audit G-033). Fails loudly when glib leaves the tree. Verified locally end-to-end. - audit.yml: checks:write + issues:write moved from workflow level to the job (Scorecard Token-Permissions; audit T-20/G-025). - .gitignore: generated *.cdx.json never committed. --- .github/scripts/annotate_sbom_glib.py | 74 +++++++++++++++++++++++++++ .github/workflows/audit.yml | 12 +++-- .github/workflows/sbom.yml | 59 +++++++++++++++++++++ .gitignore | 3 ++ 4 files changed, 144 insertions(+), 4 deletions(-) create mode 100644 .github/scripts/annotate_sbom_glib.py create mode 100644 .github/workflows/sbom.yml diff --git a/.github/scripts/annotate_sbom_glib.py b/.github/scripts/annotate_sbom_glib.py new file mode 100644 index 00000000..8b7aeec5 --- /dev/null +++ b/.github/scripts/annotate_sbom_glib.py @@ -0,0 +1,74 @@ +#!/usr/bin/env python3 +"""Annotate the Rust SBOM's glib component with its in-tree patch provenance. + +`Cargo.lock` records plain `glib 0.18.5`, but the build actually uses the +vendored fork `vendor/glib-0.18.5-patched/` carrying a soundness backport for +RUSTSEC-2024-0429 (see that directory's PROVENANCE.md). A version-keyed SBOM +consumer would otherwise misread the component as unpatched upstream — the +exact false positive OSTIF audit G-033 documents. This script records the +patch as CycloneDX pedigree on the component. + +Usage: annotate_sbom_glib.py (edits the file in place) + +Fails loudly if no glib component is found: if the vendored patch has been +removed (GTK4 migration removal gate), delete this step and this script in +the same PR. +""" + +import json +import sys + +PROVENANCE_URL = ( + "https://github.com/git-agentic/src-control/blob/main/" + "vendor/glib-0.18.5-patched/PROVENANCE.md" +) + +def main(path: str) -> None: + with open(path) as f: + sbom = json.load(f) + + glib = [ + c + for c in sbom.get("components", []) + if c.get("name") == "glib" and c.get("purl", "").startswith("pkg:cargo/glib@") + ] + if not glib: + sys.exit( + "no cargo glib component found in SBOM — if the vendored patch " + "was removed, delete this annotation step and script" + ) + + for c in glib: + c["pedigree"] = { + "patches": [ + { + "type": "backport", + "diff": {"url": PROVENANCE_URL}, + "resolves": [ + { + "type": "security", + "id": "RUSTSEC-2024-0429", + "source": {"name": "RustSec"}, + } + ], + } + ] + } + c.setdefault("properties", []).append( + { + "name": "src-control:vendored-patched-copy", + "value": ( + "built from vendor/glib-0.18.5-patched (in-tree fork, " + "[patch.crates-io]); NOT the unpatched upstream 0.18.5" + ), + } + ) + + with open(path, "w") as f: + json.dump(sbom, f, indent=2) + print(f"annotated {len(glib)} glib component(s) in {path}") + +if __name__ == "__main__": + if len(sys.argv) != 2: + sys.exit(__doc__) + main(sys.argv[1]) diff --git a/.github/workflows/audit.yml b/.github/workflows/audit.yml index be50ca8c..52b94091 100644 --- a/.github/workflows/audit.yml +++ b/.github/workflows/audit.yml @@ -22,15 +22,19 @@ on: permissions: contents: read - checks: write - # Scheduled runs file findings as GitHub issues; without this the action - # fails with "Resource not accessible by integration" after a clean audit. - issues: write jobs: audit: name: cargo audit (RustSec advisories) runs-on: ubuntu-latest + # Write scopes are job-scoped, not workflow-level (Scorecard + # Token-Permissions; OSTIF audit T-20): audit-check writes check runs on + # PRs, and scheduled runs file findings as GitHub issues — without + # issues:write it fails with "Resource not accessible by integration". + permissions: + contents: read + checks: write + issues: write steps: - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 - uses: rustsec/audit-check@69366f33c96575abad1ee0dba8212993eecbe998 # v2 diff --git a/.github/workflows/sbom.yml b/.github/workflows/sbom.yml new file mode 100644 index 00000000..5d9ffd6d --- /dev/null +++ b/.github/workflows/sbom.yml @@ -0,0 +1,59 @@ +name: sbom + +# Two-ecosystem CycloneDX SBOMs as CI artifacts (OSTIF audit T-10, G-005). +# Weekly + on lockfile change; not a PR gate. Attach to releases when a +# release pipeline exists (audit T-24). +on: + push: + branches: [main] + paths: + - "Cargo.lock" + - "apps/desktop/package-lock.json" + - ".github/workflows/sbom.yml" + - ".github/scripts/annotate_sbom_glib.py" + schedule: + # Weekly on Saturdays. + - cron: "41 6 * * 6" + workflow_dispatch: + +permissions: + contents: read + +jobs: + sbom: + name: generate SBOMs (CycloneDX) + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 + - uses: dtolnay/rust-toolchain@2fe4ca74464c5902a4f6e302d0a619b4ea911ccc # 1.96.1 + with: + toolchain: 1.96.1 + - name: install cargo-cyclonedx + run: cargo install cargo-cyclonedx --locked --version 0.5.9 + - name: rust SBOMs (binaries, all target platforms) + # --target all so the Linux-only GTK stack (incl. the vendored glib) + # is represented regardless of runner OS. + run: cargo cyclonedx --format json --spec-version 1.5 --describe binaries --target all + - name: annotate vendored-patched glib (audit G-033) + # Cargo.lock says plain "glib 0.18.5"; the build actually uses the + # in-tree patched fork. Record the patch as pedigree so SBOM + # consumers don't misread it as unpatched upstream. Fails loudly if + # glib is gone — then remove this step and the script together. + run: python3 .github/scripts/annotate_sbom_glib.py apps/desktop/src-tauri/scl-desktop_bin.cdx.json + - uses: actions/setup-node@249970729cb0ef3589644e2896645e5dc5ba9c38 # v6 + with: + node-version: 24 + - name: npm SBOM (desktop frontend, from lockfile) + working-directory: apps/desktop + run: npm sbom --sbom-format cyclonedx --package-lock-only > desktop-frontend.cdx.json + - name: collect + run: | + mkdir -p sbom-out + cp crates/cli/sc_bin.cdx.json sbom-out/ + cp apps/desktop/src-tauri/scl-desktop_bin.cdx.json sbom-out/ + cp apps/desktop/desktop-frontend.cdx.json sbom-out/ + - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 + with: + name: sbom-cyclonedx + path: sbom-out/ + retention-days: 90 diff --git a/.gitignore b/.gitignore index 2f29ba4a..0a687940 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,6 @@ target/ apps/desktop/node_modules/ apps/desktop/dist/ apps/desktop/src-tauri/gen/ + +# Generated SBOMs (CI artifacts, never committed) +*.cdx.json