action.yml 2.9 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. 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.12.1
  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 "::set-output name=digest::$(crane digest ${{ inputs.image-name }}:${{ inputs.image-tag }})"
  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. env:
  58. COSIGN_EXPERIMENTAL: "1"
  59. run: |
  60. syft "${{ inputs.image-name }}@${{ steps.container_info.outputs.digest }}" -o spdx-json=sbom-spdx.json
  61. cosign attest --predicate sbom-spdx.json --type spdx "${{ inputs.image-name }}@${{ steps.container_info.outputs.digest }}"
  62. cosign verify-attestation --type spdx ${{ inputs.image-name }}@${{ steps.container_info.outputs.digest }} | jq '.payload |= @base64d | .payload | fromjson'
  63. - name: Generate provenance
  64. uses: philips-labs/slsa-provenance-action@v0.7.2
  65. with:
  66. command: generate
  67. subcommand: container
  68. arguments: --repository "${{ inputs.image-name }}" --output-path provenance.att --digest "${{ steps.container_info.outputs.digest }}" --tags "${{ inputs.image-tag }}"
  69. env:
  70. COSIGN_EXPERIMENTAL: "0"
  71. GITHUB_TOKEN: "${{ inputs.GITHUB_TOKEN }}"
  72. - name: Attach provenance
  73. shell: bash
  74. env:
  75. COSIGN_EXPERIMENTAL: "1"
  76. run: |
  77. jq '.predicate' provenance.att > provenance-predicate.att
  78. cosign attest --predicate provenance-predicate.att --type slsaprovenance "${{ inputs.image-name }}@${{ steps.container_info.outputs.digest }}"
  79. cosign verify-attestation --type slsaprovenance ${{ inputs.image-name }}@${{ steps.container_info.outputs.digest }}