fix(ci): harden the release publish workflow after the PR review
PR Check / Security scan (Snyk) (pull_request) Skipped
PR Check / Lint + typecheck (pull_request) Successful in 1m5s
PR Check / Secret scan (gitleaks) (pull_request) Successful in 6s
PR Check / Dependency audit (pull_request) Successful in 8s
PR Check / Dockerfile lint (droast) (pull_request) Successful in 5s
PR Check / AI code review (opencode) (pull_request) Successful in 48s

Applied the findings that held up against the code:
- strict vMAJOR.MINOR.PATCH guard; v[0-9]* accepted v1, v1-foo and
  prereleases, all valid registry tags
- latest now follows the newest release, so replaying an older tag cannot
  drag it backwards; skipped with a warning if the tag list is unavailable
- smoke test starts the built image and requires 2xx on / before pushing
- timeout-minutes: 20 on the job, so a hung build cannot hold the
  capacity-1 runner indefinitely
- the decision doc records the socket's blast radius: root-equivalent,
  runner-wide, only on a label PR jobs cannot use

Rejected with evidence: the .dockerignore leak (.env*, *.pem, .git are
excluded) and the Docker client/daemon API mismatch (20.10.24 client
against a 29.9.2 daemon builds over the socket).
This commit is contained in:
Noel Sabia committed 2026-10-24 19:15:55 +02:00
1 parent f3d3e196d0
commit 435be63ae0
4 files changed
+130 -23

No files matched your search

