30
30
VERIFIER_RELEASE_BINARY_SHA256 : 60c91c9d5b9a059e37ac46da316f20c81da335b5d00e1f74d03dd50f819694bd
31
31
VERIFIER_RELEASE : v1.1.1
32
32
33
- # ##################################################################
34
- # #
35
- # Input and output argument definitions #
36
- # #
37
- # ##################################################################
38
33
on :
39
34
workflow_call :
40
35
inputs :
41
36
base64-subjects :
42
37
description : " Artifacts for which to generate provenance, formatted the same as the output of sha256sum (SHA256 NAME\\ n[...]) and base64 encoded."
43
38
required : true
44
39
type : string
40
+ upload-to-release :
41
+ description : " If true provenance is uploaded to a GitHub release for new tags."
42
+ required : false
43
+ type : boolean
44
+ default : true
45
45
compile-generator :
46
- description : " Build the generator from source. This increases build time by ~2mn ."
46
+ description : " Build the generator from source. This increases build time by ~2m ."
47
47
required : false
48
48
type : boolean
49
49
default : false
50
50
outputs :
51
+ release-id :
52
+ description : " The name of the release where provenance was uploaded."
53
+ value : ${{ jobs.create-release.outputs.release-id }}
51
54
attestation-name :
52
55
description : " The artifact name of the signed provenance"
53
56
value : ${{ jobs.generator.outputs.attestation-name }}
54
57
55
58
jobs :
59
+ # detect-env detects the reusable workflow's repository and ref for use later
60
+ # in the workflow.
56
61
detect-env :
57
62
outputs :
58
63
repository : ${{ steps.detect.outputs.repository }}
@@ -65,14 +70,19 @@ jobs:
65
70
id : detect
66
71
uses : slsa-framework/slsa-github-generator/.github/actions/detect-workflow@d995948e8d53cc639c0d3ef69db31dbc243519c4
67
72
68
- # ##################################################################
69
- # #
70
- # Build the generator #
71
- # #
72
- # ##################################################################
73
+ # generator builds the generator binary and runs it to generate SLSA
74
+ # provenance.
75
+ #
76
+ # If `compile-generator` is true then the generator is compiled
77
+ # from source at the ref detected by `detect-env`.
78
+ #
79
+ # If `compile-generator` is false, then the generator binary is downloaded
80
+ # with the release at the ref detected by `detect-env`. This must be a tag
81
+ # reference.
73
82
generator :
74
83
outputs :
75
84
attestation-name : ${{ steps.sign-prov.outputs.attestation-name }}
85
+ attestation-sha256 : ${{ steps.sign-prov.outputs.attestation-sha256 }}
76
86
runs-on : ubuntu-latest
77
87
needs : [detect-env]
78
88
permissions :
@@ -133,8 +143,11 @@ jobs:
133
143
set -euo pipefail
134
144
# Create and sign provenance
135
145
# This sets attestation-name to the name of the signed DSSE envelope.
136
- ./"$BUILDER_BINARY" attest --subjects "${SUBJECTS}" -g attestation.intoto.jsonl
137
- echo "::set-output name=attestation-name::attestation.intoto.jsonl"
146
+ attestation_name="attestation.intoto.jsonl"
147
+ ./"$BUILDER_BINARY" attest --subjects "${SUBJECTS}" -g $attestation_name
148
+ attestation_sha256=$(sha256sum $attestation_name | awk '{print $1}')
149
+ echo "::set-output name=attestation-name::$attestation_name"
150
+ echo "::set-output name=attestation-sha256::$attestation_sha256"
138
151
139
152
- name : Upload the signed provenance
140
153
uses : actions/upload-artifact@3cea5372237819ed00197afe530f5a7ea3e805c8 # v3.1.0
@@ -143,3 +156,40 @@ jobs:
143
156
path : " ${{ steps.sign-prov.outputs.attestation-name }}"
144
157
if-no-files-found : error
145
158
retention-days : 5
159
+
160
+ # create-release creates a release and uploads provenance to the release if
161
+ # `upload-to-release` is true.
162
+ create-release :
163
+ outputs :
164
+ release-id : ${{ steps.release.outputs.id }}
165
+ runs-on : ubuntu-latest
166
+ needs : [generator]
167
+ permissions :
168
+ contents : write
169
+ if : startsWith(github.ref, 'refs/tags/') && inputs.upload-to-release == true
170
+ steps :
171
+ # Verify provenance hash.
172
+ - uses : actions/download-artifact@fb598a63ae348fa914e94cd0ff38f362e927b741 # v3.0.0
173
+ with :
174
+ name : ${{ needs.generator.outputs.attestation-name }}
175
+ - name : Verify provenance hash
176
+ env :
177
+ UNTRUSTED_PROVENANCE_NAME : " ${{ needs.generator.outputs.attestation-name }}"
178
+ UNTRUSTED_PROVENANCE_HASH : " ${{ needs.generator.outputs.attestation-sha256 }}"
179
+ run : |
180
+ set -euo pipefail
181
+
182
+ echo "hash of provenance $UNTRUSTED_PROVENANCE_NAME should be $UNTRUSTED_PROVENANCE_HASH"
183
+
184
+ COMPUTED_HASH=$(sha256sum "$UNTRUSTED_PROVENANCE_NAME" | awk '{print $1}')
185
+ echo "provenance hash computed is $COMPUTED_HASH"
186
+
187
+ # Compare hashes. Explicit exit to be safe.
188
+ echo "$UNTRUSTED_PROVENANCE_HASH $UNTRUSTED_PROVENANCE_NAME" | sha256sum --strict --check --status || exit -2
189
+
190
+ - name : Release
191
+ uses : softprops/action-gh-release@1e07f4398721186383de40550babbdf2b84acfc5 # v0.1.14
192
+ id : release
193
+ with :
194
+ files : |
195
+ ${{ needs.generator.outputs.attestation-name }}
0 commit comments