ci(mod_whp_symlink): harden PR job on shared runners; publish builds never reuse cache
shared-httpd mod_whp_symlink PR check / Symlink-Module-Probe (pull_request) Successful in 2m25s
shared-httpd mod_whp_symlink PR check / Symlink-Module-Probe (pull_request) Successful in 2m25s
- PR workflow: no secrets/registry login, checkout without persisted credentials, docker build --pull --no-cache, per-run tag shared-httpd:pr-probe-<run_id>, 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 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0185ukXi4YX5FxJGqhi6qab6
This commit is contained in:
1 parent
0d9e57e012
commit
cc68d30d57
4 files changed
+106
-2
No files matched your search
@@ -286,6 +286,10 @@ jobs:
|
|||||||
id: amd64
|
id: amd64
|
||||||
uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6.19.2
|
uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6.19.2
|
||||||
with:
|
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
|
platforms: linux/amd64
|
||||||
build-args: |
|
build-args: |
|
||||||
PHPVER=${{ matrix.phpver }}
|
PHPVER=${{ matrix.phpver }}
|
||||||
@@ -306,6 +310,10 @@ jobs:
|
|||||||
timeout-minutes: 45
|
timeout-minutes: 45
|
||||||
uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6.19.2
|
uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6.19.2
|
||||||
with:
|
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
|
platforms: linux/arm64
|
||||||
build-args: |
|
build-args: |
|
||||||
PHPVER=${{ matrix.phpver }}
|
PHPVER=${{ matrix.phpver }}
|
||||||
@@ -327,6 +335,10 @@ jobs:
|
|||||||
timeout-minutes: 45
|
timeout-minutes: 45
|
||||||
uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6.19.2
|
uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6.19.2
|
||||||
with:
|
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
|
platforms: linux/arm64
|
||||||
build-args: |
|
build-args: |
|
||||||
PHPVER=${{ matrix.phpver }}
|
PHPVER=${{ matrix.phpver }}
|
||||||
@@ -482,6 +494,10 @@ jobs:
|
|||||||
id: amd64
|
id: amd64
|
||||||
uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6.19.2
|
uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6.19.2
|
||||||
with:
|
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
|
file: ./Dockerfile.fpm
|
||||||
platforms: linux/amd64
|
platforms: linux/amd64
|
||||||
build-args: |
|
build-args: |
|
||||||
@@ -503,6 +519,10 @@ jobs:
|
|||||||
timeout-minutes: 45
|
timeout-minutes: 45
|
||||||
uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6.19.2
|
uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6.19.2
|
||||||
with:
|
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
|
file: ./Dockerfile.fpm
|
||||||
platforms: linux/arm64
|
platforms: linux/arm64
|
||||||
build-args: |
|
build-args: |
|
||||||
@@ -525,6 +545,10 @@ jobs:
|
|||||||
timeout-minutes: 45
|
timeout-minutes: 45
|
||||||
uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6.19.2
|
uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6.19.2
|
||||||
with:
|
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
|
file: ./Dockerfile.fpm
|
||||||
platforms: linux/arm64
|
platforms: linux/arm64
|
||||||
build-args: |
|
build-args: |
|
||||||
@@ -695,6 +719,10 @@ jobs:
|
|||||||
- name: Build and Push LiteSpeed Image
|
- name: Build and Push LiteSpeed Image
|
||||||
uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6.19.2
|
uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6.19.2
|
||||||
with:
|
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
|
file: ./Dockerfile.litespeed
|
||||||
platforms: linux/amd64
|
platforms: linux/amd64
|
||||||
push: true
|
push: true
|
||||||
@@ -853,6 +881,10 @@ jobs:
|
|||||||
- name: Build and Push lsphp Image
|
- name: Build and Push lsphp Image
|
||||||
uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6.19.2
|
uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6.19.2
|
||||||
with:
|
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
|
file: ./Dockerfile.lsphp
|
||||||
platforms: linux/amd64
|
platforms: linux/amd64
|
||||||
push: true
|
push: true
|
||||||
@@ -954,6 +986,10 @@ jobs:
|
|||||||
id: amd64
|
id: amd64
|
||||||
uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6.19.2
|
uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6.19.2
|
||||||
with:
|
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
|
file: ./Dockerfile.shared-httpd
|
||||||
platforms: linux/amd64
|
platforms: linux/amd64
|
||||||
build-args: |
|
build-args: |
|
||||||
@@ -987,6 +1023,10 @@ jobs:
|
|||||||
timeout-minutes: 25
|
timeout-minutes: 25
|
||||||
uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6.19.2
|
uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6.19.2
|
||||||
with:
|
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
|
file: ./Dockerfile.shared-httpd
|
||||||
platforms: linux/arm64
|
platforms: linux/arm64
|
||||||
build-args: |
|
build-args: |
|
||||||
@@ -1006,6 +1046,10 @@ jobs:
|
|||||||
timeout-minutes: 25
|
timeout-minutes: 25
|
||||||
uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6.19.2
|
uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6.19.2
|
||||||
with:
|
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
|
file: ./Dockerfile.shared-httpd
|
||||||
platforms: linux/arm64
|
platforms: linux/arm64
|
||||||
build-args: |
|
build-args: |
|
||||||
@@ -1111,6 +1155,10 @@ jobs:
|
|||||||
- name: Build and Push Shared OLS Image
|
- name: Build and Push Shared OLS Image
|
||||||
uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6.19.2
|
uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6.19.2
|
||||||
with:
|
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
|
file: ./Dockerfile.shared-ols
|
||||||
platforms: linux/amd64
|
platforms: linux/amd64
|
||||||
push: true
|
push: true
|
||||||
|
|||||||
@@ -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
|
## 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
|
## 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.
|
## 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:
|
on:
|
||||||
pull_request:
|
pull_request:
|
||||||
paths:
|
paths:
|
||||||
@@ -22,6 +31,8 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
|
uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
|
||||||
|
with:
|
||||||
|
persist-credentials: false
|
||||||
|
|
||||||
# Runner images differ on whether they are root and whether sudo exists.
|
# Runner images differ on whether they are root and whether sudo exists.
|
||||||
- name: Install shellcheck
|
- name: Install shellcheck
|
||||||
@@ -38,7 +49,19 @@ jobs:
|
|||||||
shellcheck -S warning scripts/tests/whp-symlink-module.test.sh
|
shellcheck -S warning scripts/tests/whp-symlink-module.test.sh
|
||||||
|
|
||||||
- name: Build shared-httpd (amd64, local only, nothing pushed)
|
- 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)
|
- 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
|
||||||
@@ -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
|
- 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
|
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.)
|
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-<run_id>`), 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.
|
||||||
@@ -201,6 +201,25 @@ class Wiring(unittest.TestCase):
|
|||||||
self.assertIn('WHP_SYMTEST_REQUIRE=1 ./scripts/tests/whp-symlink-module.test.sh', t)
|
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.assertLess(t.index('apt-get update && apt-get install'), t.index('shellcheck -S warning'))
|
||||||
self.assertNotIn('continue-on-error', t)
|
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):
|
def test_tag_scheme_unchanged(self):
|
||||||
"""Run the assemble step's shell with a recording stub: exact tags per version."""
|
"""Run the assemble step's shell with a recording stub: exact tags per version."""
|
||||||
|
|||||||
Reference in new issue
Block a user