Skip to content

Commit 8958ae8

Browse files
author
Ian Lewis
authored
Update docs for generic workflow (slsa-framework#345)
* Update docs for generic workflow * Add section on benefits * Some changes after testing
1 parent cf4ab10 commit 8958ae8

File tree

2 files changed

+91
-9
lines changed

2 files changed

+91
-9
lines changed

.github/workflows/builder_go_slsa3.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ jobs:
475475
echo "$UNTRUSTED_PROVENANCE_HASH $UNTRUSTED_PROVENANCE_NAME" | sha256sum --strict --check --status || exit -2
476476
477477
- name: Release
478-
uses: softprops/action-gh-release@1e07f4398721186383de40550babbdf2b84acfc5
478+
uses: softprops/action-gh-release@1e07f4398721186383de40550babbdf2b84acfc5 # v0.1.14
479479
with:
480480
files: |
481481
${{ needs.build-dry.outputs.go-binary-name }}

internal/builders/generic/README.md

+90-8
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,22 @@
11
# Generation of SLSA3+ provenance for arbitrary projects
22

3-
This document explains how to use the builder for projects for which there is no language-specific builder available.
3+
This document explains how to generate SLSA provenance for projects for which
4+
there is no language or ecosystem specific builder available.
5+
6+
This can be done by adding an additional step to your existing Github Actions
7+
workflow to call a [reusable
8+
workflow](https://docs.github.com/en/actions/using-workflows/reusing-workflows)
9+
to generate generic SLSA provenance. We'll call this workflow the "generic
10+
workflow" from now on.
11+
12+
The generic workflow differs from ecosystem specific builders (like the [Go
13+
builder](../go)) which build the artifacts as well as generate provenance. This
14+
project simply generates provenance as a separate step in an existing workflow.
415

516
---
617

718
- [Project Status](#project-status)
19+
- [Benefits of Provenance](#benefits-of-provenance)
820
- [Generating Provenance](#generating-provenance)
921
- [Getting Started](#getting-started)
1022
- [Workflow Inputs](#workflow-inputs)
@@ -19,9 +31,20 @@ This document explains how to use the builder for projects for which there is no
1931
This project is currently under active development. The API could change while
2032
approaching an initial release.
2133

34+
## Benefits of Provenance
35+
36+
Using the generic workflow will generate a non-forgeable attestation to the
37+
artifacts' digests using the identity of the GitHub workflow. This can be used
38+
to create a positive attestation to a software artifact coming from your
39+
repository.
40+
41+
That means that once your users verify the artifacts they have downloaded they
42+
can be sure that the artifacts were created by your repository's workflow and
43+
haven't been tampered with.
44+
2245
## Generating Provenance
2346

24-
`slsa-github-generator` uses a Github Actions reusable workflow to generate the
47+
The generic workflow uses a Github Actions reusable workflow to generate the
2548
provenance.
2649

2750
### Getting Started
@@ -41,38 +64,97 @@ output:
4164
$ sha256sum artifact1 artifact2 ... | base64 -w0
4265
```
4366

44-
After you have encoded your digest, add a new job to call the
45-
`slsa-github-generator` reusable workflow. Here's an example of what it might
46-
look like all together.
67+
After you have encoded your digest, add a new job to call the reusable workflow.
68+
69+
```yaml
70+
provenance:
71+
permissions:
72+
actions: read # Needed for detection of GitHub Actions environment.
73+
id-token: write # Needed for provenance signing and ID
74+
contents: read # Needed for API access
75+
uses: slsa-framework/slsa-github-generator/.github/workflows/[email protected]
76+
with:
77+
base64-subjects: "${{ needs.build.outputs.digest }}"
78+
```
79+
80+
Here's an example of what it might look like all together.
4781
4882
```yaml
4983
jobs:
84+
# This step builds our artifacts, uploads them to the workflow run, and
85+
# outputs their digest.
5086
build:
5187
outputs:
5288
digest: ${{ steps.hash.outputs.digest }}
5389
runs-on: ubuntu-latest
5490
steps:
5591
- name: "build artifacts"
5692
run: |
57-
# Build build artifacts here.
93+
# These are some amazing artifacts.
94+
echo "foo" > artifact1
95+
echo "bar" > artifact2
5896
- name: "generate hash"
5997
shell: bash
6098
id: hash
6199
run: |
62-
set -euo pipefail
63100
# sha256sum generates sha256 hash for all artifacts.
64101
# base64 -w0 encodes to base64 and outputs on a single line.
65102
# sha256sum artifact1 artifact2 ... | base64 -w0
66103
echo "::set-output name=digest::$(sha256sum artifact1 artifact2 | base64 -w0)"
104+
- name: Upload artifact1
105+
uses: actions/upload-artifact@3cea5372237819ed00197afe530f5a7ea3e805c8 # v3.1.0
106+
with:
107+
name: artifact1
108+
path: artifact1
109+
if-no-files-found: error
110+
retention-days: 5
111+
- name: Upload artifact2
112+
uses: actions/upload-artifact@3cea5372237819ed00197afe530f5a7ea3e805c8 # v3.1.0
113+
with:
114+
name: artifact2
115+
path: artifact2
116+
if-no-files-found: error
117+
retention-days: 5
118+
119+
# This step calls the generic workflow to generate provenance.
67120
provenance:
68121
needs: [build]
69122
permissions:
70123
actions: read
71124
id-token: write
72125
contents: read
73-
uses: slsa-framework/slsa-github-generator/.github/workflows/generator_generic_slsa3.yml@main
126+
if: startsWith(github.ref, 'refs/tags/')
127+
uses: slsa-framework/slsa-github-generator/.github/workflows/[email protected]
74128
with:
75129
base64-subjects: "${{ needs.build.outputs.digest }}"
130+
131+
# This step creates a GitHub release with our artifacts and provenance.
132+
release:
133+
needs: [build, provenance]
134+
runs-on: ubuntu-latest
135+
if: startsWith(github.ref, 'refs/tags/')
136+
steps:
137+
- name: Download artifact1
138+
uses: actions/download-artifact@fb598a63ae348fa914e94cd0ff38f362e927b741 # v2.1.0
139+
with:
140+
name: artifact1
141+
- name: Download artifact2
142+
uses: actions/download-artifact@fb598a63ae348fa914e94cd0ff38f362e927b741 # v2.1.0
143+
with:
144+
name: artifact2
145+
- name: Download provenance
146+
uses: actions/download-artifact@fb598a63ae348fa914e94cd0ff38f362e927b741 # v2.1.0
147+
with:
148+
# The provenance step returns an output with the artifact name of
149+
# our provenance.
150+
name: ${{needs.provenance.outputs.attestation-name}}
151+
- name: Create release
152+
uses: softprops/action-gh-release@1e07f4398721186383de40550babbdf2b84acfc5 # v0.1.14
153+
with:
154+
files: |
155+
artifact1
156+
artifact2
157+
${{needs.provenance.outputs.attestation-name}}
76158
```
77159
78160
### Workflow Inputs

0 commit comments

Comments
 (0)