|
| 1 | +name: Verify runtime image provenance |
| 2 | +"on": |
| 3 | + workflow_call: |
| 4 | + inputs: |
| 5 | + runtime_docker_image: |
| 6 | + required: true |
| 7 | + type: string |
| 8 | + description: Image name and tag (for example node_24_python_3_12:v1.0.3) or full image reference |
| 9 | + registry: |
| 10 | + required: false |
| 11 | + type: string |
| 12 | + default: ghcr.io |
| 13 | + namespace: |
| 14 | + required: false |
| 15 | + type: string |
| 16 | + default: nhsdigital/eps-devcontainers |
| 17 | + owner: |
| 18 | + required: false |
| 19 | + type: string |
| 20 | + default: NHSDigital |
| 21 | + outputs: |
| 22 | + pinned_image: |
| 23 | + description: Fully qualified digest-pinned image reference |
| 24 | + value: ${{ jobs.verify.outputs.pinned_image }} |
| 25 | + digest: |
| 26 | + description: Resolved digest for the input tag |
| 27 | + value: ${{ jobs.verify.outputs.digest }} |
| 28 | + |
| 29 | +jobs: |
| 30 | + verify: |
| 31 | + runs-on: ubuntu-22.04 |
| 32 | + permissions: |
| 33 | + contents: read |
| 34 | + packages: read |
| 35 | + attestations: read |
| 36 | + outputs: |
| 37 | + pinned_image: ${{ steps.resolve.outputs.pinned_image }} |
| 38 | + digest: ${{ steps.resolve.outputs.digest }} |
| 39 | + steps: |
| 40 | + - name: Login to github container registry |
| 41 | + if: startsWith(inputs.registry, 'ghcr.io') |
| 42 | + uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 |
| 43 | + with: |
| 44 | + registry: ghcr.io |
| 45 | + username: ${{ github.actor }} |
| 46 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 47 | + |
| 48 | + - name: Resolve image tag to digest |
| 49 | + id: resolve |
| 50 | + shell: bash |
| 51 | + env: |
| 52 | + RUNTIME_IMAGE_INPUT: ${{ inputs.runtime_docker_image }} |
| 53 | + REGISTRY: ${{ inputs.registry }} |
| 54 | + NAMESPACE: ${{ inputs.namespace }} |
| 55 | + run: | |
| 56 | + set -euo pipefail |
| 57 | +
|
| 58 | + if [[ "$RUNTIME_IMAGE_INPUT" == *"/"* ]]; then |
| 59 | + IMAGE_REF="$RUNTIME_IMAGE_INPUT" |
| 60 | + else |
| 61 | + IMAGE_REF="${REGISTRY}/${NAMESPACE}/${RUNTIME_IMAGE_INPUT}" |
| 62 | + fi |
| 63 | +
|
| 64 | + if [[ "$IMAGE_REF" == *@sha256:* ]]; then |
| 65 | + DIGEST="${IMAGE_REF#*@}" |
| 66 | + IMAGE_BASE="${IMAGE_REF%@*}" |
| 67 | + else |
| 68 | + DIGEST="$(docker buildx imagetools inspect "$IMAGE_REF" | awk '/^Digest:/ {print $2; exit}')" |
| 69 | + IMAGE_BASE="${IMAGE_REF%:*}" |
| 70 | + fi |
| 71 | +
|
| 72 | + if [[ -z "$DIGEST" ]]; then |
| 73 | + echo "Failed to resolve digest for image: $IMAGE_REF" >&2 |
| 74 | + exit 1 |
| 75 | + fi |
| 76 | +
|
| 77 | + PINNED_IMAGE="${IMAGE_BASE}@${DIGEST}" |
| 78 | + echo "digest=${DIGEST}" >> "$GITHUB_OUTPUT" |
| 79 | + echo "pinned_image=${PINNED_IMAGE}" >> "$GITHUB_OUTPUT" |
| 80 | + echo "Resolved image: ${PINNED_IMAGE}" |
| 81 | +
|
| 82 | + - name: Verify provenance attestation |
| 83 | + shell: bash |
| 84 | + env: |
| 85 | + GH_TOKEN: ${{ github.token }} |
| 86 | + PINNED_IMAGE: ${{ steps.resolve.outputs.pinned_image }} |
| 87 | + OWNER: ${{ inputs.owner }} |
| 88 | + run: | |
| 89 | + set -euo pipefail |
| 90 | + gh attestation verify "oci://${PINNED_IMAGE}" --owner "$OWNER" |
| 91 | + echo "Verified attestation for ${PINNED_IMAGE}" |
0 commit comments