Skip to content

Commit

Permalink
ci: sign binaries and images with cosign
Browse files Browse the repository at this point in the history
Signs using the GHA OIDC token provided by the
build. This verifies both where it is build and
the source that was used to build it from.
  • Loading branch information
jamestelfer committed Sep 21, 2024
1 parent b155d86 commit 1bd2f63
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 2 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ on:
- "v*"

permissions:
# required for OIDC token used as the signing identity
id-token: write

# required to publish the release
contents: write

jobs:
Expand All @@ -27,6 +31,11 @@ jobs:
with:
go-version-file: go.mod

- name: Install Cosign
uses: sigstore/cosign-installer@v3
with:
cosign-release: 'v2.4.0'

- name: Login to Docker Hub
uses: docker/login-action@v3
with:
Expand Down
44 changes: 42 additions & 2 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,30 @@ builds:
- amd64
- arm64

# Sign with cosign -- this picks up the OIDC token from the environment in GHA.
# If you do this locally, sign with an OAuth identity you don't mind being permanently
# published to a transparency log.
binary_signs:
- cmd: './ci-only.sh'
args:
- "cosign"
- "sign-blob"
- "${artifact}"
- "--bundle=${artifact}.cosign.bundle"
- "--yes" # needed on cosign 2.0.0+
output: false # the necessary output is the .cosign.bundle file

checksum:
name_template: "checksums.txt"

archives:
- format: tar.gz
name_template: "{{ .ProjectName }}_{{ .Os }}_{{ .Arch }}"
files:
# cosign produces a bundle file to allow for verification of the artifacts
# this is included in the archive to allow for easier verification after download
- src: '{{ .ArtifactPath }}.cosign.bundle'
strip_parent: true

changelog:
disable: "{{ .Env.CHANGELOG_DISABLE }}"
Expand All @@ -49,8 +67,7 @@ release:
If needed, binaries of this build (including Mac) can be found below.
kos:
-
id: chinmina-bridge
- id: chinmina-bridge
build: release
working_dir: .
base_image: cgr.dev/chainguard/static
Expand All @@ -77,3 +94,26 @@ kos:

# Whether to use the base path without the MD5 hash after the repository name.
base_import_paths: true

# Sign with cosign -- this picks up the OIDC token from the environment in GHA.
# If you do this locally, sign with an OAuth identity you don't mind being permanently
# published to a transparency log.
docker_signs:
- id: ko-signing

cmd: './ci-only.sh'
args:
- "cosign"
- "sign"
- "${artifact}"
- "--yes"

artifacts: all

ids:
# id of ko image above
- chinmina-bridge

# output is not necessary, as the signing is done in place, but it helps to
# provide the index in the transparency log.
output: true
11 changes: 11 additions & 0 deletions ci-only.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/sh
set -eu

if [ "${CI:-false}" != "true" ]; then
echo "CI environment not detected, skipping script execution:"
echo " --> $*"
exit 0
fi

# execute the parameters as the script
exec "$@"

0 comments on commit 1bd2f63

Please sign in to comment.