Skip to content

Commit 4d64e6d

Browse files
aledbfclaude
andcommitted
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 <name>`, 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 <noreply@anthropic.com>
1 parent f038221 commit 4d64e6d

3 files changed

Lines changed: 32 additions & 2 deletions

File tree

‎attestgate/attestgate.go‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ type Gate struct {
2424
// Root is the repository, relative to the test that runs the gate.
2525
Root string
2626
// UploadTasks and AttestTasks are task names a step runs (`task <name>`) that publish, or
27-
// that attest what is published.
27+
// that attest what is published. A name with a space in it is a command of the repository's
28+
// own a step runs instead, by its words: "spin-os image publish" is a step that runs
29+
// `spin-os image publish ...`, as taskgate's -command lets a step be.
2830
UploadTasks, AttestTasks []string
2931
// SelfAttesting are task names that attest only what they upload themselves - a task that
3032
// packs, attests and pushes - so a step running one is attested and attests no later step.
@@ -72,9 +74,20 @@ var (
7274
mainRef = regexp.MustCompile(`github\.ref\s*==\s*'refs/heads/main'`)
7375
)
7476

75-
// runsTask is whether run starts `task <name>`, flags before the name or not.
77+
// runsTask is whether run starts `task <name>`, flags before the name or not - or, for a name
78+
// that is a command's words, whether run runs that command.
7679
func runsTask(run string, names []string) bool {
7780
for _, n := range names {
81+
if words := strings.Fields(n); len(words) > 1 {
82+
quoted := make([]string, len(words))
83+
for i, w := range words {
84+
quoted[i] = regexp.QuoteMeta(w)
85+
}
86+
if regexp.MustCompile(`(^|[\s;&|(])` + strings.Join(quoted, `\s+`) + `(\s|$)`).MatchString(run) {
87+
return true
88+
}
89+
continue
90+
}
7891
if regexp.MustCompile(`\btask\s+(-\S+\s+)*` + regexp.QuoteMeta(n) + `(\s|$)`).MatchString(run) {
7992
return true
8093
}

‎attestgate/attestgate_test.go‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,19 @@ func TestAnUploadNeedsAnAttestationBeforeIt(t *testing.T) {
126126
"tasks that publish and attest": {workflow: workflow("workflow_dispatch", "id-token: write", "", "",
127127
" - name: Sign\n run: task images:sign\n", " - name: Publish\n run: task -v publish ROLE=cp\n"),
128128
gate: attestgate.Gate{UploadTasks: []string{"publish"}, AttestTasks: []string{"images:sign"}}},
129+
"a repository's command that attests, then one that publishes": {workflow: workflow("workflow_dispatch", "id-token: write", "", "",
130+
" - name: Sign\n run: spin-os image sign\n", " - name: Publish\n run: spin-os image publish --region \"$REGIONS\"\n"),
131+
gate: attestgate.Gate{UploadTasks: []string{"spin-os image publish"}, AttestTasks: []string{"spin-os image sign"}}},
132+
"a repository's command that publishes, unattested": {workflow: workflow("workflow_dispatch", "id-token: write", "", "",
133+
" - name: Publish\n run: spin-os image publish runner\n", " - name: Sign\n run: spin-os image sign\n"),
134+
gate: attestgate.Gate{UploadTasks: []string{"spin-os image publish"}, AttestTasks: []string{"spin-os image sign"}},
135+
problems: []string{"release.yml/release/Publish: publishes with no provenance"}},
136+
"a command of two words": {workflow: workflow("workflow_dispatch", "id-token: write", "", "", " - name: Release\n run: spin-os release runner\n"),
137+
gate: attestgate.Gate{UploadTasks: []string{"spin-os release"}},
138+
problems: []string{"release.yml/release/Release: publishes with no provenance"}},
139+
"a command that only begins like the repository's": {workflow: workflow("workflow_dispatch", "id-token: write", "", "",
140+
" - name: Publish\n run: spin-os image publisher\n", " - name: Check\n run: xspin-os image publish\n"),
141+
gate: attestgate.Gate{UploadTasks: []string{"spin-os image publish"}}},
129142
"a task that publishes": {workflow: workflow("workflow_dispatch", "id-token: write", "", "", " - name: Publish\n run: task publish\n"),
130143
gate: attestgate.Gate{UploadTasks: []string{"publish"}},
131144
problems: []string{"release.yml/release/Publish: publishes with no provenance"}},

‎site/src/content/docs/supply-chain.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ fails on a step that publishes without a step before it, in the same job, that a
5353
- **attesting** is `cosign attest-blob --type slsaprovenance1`, or a task in `AttestTasks`, run
5454
unconditionally and with `id-token: write`.
5555

56+
A name in either list with a space in it is a command of the repository's own, matched by its words
57+
wherever a step runs it: `"spin-os image publish"` is a step that runs `spin-os image publish ...`,
58+
as taskgate's `-command` lets a step be the repository's command rather than a task.
59+
5660
`RequireSBOM` also demands a `cosign attest-blob --type cyclonedx`. `NotPublished` excuses a step by
5761
`<file>/<job>/<step>` with its reason, and an excuse that matches nothing fails. `MainOnly` holds
5862
release workflows to no push trigger and every job on `refs/heads/main`.

0 commit comments

Comments
 (0)