Skip to content

Commit 26f10e0

Browse files
authored
Extend the release action to sign the docker image and binary files with cosign (#781)
* Extend the release action to sign the docker image and binary files with cosign * Fix lint warnings * Fix the ling warnings * Fix the lint warnings
1 parent 7d539ed commit 26f10e0

File tree

6 files changed

+68
-17
lines changed

6 files changed

+68
-17
lines changed

.github/workflows/release.yml

+41-11
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,57 @@ jobs:
1818
uses: actions/setup-go@v2
1919
with:
2020
go-version: 1.17
21-
- name : Get release version
22-
id: get_version
23-
run: echo ::set-env name=RELEASE_VERSION::$(echo ${GITHUB_REF:10})
21+
- name: Install Cosign
22+
uses: sigstore/cosign-installer@main
23+
with:
24+
cosign-release: 'v1.5.2'
25+
- name: Store Cosign private key in a file
26+
run: 'echo "$COSIGN_KEY" > /tmp/cosign.key'
27+
shell: bash
28+
env:
29+
COSIGN_KEY: ${{secrets.COSIGN_KEY}}
30+
- name: Set up QEMU
31+
uses: docker/setup-qemu-action@v1
32+
- name: Set up Docker Buildx
33+
uses: docker/setup-buildx-action@v1
34+
- name: Login to DockerHub
35+
uses: docker/login-action@v1
36+
with:
37+
username: ${{secrets.DOCKER_USERNAME}}
38+
password: ${{secrets.DOCKER_PASSWORD}}
2439
- name: Generate SBOM
2540
uses: CycloneDX/gh-gomod-generate-sbom@v1
2641
with:
2742
version: v1
2843
args: mod -licenses -json -output bom.json
44+
- name: Docker meta
45+
uses: docker/metadata-action@v3
46+
id: meta
47+
with:
48+
images: securego/gosec
49+
flavor: |
50+
latest=true
51+
tags: |
52+
type=sha,format=long
53+
type=semver,pattern={{version}}
2954
- name: Release Binaries
3055
uses: goreleaser/goreleaser-action@v2
3156
with:
3257
version: latest
3358
args: release --rm-dist
3459
env:
35-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
60+
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
61+
COSIGN_PASSWORD: ${{secrets.COSIGN_PASSWORD}}
3662
- name: Release Docker Image
37-
uses: elgohr/Publish-Docker-Github-Action@master
63+
uses: docker/build-push-action@v2
3864
with:
39-
name: securego/gosec
40-
username: ${{ secrets.DOCKER_USERNAME }}
41-
password: ${{ secrets.DOCKER_PASSWORD }}
42-
buildargs: GO_VERSION=1.17
43-
tags: "latest,${{ env.RELEASE_VERSION }}"
44-
tag_names: true
65+
platforms: linux/amd64,linux/arm/v7,linux/arm64
66+
tags: ${{steps.meta.outputs.tags}}
67+
labels: ${{steps.meta.outputs.labels}}
68+
push: true
69+
build-args: GO_VERSION=1.17
70+
- name: Sign Docker Image
71+
run: cosign sign -key /tmp/cosign.key ${TAGS}
72+
env:
73+
TAGS: ${{steps.meta.outputs.tags}}
74+
COSIGN_PASSWORD: ${{secrets.COSIGN_PASSWORD}}

.goreleaser.yml

+8-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ release:
99
name: gosec
1010

1111
builds:
12-
- main : ./cmd/gosec/
12+
- main: ./cmd/gosec/
1313
binary: gosec
1414
goos:
1515
- darwin
@@ -21,3 +21,10 @@ builds:
2121
ldflags: -X main.Version={{.Version}} -X main.GitTag={{.Tag}} -X main.BuildDate={{.Date}}
2222
env:
2323
- CGO_ENABLED=0
24+
25+
signs:
26+
- cmd: cosign
27+
stdin: '{{ .Env.COSIGN_PASSWORD}}'
28+
args: ["sign-blob", "--key=/tmp/cosign.key", "--output=${signature}", "${artifact}"]
29+
artifacts: all
30+

README.md

+14-1
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,19 @@ git push origin v1.0.0
407407
The GitHub [release workflow](.github/workflows/release.yml) triggers immediately after the tag is pushed upstream. This flow will
408408
release the binaries using the [goreleaser](https://goreleaser.com/actions/) action and then it will build and publish the docker image into Docker Hub.
409409

410+
The released artifacts are signed using [cosign](https://docs.sigstore.dev/). You can use the public key from [cosign.pub](cosign.pub)
411+
file to verify the signature of docker image and binaries files.
412+
413+
The docker image signature can be verified with the following command:
414+
```
415+
cosign verify --key cosign.pub securego/gosec:<TAG>
416+
```
417+
418+
The binary files signature can be verified with the following command:
419+
```
420+
cosign verify-blob --key cosign.pub --signature gosec_<VERSION>_darwin_amd64.tar.gz.sig gosec_<VERSION>_darwin_amd64.tar.gz
421+
```
422+
410423
### Docker image
411424

412425
You can also build locally the docker image by using the command:
@@ -450,4 +463,4 @@ This is a [list](USERS.md) with some of the gosec's users.
450463

451464
Support this project by becoming a sponsor. Your logo will show up here with a link to your website
452465

453-
<a href="https://github.com/mercedes-benz" target="_blank"><img src="https://avatars.githubusercontent.com/u/34240465?s=80&v=4"></a>
466+
<a href="https://github.com/mercedes-benz" target="_blank"><img src="https://avatars.githubusercontent.com/u/34240465?s=80&v=4"></a>

cosign.pub

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
-----BEGIN PUBLIC KEY-----
2+
MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEFphl7f2VuFRfsi4wqiLUCQ9xHQgV
3+
O2VMDNcvh+kxiymLXa+GkPzSKExFYIlVwfg13URvCiB+kFvITmLzuLiGQg==
4+
-----END PUBLIC KEY-----

report/html/writer.go

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package html
22

33
import (
4-
54
// use go embed to import template
65
_ "embed"
76
"html/template"

report/text/writer.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ package text
33
import (
44
"bufio"
55
"bytes"
6-
7-
// use go embed to import template
8-
_ "embed"
6+
_ "embed" // use go embed to import template
97
"fmt"
108
"io"
119
"strconv"

0 commit comments

Comments
 (0)