action.yml 3.1 KB

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