| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- name: 'Provenance / SBOM / Sign'
- description: 'Creates SBOM & provenance files and signs the image'
- inputs:
- image-name:
- description: "name of the image"
- required: true
- default: ''
- image-tag:
- description: "image tag"
- required: true
- default: ""
- runs:
- using: "composite"
- steps:
- - name: Install cosign
- uses: sigstore/cosign-installer@v2
- with:
- cosign-release: v1.13.6
- - name: Install Syft
- uses: anchore/sbom-action/download-syft@v0.7.0
- - name: Check Cosign install
- shell: bash
- run: cosign version
- - name: Login to ghcr.io
- uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3.6.0
- with:
- registry: ghcr.io
- username: ${{ github.actor }}
- password: ${{ github.token }}
- - name: Setup Go
- uses: actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 # v6.0.0
- with:
- go-version-file: go.mod
- - name: Set up crane
- shell: bash
- run: go install github.com/google/go-containerregistry/cmd/crane@v0.11.0
- - name: Get docker image tag
- id: container_info
- shell: bash
- run: echo "digest=$(crane digest ${{ inputs.image-name }}:${{ inputs.image-tag }})" >> $GITHUB_OUTPUT
- - name: Sign image
- shell: bash
- env:
- COSIGN_EXPERIMENTAL: "1"
- run: cosign sign -a GITHUB_ACTOR=${{ github.triggering_actor }} "${{ inputs.image-name }}@${{ steps.container_info.outputs.digest }}"
- - name: Attach SBOM to image
- shell: bash
- id: sbom
- env:
- COSIGN_EXPERIMENTAL: "1"
- run: |
- # Image SBOM (OS + application libs contained in the image)
- syft "${{ inputs.image-name }}@${{ steps.container_info.outputs.digest }}" -o spdx-json=sbom.${{ inputs.image-tag }}.spdx.json
- cosign attest --predicate sbom.${{ inputs.image-tag }}.spdx.json --type spdx "${{ inputs.image-name }}@${{ steps.container_info.outputs.digest }}"
- cosign verify-attestation --type spdx ${{ inputs.image-name }}@${{ steps.container_info.outputs.digest }} | jq '.payload |= @base64d | .payload | fromjson'
- # Go modules SBOM (dependencies from the source tree)
- # Requires repository to be checked out before this composite action runs.
- syft dir:. -o spdx-json=sbom.gomod.${{ inputs.image-tag }}.spdx.json
- cosign attest --predicate sbom.gomod.${{ inputs.image-tag }}.spdx.json --type spdx "${{ inputs.image-name }}@${{ steps.container_info.outputs.digest }}"
- cosign verify-attestation --type spdx ${{ inputs.image-name }}@${{ steps.container_info.outputs.digest }} | jq '.payload |= @base64d | .payload | fromjson'
- - name: Generate provenance
- uses: philips-labs/slsa-provenance-action@v0.7.2
- with:
- command: generate
- subcommand: container
- arguments: --repository "${{ inputs.image-name }}" --output-path provenance.${{ inputs.image-tag }}.intoto.jsonl --digest "${{ steps.container_info.outputs.digest }}" --tags "${{ inputs.image-tag }}"
- env:
- COSIGN_EXPERIMENTAL: "0"
- GITHUB_TOKEN: "${{ github.token }}"
- - name: Attach provenance
- shell: bash
- id: provenance
- env:
- COSIGN_EXPERIMENTAL: "1"
- run: |
- jq '.predicate' provenance.${{ inputs.image-tag }}.intoto.jsonl > provenance-predicate.att
- cosign attest --predicate provenance-predicate.att --type slsaprovenance "${{ inputs.image-name }}@${{ steps.container_info.outputs.digest }}"
- cosign verify-attestation --type slsaprovenance ${{ inputs.image-name }}@${{ steps.container_info.outputs.digest }}
|