Skip to content

Commit

Permalink
ci: Use cosign to sign container images.
Browse files Browse the repository at this point in the history
This commit adds cosign to the CI pipeline. cosign is an open-source
tool developed by Chainguard that signs container images, allowing
other users to cryptographically verify the origin of container
images. [1]

cosign has different operating modes. This commit utilizes Chainguard's
signing infrastructure via "keyless signing". [2] Keyless signing makes
image signing easy for open-source projects because Chainguard operates
the signing infrastructure on behalf of others.

Note: This commit is based on work by Chris Nesbitt-Smith, who published
an example GitHub Actions workflow for running cosign. [3]

References

1. https://docs.sigstore.dev/signing/quickstart
2. https://edu.chainguard.dev/open-source/sigstore/cosign/an-introduction-to-cosign/#keyless-signing
3. https://github.com/chrisns/cosign-keyless-demo/blob/f35f6c776f/.github/workflows/ci.yml
  • Loading branch information
sfox-equinix committed Dec 8, 2023
1 parent fd28c0a commit 6f26835
Showing 1 changed file with 36 additions and 11 deletions.
47 changes: 36 additions & 11 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@

name: Create and publish a api image

on:
push:
tags:
- v**
on: push

env:
REGISTRY: ghcr.io/metal-toolbox
API_IMAGE_NAME: audito-maldito/audito-maldito
APP_IMAGE_NAME: audito-maldito/audito-maldito

jobs:
auto-release:
Expand All @@ -29,6 +27,7 @@ jobs:
permissions:
contents: read
packages: write
id-token: write # needed for signing the images with GitHub OIDC Token

steps:
- name: Checkout repository
Expand All @@ -41,6 +40,10 @@ jobs:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- uses: sigstore/[email protected]
with:
cosign-release: "v2.2.1"

- name: Get current date
id: date
run: echo "::set-output name=date::$(date -u +'%Y-%m-%dT%H:%M:%SZ')"
Expand All @@ -49,21 +52,43 @@ jobs:
id: meta-api
uses: docker/metadata-action@62339db73c56dd749060f65a6ebb93a6e056b755
with:
images: ${{ env.REGISTRY }}/${{ env.API_IMAGE_NAME }}
images: ${{ env.REGISTRY }}/${{ env.APP_IMAGE_NAME }}

- name: Build rsyslog and push Docker image
uses: docker/build-push-action@fdf7f43ecf7c1a5c7afe936410233728a8c2d9c2
id: rsyslog-build-push
uses: docker/[email protected]
with:
context: "./contrib/rsyslog"
push: true
file: ./contrib/rsyslog/Dockerfile.ubuntu
tags: ${{ env.REGISTRY }}/${{ env.API_IMAGE_NAME }}:${{ github.ref_name }}-rsyslog
tags: ${{ env.REGISTRY }}/${{ env.APP_IMAGE_NAME }}:${{ github.ref_name }}-rsyslog
labels: ${{ steps.meta-api.outputs.labels }}

- name: Get rsyslog container info
id: rsyslog-image-info
run: |
image_digest="$(docker inspect "${{ env.REGISTRY }}/${{ env.APP_IMAGE_NAME }}:${{ github.ref_name }}-rsyslog" --format '{{ index .RepoDigests 0 }}' | awk -F '@' '{ print $2 }')"
echo "::set-output name=image-digest::${image_digest}"
- run: cosign version && cosign sign -y -r ${TARGET_IMAGE}
env:
TARGET_IMAGE: ${{ steps.rsyslog-image-info.outputs.image-digest }}

- name: Build and push Docker image
uses: docker/build-push-action@fdf7f43ecf7c1a5c7afe936410233728a8c2d9c2
id: am-build-push
uses: docker/[email protected]
with:
push: true
file: Dockerfile
tags: ${{ env.REGISTRY }}/${{ env.API_IMAGE_NAME }}:${{ github.ref_name }}
labels: ${{ steps.meta-api.outputs.labels }}
tags: ${{ env.REGISTRY }}/${{ env.APP_IMAGE_NAME }}:${{ github.ref_name }}
labels: ${{ steps.meta-api.outputs.labels }}

- name: Get am container info
id: am-image-info
run: |
image_digest="$(docker inspect "${{ env.REGISTRY }}/${{ env.APP_IMAGE_NAME }}:${{ github.ref_name }}" --format '{{ index .RepoDigests 0 }}' | awk -F '@' '{ print $2 }')"
echo "::set-output name=image-digest::${image_digest}"
- run: cosign sign -y -r ${TARGET_IMAGE}
env:
TARGET_IMAGE: ${{ steps.am-image-info.outputs.image-digest }}

0 comments on commit 6f26835

Please sign in to comment.