From 6a4f05327d1a3bed3aff47fbd90508f51b9b88b6 Mon Sep 17 00:00:00 2001 From: aquint-zama Date: Tue, 16 Jul 2024 16:18:00 +0200 Subject: [PATCH] chore: add SLSA for tfhe crate --- .github/workflows/make_release.yml | 67 +++++++++++++++++++++++++++++- 1 file changed, 65 insertions(+), 2 deletions(-) diff --git a/.github/workflows/make_release.yml b/.github/workflows/make_release.yml index 0e3ccc02e5..97f1060b8b 100644 --- a/.github/workflows/make_release.yml +++ b/.github/workflows/make_release.yml @@ -30,8 +30,48 @@ env: NPM_TAG: "" jobs: + package: + runs-on: ubuntu-latest + outputs: + hash: ${{ steps.hash.outputs.hash }} + steps: + - name: Checkout + uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 + with: + fetch-depth: 0 + - name: Prepare package + run: | + cargo package -p tfhe + - uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4.3.3 + with: + name: crate + path: target/package/*.crate + - uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4.3.3 + with: + name: lockfile + path: Cargo.lock + - name: generate hash + id: hash + run: cd target/package && echo "hash=$(sha256sum ./*.crate | base64 -w0)" >> "${GITHUB_OUTPUT}" + + provenance: + if: ${{ !inputs.dry_run }} + needs: [package] + uses: slsa-framework/slsa-github-generator/.github/workflows/generator_generic_slsa3.yml@v2.0.0 + permissions: + # Needed to detect the GitHub Actions environment + actions: read + # Needed to create the provenance via GitHub OIDC + id-token: write + # Needed to upload assets/artifacts + contents: write + with: + # SHA-256 hashes of the Crate package. + base64-subjects: ${{ needs.package.outputs.hash }} + publish_release: name: Publish Release + needs: [package] # for comparing hashes runs-on: ubuntu-latest permissions: contents: read @@ -41,12 +81,19 @@ jobs: uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 with: fetch-depth: 0 - - name: Create NPM version tag if: ${{ inputs.npm_latest_tag }} run: | echo "NPM_TAG=latest" >> "${GITHUB_ENV}" - + - name: Download artifact + uses: actions/download-artifact@65a9edc5881444af0b9093a5e628f2fe47ea3b2e # v4.1.7 + with: + name: crate + path: target/package + - name: Download artifact + uses: actions/download-artifact@65a9edc5881444af0b9093a5e628f2fe47ea3b2e # v4.1.7 + with: + name: lockfile - name: Publish crate.io package if: ${{ inputs.push_to_crates }} env: @@ -55,6 +102,22 @@ jobs: run: | cargo publish -p tfhe --token ${{ env.CRATES_TOKEN }} ${{ env.DRY_RUN }} + - name: Generate hash + id: published_hash + run: cd target/package && echo "pub_hash=$(sha256sum ./*.crate | base64 -w0)" >> "${GITHUB_OUTPUT}" + + - name: Slack notification (hashes comparison) + if: ${{ needs.package.outputs.hash != steps.published_hash.outputs.pub_hash }} + continue-on-error: true + uses: rtCamp/action-slack-notify@4e5fb42d249be6a45a298f3c9543b111b02f7907 + env: + SLACK_COLOR: failure + SLACK_CHANNEL: ${{ secrets.SLACK_CHANNEL }} + SLACK_ICON: https://pbs.twimg.com/profile_images/1274014582265298945/OjBKP9kn_400x400.png + SLACK_MESSAGE: "SLSA tfhe crate - hash comparison failure: (${{ env.ACTION_RUN_URL }})" + SLACK_USERNAME: ${{ secrets.BOT_USERNAME }} + SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} + - name: Build web package if: ${{ inputs.push_web_package }} run: |