Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions attestgate/attestgate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 <name>`) 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.
Expand Down Expand Up @@ -72,9 +74,20 @@ var (
mainRef = regexp.MustCompile(`github\.ref\s*==\s*'refs/heads/main'`)
)

// runsTask is whether run starts `task <name>`, flags before the name or not.
// runsTask is whether run starts `task <name>`, 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
}
Expand Down
13 changes: 13 additions & 0 deletions attestgate/attestgate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"}},
Expand Down
4 changes: 4 additions & 0 deletions site/src/content/docs/supply-chain.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
`<file>/<job>/<step>` 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`.
Expand Down
Loading