Skip to content

ci: Check the lock files from the default branch's code - #43

Merged
cgwalters-bot merged 1 commit into
mainfrom
bot/trusted-check
Sep 30, 2026
Merged

cgwalters-bot merged 1 commit into
mainfrom
bot/trusted-check

Conversation

@cgwalters-bot

@cgwalters-bot cgwalters-bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Collaborator

Stacked on #38. Adds trusted-check.yml, which runs the stale-lock and shape checks from code the pull request can't change (#26). The trust model is R14 in docs/requirements.md.

  • The default branch's code only. It runs on pull_request_target, so the workflow and its scripts are the default branch's, with contents: read and no secrets.
    • The pull request's tree is written blob by blob by the default branch's wfc extract-tree (ls-tree plus cat-file), not git archive, which would apply the pull request's own .gitattributes. Symlinks, submodules and .. paths are refused, and nothing is executed or built.
    • wfc is built from the default branch alone, and wfc check --root head compiles the pull request's sources and checks the lock files' shape. No Node or nickel binary is involved. Evaluating the pull request's nickel can still read any file the job can (it holds no secrets); confining that step is trusted-check: confine the step that evaluates a pull request's nickel #57.
  • Label gate. A change relative to the default branch passes only on the event of someone applying compiler-change who is a human (not cgwalters-bot, which is admin here, nor any [bot]), not the pull request's author, and has the admin or maintain role, which is looked up. A failing diff, such as a head with no common history, fails the gate instead of reading as unchanged. The gated paths are lib/, runtime/, src/, build.rs, Cargo.toml, Cargo.lock, rust-toolchain.toml, rust-toolchain, .cargo/, actions.lock.json, .gitattributes, the uncompiled list and non-lock workflows. Comparing with the default branch means a stacked base can't hide a change. Any other event fails again, including labeling with another label: a passing run on an unrelated event would stand for that head.
  • Needs cgwalters (tracker#212): create the label, then in the ruleset require trusted-check pinned to the GitHub Actions app, with branches up to date.
  • The review map of the whole stack is in this gist. It was a README commit before review, and I moved it here.

Testing: GitHub runs pull_request_target workflows only from the default branch, since 2025-12-08 (changelog). So it couldn't run from test PRs against this branch; I opened three (#39-#41) and closed them. Instead I replayed the workflow's own run: steps on a 16-core devspace (cgwalters-devspace-36524004459), with gh stubbed for the role lookup:

  • An honest source change passes.
  • A hand-edited lock file fails at the compare.
  • A compiler change fails on synchronize, on another label, when the author labels it, and when a write-role user labels it. It passes when a maintainer labels it.
  • A workflow hidden with export-ignore is still extracted, and the shape check fails on it.

tests/extract.rs covers export-ignore, export-subst, ident, symlinks and submodules. I replayed the new build, extract and check steps against heads on top of this branch on cgwalters-devspace-36635170907: an honest head passes; a hand-edited lock file, a workflow hidden with export-ignore, and a symlink in the tree each fail. The label-gate step is unchanged from the replay above.

actionlint is clean. Once this is merged, the same three PRs are the end-to-end test.

Fixes #26

Generated-by: https://github.com/cgwalters/#llms

@cgwalters-bot cgwalters-bot left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review guide for head 925b0f19dc: where to look closely and what is safe to skim. It is advice from the bot's reviewer and doesn't replace reading the diff; the review app walks it.

Adds trusted-check.yml on pull_request_target: it builds wfc from the default branch's checkout, extracts the pull request's tree as data with git archive | tar, gates compiler changes on a fresh compiler-change labeling, then compiles and shape-checks head/ with the default branch's wfc and check-lock.mjs. The basics are right: contents: read, no secrets, persist-credentials: false, event text only through env, no cache, and the head SHA is re-checked after the fetch, so a stale re-run can't vouch for a newer push. The claim that the workflow comes from the default branch whatever the base is correct (changelog 2025-11-07, effective 2025-12-08: GITHUB_REF and GITHUB_SHA are the default branch's). The blocking problem is the extraction: git archive applies the archived tree's own .gitattributes, so the pull request decides what head/ holds. export-ignore hides a file (a hand-written workflow, or a tampered lock file together with its source) from both checks; export-subst, ident and eol/working-tree-encoding rewrite content. I confirmed this with git 2.52. .gitattributes isn't a gated path either. Materialize the tree without attributes: git ls-tree -r -z plus git cat-file for 100644/100755 entries, refusing 120000 and 160000; that also removes tar. Smaller points: the gate diffs against the PR's base while the code that runs is the default branch's; actions.lock.json isn't gated; the labeling actor isn't checked (triage suffices, and so does the PR's own author if they have triage); and #38's unchecked publish steps become reachable here with no label, since a source can build its own record without touching lib/.

Hotspots

  1. risky · security — .github/workflows/trusted-check.yml:63-68 (5c32614): git archive honours the archived tree's .gitattributes (and nested ones): export-ignore drops files from head/, so an unlisted workflow, or a lock file with its source, is never checked; export-subst, ident and eol rewrite content, so the checked bytes aren't the merged bytes. Extract with ls-tree -z plus cat-file per regular blob, refusing symlinks and gitlinks by mode.
  2. look-closely · security — .github/workflows/trusted-check.yml:39 (5c32614): The gated paths omit .gitattributes (moot once extraction ignores attributes) and actions.lock.json, which gha.ncl imports as trusted action metadata. Either gate actions.lock.json or say in R14 why it is safe to treat as data.
  3. look-closely · logic — .github/workflows/trusted-check.yml:79-81 (5c32614): The diff is against the PR's base.sha, but base/ and everything that runs is the default branch. For a PR into another branch (a stack like this one), compiler changes already on that base aren't gated, and head's lib/ is then used. Diff against the checked-out default branch HEAD, or fail PRs whose base isn't the default branch.
  4. look-closely · security — .github/workflows/trusted-check.yml:90-93 (5c32614): Any labeler passes the gate: triage access is enough, and the actor isn't checked, so a PR author with triage can approve their own compiler change. At least refuse github.event.sender.login equal to pull_request.user.login; better, check the sender's permission is maintain or admin.
  5. note · security — .github/workflows/trusted-check.yml:110-120 (5c32614): Head content is evaluated here by design (head/lib/gha.ncl under Landlock; head/runtime and the uncompiled list as data), as R14 says. $(ls workflows/*.ncl) word-splits head-chosen names; a bash array from a glob is cleaner. Nothing here reads cargo or git config from head/, which is a sibling of base/.
  6. look-closely · security — docs/requirements.md:575-619 (5c32614): R14 is accurate on the trigger, permissions and label semantics, but 'holds once required' also needs extraction that ignores .gitattributes, gating against the default branch, and #38's publish-step check. It should also name the ruleset settings it depends on: the check pinned to the GitHub Actions app, and branches up to date before merging.
  7. note · api — README.md:247-250 (925b0f1): An unrelated commit linking a review-map gist from the project README. It fits better in the PR description or the tracker than in the permanent docs, and its body line isn't wrapped.

Safe to skim

  • .github/uncompiled-workflows: One entry for trusted-check.yml.
  • README.md:215-243: Docs that mirror R14.

@cgwalters-bot cgwalters-bot left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review guide for head 5f6c532c88: where to look closely and what is safe to skim. It is advice from the bot's reviewer and doesn't replace reading the diff; the review app walks it.

Delta since the last guide (925b0f1): every point is addressed. lib/extract-tree.mjs writes the head tree with ls-tree -r -z plus cat-file blob, so no .gitattributes is applied. It refuses modes 120000 and 160000 and any other non-regular mode, and empty, dot, dot-dot or absolute paths. DEST must not exist and each file is written with wx, so writes stay under it. The gate diffs HEAD...HEAD_SHA in the default-branch checkout, meaning changes since the merge base with the default branch, so a stacked base's compiler changes count. With the up-to-date rule, the merge base is the default branch head. actions.lock.json, .gitattributes and non-lock workflows are gated. The labeler must not be the author and must have role_name admin or maintain. role_name is the right field (permission folds maintain into write), and a custom role fails closed. R14 names the ruleset settings. The live ruleset already requires strict up-to-date with ci pinned to the Actions app, and tracker#212 asks for the rest. The README gist commit is gone. One real problem remains: the gate reads git diff through a process substitution, whose failure set -e never sees. So if git diff fails (no merge base), the gate reports the compiler unchanged and passes. Also, the commit message still says the tree is extracted with git archive and refused for symlinks, which is now wrong. CI is green at this head.

Hotspots

  1. risky · error-handling — .github/workflows/trusted-check.yml:86-92 (5f6c532): mapfile < <(git diff ...) ignores git's exit status even under set -euo pipefail (checked: a failing diff leaves the array empty and the script goes on). So a head with no merge base with the default branch makes the gate print 'unchanged' and pass. Capture it with out=$(git -C base diff ...) first, which set -e does check, then mapfile from that.
  2. note · security — .github/workflows/trusted-check.yml:101-110 (5f6c532): The role lookup is right, and fails closed if gh api fails. Note that cgwalters-bot has the admin role on this repository, so the bot account itself can vouch for another author's compiler change. That is worth a line in R14, or an explicit refusal if it isn't intended.
  3. note · test-gap — tests/runtime/extract-tree.test.cjs:40-44 (5f6c532): Only the symlink refusal is tested. A submodule entry is one git update-index --add --cacheinfo 160000,<sha>,sub away and would pin the 160000 refusal too.

Safe to skim

  • .github/uncompiled-workflows: One entry for trusted-check.yml.
  • README.md: Docs that mirror R14.

@cgwalters-bot
cgwalters-bot force-pushed the bot/trusted-check branch 2 times, most recently from 77f01b8 to d401549 Compare September 29, 2026 05:33
@cgwalters-bot cgwalters-bot moved this to Todo in Workstream Sep 29, 2026
@cgwalters-bot
cgwalters-bot force-pushed the bot/trusted-check branch 2 times, most recently from 0776238 to 7e8ab28 Compare September 30, 2026 00:06
@cgwalters-bot cgwalters-bot moved this to Todo in Workstream Sep 30, 2026
@cgwalters-bot
cgwalters-bot force-pushed the bot/trusted-check branch 2 times, most recently from a6748d5 to 40c4d12 Compare September 30, 2026 20:23
@cgwalters-bot
cgwalters-bot force-pushed the bot/check-compiled branch 2 times, most recently from 0001136 to bb19b37 Compare September 30, 2026 22:31
Base automatically changed from bot/check-compiled to main September 30, 2026 22:38
ci's stale-lock and shape checks run from the pull request's own tree,
so a pull request can change the compiler, lib/ or ci.yml until a lock
file that doesn't match its source passes (#26).

trusted-check runs the same checks on pull_request_target, so its file
and every script it runs are the default branch's, with contents: read
and no secrets. The pull request's tree is only data: the default
branch's wfc, built from its checkout alone, writes its blobs as
committed with the new `wfc extract-tree` (git archive would apply its
.gitattributes), refusing symlinks and submodules, and nothing there is
executed or built. That wfc then runs `wfc check` on it: the lock files
must match their sources and have the compiled shape. Evaluating the
pull request's nickel can still read any file the job can, which holds
no secrets; confining that step is #57. A pull request that changes the compiler
itself passes only on the event of a maintainer applying the
`compiler-change` label, by a human maintainer other than its author,
and a push after the label fails again until it is reapplied.

GitHub runs pull_request_target only from the default branch, so this
can't run until merged; its steps were replayed on a devspace instead.
It holds once trusted-check is a required check in the branch ruleset,
which takes an administrator. docs/requirements.md has the trust model
as R14.

Fixes #26.

Generated-by: AI
@cgwalters-bot
cgwalters-bot merged commit c1bbebd into main Sep 30, 2026
8 checks passed
@cgwalters-bot
cgwalters-bot deleted the bot/trusted-check branch September 30, 2026 22:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

The stale-lock check runs the pull request's own compiler

1 participant