From e52fc3f2149b668982f1a5448be9fc14a232db1d Mon Sep 17 00:00:00 2001 From: Jonathon Anderson Date: Sat, 9 Dec 2023 16:42:15 -0700 Subject: [PATCH] Update container signing action from upstream example https://github.com/marketplace/actions/cosign-installer Signed-off-by: Jonathon Anderson --- .github/workflows/container-publish.yml | 33 ++++++++++++++----------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/.github/workflows/container-publish.yml b/.github/workflows/container-publish.yml index 98464d3..fdf86ee 100644 --- a/.github/workflows/container-publish.yml +++ b/.github/workflows/container-publish.yml @@ -87,9 +87,8 @@ jobs: - name: Checkout repository uses: actions/checkout@v3 - # Install the cosign tool except on PR + # Install the cosign tool # https://github.com/sigstore/cosign-installer - - name: Install Cosign if: github.event_name != 'pull_request' uses: sigstore/cosign-installer@v3.1.1 @@ -98,7 +97,7 @@ jobs: - name: Setup Docker buildx uses: docker/setup-buildx-action@f03ac48505955848960e80bbb68046aa35c7b9e7 - # Login against a Docker registry except on PR + # Login against a Docker registry # https://github.com/docker/login-action - name: Log into registry ghcr.io if: github.event_name != 'pull_request' @@ -121,7 +120,7 @@ jobs: type=schedule type=raw,${{ matrix.version }} - # Build and push Docker image with Buildx (don't push on PR) + # Build and push Docker image with Buildx # https://github.com/docker/build-push-action - name: Build and push image id: build-and-push @@ -136,16 +135,20 @@ jobs: cache-from: type=gha cache-to: type=gha,mode=max + # https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#using-an-intermediate-environment-variable + - name: Sign image with a key + if: github.event_name != 'pull_request' + run: | + cosign sign --yes --key env://COSIGN_PRIVATE_KEY "${TAGS}@${DIGEST}" + env: + TAGS: ${{ steps.docker_meta.outputs.tags }} + COSIGN_PRIVATE_KEY: ${{ secrets.COSIGN_PRIVATE_KEY }} + COSIGN_PASSWORD: ${{ secrets.COSIGN_PASSWORD }} + DIGEST: ${{ steps.build-and-push.outputs.digest }} - # Sign the resulting image digest except on PRs. - # This will only write to the public Rekor transparency log when the Docker - # repository is public to avoid leaking data. If you would like to publish - # transparency data even for private images, pass --force to cosign below. - # https://github.com/sigstore/cosign - - name: Sign the published image - if: ${{ github.event_name != 'pull_request' }} + - name: Sign the images with GitHub OIDC Token + if: github.event_name != 'pull_request' env: - COSIGN_EXPERIMENTAL: "true" - # This step uses the identity token to provision an ephemeral certificate - # against the sigstore community Fulcio instance. - run: echo "${{ steps.meta.outputs.tags }}" | xargs -I {} cosign sign --yes {}@${{ steps.build-and-push.outputs.digest }} + DIGEST: ${{ steps.build-and-push.outputs.digest }} + TAGS: ${{ steps.docker_meta.outputs.tags }} + run: cosign sign --yes "${TAGS}@${DIGEST}"