action.yml 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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@5e57cd118135c172c3672efd75eb46360885c0ef # v3.6.0
  26. with:
  27. registry: ghcr.io
  28. username: ${{ github.actor }}
  29. password: ${{ github.token }}
  30. - name: Setup Go
  31. uses: actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 # v6.0.0
  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. # Image SBOM (OS + application libs contained in the image)
  53. syft "${{ inputs.image-name }}@${{ steps.container_info.outputs.digest }}" -o spdx-json=sbom.${{ inputs.image-tag }}.spdx.json
  54. cosign attest --predicate sbom.${{ inputs.image-tag }}.spdx.json --type spdx "${{ inputs.image-name }}@${{ steps.container_info.outputs.digest }}"
  55. cosign verify-attestation --type spdx ${{ inputs.image-name }}@${{ steps.container_info.outputs.digest }} | jq '.payload |= @base64d | .payload | fromjson'
  56. # Go modules SBOM (dependencies from the source tree)
  57. # Requires repository to be checked out before this composite action runs.
  58. syft dir:. -o spdx-json=sbom.gomod.${{ inputs.image-tag }}.spdx.json
  59. cosign attest --predicate sbom.gomod.${{ inputs.image-tag }}.spdx.json --type spdx "${{ inputs.image-name }}@${{ steps.container_info.outputs.digest }}"
  60. cosign verify-attestation --type spdx ${{ inputs.image-name }}@${{ steps.container_info.outputs.digest }} | jq '.payload |= @base64d | .payload | fromjson'
  61. - name: Generate provenance
  62. uses: philips-labs/slsa-provenance-action@v0.7.2
  63. with:
  64. command: generate
  65. subcommand: container
  66. arguments: --repository "${{ inputs.image-name }}" --output-path provenance.${{ inputs.image-tag }}.intoto.jsonl --digest "${{ steps.container_info.outputs.digest }}" --tags "${{ inputs.image-tag }}"
  67. env:
  68. COSIGN_EXPERIMENTAL: "0"
  69. GITHUB_TOKEN: "${{ github.token }}"
  70. - name: Attach provenance
  71. shell: bash
  72. id: provenance
  73. env:
  74. COSIGN_EXPERIMENTAL: "1"
  75. run: |
  76. jq '.predicate' provenance.${{ inputs.image-tag }}.intoto.jsonl > provenance-predicate.att
  77. cosign attest --predicate provenance-predicate.att --type slsaprovenance "${{ inputs.image-name }}@${{ steps.container_info.outputs.digest }}"
  78. cosign verify-attestation --type slsaprovenance ${{ inputs.image-name }}@${{ steps.container_info.outputs.digest }}