From cc68d30d5757d786e5716718689e35c29a1ffba4 Mon Sep 17 00:00:00 2001 From: jknapp Date: Mon, 23 Nov 2026 07:35:18 -0800 Subject: [PATCH] ci(mod_whp_symlink): harden PR job on shared runners; publish builds never reuse cache - PR workflow: no secrets/registry login, checkout without persisted credentials, docker build --pull --no-cache, per-run tag shared-httpd:pr-probe-, always() cleanup of the image and containers. - build-push.yaml: every docker/build-push-action step gets pull: true and no-cache: true (base is already digest-pinned by the resolve step). - Wiring tests for both; docs: CI trust model. Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_0185ukXi4YX5FxJGqhi6qab6 --- .gitea/workflows/build-push.yaml | 48 +++++++++++++++++++ .gitea/workflows/shared-httpd-symlink-pr.yaml | 27 ++++++++++- docs/shared-httpd-symlink-module.md | 14 ++++++ scripts/tests/multiarch-workflow.test.py | 19 ++++++++ 4 files changed, 106 insertions(+), 2 deletions(-) diff --git a/.gitea/workflows/build-push.yaml b/.gitea/workflows/build-push.yaml index d127a8c..855079a 100644 --- a/.gitea/workflows/build-push.yaml +++ b/.gitea/workflows/build-push.yaml @@ -286,6 +286,10 @@ jobs: id: amd64 uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6.19.2 with: + # Never trust a cache or a local image: fresh pull of the (digest-pinned) + # base and no layer cache, whatever ran on this runner before. + pull: true + no-cache: true platforms: linux/amd64 build-args: | PHPVER=${{ matrix.phpver }} @@ -306,6 +310,10 @@ jobs: timeout-minutes: 45 uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6.19.2 with: + # Never trust a cache or a local image: fresh pull of the (digest-pinned) + # base and no layer cache, whatever ran on this runner before. + pull: true + no-cache: true platforms: linux/arm64 build-args: | PHPVER=${{ matrix.phpver }} @@ -327,6 +335,10 @@ jobs: timeout-minutes: 45 uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6.19.2 with: + # Never trust a cache or a local image: fresh pull of the (digest-pinned) + # base and no layer cache, whatever ran on this runner before. + pull: true + no-cache: true platforms: linux/arm64 build-args: | PHPVER=${{ matrix.phpver }} @@ -482,6 +494,10 @@ jobs: id: amd64 uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6.19.2 with: + # Never trust a cache or a local image: fresh pull of the (digest-pinned) + # base and no layer cache, whatever ran on this runner before. + pull: true + no-cache: true file: ./Dockerfile.fpm platforms: linux/amd64 build-args: | @@ -503,6 +519,10 @@ jobs: timeout-minutes: 45 uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6.19.2 with: + # Never trust a cache or a local image: fresh pull of the (digest-pinned) + # base and no layer cache, whatever ran on this runner before. + pull: true + no-cache: true file: ./Dockerfile.fpm platforms: linux/arm64 build-args: | @@ -525,6 +545,10 @@ jobs: timeout-minutes: 45 uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6.19.2 with: + # Never trust a cache or a local image: fresh pull of the (digest-pinned) + # base and no layer cache, whatever ran on this runner before. + pull: true + no-cache: true file: ./Dockerfile.fpm platforms: linux/arm64 build-args: | @@ -695,6 +719,10 @@ jobs: - name: Build and Push LiteSpeed Image uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6.19.2 with: + # Never trust a cache or a local image: fresh pull of the (digest-pinned) + # base and no layer cache, whatever ran on this runner before. + pull: true + no-cache: true file: ./Dockerfile.litespeed platforms: linux/amd64 push: true @@ -853,6 +881,10 @@ jobs: - name: Build and Push lsphp Image uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6.19.2 with: + # Never trust a cache or a local image: fresh pull of the (digest-pinned) + # base and no layer cache, whatever ran on this runner before. + pull: true + no-cache: true file: ./Dockerfile.lsphp platforms: linux/amd64 push: true @@ -954,6 +986,10 @@ jobs: id: amd64 uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6.19.2 with: + # Never trust a cache or a local image: fresh pull of the (digest-pinned) + # base and no layer cache, whatever ran on this runner before. + pull: true + no-cache: true file: ./Dockerfile.shared-httpd platforms: linux/amd64 build-args: | @@ -987,6 +1023,10 @@ jobs: timeout-minutes: 25 uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6.19.2 with: + # Never trust a cache or a local image: fresh pull of the (digest-pinned) + # base and no layer cache, whatever ran on this runner before. + pull: true + no-cache: true file: ./Dockerfile.shared-httpd platforms: linux/arm64 build-args: | @@ -1006,6 +1046,10 @@ jobs: timeout-minutes: 25 uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6.19.2 with: + # Never trust a cache or a local image: fresh pull of the (digest-pinned) + # base and no layer cache, whatever ran on this runner before. + pull: true + no-cache: true file: ./Dockerfile.shared-httpd platforms: linux/arm64 build-args: | @@ -1111,6 +1155,10 @@ jobs: - name: Build and Push Shared OLS Image uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6.19.2 with: + # Never trust a cache or a local image: fresh pull of the (digest-pinned) + # base and no layer cache, whatever ran on this runner before. + pull: true + no-cache: true file: ./Dockerfile.shared-ols platforms: linux/amd64 push: true diff --git a/.gitea/workflows/shared-httpd-symlink-pr.yaml b/.gitea/workflows/shared-httpd-symlink-pr.yaml index e995208..6c9382e 100644 --- a/.gitea/workflows/shared-httpd-symlink-pr.yaml +++ b/.gitea/workflows/shared-httpd-symlink-pr.yaml @@ -6,6 +6,15 @@ run-name: mod_whp_symlink probe test for ${{ gitea.actor }} ## locally (nothing is pushed, no secrets) and runs the live probe test against ## it. WHP_SYMTEST_REQUIRE=1: a missing docker/image or a failed assertion ## fails the job. Run the same thing locally: docs/shared-httpd-symlink-module.md. +## +## Untrusted code: this runs PR-supplied Dockerfile/C source. Gitea has only the +## shared `ubuntu-latest` runners (no separate label for untrusted jobs), the same +## ones the publish jobs use, so this job is hardened instead: no secrets and no registry +## login, `--pull --no-cache`, a per-run image tag, and an `if: always()` +## cleanup. The publish builds (build-push.yaml) use their own fresh buildx +## builder with `pull: true` / `no-cache: true`, so nothing built here can be +## reused by them. Repo setting (maintainer): require approval for PR workflows +## from forks. on: pull_request: paths: @@ -22,6 +31,8 @@ jobs: steps: - name: Checkout uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0 + with: + persist-credentials: false # Runner images differ on whether they are root and whether sudo exists. - name: Install shellcheck @@ -38,7 +49,19 @@ jobs: shellcheck -S warning scripts/tests/whp-symlink-module.test.sh - name: Build shared-httpd (amd64, local only, nothing pushed) - run: docker build -f Dockerfile.shared-httpd -t shared-httpd:pr-probe . + env: + TAG: shared-httpd:pr-probe-${{ gitea.run_id }} + run: docker build --pull --no-cache -f Dockerfile.shared-httpd -t "$TAG" . - name: Probe test (fails the job on any failed assertion) - run: WHP_SYMTEST_REQUIRE=1 ./scripts/tests/whp-symlink-module.test.sh shared-httpd:pr-probe + env: + TAG: shared-httpd:pr-probe-${{ gitea.run_id }} + run: WHP_SYMTEST_REQUIRE=1 ./scripts/tests/whp-symlink-module.test.sh "$TAG" + + - name: Remove this run's image and containers + if: always() + env: + TAG: shared-httpd:pr-probe-${{ gitea.run_id }} + run: | + docker ps -aq --filter "ancestor=$TAG" | xargs -r docker rm -f || true + docker rmi -f "$TAG" || true diff --git a/docs/shared-httpd-symlink-module.md b/docs/shared-httpd-symlink-module.md index 064d29f..d9f9edf 100644 --- a/docs/shared-httpd-symlink-module.md +++ b/docs/shared-httpd-symlink-module.md @@ -44,3 +44,17 @@ FAIL. Any failed assertion exits 1. - Publish: `Build-Shared-httpd` in `build-push.yaml` runs the same test against the amd64 image it just pushed by digest, before the arm64 build and the tag-assembly step. A failure publishes no tag. (amd64 only; the arm64 image is not probed.) + +## CI trust model + +Gitea has only shared `ubuntu-latest` runners (two), used by the publish jobs and by PR jobs +alike; there is no separate label for untrusted code. So: + +- The PR workflow runs PR-supplied Dockerfile and C source with no secrets and no registry + login, builds with `--pull --no-cache` under a per-run tag + (`shared-httpd:pr-probe-`), and removes its image and containers in an + `if: always()` step. +- Every `docker/build-push-action` step in `build-push.yaml` sets `pull: true` and + `no-cache: true`, on a fresh buildx builder per job and a digest-pinned base image, so no + cache or local image from an earlier job on the runner is reused by a publish build. +- Repo setting (maintainer's call): require approval for PR workflows from forks. diff --git a/scripts/tests/multiarch-workflow.test.py b/scripts/tests/multiarch-workflow.test.py index 0ed8088..cc4edbe 100755 --- a/scripts/tests/multiarch-workflow.test.py +++ b/scripts/tests/multiarch-workflow.test.py @@ -201,6 +201,25 @@ class Wiring(unittest.TestCase): self.assertIn('WHP_SYMTEST_REQUIRE=1 ./scripts/tests/whp-symlink-module.test.sh', t) self.assertLess(t.index('apt-get update && apt-get install'), t.index('shellcheck -S warning')) self.assertNotIn('continue-on-error', t) + # untrusted PR code on a shared runner: no login, no cache, per-run tag, always-cleanup + self.assertNotIn('docker login', t) + self.assertNotIn('login-action', t) + self.assertIn('docker build --pull --no-cache', t) + self.assertIn('shared-httpd:pr-probe-${{ gitea.run_id }}', t) + self.assertNotIn('pr-probe\n', t) + cl = t[t.index('Remove this run'):] + self.assertIn('if: always()', cl) + self.assertIn('docker rmi -f', cl) + + def test_every_publish_build_ignores_local_cache_and_images(self): + n = TEXT.count('uses: docker/build-push-action@') + self.assertGreater(n, 0) + blocks = re.findall(r'uses: docker/build-push-action@\S+ # \S+\n with:\n((?: .*\n)+)', TEXT) + self.assertEqual(len(blocks), n) + for b in blocks: + self.assertIn('pull: true\n', b) + self.assertIn('no-cache: true\n', b) + self.assertNotIn('cache-from', b) def test_tag_scheme_unchanged(self): """Run the assemble step's shell with a recording stub: exact tags per version."""