From 288a317b30566a65ea3a3769bc4c59e587156549 Mon Sep 17 00:00:00 2001 From: ZacxDev Date: Mon, 17 Aug 2026 17:44:25 -0500 Subject: [PATCH] fix(ci): stage only flake.nix in the vendorHash bot's PR, and ignore nix out-links MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The `bump-flake-vendorhash` bot committed a build artifact into its own PR. #450 changed two things: the legitimate `vendorHash` bump, and a NEW `result` symlink pointing at `/nix/store/kkfnywjq…-civitai-4e35eaa-dirty`. All 13 CI checks were green on it — nothing in this repo detects the artifact. Mechanism, in `.github/workflows/bump-flake-vendorhash.yml`: - the two validate steps run `nix build .#default` and `./result/bin/civitai version`, and a SUCCESSFUL `nix build` drops a `result` out-link symlink into the invocation cwd (the repo root); - `result` is not in `.gitignore`; - the `open PR if vendorHash changed` step uses peter-evans/create-pull-request without `add-paths`, and that action runs `git add -A` in that case (verified in the action's own `create-or-update-branch.ts` at the pinned SHA c5a7806) — so it stages every change in the tree, untracked files included. The ordering is why this hid: `detect changes` runs BEFORE the validate steps, so its `git status --porcelain` gate never sees `result` and the changed=true/false decision is unaffected. The symlink exists only in the window between validation and the PR step. Two independent guards: 1. `add-paths: flake.nix` on the create-pull-request step — the authoritative fix. It stages exactly the file the workflow is allowed to change, so no future artifact can ride along regardless of what a later step leaves in the workspace. Audited against every step that writes to the working tree: the recompute step's two `sed -i`s and its `git checkout --` restore touch flake.nix and nothing else, and its nix log goes to `$RUNNER_TEMP`. flake.nix is the complete write set. 2. `/result` + `/result-*` in `.gitignore` — defence in depth, covering nix's numbered/named out-link variants. Anchored to the repo root so a legitimately named file deeper in the tree is unaffected. Also applies the vendorHash bump itself (#450's legitimate half), independently re-derived here rather than copied: with `vendorHash` set to the workflow's own fake, `nix build .#default` reported `got: sha256-l0RyxhS7+tdL9FngitiUhrciQbZfyDmTp5tP3Kd6NGQ=`, matching #450 exactly. `go.mod`/`go.sum` are byte-identical between #450's head and `main`. With the real hash written back, `nix build .#default` succeeds and `./result/bin/civitai version` runs. The two sibling drift-bots that share this token and this action — `bump-scaffold-pins` and `revendor-canonical-schema` — were audited for the same defect and do NOT have it, so they keep `git add -A` and gain only a comment recording the audit and what would change that. Neither writes anything into the workspace except the file it means to commit: `bump-pins` writes only under its `--dir` (default `internal/scaffold`), the re-vendor script `cp`s to one path and downloads via `mktemp`, `go test` writes nothing, and the scaffold build validation deliberately runs in `$RUNNER_TEMP`. Measured, not just read: `git status --porcelain` was clean of artifacts after the full test suite and after a `civitai app init --dir "$RUNNER_TEMP/…"`. Supersedes #450, which should not be merged as-is. --- .github/workflows/bump-flake-vendorhash.yml | 23 +++++++++++++++++++ .github/workflows/bump-scaffold-pins.yml | 22 ++++++++++++++++++ .../workflows/revendor-canonical-schema.yml | 19 +++++++++++++++ .gitignore | 11 +++++++++ flake.nix | 2 +- 5 files changed, 76 insertions(+), 1 deletion(-) diff --git a/.github/workflows/bump-flake-vendorhash.yml b/.github/workflows/bump-flake-vendorhash.yml index 543ee337..b2e98a54 100644 --- a/.github/workflows/bump-flake-vendorhash.yml +++ b/.github/workflows/bump-flake-vendorhash.yml @@ -232,6 +232,29 @@ jobs: # the repo's normal CI (the `flake` build check). Shared with the # other drift-bots (bump-scaffold-pins / revendor-canonical-schema). token: ${{ secrets.BUMP_SCAFFOLD_PINS_TOKEN }} + # 🔴 STAGE ONLY flake.nix. Without `add-paths` this action stages + # EVERYTHING in the tree, untracked files included — and the two + # validate steps directly above run `nix build`, which drops a + # `result` symlink into the repo root on success. So the bot committed + # a pointer into /nix/store alongside its hash bump: PR #450 shipped + # `result -> /nix/store/kkfnywjq…-civitai-4e35eaa-dirty`, and all 13 + # CI checks were green on it — nothing here detects the artifact, so + # the guard has to be that it is never staged. + # + # Note the ordering that hid this: `detect changes` runs BEFORE the + # validate steps, so its `git status --porcelain` is clean of `result` + # and the changed=true/false gate is unaffected. The symlink only + # exists during the window between validation and this step. + # + # This value is the COMPLETE set of paths the job may write, not a + # convenience filter. Audited against every step: the recompute step's + # two `sed -i`s and its `git checkout --` restore touch flake.nix and + # nothing else, and its nix log goes to `$RUNNER_TEMP`. If a future + # step writes another file that BELONGS in the PR, add it here — an + # unlisted path is silently dropped from the commit, and a bot that + # opens an incomplete PR is worse than the artifact this prevents. + # `.gitignore` also carries `/result`, as a second, independent layer. + add-paths: flake.nix branch: automation/bump-flake-vendorhash delete-branch: true commit-message: "chore(nix): bump flake vendorHash to match go.sum" diff --git a/.github/workflows/bump-scaffold-pins.yml b/.github/workflows/bump-scaffold-pins.yml index bdf3c46a..ee4c6699 100644 --- a/.github/workflows/bump-scaffold-pins.yml +++ b/.github/workflows/bump-scaffold-pins.yml @@ -238,6 +238,28 @@ jobs: npm run typecheck npm run build + # NO `add-paths:` here, deliberately — and that is a decision, not an + # oversight. This action stages `git add -A` when `add-paths` is absent, + # so ANY file a step leaves in the workspace rides into the PR. That is + # exactly how the sibling `bump-flake-vendorhash` committed a `result` + # symlink into /nix/store (#450, green on all 13 checks); it now pins + # `add-paths: flake.nix`. + # + # This job was audited against that failure and does not have it: the only + # step that writes into the repo is the bumper, and `bump-pins` writes + # exclusively under its `--dir` (default `internal/scaffold`) to three + # constant sites. Everything else writes outside the tree — `go test` + # writes nothing, and `validate — scaffold builds` scaffolds and runs npm + # in `$RUNNER_TEMP` on purpose (see that step's comment). Measured, not + # just read: `git status --porcelain` is clean of artifacts after the test + # suite and after a `civitai app init --dir "$RUNNER_TEMP/…"`. + # + # 🔴 If you add a step that builds/installs/generates INTO the workspace, + # add `add-paths` naming the complete set of files this bot may commit — + # `internal/scaffold` is the bumper's provable write root. Note the + # trade-off before reaching for it as a reflex: a path that is written but + # NOT listed is silently dropped from the commit, and a bot that opens an + # incomplete PR is worse than the artifact the filter prevents. - name: open PR if pins changed id: pr if: steps.changed.outputs.changed == 'true' diff --git a/.github/workflows/revendor-canonical-schema.yml b/.github/workflows/revendor-canonical-schema.yml index 2108d6f9..fd9eed6e 100644 --- a/.github/workflows/revendor-canonical-schema.yml +++ b/.github/workflows/revendor-canonical-schema.yml @@ -152,6 +152,25 @@ jobs: # examples/*.block.manifest.json) runs too, not just internal/validate. run: go test ./... + # NO `add-paths:` here, deliberately — and that is a decision, not an + # oversight. This action stages `git add -A` when `add-paths` is absent, + # so ANY file a step leaves in the workspace rides into the PR. That is + # exactly how the sibling `bump-flake-vendorhash` committed a `result` + # symlink into /nix/store (#450, green on all 13 checks); it now pins + # `add-paths: flake.nix`. + # + # This job was audited against that failure and does not have it: the only + # step that writes into the repo is the re-vendor script, which `cp`s to a + # single path it computes from its own location + # (`schema/app-block.manifest.schema.json`) and downloads via `mktemp` + # outside the tree; `go test ./...` writes nothing. Measured, not just + # read: `git status --porcelain` is clean of artifacts after the suite. + # + # 🔴 If you add a step that builds/installs/generates INTO the workspace, + # add `add-paths` naming the complete set of files this bot may commit. + # Note the trade-off before reaching for it as a reflex: a path that is + # written but NOT listed is silently dropped from the commit, and a bot + # that opens an incomplete PR is worse than the artifact it prevents. - name: open PR if schema changed id: pr if: steps.changed.outputs.changed == 'true' diff --git a/.gitignore b/.gitignore index 8d5c404f..79a52beb 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,14 @@ coverage.html .DS_Store .venv/ /.claude/worktrees + +# `nix build` drops an out-link symlink into the invocation cwd (the repo root), +# named `result` — or `result-`/`result-` when a build has several +# outputs or several installables are built at once. It is a pointer into +# /nix/store and must never be committed. This is DEFENCE IN DEPTH behind the +# `add-paths:` on the `bump-flake-vendorhash` bot: that bot runs `nix build` +# before opening its PR, and with neither guard the symlink rode along into the +# PR diff (#450 committed `result -> /nix/store/kkfnywjq…-civitai-4e35eaa-dirty` +# and all 13 CI checks stayed green). +/result +/result-* diff --git a/flake.nix b/flake.nix index 89151fdb..fd146abe 100644 --- a/flake.nix +++ b/flake.nix @@ -33,7 +33,7 @@ # Computed from go.sum (this module is not vendored). To recompute # after a go.mod/go.sum change: set this to `lib.fakeHash`, run # `nix build`, and copy the `got: sha256-…` value from the error. - vendorHash = "sha256-prgKRC+357KX7vJ9jcIq2+1FUD91a2Gg5Q89R+FTZ+g="; + vendorHash = "sha256-l0RyxhS7+tdL9FngitiUhrciQbZfyDmTp5tP3Kd6NGQ="; # The module root is `package cli` (a library that embeds the schema); # the executable lives in ./cmd/civitai (package main). Build only it.