Skip to content

Commit bfc3207

Browse files
authored
📖 Update doc (slsa-framework#403)
* Update doc * update * update * update * update * update * update * update * comments
1 parent d65223c commit bfc3207

File tree

2 files changed

+104
-14
lines changed

2 files changed

+104
-14
lines changed

‎README.md

+23-7
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ This repository contains the code, examples and technical design for system desc
99
---
1010

1111
- [Generation of provenance](#generation-of-provenance)
12-
- [Go projects](#go-projects)
13-
- [Other projects](#other-projects)
12+
- [Builders](#builders)
13+
- [Provenance-only Generators](#provenance-only-generators)
1414
- [Verification of provenance](#verification-of-provenance)
1515
- [Installation](#installation)
1616
- [Inputs](#inputs)
@@ -24,14 +24,30 @@ This repository contains the code, examples and technical design for system desc
2424

2525
## Generation of provenance
2626

27-
### Go projects
27+
### Builders
2828

29-
To generate SLSA provenance for your [Go](https://go.dev/) project, follow
30-
[internal/builders/go/README.md](internal/builders/go/README.md).
29+
Builders build and generate provenance. They let you meet the [build](https://slsa.dev/spec/v0.1/requirements#build-requirements)
30+
and [provenance](https://slsa.dev/spec/v0.1/requirements#provenance-requirements) requirements for [SLSA Level 3 and above](https://slsa.dev/spec/v0.1/levels).
3131

32-
### Other projects
32+
Builders are able to report the exact commands used to generate your artifact in the provenance.
3333

34-
To generate SLSA provenance for other programming languages, follow
34+
The following builders are available:
35+
36+
1. [Go Builder SLSA Level 3](internal/builders/go/README.md): To generate SLSA provenance for your [Go](https://go.dev/) project, follow
37+
[internal/builders/go/README.md](internal/builders/go/README.md)
38+
39+
40+
### Provenance-only Generators
41+
42+
Provenance-only generators let you build your artifact, and only generate provenance for you.
43+
They let you meet the [provenance](https://slsa.dev/spec/v0.1/requirements#provenance-requirements) requirements
44+
for [SLSA Level 3](https://slsa.dev/spec/v0.1/levels).
45+
46+
Generators create an attestation to a software artifact coming from your repository.
47+
48+
Generators are *not* able to report the exact commands used to generate your artifact in the provenance.
49+
50+
To generate SLSA provenance using the provenance-only generator, follow
3551
[internal/builders/generic/README.md](internal/builders/generic/README.md).
3652
This is a pre-release only and we will have the official release in July 2022.
3753

‎internal/builders/generic/README.md

+81-7
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ project simply generates provenance as a separate step in an existing workflow.
2424
- [Workflow Outputs](#workflow-outputs)
2525
- [Provenance Format](#provenance-format)
2626
- [Provenance Example](#provenance-example)
27+
- [Integration With Other Build Systems](#integration-with-other-build-systems)
28+
- [Provenance with GoReleaser](#provenance-with-goreleaser)
2729

2830
---
2931

@@ -77,7 +79,7 @@ provenance:
7779
contents: read # Needed for API access
7880
uses: slsa-framework/slsa-github-generator/.github/workflows/[email protected]
7981
with:
80-
base64-subjects: "${{ needs.build.outputs.digest }}"
82+
base64-subjects: "${{ needs.build.outputs.hashes }}"
8183
```
8284
8385
Here's an example of what it might look like all together.
@@ -88,29 +90,32 @@ jobs:
8890
# outputs their digest.
8991
build:
9092
outputs:
91-
digest: ${{ steps.hash.outputs.digest }}
93+
hashes: ${{ steps.hash.outputs.hashes }}
9294
runs-on: ubuntu-latest
9395
steps:
94-
- name: "build artifacts"
96+
- name: Build artifacts
9597
run: |
9698
# These are some amazing artifacts.
9799
echo "foo" > artifact1
98100
echo "bar" > artifact2
99-
- name: "generate hash"
101+
102+
- name: Generate hashes
100103
shell: bash
101104
id: hash
102105
run: |
103106
# sha256sum generates sha256 hash for all artifacts.
104107
# base64 -w0 encodes to base64 and outputs on a single line.
105108
# sha256sum artifact1 artifact2 ... | base64 -w0
106-
echo "::set-output name=digest::$(sha256sum artifact1 artifact2 | base64 -w0)"
109+
echo "::set-output name=hashes::$(sha256sum artifact1 artifact2 | base64 -w0)"
110+
107111
- name: Upload artifact1
108112
uses: actions/upload-artifact@3cea5372237819ed00197afe530f5a7ea3e805c8 # v3.1.0
109113
with:
110114
name: artifact1
111115
path: artifact1
112116
if-no-files-found: error
113117
retention-days: 5
118+
114119
- name: Upload artifact2
115120
uses: actions/upload-artifact@3cea5372237819ed00197afe530f5a7ea3e805c8 # v3.1.0
116121
with:
@@ -126,10 +131,9 @@ jobs:
126131
actions: read
127132
id-token: write
128133
contents: read
129-
if: startsWith(github.ref, 'refs/tags/')
130134
uses: slsa-framework/slsa-github-generator/.github/workflows/[email protected]
131135
with:
132-
base64-subjects: "${{ needs.build.outputs.digest }}"
136+
base64-subjects: "${{ needs.build.outputs.hashes }}"
133137

134138
# This step creates a GitHub release with our artifacts and provenance.
135139
release:
@@ -141,16 +145,19 @@ jobs:
141145
uses: actions/download-artifact@fb598a63ae348fa914e94cd0ff38f362e927b741 # v2.1.0
142146
with:
143147
name: artifact1
148+
144149
- name: Download artifact2
145150
uses: actions/download-artifact@fb598a63ae348fa914e94cd0ff38f362e927b741 # v2.1.0
146151
with:
147152
name: artifact2
153+
148154
- name: Download provenance
149155
uses: actions/download-artifact@fb598a63ae348fa914e94cd0ff38f362e927b741 # v2.1.0
150156
with:
151157
# The provenance step returns an output with the artifact name of
152158
# our provenance.
153159
name: ${{needs.provenance.outputs.attestation-name}}
160+
154161
- name: Create release
155162
uses: softprops/action-gh-release@1e07f4398721186383de40550babbdf2b84acfc5 # v0.1.14
156163
with:
@@ -270,3 +277,70 @@ generated as an [in-toto](https://in-toto.io/) statement with a SLSA predicate.
270277
}
271278
}
272279
```
280+
281+
## Integration With Other Build Systems
282+
283+
This section explains how to generate non-forgeable SLSA provenance with existing build systems.
284+
285+
### Provenance for GoReleaser
286+
287+
If you use [GoReleaser](https://github.com/goreleaser/goreleaser-action) to generate your build, you can easily
288+
generate SLSA3 provenance by updating your existing workflow with the 4 steps indicated in the workflow below:
289+
290+
```yaml
291+
jobs:
292+
goreleaser:
293+
# =================================================
294+
#
295+
# Step 1: Declare an `outputs` for the GoReleaser job.
296+
#
297+
# =================================================
298+
outputs:
299+
hashes: ${{ steps.hash.outputs.hashes }}
300+
301+
[...]
302+
303+
steps:
304+
[...]
305+
- name: Run GoReleaser
306+
# =================================================
307+
#
308+
# Step 2: Add an `id: run-goreleaser` field
309+
# to your goreleaser step.
310+
#
311+
# =================================================
312+
id: run-goreleaser
313+
uses: goreleaser/goreleaser-action@b953231f81b8dfd023c58e0854a721e35037f28b
314+
315+
# =================================================
316+
#
317+
# Step 3: Add a step to generate the provenance subjects
318+
# as shown below.
319+
#
320+
# =================================================
321+
- name: Generate subject
322+
id: hash
323+
env:
324+
ARTIFACTS: "${{ steps.run-goreleaser.outputs.artifacts }}"
325+
run: |
326+
set -euo pipefail
327+
328+
checksum_file=$(echo "$ARTIFACTS" | jq -r '.[] | select (.type=="Checksum") | .path')
329+
echo "::set-output name=hashes::$(cat $checksum_file | base64 -w0)"
330+
331+
# =========================================================
332+
#
333+
# Step 4: Call the generic workflow to generate provenance
334+
# by declaring the job below.
335+
#
336+
# =========================================================
337+
provenance:
338+
needs: [goreleaser]
339+
permissions:
340+
actions: read
341+
id-token: write
342+
contents: read
343+
uses: slsa-framework/slsa-github-generator/.github/workflows/[email protected]
344+
with:
345+
base64-subjects: "${{ needs.goreleaser.outputs.hashes }}"
346+
```

0 commit comments

Comments
 (0)