Skip to content

Commit 2bb91aa

Browse files
committed
ci(workflow): add container image signing and verification with Cosign
1 parent 1c28d59 commit 2bb91aa

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

.github/workflows/cicd-2-publish.yaml

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ jobs:
1919
publish:
2020
runs-on: ubuntu-latest
2121
steps:
22-
- name: "🔐 Generate GitHub App token"
22+
- name: "🔐 Generate app token"
2323
uses: actions/create-github-app-token@v2
2424
id: app-token
2525
with:
2626
app-id: ${{ vars.GH_VERSIONING_APP_ID || vars.NHS_GH_VERSIONING_APP_ID }}
2727
private-key: ${{ secrets.GH_VERSIONING_APP_PRIVATE_KEY || secrets.NHS_GH_VERSIONING_APP_PRIVATE_KEY }}
2828

29-
- name: "🙈 Mask App token"
29+
- name: "🙈 Mask app token"
3030
run: echo "::add-mask::${{ steps.app-token.outputs.token }}"
3131

3232
- name: "📥 Checkout repository"
@@ -82,7 +82,7 @@ jobs:
8282
GIT_COMMITTER_NAME: ${{ vars.GIT_SIGNING_BOT_NAME || vars.NHS_GIT_SIGNING_BOT_NAME }}
8383
GIT_COMMITTER_EMAIL: ${{ vars.GIT_SIGNING_BOT_EMAIL || vars.NHS_GIT_SIGNING_BOT_EMAIL }}
8484

85-
- name: "🔑 Login to GitHub Container Registry"
85+
- name: "🔑 Login to container registry"
8686
uses: docker/login-action@v3
8787
with:
8888
registry: ghcr.io
@@ -100,6 +100,23 @@ jobs:
100100
docker push ${IMAGE_NAME}:app-${VERSION}
101101
docker push ${IMAGE_NAME}:app-latest
102102
103+
- name: "🔏 Sign container image"
104+
if: steps.release.outputs.new_release_published == 'true'
105+
env:
106+
COSIGN_PRIVATE_KEY: ${{ secrets.COSIGN_PRIVATE_KEY || secrets.NHS_COSIGN_PRIVATE_KEY }}
107+
COSIGN_PASSWORD: ${{ secrets.COSIGN_PASSWORD || secrets.NHS_COSIGN_PASSWORD }}
108+
IMAGE_NAME: ghcr.io/${{ github.repository }}
109+
VERSION: ${{ steps.release.outputs.new_release_version }}
110+
run: |
111+
wget https://github.com/sigstore/cosign/releases/latest/download/cosign-linux-amd64
112+
sudo mv cosign-linux-amd64 /usr/local/bin/cosign
113+
sudo chmod +x /usr/local/bin/cosign
114+
echo "$COSIGN_PRIVATE_KEY" > cosign.key
115+
cosign sign --key cosign.key ${IMAGE_NAME}:app-${VERSION}
116+
cosign verify --key cosign.key ${IMAGE_NAME}:app-${VERSION}
117+
cosign sign --key cosign.key ${IMAGE_NAME}:app-latest
118+
cosign verify --key cosign.key ${IMAGE_NAME}:app-latest
119+
103120
- name: "📝 Update release notes with image info"
104121
if: steps.release.outputs.new_release_published == 'true'
105122
env:

0 commit comments

Comments
 (0)