fix(744,835): review round 3 — the filter is REF-SUPPLIED, so this closes drive-by only
Round 3 (two independent cold reviews, both BLOCKED, no blocker/high between them except one guard escape) found the security framing itself overstated. **The `branches:` filter is loaded from the pushed ref, like every other line in the file.** A branch whose `ci-image.yml` deletes the filter fires exactly as before, on the same runner, with the same credential. The mechanism this change is built on — "Gitea resolves a push workflow's definition from the pushed ref" — applies to the fix as much as to the hole, and three bolded sentences said "closes that route" without noticing. What is actually closed is the DRIVE-BY case: publication as a side effect of an ordinary push of a legitimate `docker/ci` change, no deliberate act anywhere. That is real and worth closing, and it is not a boundary against someone who intends to run their own YAML. Corrected in the workflow, ci-cd.md and the record's `rule:` and bullet 1, with an explicit "do not cite this record as that boundary"; #853 updated to lead with it, and a scope note posted on #744 because the issue body frames the fix more strongly than it delivers. **Three more spellings of `actions/checkout` escaped both halves of the guard**, in the same class as rounds 1 and 2: a `.git` suffix (which is how Gitea itself writes the clone URL), `@`-userinfo before the host (splitting on the FIRST `@` stripped the host, not the version), and a doubled slash. Canonicalisation now rsplits, drops a `.git`, and absorbs empty segments; all seven spellings are pinned. Two more absence tests so the remaining boundaries report themselves instead of going blind: no job delegates to a reusable workflow (both halves would see zero and AGREE, so the count cross-check cannot report it), and nothing tracked under `.github/workflows` — which Gitea reads only when `.gitea/workflows` is absent, an unprobed precedence rule, in a directory that already exists here. Also: "had to land alone" / "forced this change to land alone" still carried the necessity premise round 2 retracted — landing alone was the cheaper option, not the only one; `ci-image-pin` was called "blocking" as though branch protection required it (it does not — the block comes from the merge-consent hook reading the COMBINED status); the pin step was still named "Verify the pin matches the last-published image" while doing no registry query at all; ci-cd.md still documented `expected` as `docker/ci/**` or `ci-image.yml`; `release.main-direct-push-disabled` carried its own stale 15-of-16 count; the ordering constraint said "below" where "in that commit or below it" is correct; and the #854 deferral undercounted the stale Dockerfile comments at one when there are two. refs #744 refs #835 Decisions-Edit: yes
This commit is contained in:
@@ -15,10 +15,11 @@ name: Build CI Toolchain Image
|
||||
#
|
||||
# ROLLOUT NOTE: the jobs pin an immutable :<sha>, never :latest — a broken toolchain image would
|
||||
# otherwise block every converted job the moment it was pushed. Bumping the toolchain is a deliberate
|
||||
# two-step, and since ersatztv#744 BOTH steps land in the SAME PR: publish (push the docker/ci commit
|
||||
# as branch HEAD, dispatch this workflow on that branch), then commit the pin bump in
|
||||
# docker-build.yml. Merging first is not available — `ci-image-pin` is blocking, so a PR that changes
|
||||
# docker/ci/** without moving the pin is red.
|
||||
# two-step, and BOTH steps land in the SAME PR: publish (push the docker/ci commit as branch HEAD,
|
||||
# dispatch this workflow on that branch), then commit the pin bump in docker-build.yml. Merging first
|
||||
# is not available: a PR that changes docker/ci/** without moving the pin turns `ci-image-pin` red,
|
||||
# and the merge-consent hook reads the COMBINED commit status, so it will not auto-grant. That much
|
||||
# predates ersatztv#744 — what #744 changed is how the publish half is performed.
|
||||
# See docs/ci-cd.md -> "Publishing from a branch is a dispatch, not a push".
|
||||
#
|
||||
# Like docker-build.yml: the Gitea registry is HTTP-only, so BuildKit needs the inline
|
||||
@@ -29,15 +30,20 @@ on:
|
||||
# Gitea resolves a `push` workflow's definition from the pushed branch, so an unfiltered `push`
|
||||
# trigger ran this file's own YAML — attacker-supplied, unreviewed, with no status check in the
|
||||
# loop — on a docker-capable runner holding the credential that writes `ersatztv:prod` and the
|
||||
# `ersatztv-ci:<sha>` five `container:` jobs execute. `branches: [main]` closes that route.
|
||||
# `workflow_dispatch` is still self-supplied from the selected branch and is the deliberate
|
||||
# publish path (docs/ci-cd.md -> "CI toolchain image"); it takes someone who already has write
|
||||
# access rather than falling out of an ordinary branch push.
|
||||
# `ersatztv-ci:<sha>` five `container:` jobs execute.
|
||||
#
|
||||
# A TAG push does not match this trigger either: Gitea's matcher gives a `branches:`-only filter no
|
||||
# match for a non-branch ref, and there is no `tags:` key to satisfy instead. So a release cut no
|
||||
# longer republishes the toolchain image as a side effect — which it could before, when `paths:`
|
||||
# was the only filter.
|
||||
# BE PRECISE ABOUT WHAT THIS BUYS, because the mechanism cuts both ways: the filter below is read
|
||||
# from the pushed ref like everything else in this file, so a branch that DELETES it re-enables
|
||||
# the route. What closes is the DRIVE-BY case — an ordinary push of a legitimate `docker/ci`
|
||||
# change publishing an image nobody asked for, with no deliberate act anywhere. This is NOT a
|
||||
# boundary against a malicious or compromised writer and must not be cited as one; that class is
|
||||
# ersatztv#853. `workflow_dispatch` is self-supplied from the selected branch in the same way, and
|
||||
# is the deliberate publish path (docs/ci-cd.md -> "CI toolchain image").
|
||||
#
|
||||
# A `v*` tag push does not match this trigger either: there is no `tags:` key, and a `branches:`
|
||||
# filter is compared against a branch ref. The exact matcher semantics are not probed here; the
|
||||
# observable claim is the one that matters — a release cut no longer republishes the toolchain
|
||||
# image as a side effect.
|
||||
#
|
||||
# `.gitea/workflows/ci-image.yml` is NOT in `paths:`, and it left `ci-image-pin`'s `expected` in
|
||||
# the same change. That pairing is a DECIDED TRADEOFF, not a necessity: keeping it works, because
|
||||
|
||||
@@ -74,7 +74,7 @@ jobs:
|
||||
# need real history: `git log -- <path>` on a shallow clone can't find the last
|
||||
# commit that touched the image sources
|
||||
fetch-depth: 0
|
||||
- name: Verify the pin matches the last-published image
|
||||
- name: Verify the pin matches the image-source commit
|
||||
run: |
|
||||
set -euo pipefail
|
||||
# ci-image.yml tags the image `git rev-parse --short HEAD` of the run that built it. Only
|
||||
|
||||
+7
-5
@@ -1805,8 +1805,10 @@ consuming branch never carries the `docker/ci` commit through a rebase.
|
||||
> **`docker/ci/**` has no cheap-edit path, comments included.** Editing any byte there re-points
|
||||
> `ci-image-pin`'s `expected` at the editing commit, so the five `container:` pins go stale and a
|
||||
> blocking job fails — a one-line comment fix costs a full publish-and-repin, and a rebase charges it
|
||||
> again. Ride prose fixes in that directory with the next genuine toolchain bump. The stale
|
||||
> publish instruction still in `docker/ci/Dockerfile` is #854, deferred on exactly these grounds.
|
||||
> again. Ride prose fixes in that directory with the next genuine toolchain bump. The TWO stale
|
||||
> publish instructions still in `docker/ci/Dockerfile` — the `PLAYWRIGHT_VERSION` bump comment, and
|
||||
> the rebase warning's "re-dispatching does not help", which is now the opposite of the documented
|
||||
> recovery — are #854, deferred on exactly these grounds.
|
||||
|
||||
**A change that lives only in `ci-image.yml` publishes nothing.** That file is no longer one of its
|
||||
own trigger paths, nor one of `ci-image-pin`'s `expected` paths. That pairing is a **decided
|
||||
@@ -1952,9 +1954,9 @@ what it establishes is the auth + HTTP-registry push path, not the toolchain bui
|
||||
|
||||
**Bumping the pin is enforced, not remembered.** The `ci-image-pin` job (blocking, PR-only; defined
|
||||
in `pr-checks.yml`, but it greps `docker-build.yml` where the pins live) fails if
|
||||
`docker-build.yml`'s pin isn't the short sha of the last commit to touch `docker/ci/**` or
|
||||
`ci-image.yml`, if that pin isn't exactly 7 chars long (see above), or if the five jobs ever pin
|
||||
different tags. This exists because **Renovate manages
|
||||
`docker-build.yml`'s pin isn't the short sha of the last commit to touch `docker/ci/**` (since
|
||||
ersatztv#744 that path alone — `ci-image.yml` is deliberately not part of it), if that pin isn't
|
||||
exactly 7 chars long (see above), or if the five jobs ever pin different tags. This exists because **Renovate manages
|
||||
`docker/ci/Dockerfile`'s base pins but cannot bump an opaque `:<sha>`** in `container.image` — so a
|
||||
Renovate base bump would otherwise publish a new image, test the *old* one, and merge with the
|
||||
Dockerfile disagreeing with the pin. A red `ci-image-pin` means: dispatch `ci-image.yml` on the
|
||||
|
||||
@@ -65,7 +65,7 @@ the link for rationale. Superseded/retired history lives in `archive/`. Regenera
|
||||
| `ci.script-tests-job` | The `scripts/tests/` pytest suite runs on every PR as a dedicated `script-tests` job in `pr-checks.yml` (`runs-on: small`, `setup-python` + `pip install pytest pyyaml`, `PYTHONPATH=. python3 -m pytest scripts/tests -q`; since #780 it also runs a pinned ruff over a `git ls-files` population first), unconditionally rather than behind a `scripts/**` path filter, and **never as a step inside `decisions-guard`** — a job whose reds a standing rule instructs sessions to ignore must never host a gate whose reds are real. Any new CI gate must be reachable by a failure that is unambiguously attributable to it. | 2026-07-26 | [link](records/ci/script-tests-job.md) |
|
||||
| `ci.shared-pr-file-enumeration` | A PR's complete set of changed file paths is computed by exactly one implementation, `scripts/pr-changed-files.sh`, called by both `.claude/hooks/pretooluse-merge-consent.sh` (advisory — a failure falls through to a human prompt) and `.gitea/workflows/review-verdict.yml` (enforced — a failure must fail closed, because a match here posts the branch-protection-required `review-verdict/h10` status with nobody in the loop). The script owns exhaustiveness (pagination, rename/path validation, head-sha binding, base-ref binding — see `ci.exemption-provenance` — and base-TIP binding, #707: the ref answers "did this PR RETARGET", the tip answers "did the base ADVANCE mid-enumeration", and only the second can see `/pulls/{n}/files` recomputing each offset-paged page against a moved base and dropping a path out of an already-consumed range; both ends of the window are bound, and an advance BEFORE the window is deliberately not an error, or ordinary churn on `main` would fail every open PR) and returns exit 0 only for a verified-complete list; it does NOT classify paths — each caller keeps its own docs-only allow-list, and the two allow-lists differ on purpose and stay separate. | 2026-07-26 | [link](records/ci/shared-pr-file-enumeration.md) |
|
||||
| `ci.small-lane-git-only` | `runs-on: small` is defined by what a job does (git-only), not its usual runtime; the two `docker build` jobs (docker-build.yml, ci-image.yml) move to `ubuntu-latest` because their worst-case memory, not median runtime, was pinning the small lane's per-slot cap. | 2026-07-20 | [link](records/ci/small-lane-git-only.md) |
|
||||
| `ci.toolchain-image-publish-is-a-dispatch` | A `push` trigger reachable from any ref other than `main` — that is `branches:` AND `tags:`, judged by the ref class it admits and never by which keyword is present — executes ref-supplied YAML, because Gitea resolves a `push` workflow's definition from the pushed ref — so `ci-image.yml` is `branches: [main]`, and publishing a toolchain image from a feature branch is a deliberate `workflow_dispatch` on that branch rather than a side effect of pushing. The self-referencing trigger path `.gitea/workflows/ci-image.yml` came out of BOTH its own `paths:` and `ci-image-pin`'s `expected` in the same change — a DECIDED tradeoff, not a necessity: keeping it is workable via the branch dispatch, but prices every edit to that file, comments included, at a ~2GB publish plus a five-pin bump, redone after every rebase. The cost is stated, not assumed away — a change to HOW the image is built that lives only in `ci-image.yml` no longer republishes, and the ONLY remedy is to make it alongside a `docker/ci/**` edit: publishing after the merge and then pinning cannot work, because `expected` is the last `docker/ci` commit and would reject that pin. This closes the push route INTO THIS FILE, not the class: `docker-build.yml` remains reachable from an arbitrary ref by a `v*` tag push and by `pull_request`, and four workflows carry an unrestricted `workflow_dispatch` (#853). | 2026-08-27 | [link](records/ci/toolchain-image-publish-is-a-dispatch.md) |
|
||||
| `ci.toolchain-image-publish-is-a-dispatch` | A `push` trigger reachable from any ref other than `main` — that is `branches:` AND `tags:`, judged by the ref class it admits and never by which keyword is present — executes ref-supplied YAML, because Gitea resolves a `push` workflow's definition from the pushed ref — so `ci-image.yml` is `branches: [main]`, and publishing a toolchain image from a feature branch is a deliberate `workflow_dispatch` on that branch rather than a side effect of pushing. Be precise about what a `branches:` filter buys: it is loaded from the pushed ref like the rest of the file, so a branch that deletes it re-enables the route — this removes the DRIVE-BY case, and is not a boundary against a writer who intends to run their own YAML. The self-referencing trigger path `.gitea/workflows/ci-image.yml` came out of BOTH its own `paths:` and `ci-image-pin`'s `expected` in the same change — a DECIDED tradeoff, not a necessity: keeping it is workable via the branch dispatch, but prices every edit to that file, comments included, at a ~2GB publish plus a five-pin bump, redone after every rebase. The cost is stated, not assumed away — a change to HOW the image is built that lives only in `ci-image.yml` no longer republishes, and the ONLY remedy is to make it alongside a `docker/ci/**` edit: publishing after the merge and then pinning cannot work, because `expected` is the last `docker/ci` commit and would reject that pin. This closes the push route INTO THIS FILE, not the class: `docker-build.yml` remains reachable from an arbitrary ref by a `v*` tag push and by `pull_request`, and four workflows carry an unrestricted `workflow_dispatch` (#853). | 2026-08-27 | [link](records/ci/toolchain-image-publish-is-a-dispatch.md) |
|
||||
| `ci.ui-e2e-harness` | The UI-interactive E2E flows run as headless Playwright specs (`web/e2e/*.spec.ts`, driven by `scripts/e2e-ui.sh`) in a **second step of the existing advisory `functional-e2e` job**, never their own job; the browser is `chromium-headless-shell` **baked into the CI toolchain image** (`docker/ci/Dockerfile`, `PLAYWRIGHT_VERSION` kept equal to `web/package.json`'s EXACT `@playwright/test` pin), never installed per run; specs are `serial` with `retries: 0` and assert only contracts the curl harness structurally cannot reach. | 2026-07-25 | [link](records/ci/ui-e2e-harness.md) |
|
||||
| `ci.verdict-write-retarget-fence` | The `review-verdict/h10` job counts `change_target_branch` events on the PR's issue timeline at run start and again immediately before its POST, and writes NOTHING if the count moved. The COUNT is the key because the branch NAME is ABA-vulnerable — `main -> S -> main` reads `main` at both ends, which is how #698 route 1 obtained a forged exemption — while the event count is monotonic and cannot alias. This NARROWS the residual, it does not resolve it — a retarget between the FINAL pre-write count and the POST still yields a PERMANENT forged green, because the successor run can consume the `edited` event and exit before the stale run posts last (corrected 2026-08-27, #849). Abstaining is a handoff, not a stall, and that is the property the design rests on — for a run that ABSTAINS; it says nothing about one that already passed its final count and then posts (see the residual, corrected #849): every retarget fires `edited`, which is in this workflow's `types:`, so the event that makes a run abstain has already queued a successor whose window opens after it; the induction terminates when retargeting stops — but ONLY over runs that ABSTAIN. A run that already passed its final count is outside it: it writes whenever it gets there, so the run that writes LAST is not necessarily the one that classified last, and that is the permanent residual (#849). `updated_at` was REJECTED as the key because it also moves for comments and labels, which fire none of this workflow's `types:` — a run could abstain with no successor coming, which is a real stall. The count is trusted only when paging reached a validated EMPTY page; an untrusted count (unreadable page, non-array body, non-numeric length, page cap hit) blocks the exemption `success` ONLY and still lets `pending` through, because `pending` blocks the merge immediately while withholding it would strand ordinary PRs whenever the timeline is unreadable — the right trade, but NOT a free one ("for no safety gain" retracted 2026-08-27): a GENERIC `pending` masks a rejection landing in its own write window, post-write verification does not run for it, and a later run re-derives it into an exemption `success` (#849). SEPARATELY, and for the human-verdict race the fence does nothing about: after posting an exemption `success` the job re-reads `/statuses/{sha}` and, if a human `Review-verdict:` row appeared with an id ABOVE a high-water mark taken just before the POST, overwrites its own status with `pending` and logs an error. The repair is `pending`, NEVER a copy of the human's state, since re-posting their `failure` under the machine credential would attribute a human verdict to the job; its description is a SENTINEL that the classification refuses to grant an exemption over AND re-writes verbatim on every later run, so the block is a FIXED POINT rather than decaying — writing the generic `pending` description there instead erases the marker and the exemption simply returns one event later. The mark is captured BEFORE the last-moment re-read, not merely before the POST — a later mark leaves a multi-round-trip blind gap in which a verdict is neither seen by the re-read nor repaired afterwards. The id comparison is load-bearing: a mere presence test would fire forever on a base-mismatched verdict that `read_existing_verdict` deliberately declines to honour, deadlocking that PR's exemption permanently. Finally, a run whose last-moment re-read finds a sentinel it did not see at its FIRST read ABSTAINS instead of posting: that can only mean an overlapping run repaired a raced verdict mid-flight, and this run's `success` — frozen at classification time, with the human row below its own mark, so neither the fence nor the post-write check would catch it — would otherwise bury the rejection. That is the one path in this design that failed toward SUCCESS rather than `pending`. The post-write check counts TWO row shapes above the mark, not one — a human `Review-verdict:` row AND a machine sentinel — because with two overlapping runs the human row can sit BELOW the second run's mark while the first masks it and only then writes the sentinel, leaving the second to post its own `success` on top; counting the sentinel converges both runs on the fixed point instead. | 2026-08-03 | [link](records/ci/verdict-write-retarget-fence.md) |
|
||||
| `ci.verify-locally-ci-confirms` | Treat the local build/verify/review pass as the decision point and CI as confirmation — don't idle waiting on a run you have no reason to doubt. | 2026-07-21 | [link](records/ci/verify-locally-ci-confirms.md) |
|
||||
|
||||
@@ -5,7 +5,7 @@ status: active
|
||||
since: '2026-08-27'
|
||||
supersedes: none
|
||||
superseded-by: none
|
||||
rule: 'A `push` trigger reachable from any ref other than `main` — that is `branches:` AND `tags:`, judged by the ref class it admits and never by which keyword is present — executes ref-supplied YAML, because Gitea resolves a `push` workflow''s definition from the pushed ref — so `ci-image.yml` is `branches: [main]`, and publishing a toolchain image from a feature branch is a deliberate `workflow_dispatch` on that branch rather than a side effect of pushing. The self-referencing trigger path `.gitea/workflows/ci-image.yml` came out of BOTH its own `paths:` and `ci-image-pin`''s `expected` in the same change — a DECIDED tradeoff, not a necessity: keeping it is workable via the branch dispatch, but prices every edit to that file, comments included, at a ~2GB publish plus a five-pin bump, redone after every rebase. The cost is stated, not assumed away — a change to HOW the image is built that lives only in `ci-image.yml` no longer republishes, and the ONLY remedy is to make it alongside a `docker/ci/**` edit: publishing after the merge and then pinning cannot work, because `expected` is the last `docker/ci` commit and would reject that pin. This closes the push route INTO THIS FILE, not the class: `docker-build.yml` remains reachable from an arbitrary ref by a `v*` tag push and by `pull_request`, and four workflows carry an unrestricted `workflow_dispatch` (#853).'
|
||||
rule: 'A `push` trigger reachable from any ref other than `main` — that is `branches:` AND `tags:`, judged by the ref class it admits and never by which keyword is present — executes ref-supplied YAML, because Gitea resolves a `push` workflow''s definition from the pushed ref — so `ci-image.yml` is `branches: [main]`, and publishing a toolchain image from a feature branch is a deliberate `workflow_dispatch` on that branch rather than a side effect of pushing. Be precise about what a `branches:` filter buys: it is loaded from the pushed ref like the rest of the file, so a branch that deletes it re-enables the route — this removes the DRIVE-BY case, and is not a boundary against a writer who intends to run their own YAML. The self-referencing trigger path `.gitea/workflows/ci-image.yml` came out of BOTH its own `paths:` and `ci-image-pin`''s `expected` in the same change — a DECIDED tradeoff, not a necessity: keeping it is workable via the branch dispatch, but prices every edit to that file, comments included, at a ~2GB publish plus a five-pin bump, redone after every rebase. The cost is stated, not assumed away — a change to HOW the image is built that lives only in `ci-image.yml` no longer republishes, and the ONLY remedy is to make it alongside a `docker/ci/**` edit: publishing after the merge and then pinning cannot work, because `expected` is the last `docker/ci` commit and would reject that pin. This closes the push route INTO THIS FILE, not the class: `docker-build.yml` remains reachable from an arbitrary ref by a `v*` tag push and by `pull_request`, and four workflows carry an unrestricted `workflow_dispatch` (#853).'
|
||||
signals: 'unfiltered push trigger, branches filter on push, attacker YAML on a runner, feature branch publishes an image, self-referencing workflow trigger, ci-image-pin expected goes stale, publish-then-pin two-step, toolchain image recovery after a rebase, workflow_dispatch on a branch · paths: `.gitea/workflows/ci-image.yml`, `.gitea/workflows/pr-checks.yml`, `.gitea/workflows/docker-build.yml`, `docker/ci/Dockerfile`, `docs/ci-cd.md`, `docs/decisions/records/ci/actions-credential-scoping.md`, `scripts/e2e-ui.sh` · issues: #744, #853, #697, #746, #835, #445, #390, #594, #597'
|
||||
mechanics: '`docs/ci-cd.md` -> "CI toolchain image" -> "Publishing from a branch is a dispatch, not a push"'
|
||||
---
|
||||
@@ -16,9 +16,13 @@ mechanics: '`docs/ci-cd.md` -> "CI toolchain image" -> "Publishing from a branch
|
||||
`push` workflow's definition from the pushed branch — so any branch push touching `docker/ci/**` or
|
||||
the workflow file ran that branch's own YAML, with no PR, no review and no status check in the loop,
|
||||
on a docker-capable runner holding the credential that writes `ersatztv:prod` and the
|
||||
`ersatztv-ci:<sha>` that five `container:` jobs execute. `branches: [main]` closes it.
|
||||
`workflow_dispatch` remains self-supplied from the selected branch and is not equivalent: it takes a
|
||||
deliberate act by someone who already has write access.
|
||||
`ersatztv-ci:<sha>` that five `container:` jobs execute. `branches: [main]` closes the **drive-by**
|
||||
route, and only that: the filter is loaded from the pushed ref like every other line in the file, so
|
||||
a branch that deletes it re-enables the route in one edit. What goes away is publication as a side
|
||||
effect of an ordinary push of a legitimate change — a real and frequently-trodden path, and not a
|
||||
boundary against someone who intends to run their own YAML. Do not cite this record as that
|
||||
boundary. `workflow_dispatch` is self-supplied from the selected branch in the same way, and is now
|
||||
the deliberate publish path.
|
||||
- **The capability removed was real, so it is replaced rather than argued away.** An earlier attempt
|
||||
(#697) justified the filter with "publishing from a feature branch was not load-bearing", which is
|
||||
false: `ci-image-pin` is blocking, so a PR changing `docker/ci/**` without moving the pin is red, and
|
||||
@@ -32,8 +36,8 @@ mechanics: '`docs/ci-cd.md` -> "CI toolchain image" -> "Publishing from a branch
|
||||
workable *because* the branch dispatch survives — push the ci-image.yml commit as HEAD, dispatch,
|
||||
pin it — so the necessity argument does not hold. What does hold is the price: that route charges a
|
||||
full ~2GB publish plus a five-pin bump for **every** edit to the file, a comment included, and a
|
||||
rebase charges it again. That price is what reverted #697's attempt and what forced this change to
|
||||
land alone. Dropping it prices the opposite risk instead (the bullet below). The second was chosen
|
||||
rebase charges it again. That price is what reverted #697's attempt and what made landing this change
|
||||
alone the cheaper option. Dropping it prices the opposite risk instead (the bullet below). The second was chosen
|
||||
because `ci-image.yml` is edited far more often for triggers, comments and runner placement than for
|
||||
build recipe, so the first cost is paid constantly and the second only on a change that can be
|
||||
paired with a `docker/ci` touch deliberately.
|
||||
|
||||
@@ -67,7 +67,7 @@ ordering is the part worth keeping, as a rule for the next time: unmask the depe
|
||||
then set the flag. Under `|| true` a credential regression does not fail the job — it yields an empty
|
||||
changed-file set that the skip logic reads as "nothing changed". The population is also wider than the
|
||||
six checkouts #743 recorded: eight in `docker-build.yml`, five in `pr-checks.yml`, one in
|
||||
`dependency-scan.yml`, plus `review-verdict.yml`'s pre-existing one — 15 of the repo's 16. Details in
|
||||
`dependency-scan.yml`, plus `review-verdict.yml`'s pre-existing one — 15 of the repo's 16; the sixteenth, `ci-image.yml`'s, followed in #744. Details in
|
||||
`ci.actions-credential-scoping`.
|
||||
|
||||
**Why this is not redundant with the Husky pre-push hooks.** `.husky/pre-push` guards (H6 done-when,
|
||||
|
||||
@@ -17,6 +17,11 @@ POPULATION. The git index, via `tracked_files.tracked_paths` — not a filesyste
|
||||
hand-written list (`testing.guard-derives-population-from-source`, ersatztv#806). Both `*.yml` and
|
||||
`*.yaml` are matched: Gitea accepts either spelling, so a `.yaml` workflow would otherwise be
|
||||
structurally invisible to a check that reads as covering all of them.
|
||||
|
||||
`.github/workflows` is OUT of the population and is asserted empty rather than assumed so: Gitea
|
||||
reads it only when `.gitea/workflows` is absent, which is a precedence rule this repo has not probed,
|
||||
and `.github/` already exists here (ISSUE_TEMPLATE), so it is a plausible place to add a workflow by
|
||||
habit. `test_no_workflow_hides_in_a_SUBDIRECTORY` covers nesting below `.gitea/workflows`.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
@@ -40,7 +45,7 @@ CHECKOUT = "actions/checkout"
|
||||
# Matches the `uses:` line the YAML walk is supposed to reach, in every spelling below. Used ONLY as
|
||||
# an independent second opinion on how many there are — never as the population itself.
|
||||
_USES_CHECKOUT = re.compile(
|
||||
r"^\s*-?\s*uses:\s*['\"]?(?:[^'\"\s]*/)?actions/checkout(@|\s|['\"]|$)",
|
||||
r"^\s*-?\s*uses:\s*['\"]?(?:[^'\"\s]*/)?actions/checkout(?:\.git)?(@|\s|['\"]|$)",
|
||||
re.M | re.I,
|
||||
)
|
||||
|
||||
@@ -56,12 +61,20 @@ def _canonical_action(uses: str) -> str:
|
||||
It over-matches in one direction on purpose: a genuinely different action whose path happens to
|
||||
END in `actions/checkout` would be treated as a checkout and required to carry the flag. That
|
||||
costs a spurious requirement on an action nobody has; the opposite error costs a live credential.
|
||||
Spellings normalised here, each of which escaped an earlier version of this function: an absolute
|
||||
URL with or without a scheme, a host with no dot, a doubled slash, `@`-userinfo before the host,
|
||||
a `.git` suffix, and any letter case.
|
||||
"""
|
||||
ref = uses.strip().strip("'\"").split("@", 1)[0].strip().lower()
|
||||
# rsplit, not split: a URL may carry userinfo (`https://user@host/actions/checkout@v4`), and
|
||||
# splitting on the FIRST `@` would strip the host instead of the version.
|
||||
ref = uses.strip().strip("'\"").rsplit("@", 1)[0].strip().lower()
|
||||
ref = re.sub(r"^https?://", "", ref)
|
||||
# Empty segments absorb a doubled slash; `.git` is how Gitea itself writes the clone URL.
|
||||
segments = [seg for seg in ref.split("/") if seg]
|
||||
if segments:
|
||||
segments[-1] = re.sub(r"\.git$", "", segments[-1])
|
||||
if ref.startswith("./") or ref.startswith("../") or len(segments) < 2:
|
||||
return ref
|
||||
return "/".join(segments) if segments else ref
|
||||
return "/".join(segments[-2:])
|
||||
|
||||
|
||||
@@ -72,12 +85,15 @@ def workflow_files() -> list[Path]:
|
||||
def _checkout_steps(doc: object) -> list[tuple[str, int, dict]]:
|
||||
"""Every `actions/checkout` step in a parsed workflow, as (job id, index within job, step).
|
||||
|
||||
Reads `jobs.<id>.steps` only, which is the whole shape this repo uses. Two different escapes are
|
||||
reported by two different tests, and they are not interchangeable:
|
||||
Reads `jobs.<id>.steps` only, which is the whole shape this repo uses. Different escapes are
|
||||
reported by different tests, and they are not interchangeable:
|
||||
`test_the_walk_finds_every_actions_checkout_the_TEXT_does` covers a shape INSIDE a workflow file
|
||||
that the walk cannot reach, because both halves read the same files. A **composite action** is
|
||||
invisible to both halves — its `action.yml` is not in the workflow population at all — so that
|
||||
case is reported by `test_no_LOCAL_COMPOSITE_ACTION_exists_AT_ALL` instead.
|
||||
case is reported by `test_no_LOCAL_COMPOSITE_ACTION_exists_AT_ALL` instead. A **reusable
|
||||
workflow** (`jobs.<id>.uses:`) is a third shape, invisible to both halves in the same way, and is
|
||||
reported by `test_no_job_DELEGATES_to_a_reusable_workflow` — it is not covered by the text
|
||||
cross-check, which would see zero on both sides and agree.
|
||||
"""
|
||||
found: list[tuple[str, int, dict]] = []
|
||||
if not isinstance(doc, dict):
|
||||
@@ -200,6 +216,11 @@ def test_the_fault_collector_reports_a_checkout_that_OMITS_the_flag() -> None:
|
||||
"github.com/actions/checkout@v4",
|
||||
# The forge is case-insensitive on owner/repo, so this runs the real checkout.
|
||||
"Actions/Checkout@v4",
|
||||
# Gitea writes the clone URL with the suffix; both halves must accept it.
|
||||
"https://github.com/actions/checkout.git@v4",
|
||||
# Userinfo before the host — splitting on the FIRST `@` used to strip the host.
|
||||
"https://user@github.com/actions/checkout@v4",
|
||||
"https://github.com//actions/checkout@v4",
|
||||
):
|
||||
as_url = {"jobs": {"j": {"steps": [{"uses": spelling}]}}}
|
||||
assert len(checkout_faults("synthetic.yml", as_url)) == 1, spelling
|
||||
@@ -239,3 +260,42 @@ def test_no_LOCAL_COMPOSITE_ACTION_exists_AT_ALL() -> None:
|
||||
"the job, so an `actions/checkout` in one is subject to the same rule and is NOT covered by "
|
||||
"the workflow-file population above — extend `_checkout_steps` to walk them."
|
||||
)
|
||||
|
||||
|
||||
def test_no_job_DELEGATES_to_a_reusable_workflow() -> None:
|
||||
"""A `jobs.<id>.uses:` callee's steps run in the job but are outside the walk.
|
||||
|
||||
Both halves would see zero and AGREE, so the count cross-check reports nothing — the same blind
|
||||
spot the composite-action test exists for. Gitea Actions has no `workflow_call` today, so assert
|
||||
the absence rather than parse a shape that cannot occur: the first one added reddens here and its
|
||||
author widens the guard.
|
||||
"""
|
||||
delegating = []
|
||||
for path in workflow_files():
|
||||
doc = yaml.safe_load(path.read_text())
|
||||
jobs = doc.get("jobs") if isinstance(doc, dict) else None
|
||||
if not isinstance(jobs, dict):
|
||||
continue
|
||||
for job_id, job in jobs.items():
|
||||
if isinstance(job, dict) and isinstance(job.get("uses"), str):
|
||||
delegating.append(f"{path.name}: job `{job_id}` -> {job['uses']}")
|
||||
assert not delegating, (
|
||||
f"job(s) delegating to a reusable workflow: {delegating}. The callee's `actions/checkout` "
|
||||
"steps run in this job and are subject to the same rule, but are NOT in the population "
|
||||
"above — extend the walk before adding one."
|
||||
)
|
||||
|
||||
|
||||
def test_no_workflow_lives_under_dot_GITHUB() -> None:
|
||||
"""`.github/workflows` is out of the population, so prove it is empty rather than assume it.
|
||||
|
||||
Gitea reads `.github/workflows` only when `.gitea/workflows` is absent — a precedence rule this
|
||||
repo has never probed — and `.github/` already exists here, so it is a plausible place to add a
|
||||
workflow out of habit. Cheap to assert; silently uncovered otherwise.
|
||||
"""
|
||||
stray = sorted(p for p in _git_ls_files() if p.startswith(".github/workflows/"))
|
||||
assert not stray, (
|
||||
f"tracked workflow file(s) under .github/workflows: {stray}. This guard's population is "
|
||||
f"{WORKFLOW_DIR} only — decide whether Gitea runs these and widen the population or delete "
|
||||
"them, but do not leave them unchecked."
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user