ci-image-pin accepts any hex length, not the exact 7-char tag ci-image.yml publishes #594

Closed
opened 2026-07-25 12:00:10 +02:00 by timothy · 2 comments
Owner

Surfaced by the adversarial review of PR #591 (#445/#533). Pre-existing — not introduced by that PR, which is why it was deferred rather than widened into it.

Problem

ci-image-pin (.gitea/workflows/pr-checks.yml) validates the toolchain pin like this:

mapfile -t pins < <(grep -oE 'ersatztv-ci:[0-9a-f]+' .gitea/workflows/docker-build.yml | cut -d: -f2 | sort -u)
...
pin_full="$(git rev-parse --verify --quiet "${pins[0]}^{commit}" || true)"
if [ "$pin_full" != "$expected" ]; then ... fi

It checks that the pin resolves to the right commit, but not that it is the exact abbreviation ci-image.yml actually publishes. ci-image.yml tags the image with git rev-parse --short HEAD computed under fetch-depth: 1, which yields 7 characters. A full clone yields 8 (the guard's own comment documents this asymmetry, and correctly compares resolved full shas to avoid a false red).

Failure mode

An 8-char (or 9-, 10-char) pin resolves to the correct commit, so ci-image-pin passes green — but no such tag exists in the registry. The failure then lands much later and much less clearly: all five container: jobs fail at image-pull time with a manifest-unknown error, which reads as a registry/infra problem rather than "your pin has one character too many."

This is a realistic mistake precisely because the natural local command (git rev-parse --short HEAD) prints 8 chars in a full clone. On PR #591 I had to know to truncate to 7 by hand, then confirm against the registry that ersatztv-ci:e9fd26f actually existed.

Suggested fix

Tighten the guard so a wrong-length pin fails at the gate, where the message can be actionable:

# ci-image.yml tags from a fetch-depth:1 clone -> always 7 chars.
if [ "${#pins[0]}" -ne 7 ]; then
  echo "::error::Pin ersatztv-ci:${pins[0]} is ${#pins[0]} chars; ci-image.yml publishes 7-char tags. A longer abbreviation resolves to the right commit but matches NO registry tag, so all five container jobs will fail at pull time. Use: git rev-parse --short=7 HEAD"
  exit 1
fi

Optionally stronger: query the registry tag list and assert the pinned tag actually exists — that checks the real invariant ("this image is pullable") rather than a proxy for it. Needs registry creds in that job, which currently has none, so the length check is the cheap 90%.

Implementation notes (2026-07-25, PR #598):

  • Implemented as suggested, with the check placed after the count check and before the resolve/staleness checks, so the most actionable diagnosis wins.
  • Uses a literal 7, deliberately not a derived git rev-parse --short=7 "$expected": in the guard's full clone git may widen an ambiguous abbreviation past 7, which would demand a pin ci-image.yml can never publish — the same clone-depth asymmetry the existing comment warns about. ${expected:0:7} (plain string truncation) is used for the suggestion instead.
  • An escape hatch is documented inline: because 7 is now mandatory, a hypothetical ambiguous 7-char prefix would deadlock the gate with no in-repo remedy. Relax the length check in that case, and say why.
  • Also fixed a pre-existing misdiagnosis found in review: zero pins (grep matched nothing) reported "pins MORE THAN ONE", the opposite diagnosis. Now has its own branch.
  • The publisher side is not yet enforced — ci-image.yml still tags with a plain auto-scaled --short, so "always 7" remains an empirical property of today's shallow clone. Tracked as #597; it cannot ride this PR because editing ci-image.yml re-points this guard's own expected at that commit and needs a publish-then-pin cycle.

Done-when

  • ci-image-pin fails on a pin whose length is not what ci-image.yml publishes, with an actionable message
  • Verified by a deliberately-wrong-length pin on a throwaway branch (must go red at the gate, not at image pull) — throwaway PR #599, run 1352: 8-char pin 4263cf79 → RED at ci-image-pin with ❌ Failure - Main Verify the pin matches the last-published image. Log confirms it cleared the count check and stopped at the length check — the resolve/staleness errors never fired, because that pin is a valid abbreviation of the correct commit. Positive control: #598's own ci-image-pin is green on the 7-char pin. Probe PR closed and branch deleted.
  • docs/ci-cd.md -> "CI toolchain image" states the exact expected tag length and the --short=7 command — plus a caveat block flagging that 7 is currently empirical (#597)
  • Adversarial review passed — two rounds; round 2 MERGEABLE @ c8e79f49

PR: #598

Surfaced by the adversarial review of PR #591 (#445/#533). **Pre-existing** — not introduced by that PR, which is why it was deferred rather than widened into it. ## Problem `ci-image-pin` (`.gitea/workflows/pr-checks.yml`) validates the toolchain pin like this: ```bash mapfile -t pins < <(grep -oE 'ersatztv-ci:[0-9a-f]+' .gitea/workflows/docker-build.yml | cut -d: -f2 | sort -u) ... pin_full="$(git rev-parse --verify --quiet "${pins[0]}^{commit}" || true)" if [ "$pin_full" != "$expected" ]; then ... fi ``` It checks that the pin **resolves to the right commit**, but not that it is the **exact abbreviation `ci-image.yml` actually publishes**. `ci-image.yml` tags the image with `git rev-parse --short HEAD` computed under `fetch-depth: 1`, which yields **7** characters. A full clone yields 8 (the guard's own comment documents this asymmetry, and correctly compares resolved full shas to avoid a false red). ## Failure mode An 8-char (or 9-, 10-char) pin resolves to the correct commit, so `ci-image-pin` passes **green** — but no such tag exists in the registry. The failure then lands much later and much less clearly: all five `container:` jobs fail at image-pull time with a manifest-unknown error, which reads as a registry/infra problem rather than "your pin has one character too many." This is a realistic mistake precisely because the natural local command (`git rev-parse --short HEAD`) prints 8 chars in a full clone. On PR #591 I had to know to truncate to 7 by hand, then confirm against the registry that `ersatztv-ci:e9fd26f` actually existed. ## Suggested fix Tighten the guard so a wrong-length pin fails at the gate, where the message can be actionable: ```bash # ci-image.yml tags from a fetch-depth:1 clone -> always 7 chars. if [ "${#pins[0]}" -ne 7 ]; then echo "::error::Pin ersatztv-ci:${pins[0]} is ${#pins[0]} chars; ci-image.yml publishes 7-char tags. A longer abbreviation resolves to the right commit but matches NO registry tag, so all five container jobs will fail at pull time. Use: git rev-parse --short=7 HEAD" exit 1 fi ``` Optionally stronger: query the registry tag list and assert the pinned tag actually exists — that checks the real invariant ("this image is pullable") rather than a proxy for it. Needs registry creds in that job, which currently has none, so the length check is the cheap 90%. > **Implementation notes (2026-07-25, PR #598):** > - Implemented as suggested, with the check placed **after** the count check and **before** the resolve/staleness checks, so the most actionable diagnosis wins. > - Uses a **literal 7**, deliberately not a derived `git rev-parse --short=7 "$expected"`: in the guard's full clone git may widen an ambiguous abbreviation past 7, which would demand a pin `ci-image.yml` can never publish — the same clone-depth asymmetry the existing comment warns about. `${expected:0:7}` (plain string truncation) is used for the suggestion instead. > - An **escape hatch** is documented inline: because 7 is now mandatory, a hypothetical ambiguous 7-char prefix would deadlock the gate with no in-repo remedy. Relax the length check in that case, and say why. > - Also fixed a **pre-existing** misdiagnosis found in review: zero pins (grep matched nothing) reported "pins MORE THAN ONE", the opposite diagnosis. Now has its own branch. > - The publisher side is **not** yet enforced — `ci-image.yml` still tags with a plain auto-scaled `--short`, so "always 7" remains an empirical property of today's shallow clone. Tracked as **#597**; it cannot ride this PR because editing `ci-image.yml` re-points this guard's own `expected` at that commit and needs a publish-then-pin cycle. ## Done-when - [x] `ci-image-pin` fails on a pin whose length is not what `ci-image.yml` publishes, with an actionable message - [x] Verified by a deliberately-wrong-length pin on a throwaway branch (must go red at the gate, not at image pull) — throwaway PR #599, [run 1352](http://192.168.1.95:3000/timothy/ersatztv/actions/runs/1352): 8-char pin `4263cf79` → **RED at `ci-image-pin`** with `❌ Failure - Main Verify the pin matches the last-published image`. Log confirms it cleared the count check and stopped at the **length** check — the resolve/staleness errors never fired, because that pin *is* a valid abbreviation of the correct commit. Positive control: #598's own `ci-image-pin` is green on the 7-char pin. Probe PR closed and branch deleted. - [x] `docs/ci-cd.md` -> "CI toolchain image" states the exact expected tag length and the `--short=7` command — plus a caveat block flagging that 7 is currently empirical (#597) - [x] Adversarial review passed — two rounds; round 2 MERGEABLE @ c8e79f49 PR: #598
timothy added the ci-cdpriority: low labels 2026-07-25 12:00:10 +02:00
timothy added the in-progress label 2026-07-25 12:18:25 +02:00
Author
Owner

Claiming — worked as part of a CI/repo-hygiene session bundle with #586 and #485 (disjoint file sets, one PR).

Claiming — worked as part of a CI/repo-hygiene session bundle with #586 and #485 (disjoint file sets, one PR).
Author
Owner

Closing record

Outcome: Shipped in PR #598 (merged). ci-image-pin now checks the pin's length as an invariant separate from its correctness, failing at the gate with a message naming the exact tag and command. Also fixed a pre-existing misdiagnosis: zero pins reported "pins MORE THAN ONE". Swept with #586 and #485.

Root cause: The guard verified that the pin resolves to the right commit, but not that it is the abbreviation ci-image.yml actually publishes. Those are two different invariants, and only the first was checked — so a correct-commit-wrong-length pin passed every check while matching no registry tag.

Decisions/conventions changed: None — this implements an existing convention (docs/ci-cd.md → "CI toolchain image") rather than establishing one. Added a caveat block there recording that 7 is currently empirical, not enforced.

Reusable knowledge:

  • A resolve-and-compare check cannot catch a wrong-length abbreviation, because every abbreviation of a commit resolves to that commit. The failure lands far downstream as five container: jobs dying at image-pull with manifest unknown — which reads like a registry outage, not a one-character pin error. Length needs its own check.
  • Don't derive the expected tag with git rev-parse --short=7. In the guard's full clone git may widen an ambiguous abbreviation past 7, demanding a pin ci-image.yml (a fetch-depth: 1 clone) can never publish. Use plain string truncation ${expected:0:7} for the suggestion. This is the same clone-depth asymmetry the guard's original comment already warned about.
  • ci-image.yml is one of the paths ci-image-pin watches (git log -1 -- docker/ci .gitea/workflows/ci-image.yml). So any commit editing it becomes the new expected and immediately stales the pin, reddening the gate — which is why the publisher-side fix needs its own publish-then-pin cycle (#597). Not blocked, just two commits; ci-image.yml's push trigger has no branches: filter, so a feature branch does publish.
  • Making 7 mandatory removes an escape hatch. If ${expected:0:7} were ever an ambiguous prefix, a longer pin — previously the workaround — is now rejected first, with no in-repo remedy. Documented inline.

Verification: Guard exercised two ways. (a) Locally: step body extracted from the YAML by real parse, run against doctored pins — 7 green, 6/8/10 red, each naming the correct tag, docker-build.yml restored clean. (b) In CI, as the Done-when box required: throwaway PR #599 with an 8-char pin went red at the gate (run 1352) with ❌ Failure - Main Verify the pin matches the last-published image; the log shows it cleared the count check and stopped at the length check — the resolve/staleness errors never fired, because that pin is a valid abbreviation of the correct commit. Positive control: #598's own ci-image-pin green on the 7-char pin. Probe PR closed, branch deleted. Two-round cold review, MERGEABLE @ c8e79f49.

Deferred: #597 — make ci-image.yml tag with --short=7 so the length is enforced on the publisher side rather than observed.

Docs updated: docs/ci-cd.md → "CI toolchain image" (exact tag length, the --short=7 command, and the empirical-not-invariant caveat).

## Closing record **Outcome:** Shipped in PR #598 (merged). `ci-image-pin` now checks the pin's **length** as an invariant separate from its correctness, failing at the gate with a message naming the exact tag and command. Also fixed a pre-existing misdiagnosis: zero pins reported "pins MORE THAN ONE". Swept with #586 and #485. **Root cause:** The guard verified that the pin *resolves to the right commit*, but not that it is the abbreviation `ci-image.yml` actually publishes. Those are two different invariants, and only the first was checked — so a correct-commit-wrong-length pin passed every check while matching no registry tag. **Decisions/conventions changed:** None — this implements an existing convention (`docs/ci-cd.md` → "CI toolchain image") rather than establishing one. Added a caveat block there recording that 7 is currently *empirical*, not enforced. **Reusable knowledge:** - **A resolve-and-compare check cannot catch a wrong-length abbreviation**, because every abbreviation of a commit resolves to that commit. The failure lands far downstream as five `container:` jobs dying at image-pull with `manifest unknown` — which reads like a registry outage, not a one-character pin error. Length needs its own check. - **Don't derive the expected tag with `git rev-parse --short=7`.** In the guard's *full* clone git may widen an ambiguous abbreviation past 7, demanding a pin `ci-image.yml` (a `fetch-depth: 1` clone) can never publish. Use plain string truncation `${expected:0:7}` for the suggestion. This is the same clone-depth asymmetry the guard's original comment already warned about. - **`ci-image.yml` is one of the paths `ci-image-pin` watches** (`git log -1 -- docker/ci .gitea/workflows/ci-image.yml`). So any commit editing it becomes the new `expected` and immediately stales the pin, reddening the gate — which is why the publisher-side fix needs its own publish-then-pin cycle (#597). Not blocked, just two commits; `ci-image.yml`'s push trigger has no `branches:` filter, so a feature branch does publish. - **Making 7 mandatory removes an escape hatch.** If `${expected:0:7}` were ever an ambiguous prefix, a longer pin — previously the workaround — is now rejected first, with no in-repo remedy. Documented inline. **Verification:** Guard exercised two ways. (a) Locally: step body extracted from the YAML by real parse, run against doctored pins — 7 green, 6/8/10 red, each naming the correct tag, `docker-build.yml` restored clean. (b) In CI, as the Done-when box required: throwaway PR #599 with an 8-char pin went **red at the gate** ([run 1352](http://192.168.1.95:3000/timothy/ersatztv/actions/runs/1352)) with `❌ Failure - Main Verify the pin matches the last-published image`; the log shows it cleared the count check and stopped at the *length* check — the resolve/staleness errors never fired, because that pin is a valid abbreviation of the correct commit. Positive control: #598's own `ci-image-pin` green on the 7-char pin. Probe PR closed, branch deleted. Two-round cold review, MERGEABLE @ c8e79f49. **Deferred:** #597 — make `ci-image.yml` tag with `--short=7` so the length is enforced on the publisher side rather than observed. **Docs updated:** `docs/ci-cd.md` → "CI toolchain image" (exact tag length, the `--short=7` command, and the empirical-not-invariant caveat).
timothy removed the in-progress label 2026-07-25 13:53:00 +02:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: timothy/ersatztv#594