Skip to content

Commit

Permalink
Merge pull request #40 from anderbubble/fix-cosign
Browse files Browse the repository at this point in the history
Update container signing action from upstream example
  • Loading branch information
anderbubble authored Dec 9, 2023
2 parents c9ccdde + e52fc3f commit 810e04a
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions .github/workflows/container-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]
Expand All @@ -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'
Expand All @@ -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
Expand All @@ -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}"

0 comments on commit 810e04a

Please sign in to comment.