From 26a57fcae5d22a8ec6cbd566fbe6b95bf97bf268 Mon Sep 17 00:00:00 2001 From: Manuel de Brito Fontes Date: Wed, 18 Nov 2026 20:40:52 -0300 Subject: [PATCH] attestgate: an upload or an attestation may be a command of the repository's own spin-ami's release workflow now runs spin-os image sign and spin-os image publish (spin-stack/ami#176) where it ran task images:sign and task publish, and attestgate saw neither: it read only `task `, so the order sign before publish was held by a test of spin-ami's own. A name in UploadTasks, AttestTasks or SelfAttesting with a space in it is now a command matched by its words, as taskgate's -command lets a step be one. Co-Authored-By: Claude Opus 5.5 --- attestgate/attestgate.go | 17 +++++++++++++++-- attestgate/attestgate_test.go | 13 +++++++++++++ site/src/content/docs/supply-chain.md | 4 ++++ 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/attestgate/attestgate.go b/attestgate/attestgate.go index 9a840b2..3ddbe10 100644 --- a/attestgate/attestgate.go +++ b/attestgate/attestgate.go @@ -24,7 +24,9 @@ type Gate struct { // Root is the repository, relative to the test that runs the gate. Root string // UploadTasks and AttestTasks are task names a step runs (`task `) that publish, or - // that attest what is published. + // that attest what is published. A name with a space in it is a command of the repository's + // own a step runs instead, by its words: "spin-os image publish" is a step that runs + // `spin-os image publish ...`, as taskgate's -command lets a step be. UploadTasks, AttestTasks []string // SelfAttesting are task names that attest only what they upload themselves - a task that // packs, attests and pushes - so a step running one is attested and attests no later step. @@ -72,9 +74,20 @@ var ( mainRef = regexp.MustCompile(`github\.ref\s*==\s*'refs/heads/main'`) ) -// runsTask is whether run starts `task `, flags before the name or not. +// runsTask is whether run starts `task `, flags before the name or not - or, for a name +// that is a command's words, whether run runs that command. func runsTask(run string, names []string) bool { for _, n := range names { + if words := strings.Fields(n); len(words) > 1 { + quoted := make([]string, len(words)) + for i, w := range words { + quoted[i] = regexp.QuoteMeta(w) + } + if regexp.MustCompile(`(^|[\s;&|(])` + strings.Join(quoted, `\s+`) + `(\s|$)`).MatchString(run) { + return true + } + continue + } if regexp.MustCompile(`\btask\s+(-\S+\s+)*` + regexp.QuoteMeta(n) + `(\s|$)`).MatchString(run) { return true } diff --git a/attestgate/attestgate_test.go b/attestgate/attestgate_test.go index 7146b11..828c8ab 100644 --- a/attestgate/attestgate_test.go +++ b/attestgate/attestgate_test.go @@ -126,6 +126,19 @@ func TestAnUploadNeedsAnAttestationBeforeIt(t *testing.T) { "tasks that publish and attest": {workflow: workflow("workflow_dispatch", "id-token: write", "", "", " - name: Sign\n run: task images:sign\n", " - name: Publish\n run: task -v publish ROLE=cp\n"), gate: attestgate.Gate{UploadTasks: []string{"publish"}, AttestTasks: []string{"images:sign"}}}, + "a repository's command that attests, then one that publishes": {workflow: workflow("workflow_dispatch", "id-token: write", "", "", + " - name: Sign\n run: spin-os image sign\n", " - name: Publish\n run: spin-os image publish --region \"$REGIONS\"\n"), + gate: attestgate.Gate{UploadTasks: []string{"spin-os image publish"}, AttestTasks: []string{"spin-os image sign"}}}, + "a repository's command that publishes, unattested": {workflow: workflow("workflow_dispatch", "id-token: write", "", "", + " - name: Publish\n run: spin-os image publish runner\n", " - name: Sign\n run: spin-os image sign\n"), + gate: attestgate.Gate{UploadTasks: []string{"spin-os image publish"}, AttestTasks: []string{"spin-os image sign"}}, + problems: []string{"release.yml/release/Publish: publishes with no provenance"}}, + "a command of two words": {workflow: workflow("workflow_dispatch", "id-token: write", "", "", " - name: Release\n run: spin-os release runner\n"), + gate: attestgate.Gate{UploadTasks: []string{"spin-os release"}}, + problems: []string{"release.yml/release/Release: publishes with no provenance"}}, + "a command that only begins like the repository's": {workflow: workflow("workflow_dispatch", "id-token: write", "", "", + " - name: Publish\n run: spin-os image publisher\n", " - name: Check\n run: xspin-os image publish\n"), + gate: attestgate.Gate{UploadTasks: []string{"spin-os image publish"}}}, "a task that publishes": {workflow: workflow("workflow_dispatch", "id-token: write", "", "", " - name: Publish\n run: task publish\n"), gate: attestgate.Gate{UploadTasks: []string{"publish"}}, problems: []string{"release.yml/release/Publish: publishes with no provenance"}}, diff --git a/site/src/content/docs/supply-chain.md b/site/src/content/docs/supply-chain.md index 3424832..827b292 100644 --- a/site/src/content/docs/supply-chain.md +++ b/site/src/content/docs/supply-chain.md @@ -53,6 +53,10 @@ fails on a step that publishes without a step before it, in the same job, that a - **attesting** is `cosign attest-blob --type slsaprovenance1`, or a task in `AttestTasks`, run unconditionally and with `id-token: write`. +A name in either list with a space in it is a command of the repository's own, matched by its words +wherever a step runs it: `"spin-os image publish"` is a step that runs `spin-os image publish ...`, +as taskgate's `-command` lets a step be the repository's command rather than a task. + `RequireSBOM` also demands a `cosign attest-blob --type cyclonedx`. `NotPublished` excuses a step by `//` with its reason, and an excuse that matches nothing fails. `MainOnly` holds release workflows to no push trigger and every job on `refs/heads/main`.