action.yml 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. # https://github.com/sigstore/cosign-installer/releases/tag/v2.8.1
  17. uses: sigstore/cosign-installer@c85d0e205a72a294fe064f618a87dbac13084086 # v2.8.1
  18. with:
  19. cosign-release: v1.13.6
  20. - name: Install Syft
  21. # https://github.com/anchore/sbom-action/releases/tag/v0.7.0
  22. uses: anchore/sbom-action/download-syft@ce4a7cf05d7b684693d7b6bba97bfbee56806edb # v0.7.0
  23. - name: Check Cosign install
  24. shell: bash
  25. run: cosign version
  26. - name: Login to ghcr.io
  27. uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3.6.0
  28. with:
  29. registry: ghcr.io
  30. username: ${{ github.actor }}
  31. password: ${{ github.token }}
  32. - name: Setup Go
  33. uses: actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 # v6.0.0
  34. with:
  35. go-version-file: go.mod
  36. - name: Set up crane
  37. shell: bash
  38. run: go install github.com/google/go-containerregistry/cmd/crane@v0.11.0
  39. - name: Get docker image tag
  40. id: container_info
  41. shell: bash
  42. env:
  43. IMAGE_NAME: ${{ inputs.image-name }}
  44. IMAGE_TAG: ${{ inputs.image-tag }}
  45. run: echo "digest=$(crane digest ${IMAGE_NAME}:${IMAGE_TAG})" >> $GITHUB_OUTPUT
  46. - name: Sign image
  47. shell: bash
  48. env:
  49. COSIGN_EXPERIMENTAL: "1"
  50. IMAGE_NAME: ${{ inputs.image-name }}
  51. CONTAINER_DIGEST: ${{ steps.container_info.outputs.digest }}
  52. GITHUB_TRIGGERING_ACTOR: ${{ github.triggering_actor }}
  53. run: cosign sign -a GITHUB_ACTOR=${GITHUB_TRIGGERING_ACTOR} "${IMAGE_NAME}@${CONTAINER_DIGEST}"
  54. - name: Attach SBOM to image
  55. shell: bash
  56. id: sbom
  57. env:
  58. COSIGN_EXPERIMENTAL: "1"
  59. IMAGE_NAME: ${{ inputs.image-name }}
  60. IMAGE_TAG: ${{ inputs.image-tag }}
  61. CONTAINER_DIGEST: ${{ steps.container_info.outputs.digest }}
  62. run: |
  63. # Image SBOM (OS + application libs contained in the image)
  64. syft "${IMAGE_NAME}@${CONTAINER_DIGEST}" -o spdx-json=sbom.${IMAGE_TAG}.spdx.json
  65. cosign attest --predicate sbom.${IMAGE_TAG}.spdx.json --type spdx "${IMAGE_NAME}@${CONTAINER_DIGEST}"
  66. cosign verify-attestation --type spdx ${IMAGE_NAME}@${CONTAINER_DIGEST} | jq '.payload |= @base64d | .payload | fromjson'
  67. # Go modules SBOM (dependencies from the source tree)
  68. # Requires repository to be checked out before this composite action runs.
  69. syft dir:. -o spdx-json=sbom.gomod.${IMAGE_TAG}.spdx.json
  70. cosign attest --predicate sbom.gomod.${IMAGE_TAG}.spdx.json --type spdx "${IMAGE_NAME}@${CONTAINER_DIGEST}"
  71. cosign verify-attestation --type spdx ${IMAGE_NAME}@${CONTAINER_DIGEST} | jq '.payload |= @base64d | .payload | fromjson'
  72. - name: Generate provenance
  73. # https://github.com/philips-labs/slsa-provenance-action/releases/tag/v0.7.2
  74. uses: philips-labs/slsa-provenance-action@dddb40e199ae28d4cd2f17bad7f31545556fdd3d # v0.7.2
  75. with:
  76. command: generate
  77. subcommand: container
  78. arguments: --repository "${{ inputs.image-name }}" --output-path provenance.${{ inputs.image-tag }}.intoto.jsonl --digest "${{ steps.container_info.outputs.digest }}" --tags "${{ inputs.image-tag }}"
  79. env:
  80. COSIGN_EXPERIMENTAL: "0"
  81. GITHUB_TOKEN: "${{ github.token }}"
  82. - name: Attach provenance
  83. shell: bash
  84. id: provenance
  85. env:
  86. COSIGN_EXPERIMENTAL: "1"
  87. IMAGE_NAME: ${{ inputs.image-name }}
  88. IMAGE_TAG: ${{ inputs.image-tag }}
  89. CONTAINER_DIGEST: ${{ steps.container_info.outputs.digest }}
  90. run: |
  91. jq '.predicate' provenance.${IMAGE_TAG}.intoto.jsonl > provenance-predicate.att
  92. cosign attest --predicate provenance-predicate.att --type slsaprovenance "${IMAGE_NAME}@${CONTAINER_DIGEST}"
  93. cosign verify-attestation --type slsaprovenance ${IMAGE_NAME}@${CONTAINER_DIGEST}