# cicd-signals / github / t1: supply-chain.yml # # A workflow for each repository that builds a container image. Copy it to # .github/workflows/supply-chain.yml in that repository. On every push to the # default branch it: # # 1. builds the image and pushes it to GitHub Container Registry # 2. writes a CycloneDX SBOM of the image, kept as a build artifact # 3. signs the image with cosign, keyless, using the workflow's own identity # 4. attaches the SBOM to the image as a signed attestation # 5. records GitHub build provenance for the image # # The admission control template's verify-images policy checks the signature # in step 3 and the SBOM attestation in step 4, so an image that skipped this # workflow is reported, or refused once that policy enforces. # # Nothing here stores a key. Signing uses a short-lived certificate issued to # this workflow run through GitHub's OIDC token, and the signature is recorded # in the public Sigstore transparency log. # # Every action is pinned to a full commit SHA, with its tag in a comment. name: supply-chain on: push: branches: [main] workflow_dispatch: {} permissions: contents: read jobs: image: runs-on: ubuntu-latest permissions: contents: read packages: write # push to GitHub Container Registry id-token: write # the OIDC token cosign and provenance sign with attestations: write # GitHub build provenance env: IMAGE: ghcr.io/${{ github.repository }} steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: persist-credentials: false - uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4.4.1 - uses: docker/login-action@dbcb813823bdd20940b903addbd779551569679f # v4.6.0 with: registry: ghcr.io username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - name: build and push id: build uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7.4.0 with: context: . push: true tags: ${{ env.IMAGE }}:${{ github.sha }} # Everything after this names the image by digest. A tag can be moved # to other content; the digest is the content. - name: SBOM, CycloneDX uses: anchore/sbom-action@3ad7283483fc7af8ff2b4ea19663c2d5ca935e26 # v0.24.2 with: image: ${{ env.IMAGE }}@${{ steps.build.outputs.digest }} format: cyclonedx-json output-file: sbom.cdx.json upload-artifact: true # Pinned to cosign 2. Cosign 3 changed how signatures are stored by # default, so move to it together with a test that the admission policy # still verifies what it writes. - uses: sigstore/cosign-installer@6f9f17788090df1f26f669e9d70d6ae9567deba6 # v4.1.2 with: cosign-release: v2.6.5 - name: sign the image, keyless env: REF: ${{ env.IMAGE }}@${{ steps.build.outputs.digest }} run: cosign sign --yes "$REF" - name: attach the SBOM as a signed attestation env: REF: ${{ env.IMAGE }}@${{ steps.build.outputs.digest }} run: cosign attest --yes --type cyclonedx --predicate sbom.cdx.json "$REF" - name: build provenance uses: actions/attest-build-provenance@4d101475d8b20a2381f78447822ac1eab6504dd8 # v4.2.2 with: subject-name: ${{ env.IMAGE }} subject-digest: ${{ steps.build.outputs.digest }} push-to-registry: true