+90 -20
View File
@@ -26,6 +26,9 @@ jobs:
publish: publish:
name: Build and push image name: Build and push image
runs-on: ubuntu-latest runs-on: ubuntu-latest
# A hung build would hold the capacity-1 runner and, through it, every
# other job on this server. Gitea's instance default is not a contract.
timeout-minutes: 20
# Same base image as the other jobs. The build runs on the runner's # Same base image as the other jobs. The build runs on the runner's
# Docker daemon (not in a nested daemon), so this container only needs # Docker daemon (not in a nested daemon), so this container only needs
# the CLI - see OKF_Nuxt/decisions/registry-publishing.md. # the CLI - see OKF_Nuxt/decisions/registry-publishing.md.
@@ -47,6 +50,12 @@ jobs:
# An unreachable daemon means the runner was started without the # An unreachable daemon means the runner was started without the
# host socket mounted: set `docker_host: automount` in the # host socket mounted: set `docker_host: automount` in the
# act_runner config and restart the service. # act_runner config and restart the service.
#
# The socket is root-equivalent on the host, and automount is a
# runner-wide setting - it applies to every job on that runner,
# including PR jobs. Only enable it on a runner label that
# PR-triggered jobs cannot use; see the trust boundary in
# OKF_Nuxt/decisions/registry-publishing.md.
run: | run: |
echo "DOCKER_HOST=${DOCKER_HOST:-<unset - the default socket path>}" echo "DOCKER_HOST=${DOCKER_HOST:-<unset - the default socket path>}"
if ! docker info > /dev/null 2>&1; then if ! docker info > /dev/null 2>&1; then
@@ -60,32 +69,43 @@ jobs:
# GITHUB_REF_NAME is the tag on a tag push. The git fallback keeps # GITHUB_REF_NAME is the tag on a tag push. The git fallback keeps
# this working if a runner version does not set it. # this working if a runner version does not set it.
version="${GITHUB_REF_NAME:-$(git describe --tags --exact-match HEAD)}" version="${GITHUB_REF_NAME:-$(git describe --tags --exact-match HEAD)}"
case "$version" in # Strict semver, not a `v[0-9]*` prefix match: that would accept
v[0-9]*) ;; # `v1`, `v1-anything` and prereleases, all valid registry tags.
*) echo "::error::expected a vX.Y.Z tag, got '${version}'"; exit 1 ;; if ! printf '%s' "$version" | grep -qE '^v[0-9]+\.[0-9]+\.[0-9]+$'; then
esac echo "::error::expected a vMAJOR.MINOR.PATCH tag, got '${version}'"
exit 1
fi
sha="$(git rev-parse --short=12 HEAD)"
# `latest` follows the newest release, not the newest build. A
# re-run of an older tag (Gitea can replay any run) must not drag
# `latest` backwards, while a re-run of the newest tag may set it:
# that release had not produced an image yet.
# A tag comparison needs the other tags, which a depth-1 tag
# checkout does not have. If the fetch fails, skip `latest` and
# say so - a wrong tag is worse than a missing one.
if git fetch --tags --force --quiet origin 2>/dev/null; then
newest="$(git tag -l | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | sort -V | tail -n 1)"
if [ "$version" = "$newest" ]; then
latest=true
else
latest=false
echo "::warning::${version} is not the newest release (${newest}) - not moving :latest"
fi
else
latest=false
echo "::warning::could not list tags - not moving :latest"
fi
# Short SHA tag alongside the version: OKF_CV_Website/architecture/ # Short SHA tag alongside the version: OKF_CV_Website/architecture/
# delivery.md asks for SHA-tagged images so every deploy is # delivery.md asks for SHA-tagged images so every deploy is
# traceable to a commit even after a tag is moved. # traceable to a commit even after a tag is moved.
sha="$(git rev-parse --short=12 HEAD)"
{ {
echo "version=${version}" echo "version=${version}"
echo "sha=${sha}" echo "sha=${sha}"
echo "latest=${latest}"
} >> "$GITHUB_OUTPUT" } >> "$GITHUB_OUTPUT"
echo "Building ${version} from ${sha}" echo "Building ${version} from ${sha} (latest: ${latest})"
- name: Log in to the registry
env:
REGISTRY_USERNAME: ${{ secrets.REGISTRY_USERNAME }}
REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }}
run: |
# Missing secrets must fail loudly: an anonymous `docker push`
# would answer 401 with a message most people misread as a
# missing repository.
[ -n "$REGISTRY_USERNAME" ] || { echo "::error::secret REGISTRY_USERNAME is empty"; exit 1; }
[ -n "$REGISTRY_PASSWORD" ] || { echo "::error::secret REGISTRY_PASSWORD is empty"; exit 1; }
printf '%s' "$REGISTRY_PASSWORD" \
| docker login registry.noelsabia.dev -u "$REGISTRY_USERNAME" --password-stdin
- name: Build image - name: Build image
env: env:
@@ -101,17 +121,67 @@ jobs:
--label "org.opencontainers.image.revision=${SHA}" \ --label "org.opencontainers.image.revision=${SHA}" \
-t "${IMAGE}:${VERSION}" \ -t "${IMAGE}:${VERSION}" \
-t "${IMAGE}:sha-${SHA}" \ -t "${IMAGE}:sha-${SHA}" \
-t "${IMAGE}:latest" \
"${APP_DIR}" "${APP_DIR}"
- name: Smoke-test the image
env:
VERSION: ${{ steps.version.outputs.version }}
run: |
# Start the real server inside the built image and require a 2xx
# from /. Cheaper than publishing a broken release, and the only
# step that proves the Nitro output actually runs. Done inside the
# container because the app's port is not reachable from this job
# container - the daemon publishes on the host, not here.
docker run --rm "${IMAGE}:${VERSION}" sh -c '
node .output/server/index.mjs &
server=$!
i=0
while [ "$i" -lt 30 ]; do
if node -e "fetch(\"http://127.0.0.1:3000/\").then(r => process.exit(r.ok ? 0 : 1)).catch(() => process.exit(1))"; then
echo "server answered 2xx after ${i}s"
kill "$server"
exit 0
fi
i=$((i + 1))
sleep 1
done
echo "server did not answer 2xx within 30s"
kill "$server"
exit 1
'
- name: Log in to the registry
env:
REGISTRY_USERNAME: ${{ secrets.REGISTRY_USERNAME }}
REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }}
run: |
# Missing secrets must fail loudly: an anonymous `docker push`
# would answer 401 with a message most people misread as a
# missing repository.
[ -n "$REGISTRY_USERNAME" ] || { echo "::error::secret REGISTRY_USERNAME is empty"; exit 1; }
[ -n "$REGISTRY_PASSWORD" ] || { echo "::error::secret REGISTRY_PASSWORD is empty"; exit 1; }
printf '%s' "$REGISTRY_PASSWORD" \
| docker login registry.noelsabia.dev -u "$REGISTRY_USERNAME" --password-stdin
- name: Tag latest
if: steps.version.outputs.latest == 'true'
env:
VERSION: ${{ steps.version.outputs.version }}
run: docker tag "${IMAGE}:${VERSION}" "${IMAGE}:latest"
- name: Push image - name: Push image
env: env:
VERSION: ${{ steps.version.outputs.version }} VERSION: ${{ steps.version.outputs.version }}
SHA: ${{ steps.version.outputs.sha }} SHA: ${{ steps.version.outputs.sha }}
LATEST: ${{ steps.version.outputs.latest }}
run: | run: |
# Explicit per tag, not `--all-tags`: --all-tags would also push # Explicit per tag, not `--all-tags`: --all-tags would also push
# stale local tags left on the shared daemon by earlier runs. # stale local tags left on the shared daemon by earlier runs.
docker push "${IMAGE}:${VERSION}" docker push "${IMAGE}:${VERSION}"
docker push "${IMAGE}:sha-${SHA}" docker push "${IMAGE}:sha-${SHA}"
if [ "$LATEST" = "true" ]; then
docker push "${IMAGE}:latest" docker push "${IMAGE}:latest"
echo "Pushed ${IMAGE}:${VERSION}, :sha-${SHA}, :latest" echo "Pushed ${IMAGE}:${VERSION}, :sha-${SHA}, :latest"
else
echo "Pushed ${IMAGE}:${VERSION}, :sha-${SHA} (:latest untouched)"
fi
+37 -1
View File
@@ -26,7 +26,7 @@ result to the own registry:
``` ```
registry.noelsabia.dev/cv_website/nuxt:v1.2.3 registry.noelsabia.dev/cv_website/nuxt:v1.2.3
registry.noelsabia.dev/cv_website/nuxt:sha-<12-char-sha> registry.noelsabia.dev/cv_website/nuxt:sha-<12-char-sha>
registry.noelsabia.dev/cv_website/nuxt:latest registry.noelsabia.dev/cv_website/nuxt:latest # newest release only
``` ```
**Trigger is the release tag, not the main push.** release-please creates **Trigger is the release tag, not the main push.** release-please creates
@@ -64,6 +64,27 @@ instead of a mid-build error. The alternative - a privileged `docker:dind`
sidecar - needs privileged mode and a second daemon per release; not worth sidecar - needs privileged mode and a second daemon per release; not worth
it on this server. it on this server.
## Trust boundary (the cost of the socket)
A mounted Docker socket is **root-equivalent on the host**: any job that
has it can run `docker run -v /:/host` and read or write anything, which on
this machine means Gitea's data, k3s, and the CV itself. `docker_host` is a
**runner-wide** setting, so enabling it gives the socket to every job on
that runner, including PR jobs whose code comes from a branch.
Therefore the rule: **the socket only ever goes on a runner label that
PR-triggered jobs do not use.** Two acceptable layouts:
* a second act_runner registration with `docker_host: automount` and a
distinct label (e.g. `publish`), used only by this workflow; or
* one runner, but this workflow moved to the dedicated label and
`pr-checker.yml` left on a label without the socket.
Not acceptable: adding `automount` to the single shared runner while
`pr-checker.yml` runs on it. If that is the only option, treat it as an
accepted risk and record it here - the trade is "PR code can become root on
the host" against "images can be built at all".
# Why `--platform linux/arm64` # Why `--platform linux/arm64`
The runner and the node are the same arm64 machine, so the build is native The runner and the node are the same arm64 machine, so the build is native
@@ -81,6 +102,15 @@ run.
Both are repo secrets. The login uses `--password-stdin` so the value never Both are repo secrets. The login uses `--password-stdin` so the value never
appears in the process list or the log. appears in the process list or the log.
# Guards in the workflow
| Guard | Why |
|---|---|
| Strict `^vMAJOR.MINOR.PATCH$` check | A `v[0-9]*` prefix match accepts `v1`, `v1-anything` and `v1.2.3-rc1`, all of which are valid registry tags and would publish silently |
| `latest` only when the built tag is the highest `vX.Y.Z` in the repository | Gitea can replay any run. Without the comparison, re-running `v1.2.0` after `v1.3.0` drags `latest` backwards. A re-run of the newest tag still moves it - that release had not produced an image yet. If the tag list cannot be fetched, `latest` is skipped with a warning rather than guessed |
| Smoke test before any push | The image is started and must answer 2xx on `/` from inside the container. Build success only proves the bundle compiled. Port publishing is not usable here: the daemon binds on the host, not in the job container |
| `timeout-minutes: 20` | A hung build would hold the capacity-1 runner and every job queued behind it |
# Costs and consequences # Costs and consequences
* **Registry storage grows** by one image per release in three tags. The * **Registry storage grows** by one image per release in three tags. The
@@ -101,10 +131,16 @@ appears in the process list or the log.
the workflow's first step answers this on the first release. the workflow's first step answers this on the first release.
* That the arm64 build succeeds: `Dockerfile` has been built on x86_64 * That the arm64 build succeeds: `Dockerfile` has been built on x86_64
only ([production image](production-image.md)). only ([production image](production-image.md)).
* That the smoke test passes on arm64. The same script was run against an
x86_64 build of the merged tree and answered 2xx; the arm64 run is the
first release.
* That `registry.noelsabia.dev` is reachable over HTTPS from the runner. * That `registry.noelsabia.dev` is reachable over HTTPS from the runner.
A plain-HTTP endpoint fails `docker login` with `server gave HTTP A plain-HTTP endpoint fails `docker login` with `server gave HTTP
response to HTTPS client` and needs `insecure-registries` on the daemon response to HTTPS client` and needs `insecure-registries` on the daemon
plus `registries.yaml` on k3s. plus `registries.yaml` on k3s.
* Whether Gitea runs a `pull_request` workflow from a fork without
maintainer approval on this instance. That answer decides how severe the
socket risk above really is.
# Revisit when # Revisit when
+1 -1
View File
@@ -22,7 +22,7 @@ config files — the configs say what, these documents say why.
* [Vulnerability audit policy](decisions/vulnerability-audit-policy.md) - Blocking audit; reviewed ignore-list for unfixable advisories in pnpm-workspace.yaml. * [Vulnerability audit policy](decisions/vulnerability-audit-policy.md) - Blocking audit; reviewed ignore-list for unfixable advisories in pnpm-workspace.yaml.
* [Release engineering](decisions/release-engineering.md) - release-please in manifest mode; conventional commits enforced at commit time. * [Release engineering](decisions/release-engineering.md) - release-please in manifest mode; conventional commits enforced at commit time.
* [Snyk paused and secrets policy](decisions/snyk-paused-and-secrets-policy.md) - Quota-paused job kept in place; `write:issue` scope required on every workflow token. * [Snyk paused and secrets policy](decisions/snyk-paused-and-secrets-policy.md) - Quota-paused job kept in place; `write:issue` scope required on every workflow token.
* [Publishing images to the own registry](decisions/registry-publishing.md) - A release tag builds the image and pushes it to registry.noelsabia.dev, with `docker_host: automount` on the runner. * [Publishing images to the own registry](decisions/registry-publishing.md) - A release tag builds the image and pushes it to registry.noelsabia.dev; the runner socket it needs is root-equivalent and belongs on a separate label.
## Docker and development environment ## Docker and development environment
+2 -1
View File
@@ -2,7 +2,8 @@
## 2026-10-24 (release publishes an image) ## 2026-10-24 (release publishes an image)
* **Creation**: [publish-image.yml](../.gitea/workflows/publish-image.yml) - a `v*` tag push builds `Dockerfile` on the arm64 runner and pushes `registry.noelsabia.dev/cv_website/nuxt` as the version, `sha-<12>`, and `latest`. Main pushes deliberately do not build: the registry holds releases, not commits. The job uses the runner's own Docker daemon (client only in the `node:22-bookworm` container), so the act_runner needs `container.docker_host: automount`; the first step fails with that cause if it is missing. Repo secrets: `REGISTRY_USERNAME`, `REGISTRY_PASSWORD`. See [Publishing images to the own registry](decisions/registry-publishing.md). * **Creation**: [publish-image.yml](../.gitea/workflows/publish-image.yml) - a `vX.Y.Z` tag push builds `Dockerfile` on the arm64 runner and pushes `registry.noelsabia.dev/cv_website/nuxt` as the version and `sha-<12>`, plus `latest` when that tag is the newest release. Main pushes deliberately do not build: the registry holds releases, not commits. The job uses the runner's own Docker daemon (client only in the `node:22-bookworm` container), so the act_runner needs `container.docker_host: automount`; the first step fails with that cause if it is missing. That socket is root-equivalent, so it may only sit on a label PR jobs cannot use - recorded under the trust boundary in [Publishing images to the own registry](decisions/registry-publishing.md). Repo secrets: `REGISTRY_USERNAME`, `REGISTRY_PASSWORD`.
* **Review follow-up** (PR #19, 1 BLOCKER + 4 WARN + 2 NIT): applied the strict `vMAJOR.MINOR.PATCH` check, the newest-release rule for `latest`, a smoke test that starts the image and requires 2xx on `/`, and `timeout-minutes: 20`. Rejected with evidence: the `.dockerignore` leak (`.env*`, `*.pem`, `.git` are excluded) and the Docker-client/daemon API mismatch (20.10.24 client against a 29.9.2 daemon built successfully over the socket).
## 2026-10-23 (PR #16 review checked, three findings applied) ## 2026-10-23 (PR #16 review checked, three findings applied)
* **Update**: [pr-checker.yml](../.gitea/workflows/pr-checker.yml) - the review prompt now states that `pnpm-lock.yaml` is excluded from `.pr-review-diff.patch` on purpose. The reviewer read the exclusion as an uncommitted lockfile and raised a false BLOCKER; the lockfile is in the PR and matches `package.json`. * **Update**: [pr-checker.yml](../.gitea/workflows/pr-checker.yml) - the review prompt now states that `pnpm-lock.yaml` is excluded from `.pr-review-diff.patch` on purpose. The reviewer read the exclusion as an uncommitted lockfile and raised a false BLOCKER; the lockfile is in the PR and matches `package.json`.