Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate SLSA provenance for released binaries #9702

Closed
wants to merge 20 commits into from
Closed
96 changes: 93 additions & 3 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,21 @@ on:
tag:
description: "Release Tag"
required: true
dry-run:
description: "Build, sign, verify but do not release"
required: false
type: boolean
default: true

permissions: read-all

env:
laurentsimon marked this conversation as resolved.
Show resolved Hide resolved
GO_VERSION: 1.18.5

jobs:
upload-release:
build:
outputs:
hashes: ${{ steps.hash.outputs.hashes }}
runs-on: ubuntu-latest
steps:
- name: Checkout code into the Go module directory
Expand All @@ -30,14 +41,93 @@ jobs:
run: make GIT_TAG=${{ github.event.inputs.tag }} -f builder.Makefile cross

- name: Compute checksums
run: cd bin; for f in *; do shasum --binary --algorithm 256 $f | tee -a checksums.txt > $f.sha256; done
working-directory: bin/
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: this change is not needed. I added working-directory to avoid the cd bin, but I can revert.

run: for f in *; do shasum --binary --algorithm 256 $f | tee -a checksums.txt > $f.sha256; done

- name: Generate SLSA subjects
id: hash
working-directory: bin/
run: |
set -euo pipefail
echo "::set-output name=hashes::$(cat checksums.txt | base64 -w0)"

- name: License
run: cp packaging/* bin/

- uses: actions/upload-artifact@v3
with:
name: "bin"
path: "bin/*"

provenance:
needs: [build]
permissions:
actions: read # To read the workflow path.
id-token: write # To sign the provenance.
contents: write # To add assets to a release.
uses: slsa-framework/slsa-github-generator/.github/workflows/[email protected]
with:
base64-subjects: "${{ needs.build.outputs.hashes }}"

release:
needs: [build, provenance]
runs-on: ubuntu-latest
permissions:
contents: write
steps:
# Install the verifier. This be replaced with the GHA in the future.
- name: Install the verfier
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -euo pipefail

gh -R slsa-framework/slsa-verifier release download v1.2.0 -p "slsa-verifier-linux-amd64"
chmod ug+x slsa-verifier-linux-amd64
# Note: see https://github.com/slsa-framework/slsa-verifier/blob/main/SHA256SUM.md
COMPUTED_HASH=$(sha256sum slsa-verifier-linux-amd64 | cut -d ' ' -f1)
EXPECTED_HASH="37db23392c7918bb4e243cdb097ed5f9d14b9b965dc1905b25bc2d1c0c91bf3d"
if [[ "$EXPECTED_HASH" != "$COMPUTED_HASH" ]];then
echo "error: expected $EXPECTED_HASH, computed $COMPUTED_HASH"
exit 1
fi
# Download binaries and license.
- uses: actions/download-artifact@v3
with:
name: "bin"
# Download provenance file.
- uses: actions/download-artifact@v3
with:
name: "${{ needs.provenance.outputs.attestation-name }}"
# Verify binaries.
- name: Verify binaries
env:
PROVENANCE: "${{ needs.provenance.outputs.attestation-name }}"
run: |
set -euo pipefail

for f in *;
do
if [[ ! -f "$f.sha256" ]]; then
continue
fi

echo "Verifying $f"
./slsa-verifier-linux-amd64 -artifact-path "$f" \
-provenance "$PROVENANCE" \
-source "github.com/$GITHUB_REPOSITORY" \
-branch v2

done

# The slsa verifier is not part of the project, so remove it.
rm ./slsa-verifier-linux-amd64

# Upload to release.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Upload to release.
# Verify binaries if dry run
- name: Verify binaries
if: 'inputs.dry-run'
run: |
echo TODO: verify with slsa-verifier
# Upload to release.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we need to put in the actual steps here. Don't suppose you have a packaged action for verifying yet?

Copy link
Author

@laurentsimon laurentsimon Aug 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not yet, but we are working on it.
Would you like me to add the steps in this PR or do that in a follow-up PR?
We have 2 options:

  • go install [email protected]. This will build from source. Takes about 2-3mn for the verifier to build
  • pull the binary from our release. This would allow simulating what users do, ie using the latest version of the verifier. (Note: we can verify the hash of the pulled binary)

Let me know what you prefer.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cheapest option is to use the pre-compiled binary. But if you don't mind 2-3mn to build the verifier, it's the simplest option.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the code for verification. PTAL

I also created a tracking issue slsa-framework/slsa-verifier#206 on our repo as an AI to send a PR to update your workflow when we have the GHA released.

- uses: ncipollo/release-action@v1
if: '! inputs.dry-run'
with:
laurentsimon marked this conversation as resolved.
Show resolved Hide resolved
artifacts: "bin/*"
artifacts: "*"
generateReleaseNotes: true
draft: true
commit: "v2"
Expand Down
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Docker Compose v2

[![Actions Status](https://github.com/docker/compose/workflows/Continuous%20integration/badge.svg)](https://github.com/docker/compose/actions)
[![SLSA 3](https://slsa.dev/images/gh-badge-level3.svg)](https://slsa.dev/images/gh-badge-level3.svg)

![Docker Compose](logo.png?raw=true "Docker Compose Logo")

Expand Down Expand Up @@ -30,6 +31,16 @@ for Windows and macOS.
You can download Docker Compose binaries from the
[release page](https://github.com/docker/compose/releases) on this repository.

We generate [SLSA3 provenance](slsa.dev) using the OpenSSF's [slsa-framework/slsa-github-generator](https://github.com/slsa-framework/slsa-github-generator). To verify the binaries:
1. Install the verification tool from [slsa-framework/slsa-verifier#installation](https://github.com/slsa-framework/slsa-verifier#installation)
1. Download the file named `attestation.intoto.jsonl` from the release
1. Run:
```shell
$ slsa-verifier -artifact-path <binary> -provenance attestation.intoto.jsonl -source github.com/docker/compose -branch v2 -workflow-input tag=<tag>
PASSED: Verified SLSA provenance
```


Rename the relevant binary for your OS to `docker-compose` and copy it to `$HOME/.docker/cli-plugins`

Or copy it into one of these folders for installing it system-wide:
Expand Down