ci: release-images — advisory gates in a job without secrets, image job runs no third-party code before login, fresh config dir via GITHUB_ENV, run-id builder name, empty digest refused, cleanup order; docs: SAFETY markers consistent, iCCP fixture comment

This commit is contained in:
bchanot committed 2026-10-13 00:53:46 +02:00
1 parent 3af2861be7
commit 47d84161f5
4 files changed
+54 -26

No files matched your search

+44 -18
View File
@@ -5,16 +5,18 @@
# yet applied)" is the runbook.
#
# Hardening (security audits of R0): the dispatch input is a typed choice re-validated in
# the shell through an environment variable (never interpolated into a script); the registry
# the shell through an environment variable (never interpolated into a script); the
# advisory gates (RustSec, npm) run in a job that holds no secret, and the image job runs no
# third-party code before its login (no npm install, only the pinned checkout); the registry
# token reaches the login step only, through env, into a per-job DOCKER_CONFIG under
# RUNNER_TEMP created before any step and removed by a literal path; the images are built by
# a named ephemeral buildx builder (`--builder`, so a missing builder fails instead of
# falling back to the daemon's shared BuildKit and its cache mounts); the RustSec and npm
# advisories gates run before any push; `actions/checkout` is pinned to a commit. The
# RUNNER_TEMP created fresh before the login and removed by a literal path; the images are
# built by a named ephemeral buildx builder (`--builder`, so a missing builder fails instead
# of falling back to the daemon's shared BuildKit and its cache mounts). The
# `if: github.ref` line keeps honest runs on main or develop: it is not a security boundary
# (whoever can push a branch can dispatch a copy of this file), push access and the token's
# scope are. The real isolation from pull-request jobs is a dedicated release runner label
# that never runs them (Step 27 operations).
# that never runs them (Step 27 operations). Known mutable references, to pin at Step 27:
# the buildkit engine image of the builder, the base images of the Dockerfiles.
#
# Secrets expected on the forge: REGISTRY (host, e.g. the Gitea container registry of this
# forge), REGISTRY_USER, REGISTRY_TOKEN (write:package scope). Images are pushed as
@@ -34,21 +36,19 @@ on:
- draft
default: none
concurrency:
group: release-images-${{ github.sha }}
cancel-in-progress: false
jobs:
images:
# No secret here: this job runs third-party code (pnpm install for the audit, the
# builder image) and must never see the registry token.
gates:
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop'
runs-on: ubuntu-latest
env:
SHEET_BUNDLE: ${{ inputs.sheet_bundle }}
REGISTRY: ${{ secrets.REGISTRY }}
NAMESPACE: ${{ github.repository_owner }}
GIT_SHA: ${{ github.sha }}
# Per-job Docker config, set before any step runs: the login and the builder live here.
DOCKER_CONFIG: ${{ runner.temp }}/faunosteo-release-docker
BUILDER: faunosteo_release_${{ github.sha }}
steps:
- name: Per-job Docker config directory
run: mkdir -m 700 -p "$DOCKER_CONFIG"
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Validate the dispatch input (the shell trusts the env value only after this)
run: |
@@ -68,6 +68,28 @@ jobs:
corepack enable && corepack prepare --activate
pnpm install --frozen-lockfile
pnpm audit --prod --audit-level=high
images:
needs: gates
runs-on: ubuntu-latest
env:
SHEET_BUNDLE: ${{ inputs.sheet_bundle }}
REGISTRY: ${{ secrets.REGISTRY }}
NAMESPACE: ${{ github.repository_owner }}
GIT_SHA: ${{ github.sha }}
BUILDER: faunosteo_release_${{ github.run_id }}
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Re-validate the dispatch input in this job
run: |
case "$SHEET_BUNDLE" in
none|draft) ;;
*) echo "refused SHEET_BUNDLE value" >&2; exit 1 ;;
esac
- name: Fresh per-job Docker config (fails if the directory already exists)
run: |
mkdir -m 700 "$RUNNER_TEMP/faunosteo-release-docker"
echo "DOCKER_CONFIG=$RUNNER_TEMP/faunosteo-release-docker" >> "$GITHUB_ENV"
- name: Ephemeral builder with its own cache (named; every build names it explicitly)
run: docker buildx create --name "$BUILDER" --driver docker-container
- name: Registry login (token in this step's env only, never on the command line)
@@ -82,7 +104,8 @@ jobs:
--metadata-file "$RUNNER_TEMP/app-metadata.json" \
--build-arg "SHEET_BUNDLE=$SHEET_BUNDLE" -t "$image" .
digest="$(sed -n 's/.*"containerimage.digest": *"\([^"]*\)".*/\1/p' "$RUNNER_TEMP/app-metadata.json")"
echo "app: $image@$digest" >> "$GITHUB_STEP_SUMMARY"
[ -n "$digest" ] || { echo "no digest in the build metadata" >&2; exit 1; }
echo "app: faunosteo_app:$GIT_SHA@$digest" >> "$GITHUB_STEP_SUMMARY"
- name: Build and push the worker image
run: |
image="$REGISTRY/$NAMESPACE/faunosteo_worker:$GIT_SHA"
@@ -90,10 +113,13 @@ jobs:
--metadata-file "$RUNNER_TEMP/worker-metadata.json" \
-f crates/worker/Dockerfile -t "$image" .
digest="$(sed -n 's/.*"containerimage.digest": *"\([^"]*\)".*/\1/p' "$RUNNER_TEMP/worker-metadata.json")"
echo "worker: $image@$digest" >> "$GITHUB_STEP_SUMMARY"
[ -n "$digest" ] || { echo "no digest in the build metadata" >&2; exit 1; }
echo "worker: faunosteo_worker:$GIT_SHA@$digest" >> "$GITHUB_STEP_SUMMARY"
- name: Logout, remove the builder and the per-job Docker config (literal path)
if: always()
run: |
rc=0
docker logout "$REGISTRY" || true
docker buildx rm "$BUILDER"
docker buildx rm "$BUILDER" || rc=$?
rm -rf -- "${RUNNER_TEMP:?}/faunosteo-release-docker"
exit "$rc"