Skip to content

Commit b045ad4

Browse files
committed
Merge pull request #2 from goreleaser/feature/container-image-slsa-provenance
image provenance Signed-off-by: Batuhan Apaydın <[email protected]>
2 parents 354c3e6 + 9418ada commit b045ad4

File tree

2 files changed

+90
-24
lines changed

2 files changed

+90
-24
lines changed

.github/workflows/goreleaser.yml

Lines changed: 75 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,17 @@ on:
55
tags:
66
- "v*" # triggers only if push new tag version, like `0.8.4` or else
77

8-
permissions:
9-
contents: read
10-
118
jobs:
129
goreleaser:
1310
outputs:
14-
hashes: ${{ steps.hash.outputs.hashes }}
15-
permissions:
16-
contents: write # for goreleaser/goreleaser-action to create a GitHub release
11+
hashes: ${{ steps.binary.outputs.hashes }}
12+
image: ${{ steps.image.outputs.name }}
13+
digest: ${{ steps.image.outputs.digest }}
1714
runs-on: ubuntu-latest
15+
permissions:
16+
contents: write
17+
packages: write
18+
# id-token: write
1819
steps:
1920
- name: Checkout
2021
uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v2.3.4
@@ -25,47 +26,77 @@ jobs:
2526
with:
2627
go-version: "1.20"
2728
check-latest: true
29+
- uses: docker/login-action@v1
30+
with:
31+
registry: ghcr.io
32+
username: ${{ github.repository_owner }}
33+
password: ${{ secrets.GITHUB_TOKEN }}
2834
- name: Run GoReleaser
29-
id: run-goreleaser
35+
id: goreleaser
3036
uses: goreleaser/goreleaser-action@8f67e590f2d095516493f017008adc464e63adb1 # v2.5.0
3137
with:
3238
version: latest
3339
args: release --rm-dist
3440
env:
3541
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
36-
VERSION_LDFLAGS: ${{ steps.ldflags.outputs.version }}
37-
- name: Generate subject
38-
id: hash
42+
- name: Generate binary hashes
43+
id: binary
3944
env:
40-
ARTIFACTS: "${{ steps.run-goreleaser.outputs.artifacts }}"
45+
ARTIFACTS: "${{ steps.goreleaser.outputs.artifacts }}"
4146
run: |
4247
set -euo pipefail
4348
4449
checksum_file=$(echo "$ARTIFACTS" | jq -r '.[] | select (.type=="Checksum") | .path')
4550
echo "hashes=$(cat $checksum_file | base64 -w0)" >> "$GITHUB_OUTPUT"
51+
- name: Image digest
52+
id: image
53+
env:
54+
ARTIFACTS: "${{ steps.goreleaser.outputs.artifacts }}"
55+
run: |
56+
set -euo pipefail
57+
image_and_digest=$(echo "$ARTIFACTS" | jq -r '.[] | select (.type=="Docker Manifest") | .path')
58+
image=$(echo "${image_and_digest}" | cut -d'@' -f1 | cut -d':' -f1)
59+
digest=$(echo "${image_and_digest}" | cut -d'@' -f2)
60+
echo "name=$image" >> "$GITHUB_OUTPUT"
61+
echo "digest=$digest" >> "$GITHUB_OUTPUT"
4662
47-
provenance:
63+
binary-provenance:
4864
needs: [goreleaser]
4965
permissions:
5066
actions: read # To read the workflow path.
5167
id-token: write # To sign the provenance.
5268
contents: write # To add assets to a release.
53-
uses: slsa-framework/slsa-github-generator/.github/workflows/generator_generic_slsa3.yml@v1.5.0
69+
uses: slsa-framework/slsa-github-generator/.github/workflows/generator_generic_slsa3.yml@v1.9.0
5470
with:
5571
base64-subjects: "${{ needs.goreleaser.outputs.hashes }}"
5672
upload-assets: true # upload to a new release
57-
verification:
58-
needs: [goreleaser, provenance]
73+
74+
image-provenance:
75+
needs: [goreleaser]
76+
permissions:
77+
actions: read
78+
id-token: write
79+
packages: write
80+
uses: slsa-framework/slsa-github-generator/.github/workflows/[email protected]
81+
with:
82+
image: ${{ needs.goreleaser.outputs.image }}
83+
digest: ${{ needs.goreleaser.outputs.digest }}
84+
registry-username: ${{ github.actor }}
85+
secrets:
86+
registry-password: ${{ secrets.GITHUB_TOKEN }}
87+
88+
verification-with-slsa-verifier:
89+
needs: [goreleaser, binary-provenance]
5990
runs-on: ubuntu-latest
6091
permissions: read-all
6192
steps:
6293
- name: Install the verifier
63-
uses: slsa-framework/slsa-verifier/actions/installer@v2.1.0
94+
uses: slsa-framework/slsa-verifier/actions/installer@v2.4.0
6495

