|
| 1 | +# Artifact Signing Workflow |
| 2 | +# |
| 3 | +# This workflow handles container images and helm charts signing using Cosign. |
| 4 | +# |
| 5 | +# Key Features: |
| 6 | +# - Signs container images and helm charts using GitHub OIDC Token (keyless signing). |
| 7 | +# - Verifies the signatures against a specified certificate identity. |
| 8 | +# |
| 9 | +# Process Stages: |
| 10 | +# 1. Install Cosign. |
| 11 | +# 2. Install Crane. |
| 12 | +# 3. Login to ghcr.io using GitHub secrets. |
| 13 | +# 4. Get the image digest. |
| 14 | +# 5. Sign the images or helm charts with GitHub OIDC Token. |
| 15 | +# 6. Verify the signature using the specified certificate identity. |
| 16 | +# |
| 17 | +# Inputs: |
| 18 | +# - `image_uri`: The container image to sign. |
| 19 | +# |
| 20 | +# Example usage: |
| 21 | +# 1. Call this workflow manually from Github Actions page |
| 22 | +# 2. Create a `repository_dispatch` event to trigger this workflow |
| 23 | + |
| 24 | +name: Sign artifacts created for release |
| 25 | + |
| 26 | +on: |
| 27 | + workflow_dispatch: |
| 28 | + inputs: |
| 29 | + image_uri: |
| 30 | + description: 'Container image URI (repository, name and tag) (e.g. ghcr.io/open-edge-platform/my-image:latest)' |
| 31 | + required: true |
| 32 | + type: string |
| 33 | + repository_dispatch: |
| 34 | + types: [sign-artifacts] |
| 35 | + |
| 36 | +permissions: {} |
| 37 | + |
| 38 | +jobs: |
| 39 | + sign-artifacts: |
| 40 | + name: Sign artifacts created for release |
| 41 | + runs-on: ubuntu-latest |
| 42 | + permissions: |
| 43 | + id-token: write # needed for keyless signing |
| 44 | + packages: write # needed for ghcr.io access |
| 45 | + steps: |
| 46 | + - name: Install Cosign |
| 47 | + uses: sigstore/cosign-installer@d58896d6a1865668819e1d91763c7751a165e159 # v3.9.2 |
| 48 | + with: |
| 49 | + cosign-release: v2.5.3 |
| 50 | + |
| 51 | + - name: Install Crane |
| 52 | + run: | |
| 53 | + VERSION=v0.20.6 |
| 54 | + OS=Linux |
| 55 | + ARCH=x86_64 |
| 56 | + curl -sL "https://github.com/google/go-containerregistry/releases/download/${VERSION}/go-containerregistry_${OS}_${ARCH}.tar.gz" > go-containerregistry.tar.gz |
| 57 | + tar -zxvf go-containerregistry.tar.gz -C /usr/local/bin/ crane |
| 58 | +
|
| 59 | + - name: Login crane to ghcr.io |
| 60 | + run: | |
| 61 | + echo "${{ secrets.GITHUB_TOKEN }}" | crane auth login ghcr.io -u "dummy" --password-stdin |
| 62 | +
|
| 63 | + - name: Get image digest |
| 64 | + env: |
| 65 | + IMAGE: ${{ inputs.image_uri }} |
| 66 | + run: | |
| 67 | + DIGEST=$(crane digest "${IMAGE}" | tr -d '\n\r') |
| 68 | + echo "Digest for ${IMAGE} is ${DIGEST}" |
| 69 | + # Only allow digests matching the expected format (https://github.com/opencontainers/image-spec/blob/main/descriptor.md#sha-256) |
| 70 | + if ! echo "${DIGEST}" | grep -Eq '^sha256:[a-f0-9]{64}$'; then |
| 71 | + echo "Invalid digest format: ${DIGEST}" >&2 |
| 72 | + exit 1 |
| 73 | + fi |
| 74 | + echo "DIGEST=${DIGEST}" >> $GITHUB_ENV |
| 75 | +
|
| 76 | + - name: Sign the images with GitHub OIDC Token (keyless mode) |
| 77 | + env: |
| 78 | + DIGEST: ${{ env.DIGEST }} |
| 79 | + IMAGE: ${{ inputs.image_uri }} |
| 80 | + run: | |
| 81 | + echo "Signing ${IMAGE}@${DIGEST}" |
| 82 | + cosign sign --yes "${IMAGE}@${DIGEST}" |
| 83 | +
|
| 84 | + - name: Verify the signature |
| 85 | + env: |
| 86 | + DIGEST: ${{ env.DIGEST }} |
| 87 | + IMAGE: ${{ inputs.image_uri }} |
| 88 | + run: | |
| 89 | + echo "Verifying signature for ${IMAGE}@${DIGEST}" |
| 90 | + echo "Using certificate identity: https://github.com/open-edge-platform/geti/.github/workflows/sign_artifacts.yml" |
| 91 | + echo "OIDC Issuer: https://token.actions.githubusercontent.com" |
| 92 | + cosign verify \ |
| 93 | + --certificate-identity-regexp=https://github.com/open-edge-platform/geti/.github/workflows/sign_artifacts.yml \ |
| 94 | + --certificate-oidc-issuer=https://token.actions.githubusercontent.com \ |
| 95 | + "${IMAGE}@${DIGEST}" |
0 commit comments