|
| 1 | +name: Sign attestation files |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + inputs: |
| 6 | + image-digest: |
| 7 | + type: string |
| 8 | + required: true |
| 9 | + |
| 10 | +jobs: |
| 11 | + sbom: |
| 12 | + name: Fetch, sign and verify SBOM and provenance files |
| 13 | + strategy: |
| 14 | + matrix: |
| 15 | + arch: [amd64, arm64] |
| 16 | + |
| 17 | + permissions: |
| 18 | + packages: write |
| 19 | + id-token: write |
| 20 | + |
| 21 | + runs-on: ubuntu-latest |
| 22 | + steps: |
| 23 | + - name: Install cosign |
| 24 | + uses: sigstore/cosign-installer@4959ce089c160fddf62f7b42464195ba1a56d382 # v3.6.0 |
| 25 | + |
| 26 | + - name: Install the crane command |
| 27 | + uses: kubewarden/github-actions/crane-installer@d94509d260ee11a92b4f65bc0acd297feec24d7f # v3.3.5 |
| 28 | + |
| 29 | + - name: Login to GitHub Container Registry |
| 30 | + uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0 |
| 31 | + with: |
| 32 | + registry: ghcr.io |
| 33 | + username: ${{ github.repository_owner }} |
| 34 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 35 | + |
| 36 | + - name: Verify container image signature |
| 37 | + run: | |
| 38 | + cosign verify \ |
| 39 | + --certificate-oidc-issuer=https://token.actions.githubusercontent.com \ |
| 40 | + --certificate-identity-regexp="https://github.com/${{github.repository_owner}}/policy-server/.github/workflows/sign-image.yml@${{ github.ref }}" \ |
| 41 | + ghcr.io/${{ github.repository_owner }}/policy-server@${{ inputs.image-digest }} |
| 42 | +
|
| 43 | + - name: Find platform digest |
| 44 | + shell: bash |
| 45 | + run: | |
| 46 | + set -e |
| 47 | + DIGEST=$(crane digest \ |
| 48 | + --platform "linux/${{ matrix.arch }}" \ |
| 49 | + ghcr.io/${{ github.repository_owner }}/policy-server@${{ inputs.image-digest }}) |
| 50 | + echo "PLATFORM_DIGEST=${DIGEST}" >> "$GITHUB_ENV" |
| 51 | +
|
| 52 | + - name: Find attestation digest |
| 53 | + run: | |
| 54 | + set -e |
| 55 | + DIGEST=$(crane manifest ghcr.io/${{github.repository_owner}}/policy-server@${{ inputs.image-digest }} \ |
| 56 | + | jq '.manifests[] | select(.annotations["vnd.docker.reference.type"]=="attestation-manifest") | select(.annotations["vnd.docker.reference.digest"]=="${{ env.PLATFORM_DIGEST }}") | .digest' |
| 57 | + ) |
| 58 | + echo "ATTESTATION_MANIFEST_DIGEST=${DIGEST}" >> "$GITHUB_ENV" |
| 59 | +
|
| 60 | + - name: Sign attestation manifest |
| 61 | + run: | |
| 62 | + cosign sign --yes \ |
| 63 | + ghcr.io/${{github.repository_owner}}/policy-server@${{ env.ATTESTATION_MANIFEST_DIGEST}} |
| 64 | +
|
| 65 | + cosign verify \ |
| 66 | + --certificate-oidc-issuer=https://token.actions.githubusercontent.com \ |
| 67 | + --certificate-identity-regexp="https://github.com/${{github.repository_owner}}/policy-server/.github/workflows/attestation.yml@${{ github.ref }}" \ |
| 68 | + ghcr.io/${{github.repository_owner}}/policy-server@${{ env.ATTESTATION_MANIFEST_DIGEST}} |
| 69 | +
|
| 70 | + - name: Find provenance manifest digest |
| 71 | + run: | |
| 72 | + set -e |
| 73 | + DIGEST=$(crane manifest ghcr.io/${{github.repository_owner}}/policy-server@${{ env.ATTESTATION_MANIFEST_DIGEST}} | \ |
| 74 | + jq '.layers[] | select(.annotations["in-toto.io/predicate-type"] == "https://slsa.dev/provenance/v0.2") | .digest') |
| 75 | + echo "PROVENANCE_DIGEST=${DIGEST}" >> "$GITHUB_ENV" |
| 76 | +
|
| 77 | + - name: Sign provenance manifest |
| 78 | + run: | |
| 79 | + cosign sign --yes \ |
| 80 | + ghcr.io/${{github.repository_owner}}/policy-server@${{ env.PROVENANCE_DIGEST}} |
| 81 | +
|
| 82 | + cosign verify \ |
| 83 | + --certificate-oidc-issuer=https://token.actions.githubusercontent.com \ |
| 84 | + --certificate-identity-regexp="https://github.com/${{github.repository_owner}}/policy-server/.github/workflows/attestation.yml@${{ github.ref }}" \ |
| 85 | + ghcr.io/${{github.repository_owner}}/policy-server@${{ env.PROVENANCE_DIGEST}} |
| 86 | +
|
| 87 | + - name: Find SBOM manifest layers digest |
| 88 | + run: | |
| 89 | + set -e |
| 90 | + DIGEST=$(crane manifest ghcr.io/${{github.repository_owner}}/policy-server@${{ env.ATTESTATION_MANIFEST_DIGEST}} | \ |
| 91 | + jq '.layers | map(select(.annotations["in-toto.io/predicate-type"] == "https://spdx.dev/Document")) | map(.digest) | join(" ")') |
| 92 | + echo "SBOM_DIGEST=${DIGEST}" >> "$GITHUB_ENV" |
| 93 | +
|
| 94 | + - name: Sign SBOM layers |
| 95 | + run: | |
| 96 | + for sbom_digest in "${{ env.SBOM_DIGEST }}"; do |
| 97 | + cosign sign --yes \ |
| 98 | + ghcr.io/${{github.repository_owner}}/policy-server@$sbom_digest |
| 99 | + done |
| 100 | +
|
| 101 | + - name: Verify SBOM layers |
| 102 | + run: | |
| 103 | + for sbom_digest in "${{ env.SBOM_DIGEST }}"; do |
| 104 | + cosign verify \ |
| 105 | + --certificate-oidc-issuer=https://token.actions.githubusercontent.com \ |
| 106 | + --certificate-identity-regexp="https://github.com/${{github.repository_owner}}/policy-server/.github/workflows/attestation.yml@${{ github.ref }}" \ |
| 107 | + ghcr.io/${{github.repository_owner}}/policy-server@$sbom_digest |
| 108 | + done |
| 109 | +
|
| 110 | + - name: Download provenance and SBOM files |
| 111 | + run: | |
| 112 | + set -e |
| 113 | + crane blob ghcr.io/${{github.repository_owner}}/policy-server@${{ env.PROVENANCE_DIGEST}} > policy-server-attestation-${{ matrix.arch }}-provenance.json |
| 114 | + md5sum policy-server-attestation-${{ matrix.arch }}-provenance.json >> policy-server-attestation-${{ matrix.arch }}-checksum.txt |
| 115 | +
|
| 116 | +
|
| 117 | + for sbom_digest in "${{ env.SBOM_DIGEST }}"; do |
| 118 | + crane blob ghcr.io/${{github.repository_owner}}/policy-server@$sbom_digest > policy-server-attestation-${{ matrix.arch }}-sbom-${sbom_digest#"sha256:"}.json |
| 119 | + md5sum policy-server-attestation-${{ matrix.arch }}-sbom-${sbom_digest#"sha256:"}.json >> policy-server-attestation-${{ matrix.arch }}-checksum.txt |
| 120 | + done |
| 121 | + |
| 122 | + - name: Sign checksum file |
| 123 | + run: | |
| 124 | + cosign sign-blob --yes \ |
| 125 | + --bundle policy-server-attestation-${{ matrix.arch }}-checksum-cosign.bundle \ |
| 126 | + policy-server-attestation-${{ matrix.arch }}-checksum.txt |
| 127 | + |
| 128 | + cosign verify-blob \ |
| 129 | + --bundle policy-server-attestation-${{ matrix.arch }}-checksum-cosign.bundle \ |
| 130 | + --certificate-oidc-issuer=https://token.actions.githubusercontent.com \ |
| 131 | + --certificate-identity-regexp="https://github.com/${{github.repository_owner}}/policy-server/.github/workflows/attestation.yml@${{ github.ref }}" \ |
| 132 | + policy-server-attestation-${{ matrix.arch }}-checksum.txt |
| 133 | +
|
| 134 | + - name: Upload SBOMs as artifacts |
| 135 | + uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # v4.4.0 |
| 136 | + with: |
| 137 | + name: attestation-${{ matrix.arch }} |
| 138 | + path: policy-server-attestation-${{ matrix.arch }}* |
0 commit comments