Skip to content

Commit cfe4706

Browse files
authored
feat: sign containers
This adds container signing based on the GitHub Actions OpenID token, cosign, and Rekor. The signing is taken care of in the actions, and the workflows simply pass in a flag to enable it. Fixes: #126 Signed-off-by: Jaremy Hatler <hatler.jaremy@gmail.com>
1 parent ca10223 commit cfe4706

File tree

4 files changed

+49
-0
lines changed

4 files changed

+49
-0
lines changed

.github/actions/container/action.yml

+21
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,21 @@ inputs:
3838
password:
3939
description: 'OCI Registry Password'
4040
required: true
41+
sign:
42+
description: 'Sign images?'
43+
required: false
44+
default: false
4145

4246
runs:
4347
using: "composite"
4448
steps:
4549
- name: Set up QEMU
4650
uses: docker/setup-qemu-action@v3
4751

52+
- name: Install cosign
53+
if: inputs.sign != 'false'
54+
uses: sigstore/cosign-installer@v3.5.0
55+
4856
- name: Set up Docker Buildx
4957
uses: docker/setup-buildx-action@v3
5058

@@ -80,6 +88,19 @@ runs:
8088
${{ inputs.repository }}:v${{ inputs.semver_major }}
8189
platforms: ${{ inputs.platforms }}
8290

91+
- name: Sign the published images
92+
if: inputs.sign == 'true' && inputs.push == 'true'
93+
shell: bash
94+
env:
95+
TAGS: |
96+
${{ inputs.repository }}:latest
97+
${{ inputs.repository }}:${{ steps.git.outputs.short_sha }}
98+
${{ inputs.repository }}:v${{ inputs.semver_major }}.${{ inputs.semver_minor }}.${{ inputs.semver_patch }}
99+
${{ inputs.repository }}:v${{ inputs.semver_major }}.${{ inputs.semver_minor }}
100+
${{ inputs.repository }}:v${{ inputs.semver_major }}
101+
DIGEST: ${{ steps.build.outputs.digest }}
102+
run: echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST}
103+
83104
- name: Attest
84105
uses: actions/attest-build-provenance@v1
85106
id: attest

.github/actions/devcontainer/action.yml

+21
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,21 @@ inputs:
4343
description: 'Cleanup images after build?'
4444
required: true
4545
default: true
46+
sign:
47+
description: 'Sign images?'
48+
required: false
49+
default: false
4650

4751
runs:
4852
using: "composite"
4953
steps:
5054
- name: Set up QEMU
5155
uses: docker/setup-qemu-action@v3
5256

57+
- name: Install cosign
58+
if: inputs.sign != 'false'
59+
uses: sigstore/cosign-installer@v3.5.0
60+
5361
- name: Set up Docker Buildx
5462
uses: docker/setup-buildx-action@v3
5563

@@ -144,6 +152,19 @@ runs:
144152
docker push ${{ inputs.repository }}:v${{ inputs.semver_major }}.${{ inputs.semver_minor }}
145153
docker push ${{ inputs.repository }}:v${{ inputs.semver_major }}
146154
155+
- name: Sign the published images
156+
if: inputs.sign == 'true' && inputs.push == 'true'
157+
shell: bash
158+
env:
159+
TAGS: |
160+
${{ inputs.repository }}:latest
161+
${{ inputs.repository }}:${{ steps.git.outputs.short_sha }}
162+
${{ inputs.repository }}:v${{ inputs.semver_major }}.${{ inputs.semver_minor }}.${{ inputs.semver_patch }}
163+
${{ inputs.repository }}:v${{ inputs.semver_major }}.${{ inputs.semver_minor }}
164+
${{ inputs.repository }}:v${{ inputs.semver_major }}
165+
DIGEST: ${{ steps.tag.outputs.digest }}
166+
run: echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST}
167+
147168
# jscpd:ignore-start
148169
- name: Attest
149170
uses: actions/attest-build-provenance@v1

.github/workflows/containers.yml

+5
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ on:
99
- '!devcontainers/janus/CHANGELOG.md'
1010
- '.devcontainer/**'
1111
- '!.devcontainer/CHANGELOG.md'
12+
- '.github/workflows/containers.yml'
13+
- '.github/actions/container/**'
14+
- '.github/actions/devcontainer/**'
1215

1316
concurrency:
1417
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
@@ -57,6 +60,7 @@ jobs:
5760
context: "{{defaultContext}}:containers/janus"
5861
platforms: linux/amd64,linux/arm64
5962
push: true
63+
sign: true
6064
repository: ghcr.io/jhatler/janus
6165
registry: ghcr.io
6266
username: ${{ github.repository_owner }}
@@ -107,6 +111,7 @@ jobs:
107111
workspace: ${{ github.workspace }}/devcontainers/janus
108112
platforms: linux/amd64,linux/arm64
109113
push: true
114+
sign: true
110115
repository: ghcr.io/jhatler/janus-devcontainer
111116
registry: ghcr.io
112117
username: ${{ github.repository_owner }}

.github/workflows/release-please.yml

+2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ jobs:
3636
context: "{{defaultContext}}:containers/janus"
3737
platforms: linux/amd64
3838
push: true
39+
sign: true
3940
repository: ghcr.io/jhatler/janus
4041
registry: ghcr.io
4142
username: ${{ github.repository_owner }}
@@ -53,6 +54,7 @@ jobs:
5354
workspace: ${{ github.workspace }}/devcontainers/janus
5455
platforms: linux/amd64
5556
push: true
57+
sign: true
5658
repository: ghcr.io/jhatler/janus-devcontainer
5759
registry: ghcr.io
5860
username: ${{ github.repository_owner }}

0 commit comments

Comments
 (0)