@@ -26,6 +26,7 @@ project simply generates provenance as a separate step in an existing workflow.
26
26
- [ Provenance Example] ( #provenance-example )
27
27
- [ Integration With Other Build Systems] ( #integration-with-other-build-systems )
28
28
- [ Provenance for GoReleaser] ( #provenance-for-goreleaser )
29
+ - [ Provenance for Bazel] ( #provenance-for-bazel )
29
30
30
31
---
31
32
@@ -341,3 +342,82 @@ jobs:
341
342
base64-subjects : " ${{ needs.goreleaser.outputs.hashes }}"
342
343
upload-assets : true # upload to a new release
343
344
` ` `
345
+
346
+ ### Provenance for Bazel
347
+
348
+ If you use [Bazel](https://bazel.build/) to generate your artifacts, you can
349
+ easily generate SLSA3 provenance by updating your existing workflow with the 4
350
+ steps indicated in the workflow below:
351
+
352
+ ` ` ` yaml
353
+ jobs :
354
+ build :
355
+ # ==================================================
356
+ #
357
+ # Step 1: Declare an `outputs` for the hashes.
358
+ #
359
+ # ==================================================
360
+ outputs :
361
+ hashes : ${{ steps.hash.outputs.hashes }}
362
+
363
+ [...]
364
+
365
+ steps :
366
+ [...]
367
+ - name : Build using bazel
368
+ # =================================================
369
+ #
370
+ # Step 2: Add an `id: bazel-build` field
371
+ # to your goreleaser step.
372
+ #
373
+ # =================================================
374
+ id : build
375
+ run : |
376
+ # Your normal build workflow targets here
377
+ bazel build //path/to/target_binary //path/to_another/binary
378
+ # ======================================================
379
+ #
380
+ # Step 3: Copy the binaries from `bazel-bin` path (i.e.,
381
+ # Bazel sandbox) to the root of the repository
382
+ # for easier reference (this makes it easier to
383
+ # upload these to the release too!).
384
+ #
385
+ # =====================================================
386
+ cp bazel-bin/path/to/target_binary .
387
+ cp bazel-bin/path/to/another/binary .
388
+
389
+
390
+ # ========================================================
391
+ #
392
+ # Step 4: Add a step to generate the provenance subjects
393
+ # as shown below. Update the sha256 sum arguments
394
+ # to include all binaries that you generate
395
+ # provenance for.
396
+ #
397
+ # ========================================================
398
+ - name : Generate subject
399
+ id : hash
400
+ run : |
401
+ set -euo pipefail
402
+
403
+ sha256sum target_binary binary > checksums
404
+
405
+ echo "::set-output name=hashes::$(cat checksums | base64 -w0)"
406
+
407
+ # =========================================================
408
+ #
409
+ # Step 5: Call the generic workflow to generate provenance
410
+ # by declaring the job below.
411
+ #
412
+ # =========================================================
413
+ provenance :
414
+ needs : [build]
415
+ permissions :
416
+ actions : read
417
+ id-token : write
418
+ contents : read
419
+ uses :
slsa-framework/slsa-github-generator/.github/workflows/[email protected]
420
+ with :
421
+ base64-subjects : " ${{ needs.build.outputs.hashes }}"
422
+ upload-assets : true # upload to a new release
423
+ ` ` `
0 commit comments