Repository navigation
ci: Check the lock files from the default branch's code - #43
Conversation
cgwalters-bot
left a comment
There was a problem hiding this comment.
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
- 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. - 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. - 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. - 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. - 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/. - 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. - 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.
851b57c to
bf28997
Compare
925b0f1 to
5f6c532
Compare
cgwalters-bot
left a comment
There was a problem hiding this comment.
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
- 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. - 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. - 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.
bf28997 to
4c997f3
Compare
77f01b8 to
d401549
Compare
4c997f3 to
b1d31ec
Compare
d401549 to
e7d1b12
Compare
b1d31ec to
84beb60
Compare
0776238 to
7e8ab28
Compare
84beb60 to
6b33f3e
Compare
a6748d5 to
40c4d12
Compare
0001136 to
bb19b37
Compare
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
40c4d12 to
7630a0d
Compare
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 indocs/requirements.md.pull_request_target, so the workflow and its scripts are the default branch's, withcontents: readand no secrets.wfc extract-tree(ls-treepluscat-file), notgit archive, which would apply the pull request's own.gitattributes. Symlinks, submodules and..paths are refused, and nothing is executed or built.wfcis built from the default branch alone, andwfc check --root headcompiles 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.compiler-changewho is a human (notcgwalters-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 arelib/,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.trusted-checkpinned to the GitHub Actions app, with branches up to date.Testing: GitHub runs
pull_request_targetworkflows 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 ownrun:steps on a 16-core devspace (cgwalters-devspace-36524004459), withghstubbed for the role lookup:synchronize, on another label, when the author labels it, and when awrite-role user labels it. It passes when a maintainer labels it.export-ignoreis still extracted, and the shape check fails on it.tests/extract.rscoversexport-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 withexport-ignore, and a symlink in the tree each fail. The label-gate step is unchanged from the replay above.actionlintis clean. Once this is merged, the same three PRs are the end-to-end test.Fixes #26
Generated-by: https://github.com/cgwalters/#llms