6596
- name: Download assets
6697
env:
6798
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
68-
PROVENANCE: "${{ needs.provenance.outputs.provenance-name }}"
99+
PROVENANCE: "${{ needs.binary-provenance.outputs.provenance-name }}"
69100
run: |
70101
set -euo pipefail
71102
gh -R "$GITHUB_REPOSITORY" release download "$GITHUB_REF_NAME" -p "*.tar.gz"
@@ -74,7 +105,7 @@ jobs:
74105
- name: Verify assets
75106
env:
76107
CHECKSUMS: ${{ needs.goreleaser.outputs.hashes }}
77-
PROVENANCE: "${{ needs.provenance.outputs.provenance-name }}"
108+
PROVENANCE: "${{ needs.binary-provenance.outputs.provenance-name }}"
78109
run: |
79110
set -euo pipefail
80111
checksums=$(echo "$CHECKSUMS" | base64 -d)
@@ -86,3 +117,29 @@ jobs:
86117
--source-tag "$GITHUB_REF_NAME" \
87118
"$fn"
88119
done <<<"$checksums"
120+
121+
verification-with-cosign:
122+
needs: [goreleaser, image-provenance]
123+
runs-on: ubuntu-latest
124+
permissions: read-all
125+
steps:
126+
- name: Login
127+
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0
128+
with:
129+
registry: ghcr.io
130+
username: ${{ github.actor }}
131+
password: ${{ secrets.GITHUB_TOKEN }}
132+
133+
- name: Install Cosign
134+
uses: sigstore/cosign-installer@11086d25041f77fe8fe7b9ea4e48e3b9192b8f19 # v3.1.2
135+
136+
- name: Verify image
137+
env:
138+
IMAGE: ${{ needs.goreleaser.outputs.image }}
139+
DIGEST: ${{ needs.goreleaser.outputs.digest }}
140+
run: |
141+
cosign verify-attestation \
142+
--type slsaprovenance \
143+
--certificate-oidc-issuer https://token.actions.githubusercontent.com \
144+
--certificate-identity-regexp '^https://github.com/slsa-framework/slsa-github-generator/.github/workflows/generator_container_slsa3.yml@refs/tags/v[0-9]+.[0-9]+.[0-9]+$' \
145+
$IMAGE@$DIGEST

.goreleaser.yaml

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
# This is an example .goreleaser.yml file with some sensible defaults.
2-
# Make sure to check the documentation at https://goreleaser.com
3-
before:
4-
hooks:
5-
# You may remove this if you don't use go modules.
6-
- go mod tidy
71
builds:
82
- env:
93
- CGO_ENABLED=0
@@ -12,6 +6,21 @@ builds:
126
- windows
137
- darwin
148

9+
kos:
10+
- repository: ghcr.io/goreleaser/goreleaser-example-slsa-provenance
11+
tags:
12+
- '{{.Tag}}'
13+
- '{{ if not .Prerelease }}latest{{ end }}'
14+
bare: true
15+
preserve_import_paths: false
16+
sbom: none
17+
platforms:
18+
- all
19+
flags:
20+
- -trimpath
21+
ldflags:
22+
- -s -w
23+
1524
archives:
1625
- format: tar.gz
1726
# this name template makes the OS and Arch compatible with the results of uname.

0 commit comments

Comments
 (0)