action.yml 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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/v4.0.0
  17. uses: sigstore/cosign-installer@faadad0cce49287aee09b3a48701e75088a2c6ad # v4.0.0
  18. with:
  19. cosign-release: 'v3.0.2'
  20. - name: Install Syft
  21. # https://github.com/anchore/sbom-action/releases/tag/v0.22.2
  22. uses: anchore/sbom-action/download-syft@28d71544de8eaf1b958d335707167c5f783590ad # v0.22.2
  23. with:
  24. syft-version: v1.41.2
  25. - name: Check Cosign install
  26. shell: bash
  27. run: cosign version
  28. - name: Login to ghcr.io
  29. uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3.6.0
  30. with:
  31. registry: ghcr.io
  32. username: ${{ github.actor }}
  33. password: ${{ github.token }}
  34. - name: Setup Go
  35. uses: actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 # v6.0.0
  36. with:
  37. go-version-file: go.mod
  38. - name: Set up crane
  39. shell: bash
  40. run: go install github.com/google/go-containerregistry/cmd/crane@v0.11.0
  41. - name: Get docker image tag
  42. id: container_info
  43. shell: bash
  44. env:
  45. IMAGE_NAME: ${{ inputs.image-name }}
  46. IMAGE_TAG: ${{ inputs.image-tag }}
  47. run: |
  48. echo "::group::Crane digest lookup"
  49. echo "Looking up digest for ${IMAGE_NAME}:${IMAGE_TAG}"
  50. DIGEST=$(crane digest ${IMAGE_NAME}:${IMAGE_TAG})
  51. echo "Found digest: ${DIGEST}"
  52. echo "digest=${DIGEST}" >> $GITHUB_OUTPUT
  53. echo "::endgroup::"
  54. - name: Sign image
  55. shell: bash
  56. env:
  57. IMAGE_NAME: ${{ inputs.image-name }}
  58. CONTAINER_DIGEST: ${{ steps.container_info.outputs.digest }}
  59. GITHUB_TRIGGERING_ACTOR: ${{ github.triggering_actor }}
  60. run: |
  61. echo "::group::Cosign sign"
  62. echo "Signing ${IMAGE_NAME}@${CONTAINER_DIGEST}"
  63. cosign sign --yes --new-bundle-format=false --use-signing-config=false -a GITHUB_ACTOR=${GITHUB_TRIGGERING_ACTOR} "${IMAGE_NAME}@${CONTAINER_DIGEST}"
  64. echo "::endgroup::"
  65. - name: Attach SBOM to image
  66. shell: bash
  67. id: sbom
  68. env:
  69. IMAGE_NAME: ${{ inputs.image-name }}
  70. IMAGE_TAG: ${{ inputs.image-tag }}
  71. CONTAINER_DIGEST: ${{ steps.container_info.outputs.digest }}
  72. run: |
  73. echo "::group::Image SBOM generation"
  74. # Image SBOM (OS + application libs contained in the image)
  75. echo "Generating image SBOM for ${IMAGE_NAME}@${CONTAINER_DIGEST}"
  76. syft "${IMAGE_NAME}@${CONTAINER_DIGEST}" -o spdx-json=sbom.${IMAGE_TAG}.spdx.json
  77. echo "::endgroup::"
  78. echo "::group::Attest image SBOM"
  79. cosign attest --yes --new-bundle-format=false --use-signing-config=false --predicate sbom.${IMAGE_TAG}.spdx.json --type spdx "${IMAGE_NAME}@${CONTAINER_DIGEST}"
  80. echo "::endgroup::"
  81. echo "::group::Verify image SBOM attestation"
  82. echo "Using certificate-identity-regexp: https://github.com/$GITHUB_REPOSITORY/.*"
  83. cosign verify-attestation --type spdx ${IMAGE_NAME}@${CONTAINER_DIGEST} \
  84. --certificate-identity-regexp "https://github.com/$GITHUB_REPOSITORY/.*" \
  85. --certificate-oidc-issuer https://token.actions.githubusercontent.com | jq '.payload |= @base64d | .payload | fromjson'
  86. echo "::endgroup::"
  87. echo "::group::Go modules SBOM generation"
  88. # Go modules SBOM (dependencies from the source tree)
  89. # Requires repository to be checked out before this composite action runs.
  90. syft dir:. -o spdx-json=sbom.gomod.${IMAGE_TAG}.spdx.json
  91. echo "::endgroup::"
  92. echo "::group::Attest Go modules SBOM"
  93. cosign attest --yes --new-bundle-format=false --use-signing-config=false --predicate sbom.gomod.${IMAGE_TAG}.spdx.json --type spdx "${IMAGE_NAME}@${CONTAINER_DIGEST}"
  94. echo "::endgroup::"
  95. echo "::group::Verify Go modules SBOM attestation"
  96. cosign verify-attestation --type spdx ${IMAGE_NAME}@${CONTAINER_DIGEST} \
  97. --certificate-identity-regexp "https://github.com/$GITHUB_REPOSITORY/.*" \
  98. --certificate-oidc-issuer https://token.actions.githubusercontent.com | jq ' .payload |= @base64d | .payload | fromjson | .subject'
  99. echo "::endgroup::"
  100. - name: Generate provenance
  101. shell: bash
  102. env:
  103. IMAGE_NAME: ${{ inputs.image-name }}
  104. IMAGE_TAG: ${{ inputs.image-tag }}
  105. CONTAINER_DIGEST: ${{ steps.container_info.outputs.digest }}
  106. run: |
  107. echo "::group::Generate provenance"
  108. ./hack/generate-provenance.sh \
  109. --repository "${IMAGE_NAME}" \
  110. --digest "${CONTAINER_DIGEST}" \
  111. --tags "${IMAGE_TAG}" \
  112. --output-path "provenance.${IMAGE_TAG}.intoto.jsonl"
  113. echo "::endgroup::"
  114. - name: Attach provenance
  115. shell: bash
  116. id: provenance
  117. env:
  118. IMAGE_NAME: ${{ inputs.image-name }}
  119. IMAGE_TAG: ${{ inputs.image-tag }}
  120. CONTAINER_DIGEST: ${{ steps.container_info.outputs.digest }}
  121. run: |
  122. echo "::group::Prepare provenance predicate"
  123. jq '.predicate' provenance.${IMAGE_TAG}.intoto.jsonl > provenance-predicate.att
  124. echo "::endgroup::"
  125. echo "::group::Attest provenance"
  126. cosign attest --yes --new-bundle-format=false --use-signing-config=false --predicate provenance-predicate.att --type slsaprovenance "${IMAGE_NAME}@${CONTAINER_DIGEST}"
  127. echo "::endgroup::"
  128. echo "::group::Verify provenance attestation"
  129. cosign verify-attestation --type slsaprovenance ${IMAGE_NAME}@${CONTAINER_DIGEST} \
  130. --certificate-identity-regexp "https://github.com/$GITHUB_REPOSITORY/.*" \
  131. --certificate-oidc-issuer https://token.actions.githubusercontent.com
  132. echo "::endgroup::"