Skip to content

Commit 0f97cca

Browse files
Haskell provenance (slsa-framework#595)
* Add provenance for Haskell. Allows using either Stack or Cabal build tools Tested via example repo ([Cabal](https://github.com/mihaimaruseac/slsa-lvl3-generic-provenance-in-haskell-example/blob/v0.0.1.1/.github/workflows/ci.yaml), [Stack](https://github.com/mihaimaruseac/slsa-lvl3-generic-provenance-in-haskell-example/blob/v0.0.1.0/.github/workflows/ci.yaml)). Signed-off-by: Mihai Maruseac <[email protected]> * Fix off-by-one counting errors Signed-off-by: Mihai Maruseac <[email protected]> * Remove trailing whitespace Signed-off-by: Mihai Maruseac <[email protected]> * Remove the build id step as it is not needed Signed-off-by: Mihai Maruseac <[email protected]> * Update README.md Co-authored-by: laurentsimon <[email protected]>
1 parent 1d7962b commit 0f97cca

File tree

1 file changed

+77
-8
lines changed

1 file changed

+77
-8
lines changed

internal/builders/generic/README.md

+77-8
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ project simply generates provenance as a separate step in an existing workflow.
2929
- [Provenance for Bazel](#provenance-for-bazel)
3030
- [Provenance for Java](#provenance-for-java)
3131
- [Provenance for Rust](#provenance-for-rust)
32+
- [Provenance for Haskell](#provenance-for-haskell)
3233

3334
---
3435

@@ -351,7 +352,7 @@ jobs:
351352
### Provenance for Bazel
352353
353354
If you use [Bazel](https://bazel.build/) to generate your artifacts, you can
354-
easily generate SLSA3 provenance by updating your existing workflow with the 4
355+
easily generate SLSA3 provenance by updating your existing workflow with the 5
355356
steps indicated in the workflow below:
356357
357358
```yaml
@@ -462,7 +463,7 @@ jobs:
462463
run: |
463464
# Your normal build workflow targets here
464465
mvn clean package
465-
466+
466467
# ======================================================
467468
#
468469
# Step 3: Save the location of the maven output files
@@ -484,7 +485,7 @@ jobs:
484485
id: hash
485486
run: |
486487
echo "::set-output name=hashes::$(sha256sum ${{ steps.build.outputs.artifact_pattern }} | base64 -w0)"
487-
488+
488489
- name: Upload build artifacts
489490
uses: actions/upload-artifact@3cea5372237819ed00197afe530f5a7ea3e805c8 # tag=v3.1.0
490491
with:
@@ -541,7 +542,7 @@ jobs:
541542
542543
# ========================================================
543544
#
544-
# Step 4: Add a step to generate the provenance subjects
545+
# Step 3: Add a step to generate the provenance subjects
545546
# as shown below. Update the sha256 sum arguments
546547
# to include all binaries that you generate
547548
# provenance for.
@@ -553,7 +554,7 @@ jobs:
553554
id: hash
554555
run: |
555556
echo "::set-output name=hashes::$(sha256sum ./build/libs/* | base64 -w0)"
556-
557+
557558
- name: Upload build artifacts
558559
uses: actions/upload-artifact@3cea5372237819ed00197afe530f5a7ea3e805c8 # tag=v3.1.0
559560
with:
@@ -563,7 +564,7 @@ jobs:
563564

564565
# =========================================================
565566
#
566-
# Step 5: Call the generic workflow to generate provenance
567+
# Step 4: Call the generic workflow to generate provenance
567568
# by declaring the job below.
568569
#
569570
# =========================================================
@@ -616,7 +617,7 @@ jobs:
616617
617618
# ========================================================
618619
#
619-
# Step 4: Add a step to generate the provenance subjects
620+
# Step 3: Add a step to generate the provenance subjects
620621
# as shown below. Update the sha256 sum arguments
621622
# to include all binaries that you generate
622623
# provenance for.
@@ -631,7 +632,75 @@ jobs:
631632
632633
# =========================================================
633634
#
634-
# Step 5: Call the generic workflow to generate provenance
635+
# Step 4: Call the generic workflow to generate provenance
636+
# by declaring the job below.
637+
#
638+
# =========================================================
639+
provenance:
640+
needs: [build]
641+
permissions:
642+
actions: read # To read the workflow path.
643+
id-token: write # To sign the provenance.
644+
contents: write # To add assets to a release.
645+
uses: slsa-framework/slsa-github-generator/.github/workflows/[email protected]
646+
with:
647+
base64-subjects: "${{ needs.build.outputs.hashes }}"
648+
upload-assets: true # Optional: Upload to a new release
649+
```
650+
651+
### Provenance for Haskell
652+
653+
If you use [Haskell](https://www.haskell.org/) (either via
654+
[`cabal`](https://www.haskell.org/cabal/) or
655+
[`stack`](https://docs.haskellstack.org/en/stable/README/)) to generate your
656+
artifacts, you can easily generate SLSA3 provenance by updating your existing
657+
workflow with the steps indicated in the workflow below.
658+
659+
```yaml
660+
jobs:
661+
build:
662+
# ==================================================
663+
#
664+
# Step 1: Declare an `outputs` for the hashes to be
665+
# used during the provenance steps.
666+
#
667+
# ==================================================
668+
outputs:
669+
hashes: ${{ steps.hash.outputs.hashes }}
670+
671+
[...]
672+
673+
steps:
674+
[...]
675+
- name: Build using Haskell
676+
run: |
677+
# Your normal build workflow targets here.
678+
cabal build # or stack build
679+
680+
# Copy the binary to the root directory for easier reference
681+
# For Cabal, use the following command
682+
cp $(cabal list-bin .) .
683+
# For Stack, use the following command instead
684+
# cp $(stack path --local-install-root)/bin/target_binary .
685+
686+
# ========================================================
687+
#
688+
# Step 2: Add a step to generate the provenance subjects
689+
# as shown below. Update the sha256 sum arguments
690+
# to include all binaries that you generate
691+
# provenance for.
692+
#
693+
# ========================================================
694+
- name: Generate subject
695+
id: hash
696+
run: |
697+
set -euo pipefail
698+
699+
echo "::set-output name=hashes::$(sha256sum target_binary | base64 -w0)"
700+
701+
# =========================================================
702+
#
703+
# Step 3: Call the generic workflow to generate provenance
635704
# by declaring the job below.
636705
#
637706
# =========================================================

0 commit comments

Comments
 (0)