action.yml 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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.3'
  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: echo "digest=$(crane digest ${IMAGE_NAME}:${IMAGE_TAG})" >> $GITHUB_OUTPUT
  48. - name: Sign image
  49. shell: bash
  50. env:
  51. IMAGE_NAME: ${{ inputs.image-name }}
  52. CONTAINER_DIGEST: ${{ steps.container_info.outputs.digest }}
  53. GITHUB_TRIGGERING_ACTOR: ${{ github.triggering_actor }}
  54. run: cosign sign --yes -a GITHUB_ACTOR=${GITHUB_TRIGGERING_ACTOR} "${IMAGE_NAME}@${CONTAINER_DIGEST}"
  55. - name: Attach SBOM to image
  56. shell: bash
  57. id: sbom
  58. env:
  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 attest --yes --predicate sbom.${IMAGE_TAG}.spdx.json --type spdx "${IMAGE_NAME}@${CONTAINER_DIGEST}"
  67. # cosign verify-attestation --type spdx ${IMAGE_NAME}@${CONTAINER_DIGEST} | jq '.payload |= @base64d | .payload | fromjson'
  68. cosign verify-attestation --type spdx ${IMAGE_NAME}@${CONTAINER_DIGEST} \
  69. --certificate-identity-regexp "https://github.com/$GITHUB_REPOSITORY/.*" \
  70. --certificate-oidc-issuer https://token.actions.githubusercontent.com | jq '.payload |= @base64d | .payload | fromjson'
  71. # Go modules SBOM (dependencies from the source tree)
  72. # Requires repository to be checked out before this composite action runs.
  73. syft dir:. -o spdx-json=sbom.gomod.${IMAGE_TAG}.spdx.json
  74. # cosign attest --predicate sbom.gomod.${IMAGE_TAG}.spdx.json --type spdx "${IMAGE_NAME}@${CONTAINER_DIGEST}"
  75. cosign attest --yes --predicate sbom.gomod.${IMAGE_TAG}.spdx.json --type spdx "${IMAGE_NAME}@${CONTAINER_DIGEST}"
  76. cosign verify-attestation --type spdx ${IMAGE_NAME}@${CONTAINER_DIGEST} \
  77. --certificate-identity-regexp "https://github.com/$GITHUB_REPOSITORY/.*" \
  78. --certificate-oidc-issuer https://token.actions.githubusercontent.com | jq '.payload |= @base64d | .payload | fromjson'
  79. - name: Generate provenance
  80. # https://github.com/philips-labs/slsa-provenance-action/releases/tag/v0.7.2
  81. uses: philips-labs/slsa-provenance-action@dddb40e199ae28d4cd2f17bad7f31545556fdd3d # v0.7.2
  82. with:
  83. command: generate
  84. subcommand: container
  85. arguments: --repository "${{ inputs.image-name }}" --output-path provenance.${{ inputs.image-tag }}.intoto.jsonl --digest "${{ steps.container_info.outputs.digest }}" --tags "${{ inputs.image-tag }}"
  86. env:
  87. COSIGN_EXPERIMENTAL: "0"
  88. GITHUB_TOKEN: "${{ github.token }}"
  89. - name: Attach provenance
  90. shell: bash
  91. id: provenance
  92. env:
  93. IMAGE_NAME: ${{ inputs.image-name }}
  94. IMAGE_TAG: ${{ inputs.image-tag }}
  95. CONTAINER_DIGEST: ${{ steps.container_info.outputs.digest }}
  96. run: |
  97. jq '.predicate' provenance.${IMAGE_TAG}.intoto.jsonl > provenance-predicate.att
  98. # cosign attest --predicate provenance-predicate.att --type slsaprovenance "${IMAGE_NAME}@${CONTAINER_DIGEST}"
  99. cosign attest --yes --predicate provenance-predicate.att --type slsaprovenance "${IMAGE_NAME}@${CONTAINER_DIGEST}"
  100. # cosign verify-attestation --type slsaprovenance ${IMAGE_NAME}@${CONTAINER_DIGEST}
  101. cosign verify-attestation --type slsaprovenance ${IMAGE_NAME}@${CONTAINER_DIGEST} \
  102. --certificate-identity-regexp "https://github.com/$GITHUB_REPOSITORY/.*" \
  103. --certificate-oidc-issuer https://token.actions.githubusercontent.com