Skip to content

Commit 4c2025b

Browse files
Add provenance instruction for Bazel based builds. (slsa-framework#556)
Based on the [example-package](https://github.com/slsa-framework/example-package) example workflows, reduced to the instructions that are needed to build and generate provenance. Included 2 artifacts in the example, for the scenarios where multiple artifacts are built in the same job. Signed-off-by: Mihai Maruseac <[email protected]>
1 parent c2878fe commit 4c2025b

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed

internal/builders/generic/README.md

+80
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ project simply generates provenance as a separate step in an existing workflow.
2626
- [Provenance Example](#provenance-example)
2727
- [Integration With Other Build Systems](#integration-with-other-build-systems)
2828
- [Provenance for GoReleaser](#provenance-for-goreleaser)
29+
- [Provenance for Bazel](#provenance-for-bazel)
2930

3031
---
3132

@@ -341,3 +342,82 @@ jobs:
341342
base64-subjects: "${{ needs.goreleaser.outputs.hashes }}"
342343
upload-assets: true # upload to a new release
343344
```
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

Comments
 (0)