action.yml 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. name: 'Provenance / SBOM / Sign'
  2. description: 'Creates SBOM & provenance files and signs the image'
  3. inputs:
  4. image-name:
  5. description: "name of the image"
  6. required: true
  7. default: ''
  8. image-tag:
  9. description: "image tag"
  10. required: true
  11. default: ""
  12. runs:
  13. using: "composite"
  14. steps:
  15. - name: Install cosign
  16. uses: sigstore/cosign-installer@v2
  17. with:
  18. cosign-release: v1.13.6
  19. - name: Install Syft
  20. uses: anchore/sbom-action/download-syft@v0.7.0
  21. - name: Check Cosign install
  22. shell: bash
  23. run: cosign version
  24. - name: Login to ghcr.io
  25. uses: docker/login-action@v1.14.1
  26. with:
  27. registry: ghcr.io
  28. username: ${{ github.actor }}
  29. password: ${{ github.token }}
  30. - name: Setup Go
  31. uses: actions/setup-go@v3
  32. with:
  33. go-version-file: "go.mod"
  34. - name: Set up crane
  35. shell: bash
  36. run: go install github.com/google/go-containerregistry/cmd/crane@v0.11.0
  37. - name: Get docker image tag
  38. id: container_info
  39. shell: bash
  40. run: echo "digest=$(crane digest ${{ inputs.image-name }}:${{ inputs.image-tag }})" >> $GITHUB_OUTPUT
  41. - name: Sign image
  42. shell: bash
  43. env:
  44. COSIGN_EXPERIMENTAL: "1"
  45. run: cosign sign -a GITHUB_ACTOR=${{ github.triggering_actor }} "${{ inputs.image-name }}@${{ steps.container_info.outputs.digest }}"
  46. - name: Attach SBOM to image
  47. shell: bash
  48. id: sbom
  49. env:
  50. COSIGN_EXPERIMENTAL: "1"
  51. run: |
  52. syft "${{ inputs.image-name }}@${{ steps.container_info.outputs.digest }}" -o spdx-json=sbom.${{ inputs.image-tag }}.spdx.json
  53. cosign attest --predicate sbom.${{ inputs.image-tag }}.spdx.json --type spdx "${{ inputs.image-name }}@${{ steps.container_info.outputs.digest }}"
  54. cosign verify-attestation --type spdx ${{ inputs.image-name }}@${{ steps.container_info.outputs.digest }} | jq '.payload |= @base64d | .payload | fromjson'
  55. - name: Generate provenance
  56. uses: philips-labs/slsa-provenance-action@v0.7.2
  57. with:
  58. command: generate
  59. subcommand: container
  60. arguments: --repository "${{ inputs.image-name }}" --output-path provenance.${{ inputs.image-tag }}.intoto.jsonl --digest "${{ steps.container_info.outputs.digest }}" --tags "${{ inputs.image-tag }}"
  61. env:
  62. COSIGN_EXPERIMENTAL: "0"
  63. GITHUB_TOKEN: "${{ github.token }}"
  64. - name: Attach provenance
  65. shell: bash
  66. id: provenance
  67. env:
  68. COSIGN_EXPERIMENTAL: "1"
  69. run: |
  70. jq '.predicate' provenance.${{ inputs.image-tag }}.intoto.jsonl > provenance-predicate.att
  71. cosign attest --predicate provenance-predicate.att --type slsaprovenance "${{ inputs.image-name }}@${{ steps.container_info.outputs.digest }}"
  72. cosign verify-attestation --type slsaprovenance ${{ inputs.image-name }}@${{ steps.container_info.outputs.digest }}