From 85c3d0fdd75284db217366550437e2ecb7c2e6e4 Mon Sep 17 00:00:00 2001 From: stefansorge <3419073+sorge-it@users.noreply.github.com> Date: Sat, 21 Nov 2026 09:32:41 +0100 Subject: [PATCH] ci: check the attestation of FrankenPHP before the binary first runs The Docker images have no gh, so the binary of the Debian and Alpine jobs ran unchecked, and linux-arm64 never got a check. These jobs now install it on the runner. The installer checks the attestation before it runs the binary for its versions. --- .github/workflows/tests.yml | 24 ++++++++++++++++++++---- CONTRIBUTING.md | 3 ++- tests/FrankenPhp/install-frankenphp.php | 23 ++++++++++++++--------- 3 files changed, 36 insertions(+), 14 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 626fc12..ace0942 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -248,11 +248,19 @@ jobs: - name: Build run: docker build --quiet --tag tests .github/docker/alpine - # Into the tree, so the cache keeps it and the container of the test copies it. + # On the runner, because the image has no gh to check the attestation. Into the tree, so the + # cache keeps it and the container of the test copies it. + - name: Setup PHP + uses: shivammathur/setup-php@eb7c497e18156a6bbabfef1d3a82760b9eda3962 # 2.40.0 + with: + php-version: '8.5' + coverage: none + tools: none + - name: Install FrankenPHP env: GITHUB_TOKEN: ${{ github.token }} - run: docker run --rm --env GITHUB_TOKEN --volume "$PWD:/src" --workdir /src --entrypoint php tests tests/FrankenPhp/install-frankenphp.php + run: php tests/FrankenPhp/install-frankenphp.php && test -f .frankenphp/ATTESTED - name: Test run: | @@ -284,11 +292,19 @@ jobs: - name: Build run: docker build --quiet --tag tests .github/docker/debian - # Into the tree, so the cache keeps it and the container of the test copies it. + # On the runner, because the image has no gh to check the attestation. Into the tree, so the + # cache keeps it and the container of the test copies it. + - name: Setup PHP + uses: shivammathur/setup-php@eb7c497e18156a6bbabfef1d3a82760b9eda3962 # 2.40.0 + with: + php-version: '8.5' + coverage: none + tools: none + - name: Install FrankenPHP env: GITHUB_TOKEN: ${{ github.token }} - run: docker run --rm --env GITHUB_TOKEN --volume "$PWD:/src" --workdir /src --entrypoint php tests tests/FrankenPhp/install-frankenphp.php + run: php tests/FrankenPhp/install-frankenphp.php && test -f .frankenphp/ATTESTED - name: Test run: | diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a8b08e6..1fd9e0f 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -30,7 +30,8 @@ composer test # Pint and Rector dry runs, PHPStan, 100% type cove (see [Before you open a pull request](#before-you-open-a-pull-request)). - Where `gh` has a login or a token, `frankenphp:install` also uses `gh attestation verify` to check that FrankenPHP's workflow built the binary. A binary that fails the check is deleted. - Where `gh` has neither, the binary runs unchecked, as in the Docker jobs. + The check comes before the binary first runs. Where `gh` has neither, as in a Docker image, the + binary runs unchecked; so in CI, a Docker job installs the binary on the runner, which has `gh`. ## Reporting a bug diff --git a/tests/FrankenPhp/install-frankenphp.php b/tests/FrankenPhp/install-frankenphp.php index 5cb3959..a224557 100644 --- a/tests/FrankenPhp/install-frankenphp.php +++ b/tests/FrankenPhp/install-frankenphp.php @@ -31,8 +31,8 @@ } // Upstream rebuilds a release, so release.lock pins no SHA-256; the attestation shows who built the -// binary of today. Where gh cannot check, as in the Docker jobs, the binary runs unchecked until an -// install where it can; on CI, linux-arm64 runs only in Docker and stays unchecked. +// binary of today. Where gh cannot check, as in a Docker image, the binary runs unchecked until an +// install where it can; in CI, a Docker job installs it on the runner, which has gh. $canAttest = Release::canAttest(); if ($installed && ! $canAttest) { @@ -55,15 +55,9 @@ echo 'Download FrankenPHP '.$tag.' for '.$system.PHP_EOL; $sha256 = Release::digests($tag)[$asset] ?? throw new RuntimeException('FrankenPHP '.$tag.' has no '.$asset.'.'); Release::download($tag, $asset, $sha256, $directory.'/frankenphp', 'the API of GitHub'); - $found = Release::versionOf($directory.'/frankenphp'); - - if ($found !== $version) { - unlink($directory.'/frankenphp'); - - throw new RuntimeException('The binary of FrankenPHP '.$tag.' names '.$found.', release.lock '.$version.'. Upstream built it again with other versions: run composer frankenphp:lock.'); - } } + // The check comes before the binary runs for its versions. if ($canAttest) { try { Release::attest($directory.'/frankenphp', $asset); @@ -79,6 +73,17 @@ } else { echo 'No gh with a login or a token: the attestation is not checked.'.PHP_EOL; } + + if (! $installed) { + $found = Release::versionOf($directory.'/frankenphp'); + + if ($found !== $version) { + @unlink($directory.'/ATTESTED'); + unlink($directory.'/frankenphp'); + + throw new RuntimeException('The binary of FrankenPHP '.$tag.' names '.$found.', release.lock '.$version.'. Upstream built it again with other versions: run composer frankenphp:lock.'); + } + } } catch (RuntimeException|JsonException $exception) { fwrite(STDERR, $exception->getMessage().PHP_EOL);