From 51e78284ca80c58589fe5ad9bbddb6a8db2aab94 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Tue, 23 Jul 2024 13:04:46 +0200 Subject: [PATCH] GH Actions: provide attestations for release PHAR files GitHub has released a new feature called Artifact Attestations, which allows for verifying the integrity of artifacts build via GitHub Actions. This is an additional security and compliance feature, which allows for checking which workflow build the artifact and ensuring the artifact has not been tampered with after the generation via the workflow. To me, this sounds like a good addition to the build process for release phars, so this commit implements attesting PHARS for releases. To verify the phar files (after the next release, which will be the first to use this feature): * Download the PHAR file(s), either from "Releases", from the tag "Test" workflow run or via PHIVE. * If downloaded as a zipped artifact, unzip to get to the actual PHAR files. * Using the GitHub CLI tool, run the below command to verify: ```bash gh attestation verify phpcs.phar -o PHPCSStandards gh attestation verify phpcbf.phar -o PHPCSStandards ``` References: * https://github.blog/changelog/2024-06-25-artifact-attestations-is-generally-available/ * https://docs.github.com/en/actions/security-guides/using-artifact-attestations-to-establish-provenance-for-builds * https://github.com/actions/attest-build-provenance * https://cli.github.com/ * https://github.com/cli/cli --- .github/workflows/test.yml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 59df883a74..d402c1ade0 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -25,6 +25,11 @@ jobs: runs-on: ubuntu-latest name: "Build Phar on PHP: 8.0" + permissions: + id-token: write + contents: read + attestations: write + steps: - name: Checkout code uses: actions/checkout@v4 @@ -39,6 +44,17 @@ jobs: - name: Build the phar run: php scripts/build-phar.php + # Provide provenance for generated binaries. + # Only attests the build artifacts which will be used in the published releases as per the guidelines in "what to attest". + # https://docs.github.com/en/actions/security-guides/using-artifact-attestations-to-establish-provenance-for-builds + - name: Generate artifact attestations + if: ${{ github.ref_type == 'tag' }} + uses: actions/attest-build-provenance@v1 + with: + subject-path: | + ${{ github.workspace }}/phpcs.phar + ${{ github.workspace }}/phpcbf.phar + - name: Upload the PHPCS phar uses: actions/upload-artifact@v4 with: