Repository navigation
wfc: Check that every workflow is compiled - #38
Conversation
cgwalters-bot
left a comment
There was a problem hiding this comment.
Review guide for head 44fee59522: 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 lib/check-lock.mjs, which compile.mjs --check runs on every lock file to prove its shape independently of its source (#13), plus a listed-exceptions file for hand-written workflows (ci.yml). The structure is right and CI is green, but the check is a denylist of known-bad keys over steps it otherwise matches only by shell and run text, so it accepts several records gha.compile can never emit: an enter step whose CONFIG JSON is free (sandbox user, lockRunnerSudo, workspace path), generated steps with extra keys (if: false or continue-on-error on secure-host or enter, background: true), and env on a --stage step, which runs as runner under bash, where SHELLOPTS=xtrace plus PS4 executes code. The fix is an allowlist per step kind mirroring gha.ncl's closed contracts, plus validating CONFIG. The uncompiled-workflows list is read from the PR's own tree, so it only means something with #26, which should cover this file too. Separately, and not from this PR: gha.ncl's USER_RE accepts sandbox.user = runner or root (verified with nickel 1.18.0), and install.cjs doesn't refuse them, so R1's new status of holds overstates it.
Hotspots
- risky · security —
lib/check-lock.mjs:40-58(44fee59): CONFIG is accepted as any JSON object, so the enter step is not byte-identical to what the compiler makes: {user: runner} runs sandboxed steps as runner, lockRunnerSudo: false with publish steps bypasses PublishNeedsLock, and workspace can point handoff at /home/runner. Validate the exact key set and values. - risky · security —
lib/check-lock.mjs:60-62(44fee59): Generated steps are matched on shell/run/env only; extra keys pass: secure-host with if: false (skipped, job continues) or continue-on-error, enter with continue-on-error (bypasses its fail-closed sudo check), background: true. Require the exact key set of each generated step. - risky · security —
lib/check-lock.mjs:83-96(44fee59): Denylist per sandboxed step: a --stage step (shell bash, runs as runner) may carry any env not in DENIED_ENV, and SHELLOPTS=xtrace with PS4 set to a command substitution runs code as runner mid-sandbox. The compiler never sets env on stage steps; unknown keys such as background: true also pass. Allowlist keys per step kind. - look-closely · logic —
lib/check-lock.mjs:37-38(44fee59): Forbidden-key lists at job and workflow level, not the compiler's closed key sets; strategy, environment, outputs, continue-on-error and new GitHub keys pass. Most are R10 issues (#28, #29), but an allowlist mirroring gha.ncl's Job and Workflow contracts would make 'went through gha.compile' true by construction. - look-closely · security —
compile.mjs:211-236(44fee59): The exemption list is read from the PR's own tree, so a PR can add a workflow and list it; only review stops it until #26, whose CODEOWNERS list should include .github/uncompiled-workflows and .github/workflows/. A reason after # is documented as required but not enforced; non-.yml names are skipped rather than flagged. - note · test-gap —
tests/runtime/check-lock.test.cjs:67-94(44fee59): Good table of negatives, but none for a missing or modified secure-host step, a modified seal, a seal before enter, job uses/services/defaults, working-directory, CONFIG mutations, or extra keys on generated steps. The compile.mjs file-listing half (orphan lock, unlisted workflow) has no automated test.
Safe to skim
README.md: Docs: mirrors the requirements text; the roadmap entry for #13 is removed..github/uncompiled-workflows: One entry, ci.yml, which is contents: read with no secrets.
44fee59 to
851b57c
Compare
cgwalters-bot
left a comment
There was a problem hiding this comment.
Review guide for head 851b57cd5f: 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 (44fee59): check-lock.mjs moved from a denylist to allowlists. The enter step is now matched on its exact key set and exact CONFIG (user not runner or root, workspace fixed, hand-off shape, lockRunnerSudo with the PublishNeedsLock rule); secure-host and seal must have exactly their keys; stage and wrapper steps have per-kind key allowlists; job and workflow keys mirror gha.ncl's Job and Workflow contracts; uncompiled-workflows reasons are enforced and .YML files are flagged. The first commit refuses runner and root as sandbox.user in gha.ncl and, by name and uid, in install.cjs. Every point from the last review is fixed and tested, and compile --check, node --test and cargo test pass on a devspace. What remains is scope: steps after the seal are checked only for the seal condition, so a hand-built record could have a publish step that expands a sandboxed step's outputs (script injection as runner, the #1 class) or uses an unpinned action, both of which PublishStep refuses. Sandboxed steps' values aren't checked for secrets or github.token, and runner_steps aren't checked at all. R1's text is accurate about what is checked, but its claim that a hand-built record fails is broader. The earlier probe harness now reports every case caught, but only because its step names no longer match (its baseline is caught too). With the names fixed, five cases still pass: a stage path with .., an action path with .. (the runtime refuses both), OPENSSL_CONF (gha.ncl allows it too), permissions: write-all (gha.ncl requires a record), and a post-seal step with an unpinned uses and env.
Hotspots
-
risky · security —
lib/check-lock.mjs:183-185(851b57c): Steps after the seal are checked only for the seal condition. PublishStep also refuses sandboxed steps' outputs in run/with/env (script injection as runner with the job token, #1), unpinned uses and untrusted event text, and a hand-built record gets none of these checks. Mirror NoSandboxOutputs and Pinned, or narrow the header's and R1's claim. -
look-closely · security —
lib/check-lock.mjs:137-151(851b57c): Sandboxed steps are checked for keys and env names only, not values: a hand-built record can put a secrets.X or github.token expression into a sandboxed step's run or env, which NoCredentials refuses in gha.ncl. Testing every string of such a step against CREDENTIALS_RE would mirror it. -
look-closely · security —
lib/check-lock.mjs:77-83(851b57c): This mirrors a gap that already exists in gha.ncl's WorkspacePath: a handoff.include path may contain a ${{ }} expression. Actions expands it inside the enter step's JS source, which runs as root, so event text there is script injection. Refuse '${{' in include paths in both places. -
note · logic —
lib/check-lock.mjs:29-34(851b57c): STAGE_RUN and the --action-path form accept .. components, which gha.ncl's StagePath refuses. runtime/run.cjs refuses both at run time, so this is only a mirror gap, but reusing gha.ncl's dot-component test would make the check exact. -
note · logic —
lib/check-lock.mjs:48-50(851b57c): Keys are allowlisted, but values aren't type-checked: permissions: write-all passes here, while gha.ncl's { _ : String } refuses a string. The impact is low, since permissions are the author's to choose (R10, #29). -
note · security —
runtime/install.cjs:46-68(a91e428): The user is refused by name before useradd, and by uid after the passwd lookup, before anything is handed off, which is correct. gha.ncl can refuse only the literal names root and runner, so a self-hosted runner under another name relies on this check. -
note · test-gap —
tests/runtime/check-lock.test.cjs:68-130(851b57c): Covers every point from the last review. There are no cases for publish steps beyond the seal condition, or for secrets in sandboxed steps; add them with the fixes above.
Safe to skim
.github/workflows/actions-test.lock.yml: Regenerated: install.cjs grew five lines..github/workflows/agent-review.lock.yml: Regenerated: install.cjs grew five lines..github/workflows/sandbox-test.lock.yml: Regenerated: install.cjs grew five lines.tests/accept/composite.expected.yml: Regenerated expected output.tests/reject/sandbox-user-root.ncl: Reject fixture.tests/reject/sandbox-user-runner.ncl: Reject fixture.README.md: Docs that mirror requirements.md.
cdc682c to
c60673c
Compare
851b57c to
bf28997
Compare
cgwalters-bot
left a comment
There was a problem hiding this comment.
Review guide for head bf28997655: 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 (851b57c): every point is fixed. Steps after the seal are now held to gha.ncl's PublishStep: the same key set, exactly one of run or uses, Pinned, NoSandboxOutputs and NoUntrustedTextInScript. The regexes are copied verbatim from gha.ncl, and nested with values are checked too, which is stricter. Every string of a sandboxed step is tested against CREDENTIALS_RE. Stage and action paths with . or .. are refused. Permissions must be maps, and jobs must be a map. handoff.include refuses ${{ here and in gha.ncl's WorkspacePath. That gha.ncl change and its reject test landed in 28c2d39 lower in the stack, where WorkspacePath was introduced, which is the right place. The probe cases are now a real test in check-lock.test.cjs. The corrected probe harness from the last review catches 17 of 18 probes and accepts the baseline. The one that still passes is OPENSSL_CONF on a sandboxed step, which gha.ncl's DENIED_ENV_RE allows too, so the mirror is exact, and the new test names it as known. What remains is doc drift: the commit body and R1's status still describe the post-seal check as the seal condition only. compile --check and node --test pass on a devspace, and CI is green at this head.
Hotspots
- note · security —
lib/check-lock.mjs:54(bf28997): OPENSSL_CONF (and OPENSSL_MODULES) aren't denied here or in gha.ncl's DENIED_ENV_RE. The wrapper's runner side is node, which reads OPENSSL_CONF at startup, so it is worth adding to both in a follow-up. It is the one probe from the last review that still passes. - note · logic —
lib/check-lock.mjs:164-165(bf28997): The action-path dot check is stricter than gha.ncl, which only applies Pinned to a composite's ref, and matches runtime/run.cjs instead. A source using owner/repo/../x@sha compiles but fails here, which is fine since the runtime would refuse it. - note · api —
docs/requirements.md:200-218(bf28997): R1's status, and the commit body, still say only that steps after the seal require it to have succeeded. They now get PublishStep's checks too, and sandboxed steps' values are checked for secrets and the token. Add a clause to each, and to the Proof list.
Safe to skim
.github/workflows/actions-test.lock.yml: Regenerated: install.cjs grew five lines..github/workflows/agent-review.lock.yml: Regenerated: install.cjs grew five lines..github/workflows/sandbox-test.lock.yml: Regenerated: install.cjs grew five lines.tests/accept/composite.expected.yml: Regenerated expected output.tests/reject/sandbox-user-root.ncl: Reject fixture.tests/reject/sandbox-user-runner.ncl: Reject fixture.
bf28997 to
4c997f3
Compare
c60673c to
db27bf1
Compare
4c997f3 to
b1d31ec
Compare
db27bf1 to
2c451f8
Compare
84beb60 to
6b33f3e
Compare
2c451f8 to
837063e
Compare
837063e to
f4e0cbb
Compare
6b33f3e to
0001136
Compare
f4e0cbb to
132c212
Compare
`sandbox.user` took any valid user name, so `runner` or `root` compiled, and every "sandboxed" step then ran as the very user the sandbox keeps it from: the one holding the job's tokens, or root. Found by the review of the compiled-shape check. gha.ncl refuses both names, and install.cjs refuses the runner's name, root, and any user whose uid is root's or the runner's, since another name for them is still them. Fixes #42. Generated-by: AI
`wfc check` proved each lock file matches its source, but not that the source went through gha.compile (a source can build its own record), nor that no hand-written workflow sits next to the lock files, running with none of the compiler's guarantees (#13). It now checks the output itself, independently of the source: each job has exactly one enter step, byte for byte what runtime/ makes it, after the secure-host step; every step up to the one seal step runs through the step wrapper, with only the keys such a step has, no environment for the wrapper's runner side and no secret or token; every later step requires the seal to have succeeded and is held to what gha.ncl's PublishStep refuses (unpinned actions, sandboxed steps' outputs, event text in scripts); and jobs and workflows have only the keys gha.ncl's contracts let through, so the check requires exactly what the compiler emits rather than refusing what it knows to be dangerous. Any other workflow file must be listed, with its reason, in .github/uncompiled-workflows, and a lock file without a source fails. src/shape.rs holds the rules, and tests/shape.rs builds a workflow of the compiled shape and each way out of it. This proves the tree the check runs on; running the check from a tree the pull request can't change is #26. Fixes #13. Generated-by: AI
A sandboxed step's env applies to the runner side of the step wrapper, which is node, and node reads OPENSSL_CONF and OPENSSL_MODULES at start, so a config file there could load a module as runner. Both join the names a sandboxed step can't set, in gha.ncl and in the compiled-shape check. Found by the review of the check. Generated-by: AI
0001136 to
bb19b37
Compare
Stacked on #37.
wfc checknow checks each compiled workflow's shape, not just that it matches its source (#13). It requires exactly whatgha.compileemits: keys are allowlisted, mirroring gha.ncl's closed contracts, rather than refusing a list of known-dangerous ones. The first commit fixes #42: the runner and root can no longer be the sandbox user, in gha.ncl or install.cjs.src/shape.rs, a port of what waslib/check-lock.mjs):runtime/makes it, with the CONFIG the compiler writes, right after the generated secure-host step. Generated steps must have exactly their keys.--stageonly as generated), with only a sandboxed step's keys (stage steps withoutenv) and no environment for the wrapper's runner side.PublishStep: allowed keys only, exactly one ofrunoruses, pinned actions, no sandbox outputs inrun,working-directory,withorenv, and no untrusted text in scripts.....github/uncompiled-workflowswith a# reason, which is enforced. Here that isci.yml. A lock file without a source also fails.docs/requirements.mdis now holds. Whether the check itself can be trusted, since it runs from the pull request's tree, is The stale-lock check runs the pull request's own compiler #26.Testing: Tested on cgwalters-devspace-36635170907 (16-core RHEL 10): at every commit of the restacked stack,
cargo fmt --check,cargo clippy --locked --all-targets -- -D warnings,cargo test --locked(wfc's tests andwfc checkof the repository) andnode --testfor the runtime scripts pass.wfc compilereproduces every committed lock file, and relocking from an emptyactions.lock.jsonrefetches its entries byte for byte.tests/shape.rschecks that the compiled shape passes, and finds each way out that the review probed: unknown or dangerous keys on steps, jobs and the workflow, a stage step withenv, and a modified, skippable or missing enter, secure-host or seal step. It also covers a seal before entering, and CONFIG with the runner or root as the sandbox user, another workspace, a bad hand-off or no sudo lock. At the tree level it covers an unlisted or.YMLworkflow, an orphan lock file, and a listed workflow without its reason or that doesn't exist. New reject tests refusesandbox.userofrootandrunner.ciruns the same.Fixes #13
Generated-by: https://github.com/cgwalters/#llms