Skip to content

Commit 55827f2

Browse files
Add provenance for Haskell (slsa-framework#608)
Signed-off-by: Mihai Maruseac <[email protected]>
1 parent e3a5704 commit 55827f2

File tree

1 file changed

+115
-9
lines changed

1 file changed

+115
-9
lines changed

internal/builders/generic/README.md

+115-9
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

@@ -403,7 +404,7 @@ jobs:
403404
run: |
404405
# Your normal build workflow targets here
405406
bazel build //path/to/target_binary //path/to_another/binary
406-
407+
407408
# Copy the binaries.
408409
cp bazel-bin/path/to/target_binary .
409410
cp bazel-bin/path/to/another/binary .
@@ -425,7 +426,7 @@ jobs:
425426
```
426427

427428
4. Call the generic workflow to generate provenance by declaring the job below:
428-
429+
429430
```yaml
430431
provenance:
431432
needs: [build]
@@ -456,7 +457,7 @@ jobs:
456457
run: |
457458
# Your normal build workflow targets here
458459
bazel build //path/to/target_binary //path/to_another/binary
459-
460+
460461
# Copy the binaries.
461462
cp bazel-bin/path/to/target_binary .
462463
cp bazel-bin/path/to/another/binary .
@@ -512,7 +513,7 @@ jobs:
512513
run: |
513514
# Your normal build workflow targets here
514515
mvn clean package
515-
516+
516517
# Save the location of the maven output files for easier reference
517518
ARTIFACT_PATTERN=./target/$(mvn help:evaluate -Dexpression=project.artifactId -q -DforceStdout)-$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)*.jar
518519
echo "::set-output name=artifact_pattern::$ARTIFACT_PATTERN"
@@ -563,7 +564,7 @@ jobs:
563564
run: |
564565
# Your normal build workflow targets here
565566
mvn clean package
566-
567+
567568
# Save the location of the maven output files for easier reference
568569
ARTIFACT_PATTERN=./target/$(mvn help:evaluate -Dexpression=project.artifactId -q -DforceStdout)-$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)*.jar
569570
echo "::set-output name=artifact_pattern::$ARTIFACT_PATTERN"
@@ -572,7 +573,7 @@ jobs:
572573
id: hash
573574
run: |
574575
echo "::set-output name=hashes::$(sha256sum ${{ steps.build.outputs.artifact_pattern }} | base64 -w0)"
575-
576+
576577
- name: Upload build artifacts
577578
uses: actions/upload-artifact@3cea5372237819ed00197afe530f5a7ea3e805c8 # tag=v3
578579
with:
@@ -606,7 +607,7 @@ jobs:
606607
```
607608

608609
2. Add an `id: build` field to your gradle build ste:
609-
610+
610611
```yaml
611612
steps:
612613
[...]
@@ -665,7 +666,7 @@ jobs:
665666
id: hash
666667
run: |
667668
echo "::set-output name=hashes::$(sha256sum ./build/libs/* | base64 -w0)"
668-
669+
669670
- name: Upload build artifacts
670671
uses: actions/upload-artifact@3cea5372237819ed00197afe530f5a7ea3e805c8 # tag=v3
671672
with:
@@ -778,4 +779,109 @@ jobs:
778779
base64-subjects: "${{ needs.build.outputs.hashes }}"
779780
upload-assets: true # Optional: Upload to a new release
780781
781-
```
782+
```
783+
784+
### Provenance for Haskell
785+
786+
If you use [Haskell](https://www.haskell.org/) (either via
787+
[`cabal`](https://www.haskell.org/cabal/) or
788+
[`stack`](https://docs.haskellstack.org/en/stable/README/)) to generate your
789+
artifacts, you can easily generate SLSA3 provenance by updating your existing
790+
workflow with the steps indicated in the workflow below.
791+
792+
1. Declare an `outputs` for the hashes:
793+
794+
```yaml
795+
jobs:
796+
build:
797+
outputs:
798+
hashes: ${{ steps.hash.outputs.hashes }}
799+
800+
```
801+
802+
2. Build your binaries. Then add a step to generate the provenance subjects as shown below. Update the sha256 sum arguments to include all binaries that you generate provenance for:
803+
804+
```yaml
805+
steps:
806+
[...]
807+
- name: Build using Haskell
808+
run: |
809+
# Your normal build workflow targets here.
810+
cabal build # or stack build
811+
812+
# Copy the binary to the root directory for easier reference
813+
# For Cabal, use the following command
814+
cp $(cabal list-bin .) .
815+
# For Stack, use the following command instead
816+
# cp $(stack path --local-install-root)/bin/target_binary .
817+
818+
# Generate the subject.
819+
- name: Generate subject
820+
id: hash
821+
run: |
822+
set -euo pipefail
823+
824+
echo "::set-output name=hashes::$(sha256sum target_binary | base64 -w0)"
825+
826+
```
827+
828+
3. Call the generic workflow to generate provenance by declaring the job below:
829+
830+
```yaml
831+
provenance:
832+
needs: [build]
833+
permissions:
834+
actions: read # To read the workflow path.
835+
id-token: write # To sign the provenance.
836+
contents: write # To add assets to a release.
837+
uses: slsa-framework/slsa-github-generator/.github/workflows/[email protected]
838+
with:
839+
base64-subjects: "${{ needs.build.outputs.hashes }}"
840+
upload-assets: true # Optional: Upload to a new release
841+
842+
```
843+
844+
All in all, it will look as the following:
845+
846+
```yaml
847+
jobs:
848+
build:
849+
outputs:
850+
hashes: ${{ steps.hash.outputs.hashes }}
851+
852+
steps:
853+
- name: Checkout repository
854+
uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # tag=v3
855+
- name: Setup Haskell
856+
uses: haskell/actions/setup@745062a754c3c4b70b87cb93937ad443096cc94d # tag=v1
857+
858+
- name: Build using Haskell
859+
run: |
860+
# Your normal build workflow targets here.
861+
cabal build # or stack build
862+
863+
# Copy the binary to the root directory for easier reference
864+
# For Cabal, use the following command
865+
cp $(cabal list-bin .) .
866+
# For Stack, use the following command instead
867+
# cp $(stack path --local-install-root)/bin/target_binary .
868+
869+
# Generate the subject.
870+
- name: Generate subject
871+
id: hash
872+
run: |
873+
set -euo pipefail
874+
875+
echo "::set-output name=hashes::$(sha256sum target_binary | base64 -w0)"
876+
877+
provenance:
878+
needs: [build]
879+
permissions:
880+
actions: read # To read the workflow path.
881+
id-token: write # To sign the provenance.
882+
contents: write # To add assets to a release.
883+
uses: slsa-framework/slsa-github-generator/.github/workflows/[email protected]
884+
with:
885+
base64-subjects: "${{ needs.build.outputs.hashes }}"
886+
upload-assets: true # Optional: Upload to a new release
887+
```

0 commit comments

Comments
 (0)