From 25a41a12d46e71ff52ce5bb5f1be4e6233d9a7fe Mon Sep 17 00:00:00 2001 From: Taksh Date: Mon, 5 Oct 2026 16:10:50 +0530 Subject: [PATCH 1/3] Bind source manifests to their publishing run Split the existing PR change into a smaller reviewable piece. Original change: fix: bind source manifests to workflow provenance and published releases --- .github/workflows/source-manifest.yml | 32 +++++++++++++++++++++------ 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/.github/workflows/source-manifest.yml b/.github/workflows/source-manifest.yml index 0131c066..4b05f2d5 100644 --- a/.github/workflows/source-manifest.yml +++ b/.github/workflows/source-manifest.yml @@ -15,10 +15,12 @@ on: push: tags: - 'v*' + release: + types: [published] workflow_dispatch: inputs: ref: - description: 'Tag or commit to produce a manifest for' + description: 'Tag or commit to produce a manifest for (must match the workflow run ref)' required: true permissions: @@ -27,6 +29,13 @@ permissions: jobs: manifest: runs-on: ubuntu-latest + # A tag-push run and the later release publication must not race uploads. + concurrency: + group: source-manifest-${{ github.event.inputs.ref || github.ref }} + cancel-in-progress: false + env: + SOURCE_REF: ${{ github.event.inputs.ref || github.ref_name }} + RELEASE_TAG: ${{ github.event.release.tag_name || github.ref_name }} permissions: contents: write # attach the manifest to the release id-token: write # provenance attestation @@ -38,11 +47,19 @@ jobs: # Full history so the commit the tag names can be recorded exactly. fetch-depth: 0 + - name: Verify source provenance + run: | + set -euo pipefail + if [ "$(git rev-parse HEAD)" != "$GITHUB_SHA" ]; then + echo "error: select the same workflow run ref as the requested source ref" >&2 + exit 1 + fi + - name: Build manifest id: build run: | set -euo pipefail - ref_name="${{ github.event.inputs.ref || github.ref_name }}" + ref_name="$SOURCE_REF" commit="$(git rev-parse HEAD)" tree="$(git rev-parse HEAD^{tree})" @@ -98,15 +115,16 @@ jobs: path: SOURCE-MANIFEST.txt - name: Attach to release - if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') + if: github.event_name == 'release' || (github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')) env: GH_TOKEN: ${{ github.token }} run: | set -euo pipefail # A tag may be pushed before its release exists; only attach when - # there is a release to attach to, and never fail the run over it. - if gh release view "${{ github.ref_name }}" >/dev/null 2>&1; then - gh release upload "${{ github.ref_name }}" SOURCE-MANIFEST.txt --clobber + # there is a release to attach to. Publication runs this workflow + # again, so a tag-first release does not require a manual upload. + if [ "$GITHUB_EVENT_NAME" = "release" ] || gh release view "$RELEASE_TAG" >/dev/null 2>&1; then + gh release upload "$RELEASE_TAG" SOURCE-MANIFEST.txt --clobber else - echo "no release for ${{ github.ref_name }} yet; manifest is available as a workflow artifact" + echo "no release for $RELEASE_TAG yet; manifest is available as a workflow artifact" fi From 67f8d3054170cca9ea935360b0ed1000d202c0c6 Mon Sep 17 00:00:00 2001 From: Taksh Date: Mon, 5 Oct 2026 16:10:50 +0530 Subject: [PATCH 2/3] Test source manifest provenance in CI Split the existing PR change into a smaller reviewable piece. Original change: fix: bind source manifests to workflow provenance and published releases --- .github/workflows/swift-tests.yml | 7 ++ .../tests/test_source_manifest_workflow.py | 97 +++++++++++++++++++ 2 files changed, 104 insertions(+) create mode 100644 scripts/tests/test_source_manifest_workflow.py diff --git a/.github/workflows/swift-tests.yml b/.github/workflows/swift-tests.yml index e64683de..c53ad415 100644 --- a/.github/workflows/swift-tests.yml +++ b/.github/workflows/swift-tests.yml @@ -7,6 +7,13 @@ on: pull_request: jobs: + source-workflow-tests: + name: Source workflow regression tests + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v5 + - run: python3 -m unittest discover -s scripts/tests -p "test_*.py" -v + test: name: Run Swift Tests (${{ matrix.name }}) runs-on: macos-latest diff --git a/scripts/tests/test_source_manifest_workflow.py b/scripts/tests/test_source_manifest_workflow.py new file mode 100644 index 00000000..bfb9c836 --- /dev/null +++ b/scripts/tests/test_source_manifest_workflow.py @@ -0,0 +1,97 @@ +"""Exercise the checked-in shell steps using only a synthetic Git repository.""" +import os +from pathlib import Path +import re +import subprocess +import tempfile +import unittest + +ROOT = Path(__file__).resolve().parents[2] +WORKFLOW = ROOT / ".github/workflows/source-manifest.yml" + + +class SourceManifestWorkflowTests(unittest.TestCase): + def setUp(self): + self.workflow = WORKFLOW.read_text() + self.temp = tempfile.TemporaryDirectory() + self.addCleanup(self.temp.cleanup) + self.root = Path(self.temp.name) + self.repo = self.root / "repo" + self.repo.mkdir() + self.run_command("git", "init", "-q") + self.run_command("git", "config", "user.name", "Fixture") + self.run_command("git", "config", "user.email", "fixture@example.invalid") + (self.repo / "source.txt").write_text("synthetic source\n") + self.run_command("git", "add", "source.txt") + self.run_command("git", "commit", "-qm", "fixture") + self.commit = self.run_command("git", "rev-parse", "HEAD").stdout.decode().strip() + self.env = dict(os.environ, GITHUB_SHA=self.commit, GITHUB_OUTPUT=str(self.root / "output"), + SOURCE_REF="v1.2.3", RELEASE_TAG="v1.2.3", GITHUB_EVENT_NAME="release") + # The manifest workflow runs on Ubuntu. Provide the equivalent local + # hash executable when only macOS's shasum is available. + self.bin = self.root / "bin" + self.bin.mkdir() + shim = self.bin / "sha256sum" + shim.write_text('#!/bin/sh\nexec shasum -a 256 "$@"\n') + shim.chmod(0o755) + self.env["PATH"] = str(self.bin) + os.pathsep + os.environ["PATH"] + + def run_command(self, *args): + return subprocess.run(args, cwd=self.repo, stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=True) + + def step(self, name): + match = re.search(r"^ - name: " + re.escape(name) + r"\n(.*?)(?=^ - |\Z)", + self.workflow, re.M | re.S) + self.assertIsNotNone(match, "missing workflow step: " + name) + return match.group(1) + + def run_step(self, name): + block = self.step(name) + match = re.search(r"^ run: \|\n((?:^ .*\n|^\n)*)", block, re.M) + self.assertIsNotNone(match) + script = "\n".join(line[10:] if line.startswith(" ") else line + for line in match.group(1).splitlines()) + # Model Actions expression substitution for the original unsafe steps. + script = script.replace("${{ github.event.inputs.ref || github.ref_name }}", self.env["SOURCE_REF"]) + script = script.replace("${{ github.ref_name }}", self.env["RELEASE_TAG"]) + return subprocess.run(["bash", "-c", script], cwd=self.repo, env=self.env, + stdout=subprocess.PIPE, stderr=subprocess.PIPE) + + def test_ref_is_data_not_shell_code(self): + self.env["SOURCE_REF"] = "v$(touch${IFS}injected)" + self.run_command("git", "check-ref-format", "refs/tags/" + self.env["SOURCE_REF"]) + result = self.run_step("Build manifest") + self.assertEqual(result.returncode, 0, result.stderr.decode()) + self.assertFalse((self.repo / "injected").exists()) + self.assertIn(self.env["SOURCE_REF"], (self.repo / "SOURCE-MANIFEST.txt").read_text()) + + def test_provenance_rejects_checkout_from_another_commit(self): + self.env["GITHUB_SHA"] = "0" * 40 + self.assertNotEqual(self.run_step("Verify source provenance").returncode, 0) + + def test_provenance_accepts_matching_commit(self): + self.assertEqual(self.run_step("Verify source provenance").returncode, 0) + + def test_generated_manifest_self_checks(self): + result = self.run_step("Build manifest") + self.assertEqual(result.returncode, 0, result.stderr.decode()) + result = self.run_step("Self-check the manifest") + self.assertEqual(result.returncode, 0, result.stderr.decode()) + + def test_published_release_runs_attachment(self): + self.assertRegex(self.workflow, r"(?m)^ release:\n types: \[published\]") + block = self.step("Attach to release") + self.assertIn("github.event_name == 'release'", block) + # An already-created release must be uploaded to, even if no release + # existed during the earlier tag-push run. + gh = self.bin / "gh" + gh.write_text('#!/bin/sh\nprintf "%s\\n" "$*" >> "$GH_CALLS"\n') + gh.chmod(0o755) + self.env["GH_CALLS"] = str(self.root / "gh-calls") + result = self.run_step("Attach to release") + self.assertEqual(result.returncode, 0, result.stderr.decode()) + self.assertIn("release upload v1.2.3 SOURCE-MANIFEST.txt", Path(self.env["GH_CALLS"]).read_text()) + + +if __name__ == "__main__": + unittest.main() From 9acac9b17c3f3d4ce4237e9e70493041918baf80 Mon Sep 17 00:00:00 2001 From: Taksh Date: Mon, 5 Oct 2026 16:10:51 +0530 Subject: [PATCH 3/3] Document source manifest verification Split the existing PR change into a smaller reviewable piece. Original change: fix: bind source manifests to workflow provenance and published releases --- docs/VERIFYING-A-BUILD.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/VERIFYING-A-BUILD.md b/docs/VERIFYING-A-BUILD.md index 23b5181b..d432ce5f 100644 --- a/docs/VERIFYING-A-BUILD.md +++ b/docs/VERIFYING-A-BUILD.md @@ -83,7 +83,8 @@ Do not rely on the app looking right. A modified build has no reason to look dif Cutting a release: -- Push the tag. `source-manifest.yml` runs and attaches `SOURCE-MANIFEST.txt` to the release; if the release does not exist yet, collect the manifest from the workflow artifact and attach it when you publish. +- Push the tag. `source-manifest.yml` produces an attested `SOURCE-MANIFEST.txt` and attaches it if the release already exists. Publishing a release (including a prerelease) also runs the workflow, so a release created after its tag receives the manifest. The workflow artifact remains available if an upload needs to be recovered manually. +- For a manual run, select the same workflow run ref as the requested source ref. The workflow checks that the checked-out commit equals the run's `GITHUB_SHA` before creating an attestation; a request to attest a different commit fails. - Sign the tag (`git tag -s`). A signed tag lets anyone verify the release came from a key you control, independent of GitHub. This needs a published key fingerprint to be useful — see the gap below. - Note the commit hash somewhere outside this repository. If the repository is taken down, a hash recorded elsewhere is what lets people verify a mirror.