Skip to content

ci(runner): job-started.sh refuses fork jobs on the Mac runner too, tested in a hosted container - #3984

Merged
devswha merged 13 commits into
mainfrom
ci/mac-runner-refuses-forks
Nov 16, 2026
Merged

devswha merged 13 commits into
mainfrom
ci/mac-runner-refuses-forks

Conversation

@devswha

@devswha devswha commented Nov 16, 2026 •

Copy link
Copy Markdown
Owner

What

scripts/self-hosted-runner/job-started.sh refuses fork jobs on the self-hosted Mac runner as well as in the Linux runner image, from the same input (GITHUB_REPOSITORY, GITHUB_EVENT_NAME, GITHUB_EVENT_PATH, read with jq). This PR also changes how a refusal ends the job: the hook kills exactly one process, and only when it has proved that process is the job's Runner.Worker. Otherwise it kills nothing and blocks.

AGENTS.md: a pull request that touches scripts/self-hosted-runner/ or its test file waits for GitHub's checks (the local merge gate's Fast checks skip the isolated hook tests).

The refusal: a proven worker, or nothing

A failing hook alone only fails its own "Set up runner" step: runner v2.338 still runs the job's if: always() and if: failure() steps, so the hook ends the job by SIGKILLing its Runner.Worker. The runner starts the hook as the worker's direct child (runner v2.338.2: JobHookProvider.cs hands the hook to ScriptHandler, which starts bash through ProcessInvoker with UseShellExecute = false). So the only candidate is the hook's own parent, the $PPID that bash recorded at start. It is killed only when every check below holds:

  • it is still the hook's parent (a parent that ended since the hook started is caught here);
  • its executable is Runner.Worker:
    • on Linux, the basename of /proc/<pid>/exe (which a process cannot rename) and its name in /proc/<pid>/comm;
    • on macOS, the basename of the path /bin/ps -o comm= prints. On macOS that path is the only proof of the executable, and any executable file named Runner.Worker satisfies it.
  • it runs as the hook's user (real and effective);
  • its start time is no later than the hook's (Linux).

Right before the kill the hook reads the parent's start time and then its own parent again; both must be unchanged. It does not read the executable, name or user again at that point. The OS is chosen once (/proc/$$/stat readable or not). Every number read from /proc or ps is checked to be a pid before any arithmetic, and the kill is builtin kill. Nothing walks the ancestors, there is no fallback to $PPID, and nothing treats "pid > 1" as safe.

The limits

  1. The check and the signal are not atomic.
    • After the hook's last read of its own parent, the worker could exit, be reaped and have its pid handed to a new process before kill.
    • The executable, name and user are not read again right before the kill, so a parent that ran another program after those checks would keep its pid and start time and still be killed. The runner's worker does not do that.
    • By reading, the window is a few builtin operations on Linux and one ps run on macOS; it has not been measured.
    • A shell cannot close it, because kill takes a number. On Linux a pidfd helper (pidfd_send_signal) could; this pull request does not add one.
  2. On macOS, ps -o comm= is the only proof of the executable. Any executable file named Runner.Worker satisfies it.
  3. An orphaned hook and its adopter.
    • A hook orphaned before its bash starts records whoever adopted it as its parent: the nearest child subreaper above it, or init.
    • It could pass the proof only if that adopter were a same-user process running an executable named Runner.Worker.
    • The runner's own worker is not a subreaper. Read over the whole source tree at v2.338.2 (1076 files): no prctl and no subreaper; its only libc imports are kill and socket. The .NET 8 runtime it targets has no prctl call in its System.Native.
    • The test harness's stand-in by that name exists only inside the test container.
    • Nothing else on a runner or a host is a subreaper by that name. On macOS an orphan goes to launchd (XNU bsd/kern/kern_exit.c, proc_reparentlocked(q, initproc, …)), and in a runner container to the image's init (ENTRYPOINT ["tini", "--", …]).
    • A kill on a host through the allow test would need three independent faults at once: the hook refusing an event it allows; its parent dying before the hook's bash starts; and such an adopter existing.
  4. A process between the worker and the hook. If one were ever started there, and it exited while the worker lives, the worker would complete the step itself 5 s later, whether or not the hook still holds its output (ProcessInvoker.cs:485-499). The job's always() and failure() steps could then run, and the hook cannot prevent that: its parent is then not the proven worker. The runner starts the hook directly from the worker, so no such process is there.
  5. The hook allows events it does not know. It refuses the events it knows can carry a fork's code, and allows an event of any other name as this repository's own. The README's security model names the events it refuses; "What it lets through" below lists them.

When the worker is not proven: block, then end

When any check fails, the hook kills nothing. It writes the refusal with its own pid and blocks in its step, ignoring HUP, INT and TERM, so no later step starts. About every 5 seconds (a sleep, plus scheduling) it reads its own parent again. On Linux that read is /proc/self/stat, and it counts only when that /proc numbers the hook as $$. Once a read succeeds and names a process other than the one it started under, it exits non-zero. A failed read keeps it blocking, and it never signals anything. So a blocked hook that cannot read its parent never ends by itself, and signals nothing. On a host that would take the allow test refusing wrongly AND its parent reads failing persistently.

  • When ending releases nothing. Only the hook's direct parent waits on it, and steps run only inside the worker. The runner starts the hook directly from the worker (JobHookProvider.cs → ScriptHandler → ProcessInvoker, UseShellExecute = false), so that parent is the worker, and once the worker is gone no step can run.
  • The exception is limit 4: a process between the worker and the hook that exits while the worker lives.

Under a shell other than bash, which need not even set $PPID, the hook cannot tell when its parent is gone, so it blocks for good and kills nothing. That branch has no exit statement and turns errexit off (set +e), because the runner starts sh with -e (ScriptHandlerHelpers.cs:19). The runner starts the hook with bash wherever bash is on its PATH.

Read from runner v2.338.2's source, not yet seen on a live runner: the hook's step runs under always() (JobExtension.cs:309-312), so a cancel or the job's timeout does not cancel it. The worker stays in it, and the listener kills the worker once the cancel timeout has passed (at least 45 s, JobDispatcher.cs:1279-1285). No later step runs, and the blocked hook then ends by itself. A person has nothing to end by hand.

What it lets through

A job runs only when its event names no other head repository:

  • push, workflow_dispatch, schedule, repository_dispatch, merge_group and comment events run this repository's code (a fork's push runs in the fork);
  • pull_request, pull_request_review and pull_request_review_comment run only when the payload names this repository as the head;
  • pull_request_target from a fork is refused, because its workflow may check out the fork's head;
  • workflow_run runs only when the triggering run's head repository is this one;
  • fail closed: a missing, unreadable or malformed event file (not exactly one JSON object), a missing head repository, a pull_request* or workflow_run event that names none, an issue_comment without object-valued issue and comment, a missing event name, or an unset variable is a refusal;
  • an event of any other name is taken as this repository's own and allowed (limit 5). jq compares the names itself, so no trailing newline or look-alike name passes. A crafted name cannot add a line to ::error:: (tojson).

The repository's approval policy for outside contributors' fork runs is unchanged: the hook is the second lock, the one a fork's workflow files cannot change. No repository setting or variable is changed.

Tests

  • On any host (scripts/self-hosted-runner.test.ts, "runs a job from this repository"): only jobs the hook allows, under a parent that can never pass the proof. That parent is a copy of bash named not-the-worker (on macOS a symlink to bash); /proc/<pid>/exe and its name on Linux, and on macOS whatever ps prints, never end in Runner.Worker. A refusal nobody meant there blocks and kills nothing, and the test fails at its own timeout, which signals only the parent it spawned.

  • Isolated only (scripts/self-hosted-runner/hook-test-harness.sh): every case that can reach a refusal. The harness starts the hook, and any parent for it, only after one of two guards passes:

    • A PID namespace of its own (unshare --user --map-root-user --pid --fork --mount-proc --kill-child): the harness is PID 1, PID 1 of /proc carries the run's random token, and no other process is visible.

    • A throwaway container of an image that carries the marker, hook-test.Dockerfile's (not the runner image): the root-owned, read-only marker /opt/runner-hooks/ovis-runner-image added. The live runner image has no marker, so these tests never run in a live runner's container. The guard needs four more things:

      • /.dockerenv;
      • tini or docker-init as PID 1;
      • a PID namespace other than the host's initial one (/proc/self/ns/pid is not pid:[4026531836]);
      • at probe time, no process in /proc that is neither the harness nor above it. That refuses a container sharing another's PID namespace.

      The harness is also made a child subreaper, and it proves that an orphan of its subtree comes to it.

    Anywhere else the tests skip and print why. A failed unshare or a missing marker only ever leads to a skip.

  • Cases:

    • the refusals above: the parent SIGKILLed, no next step;
    • the macOS path, run on Linux through a copy that differs only in its proc=/proc ps=/bin/ps line: procps proves and kills, while a failing, silent or look-alike ps blocks;
    • blocks that kill nothing: a live parent that is not the worker (systemd, Runner.Worker2, Runner.Worke), the worker as a grandparent, a worker renamed systemd, and a systemd that names itself Runner.Worker;
    • ends after a block: a parent that ends before the refusal, and a parent that ends after the hook says it blocks.

    The harness recognises a block by the hook's own "this hook blocks (pid N)" line. It then requires the block to hold: pid N must start a second /bin/sleep (it has read its parent again and stayed), with the hook and its parent running at every poll of /proc, within at most 150 polls 0.1 s apart (15 s of waits plus the reads and scheduling, not a strict bound). The bound is the hook's own loop, never a silence, and it shows the block held through one more read of its parent, not forever. Every case asserts that two decoys (another Runner.Worker and a Runner.Worker2) still run, and that every process above the harness still runs with the same start time.

  • CI runs them in a container on every pull request and every push to main: the new check "Hook kill tests (container)" (.github/workflows/hook-kill-tests.yml).

    • Where it runs: on GitHub's hosted ubuntu-24.04, written literally in the job.
    • What it runs: it builds scripts/self-hosted-runner/hook-test.Dockerfile's image (not the runner image). That image is oven/bun:1.4.2-debian pinned by digest, plus jq, procps, python3, a non-root user and the marker. It installs dependencies on the VM with --ignore-scripts, then runs hook-test-container.sh.
    • How the container is confined: --rm --init --network none --cap-drop ALL --security-opt no-new-privileges --pids-limit 2048, the source read-only, no socket, no --pid.
    • Proofs first: the script prints and checks the container's isolation before any test starts (docker inspect's HostConfig and mounts, PID 1 docker-init, a PID namespace other than the VM's and the initial one, no docker socket, empty capability sets, lo alone, /src read-only).
    • Counts: it then requires exactly 8 passes, 0 failures and no skip: the allow test and the 7 isolated tests.
    • Permissions: a read token only; no secret, no environment; 20 minutes at most.
    • Not covered: the macOS proof path runs there through a ps stub. On a real macOS bash and jq, the macOS CI job runs the allow test alone.

Which case runs where

Case Hosts, Fast checks and the macOS job (the test file outside the container) The container check "Hook kill tests (container)" (CI)
A job from this repository is allowed (8 events) yes yes
A fork's code is refused, and the worker is SIGKILLed (14: pull_request, pull_request_target, review, review comment, deleted head, workflow_run of a fork or with no head, 7 look-alike names) no yes
A job it cannot check is refused and the worker SIGKILLed (15: missing, directory or unset event path, empty, truncated, non-JSON, [], a string, a wrong shape, two documents, unset repository, no jq, and 3 with a closed output) no yes
An event that must name its head repository and does not is refused (11) no yes
The macOS proof path, through ps (a procps ps on Linux) no yes
A parent that is not proven the worker: the hook blocks and kills nothing (9 parents) no yes
A block ends once its parent is gone, killing nothing (2) no yes

Against main. On main, Linux CI ran 14 refusal cases asserting SIGKILL in Fast checks, under a hook that killed whichever ancestor was named Runner.Worker. All 14 are in the container check, together with the rest above.

The check becomes required. "Hook kill tests (container)" becomes a required check on main after this pull request merges, by the maintainer's decision of 2026-11-17, once it has run green on main. Nothing in the repository asserts that it is or is not required. The workflow test pins its name, runner, permissions, triggers, confinement and its last step: the check of the files the container wrote.

When it runs.

  • It runs on pull_request with ci.yml's own types (opened, synchronize, reopened, ready_for_review), so it appears wherever the required checks do, and on a push to main. Retargeting a pull request's base does not start it, as it does not start CI today.
  • It has no path filter and no condition, so it runs on drafts and on docs-only changes too.
  • A pull request runs the workflow file of its merge commit with main. An open pull request therefore gets the job on its next push (or reopen) once this file is on main, without merging main itself.
  • A first-time contributor's run waits for a maintainer's approval, and its check stays expected until then.
  • A pull request with a merge conflict starts no pull_request run, for this check as for every other.
  • It ends with its own check of the result: a last step reads the files the container itself wrote (its command's status, and the tests' output). It fails unless they say status 0 and exactly 0 fail;8 pass; with no skip. A script that returned early leaves no such files.
  • Known and stated:
    • The image's apt packages (jq, procps, python3) are not version-pinned. The build pulls from Docker Hub and Debian at run time; the base image is pinned by digest, and Bun by version.
    • The job's measured time, locally in a confined container: the image build 17 s, the run 27 s with the last check (the tests themselves 22.6 s). Its time on GitHub, with its install step, is added after its first run there.
    • In the container, a blocked hook and its fake parent are left running when the harness returns. They are the harness's own, in the container's own PID namespace, and they end with the container.

What a pull request can change

A pull request runs its own copy of this workflow, which it may change like any workflow. The job's last step trusts files written by scripts the pull request itself can edit, as does every check whose workflow a pull request can edit. Closing that would need an organisation-level required workflow, which a repository owned by a personal account does not have. Reviewers read the diff of scripts/self-hosted-runner/ and of this workflow on every pull request that touches them.

Events the hook cannot judge

The hook judges a job by its event alone.

  • Allowed: issue_comment, workflow_dispatch, schedule, push, merge_group and repository_dispatch run this repository's own workflow files.
  • Refused: pull_request_target from a fork, because its workflow may check out the fork's head.
  • The gap: a comment-triggered workflow could do the same, and the hook would not see it.

What this branch's workflows do:

  • issue_comment: only cla.yml uses it, and it runs on ubuntu-24.04.

  • schedule: growth-snapshot, omp-question-compat, windows-install and windows-terminal-qa run on GitHub's runners.

  • Jobs that can take a self-hosted label on workflow_dispatch, push or workflow_run:

    • ci.yml and remote-bundles.yml check out github.sha;
    • mac-dmg.yml and windows-app.yml check out an input tag of this repository;
    • release.yml checks out github.sha or a tag of this repository;
    • pages.yml checks out workflow_run.head_sha, only when the triggering run was a push of this repository.

    Each downloads only its own run's artifacts.

None of them checks out or runs a pull request's code, or a comment's text. A workflow added later that does must not take a self-hosted label.

Mac runner

scripts/self-hosted-runner/README.md "Mac runner" says how to install, check and undo the hook there, with placeholders for the machine's paths, account, service label and runner name. It asks no one to run a refusal by hand, or to end a blocked hook: cancelling the job is enough.

Validation

Why it was tested this way: an earlier, uncommitted version of this change, tested on a host, signalled its startup parent and ended a whole user session. The hook now signals only a proven worker and otherwise blocks. Its refusal and kill tests refuse to run outside a private PID namespace or a marked container.

At 2c2afb34 (the hook as it is in this pull request), locally, in confined containers, never on a host:

  • The kill tests ran in one throwaway container of the runner image with the marker added: 8 pass, 0 fail. The container was started with --rm --init --user runner --network none --cap-drop ALL --security-opt no-new-privileges, in its own PID namespace (checked inside and from docker inspect), with no docker socket and the source read-only.

  • In a container of the live runner image, the same file skips them: 1 pass, 7 skipped, 0 fail, with both reasons named.

  • bun run check fast in a confined container without network: workflow syntax, generated types and themes, typecheck, build and unit tests all ok; unit tests 17863 pass, 0 fail.

  • On GitHub's run at that head:

    • Fast checks printed the skip warning, and 63 pass, 7 skip for this file;
    • the macOS job ran the allow test: 1 pass, 7 skip.

    Every check passed.

At ec206b58 (this pull request's head), locally, in confined containers, never on a host:

  • The job's own lines (its build step, its run step and its last check, run verbatim): 8 pass, 0 fail. The image build took 17 s, and the run 27 s with the last check. The container printed and checked its proofs before any test started: docker-init as PID 1, its own PID namespace, no docker socket, empty capability sets, lo alone, /src read-only, and docker inspect's Privileged=false CapDrop=[ALL] CapAdd=[] NetworkMode=none PidMode= SecurityOpt=[no-new-privileges].
  • The same file in a container of the live runner image: 1 pass, 7 skipped, 0 fail, with the skip warning naming both reasons.
  • bun run check fast in a confined container without network: 17872 unit tests pass, 0 fail, and the six stages ok (workflow syntax, generated types, generated themes, typecheck, build, unit tests).
  • GitHub's first run of "Hook kill tests (container)" at this head, on a GitHub-hosted ubuntu-24.04 runner: the job took 52 s (about 56 s from the pull request event to its result). Install took about 0.4 s with the cache restored, the image build about 14 s, and the run 27 s with the last check. The copy that leaves .ci-cache out took at most about 1.4 s, with the Bun cache restored into the checkout. 8 pass, 0 fail, with the proofs printed before any test.

The live runner image is not rebuilt for this pull request. The marker is only in the test image.

No changelog fragment: this is a CI runner change users do not notice.

The hook found the job's Runner.Worker and wrote its refusal through /proc, which macOS does
not have, so on the Apple Silicon runner eamac-ovis-mac it would refuse a fork's job without
killing the worker. Where /proc is missing it now asks ps for the parent and name, and writes
the refusal to the system log (logger -t ovis-runner-guard). The decision and the Linux path
are unchanged. The hook tests now run on macOS too: on Linux a failing ps stub keeps them on
/proc, and on macOS a symlinked bash stands in for Runner.Worker. README: a "Mac runner"
section under Security model.
@coderabbitai

coderabbitai Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • New Features
    • Runner safeguards now identify worker processes on both Linux and macOS, with refusal messages sent to an available logging destination.
  • Documentation
    • Added setup, verification, and rollback guidance for the Mac runner, including job eligibility conditions and the continued approval requirement for fork runs.
  • Tests
    • Expanded job-started hook coverage to non-Windows platforms, including checks for process discovery and refusal logging.

The job-started guard now discovers worker processes on Linux and macOS and uses a fallback logger when /proc/1/fd/2 is unavailable. Tests cover non-Windows platforms, and the runner README documents Mac setup and guard behavior.

Changes: Runner guard portability

Layer / File(s) Summary
Process discovery and refusal logging
scripts/self-hosted-runner/job-started.sh
The guard reads process ancestry from /proc when available and uses ps otherwise. It writes refusal messages to /proc/1/fd/2 when available and falls back to logger.
Cross-platform tests and Mac runner instructions
scripts/self-hosted-runner.test.ts, scripts/self-hosted-runner/README.md
The hook tests run on non-Windows platforms and check process-discovery and refusal logging behavior. The README documents Mac runner setup, guard conditions, verification, and rollback.

Estimated code review effort: 2 (Simple) | ~12 minutes

Change: Feature

Possibly related PRs

  • devswha/ovis#1743: Adds the existing runner-side job-started guard that this change extends to macOS.
  • devswha/ovis#2835: Adapts the fork guard to find Runner.Worker on macOS.
  • devswha/ovis#3981: Enables same-repository macOS session runs through the self-hosted Mac runner, whose guard behavior this change addresses.
Merge Risk: Minimal · up to fb425

This change lets the fork-job guard run on the Apple Silicon runner and adds tests and documentation for it. No concrete defect was found, and the Linux behavior is unchanged. The risk of merging is minimal.

Pre-merge checks: Passed 4

Check name Status Explanation
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Title check Passed The title names the main change: job-started.sh now refuses fork jobs on the Mac runner, not only Linux. The diff matches this. The summary confirms the refuse logic now uses ps on macOS and the tests…
Description check Passed The description follows the repository template. It has the Change section, which explains the problem and behavior, and the Validation section, which lists the checks run and their results. It is ver…
Full details: Title check

Explanation

The title names the main change: job-started.sh now refuses fork jobs on the Mac runner, not only Linux. The diff matches this. The summary confirms the refuse logic now uses ps on macOS and the tests cover macOS. The title also mentions the hosted-container testing, which is a minor detail and not the main change. Length is long but the wording is specific.

Full details: Description check

Explanation

The description follows the repository template. It has the Change section, which explains the problem and behavior, and the Validation section, which lists the checks run and their results. It is very long, and it has an extra Mac runner section. The Change section does not link a maintainer-agreed issue, which the template asks for on feature work. The description covers the required content in detail, so the check passes.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 7e778e3 and fb425e7.

Files selected for processing: 3

  • scripts/self-hosted-runner.test.ts
  • scripts/self-hosted-runner/README.md
  • scripts/self-hosted-runner/job-started.sh

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 5 remain after this review.

devswha added a commit that referenced this pull request Nov 16, 2026
…lf-hosted Mac (#3981)

## Why

On 2026-11-16, GitHub's hosted macOS arm64 runners ran short. Since
18:00 KST, five macOS jobs never got a runner and were cancelled after
15 minutes in the queue ("The job was not acquired by Runner of type
hosted even after multiple attempts"). Four of them were this check,
"Native macOS session identity". The ones the Actions API still lists:

| Run | Job | Queued (UTC) | Cancelled (UTC) |
|---|---|---|---|
| 43844908713 | desktop (darwin-arm64) | 10:01:18 | 10:16:19 |
| 43871878368 | Native macOS session identity | 13:02:19 | 13:17:20 |
| 43879220298 | Native macOS session identity | 13:48:17 | 14:03:18 |

Each cancel turns the PR red until someone reruns the job, so a merge
waits 20 minutes or more. On a hosted runner the check takes 40 s
(median of 25 recent green runs; max 54 s). The project's self-hosted
Mac runner (Apple Silicon; labels `self-hosted, macOS, ARM64,
self-hosted-ovis-mac`) is registered in this repository, online and
idle.

This PR adds a switch to move only this one check to that runner. **It
changes nothing until the repository variable `CI_MAC_LABELS` is set**,
and that must not happen before the fork refusal below exists on the
Mac.

## Where the job runs

`runs-on: ${{ github.event.pull_request &&
github.event.pull_request.head.repo.full_name != github.repository &&
'macos-15' || fromJSON(github.workflow == 'CI' && github.ref !=
'refs/heads/main' && vars.CI_MAC_LABELS || '"macos-15"') }}`

| Run | `CI_MAC_LABELS` unset | set to
`["self-hosted","self-hosted-ovis-mac"]` |
|---|---|---|
| Fork pull request (the guard decides before the variable is read; also
a deleted head repository) | macos-15 | macos-15 |
| Same-repository pull request, branch push or manual CI run off main |
macos-15 | the Mac |
| Push to main | macos-15 | macos-15 |
| Release validation (`release.yml` → `release-validate.yml` → ci.yml as
a called workflow) | macos-15 | macos-15 |

- **The guard** is the light jobs' fork guard character for character
(`remote-bundles.yml` `bundle-windows`), with `'macos-15'` in place of
`'ubuntu-24.04'`. `&&` and `||` short-circuit, so for a fork `fromJSON`
is never evaluated, whatever the variable holds.
- **What a release does:** it never validates on the Mac. A called
ci.yml runs under its caller's name ("Release validation"), so
`github.workflow == 'CI'` is false there. A Release run may also take
main's push run in place of its own, so main's runs stay on `macos-15`
as well (`docs/development.md`'s release table stays true).
`scripts/release-ci-reuse.test.ts` fails if any workflow other than
ci.yml reads `CI_MAC_LABELS`, or if ci.yml reads it without that gate.

## What protects the Mac today

A fork's pull request runs the fork's own workflow files. So a fork can
write `runs-on: [self-hosted, self-hosted-ovis-mac]` itself, whatever
this expression says. That path is older than this PR: the runner is
already registered and online. The self-hosted Linux runners refuse fork
jobs in `scripts/self-hosted-runner/job-started.sh`, but that hook finds
and kills the job's `Runner.Worker` through `/proc`, which macOS does
not have. The repository has no refusal that works on the Mac. Today two
things protect it: the repository's approval policy for fork pull
request workflows, `all_external_contributors` (every outside
contributor's run waits for a maintainer's approval), and a job-started
hook on that runner since 2026-11-05 that refuses fork jobs. That hook
is a copy from the branch of #2835, which was closed unmerged: it is not
in this repository and was never reviewed. #3984 brings a reviewed hook
that works on macOS.

**`CI_MAC_LABELS` must not be set before a reviewed fork refusal that
works on macOS is in place on that runner.** That refusal is a separate
change (#3984), not part of this PR.

## What changes

- `ci.yml` `macos-session`: the `runs-on` above, plus
`CLAUDE_CONFIG_DIR: ''` in the job's env. `server/claude-store.test.ts`
skips two session-identity tests (:83 and :440, 8 assertions) when a
Claude config dir is exported, and still exits 0. A runner whose
environment carries the variable would turn them off silently. In the
job's eight test files, every other skip depends on the platform, on
running as root (`getuid() === 0`), or on `/proc` (Linux). One assertion
in `scripts/install-herdr-core.test.ts:292` runs only when `plutil` is
on PATH, which is `/usr/bin` on every Mac.
- `.github/actions/setup-ci`:
- **On the Mac:** `oven-sh/setup-bun` installs into `$HOME/.bun/bin`
(`src/action.ts` at the pinned 0c5077e5: `join(homedir(), ".bun",
"bin")`, then rename over `bun`). The Mac runner runs as the Mac's own
account, so a job would replace that person's Bun. A second setup-bun
step, for self-hosted non-Linux runners only, gives it `HOME: ${{
runner.temp }}/setup-bun-home`. The runner empties that folder at the
start and end of every job, and setup-bun puts that `bin` on the job's
PATH. I dry-ran the action at the pinned SHA on the project's
self-hosted Mac runner with that HOME (cache off, since there is no
Actions token outside a job). Bun 1.4.2 landed only under the temp HOME,
the real `~/.bun/bin/bun` kept its SHA-256, and nothing under `~/.bun`
changed.
- **On self-hosted Linux:** nothing changes. "Verify prepared
self-hosted tools" and "Seed Bun cache from the runner host" went from
`runner.environment == 'self-hosted'` to `runner.environment ==
'self-hosted' && runner.os == 'Linux'`. That is the same on every
self-hosted Linux runner and false on the Mac, where the prepared-image
check refuses anything but Linux x64 (`::error::The prepared CI image
requires Linux x64.`) and there is no host cache. The hosted setup-bun
and setup-node steps keep main's exact conditions.
- **Test gap (older than this PR):** no test pinned the verify step's
`if`, and the setup-bun check was a loose `toContain`, so turning the
Linux check off broke nothing. `scripts/ci-setup.test.ts` now pins the
verify step's condition, both setup-bun conditions and the Mac step's
HOME.
- `scripts/light-runner-workflow.test.ts` pins this job's expression,
its `CLAUDE_CONFIG_DIR: ''`, the fork guard coming before any variable,
and hosted labels for a fork and for an unset variable. Its existing
check (no pull request job reaches a self-hosted runner without the fork
guard) accepts exactly this expression.
`scripts/release-ci-reuse.test.ts` lists the new event read in
`EVENT_READS` and adds the release test above.
- Docs: `docs/development.md` (variable, release, account, fork refusal)
and `scripts/self-hosted-runner/README.md`.

I mutation-checked each guard by removing it in a scratch edit; each
removal fails its test: the workflow/main gate (4 tests),
`CLAUDE_CONFIG_DIR` (1), the Linux-only verify step (1) and the Mac
setup-bun HOME (1).

## Measured on the project's self-hosted Mac runner (by hand, as close
to the job as possible)

macOS 27.0.1 arm64. Fresh shallow clone of main `00069b4`. Bun 1.4.2
downloaded into a scratch folder. `BUN_INSTALL_CACHE_DIR` inside the
checkout, emptied before each run (the self-hosted path skips the
Actions cache). The runner's PATH. `HERDR_TEST_MODE=unit`. The job's
exact `bun test` line (8 files):

| Run | `bun install --frozen-lockfile` | `bun test` | Result |
|---|---|---|---|
| 1 | 8.7 s | 29.8 s | 263 pass, 7 skip, 0 fail |
| 2 | 10.8 s | 27.7 s | 263 pass, 7 skip, 0 fail |
| 3 | 17.7 s | 28.5 s | 263 pass, 7 skip, 0 fail |
| 4 | 17.6 s | 28.1 s | 263 pass, 7 skip, 0 fail |
| 5 | 16.8 s | 28.9 s | 263 pass, 7 skip, 0 fail |

All 8 files passed in every run (the 7 skips are platform skips, the
same as on the hosted runner). That is 38-46 s for install and tests,
plus checkout (5.5 s in the runner's 2026-11-05 log of this job) and Bun
setup: about the hosted 40 s, without the queue.

The tests keep off the real state on that Mac, where the account's herdr
and Ovis are running. They give their spawns a temporary
`HOME`/`XDG_CONFIG_HOME`, use `port: 0` on loopback and `mkdtemp` roots,
and the `bunfig.toml` preload points `HERDR_SOCKET` at a missing socket.
macOS herdr discovery lists the account's processes with `ps eww` but
probes only sockets of a server whose `HOME` is the test's temp home.
The installer test puts stand-in `launchctl`/`id` first on PATH. After
the five runs, nothing under that account's herdr, Ovis or Claude
folders had changed, and its herdr and Ovis processes kept their start
times.

Context: #2835 (all macOS jobs to this Mac, with a heartbeat route) was
closed on 2026-11-09 because that machine is too slow as a general CI
runner. This PR moves only this one ~40 s unit check, measured above.

## How to switch on, and back

- **On** (only after the fork refusal above is installed on the Mac):
set the repository variable `CI_MAC_LABELS` to
`["self-hosted","self-hosted-ovis-mac"]`.
- **Back:** delete the variable (or set it to `"macos-15"`). The next
run is hosted again.
- A non-JSON value fails the job on same-repository runs (a red check,
forks unaffected). A list that does not name the Mac, such as
`["self-hosted"]`, could match the Linux runners; use the exact value
above.

## Risk

- One runner: these jobs queue behind each other, about 40 s each.
- If the Mac is off or asleep, the check waits for it instead of
failing; delete the variable to go back. This check is not one of the
required checks.
- With the variable set, Dependabot's same-repository PRs (SHA-pinned
action bumps) also run this job on the Mac.

## Not measured

A real Actions job on that runner with this diff (setup-bun with the
temp HOME inside the runner, its post-job cache save, the runner's
job-started hook). That first happens when the variable is set.

## Validation

- `bun test scripts/light-runner-workflow.test.ts
scripts/ci-setup.test.ts scripts/release-ci-reuse.test.ts`: 123 pass, 0
fail, plus the mutation runs above.
- `bun run check fast` on the final tree: passed (workflow syntax,
generated files, typecheck, build, unit tests).
- No changelog fragment: CI-only, nothing users notice.
A refusal kills the hook's own parent only when every check proves it the job's
Runner.Worker, made again right before the kill: still the hook's parent, its
executable Runner.Worker (/proc/<pid>/exe and name on Linux, /bin/ps on macOS),
the hook's user, an unchanged start time. No ancestor walk, no $PPID fallback.
When a check fails it kills nothing and blocks in its step.

The event filter goes by the event's name as well as the payload, and jq compares
the names itself.

Every test that can reach a refusal runs only under hook-test-harness.sh, behind a
guard it proves first: a PID namespace of its own, or the runner image's container
(a new read-only marker in the image, its init as PID 1, the harness a subreaper).
Elsewhere those tests skip. The macOS CI step runs the allow-path test alone. The
README's Mac runner section uses placeholders, and its hand check blocks rather
than kills.
…test image

- runJobStarted runs the hook under a parent named not-the-worker, so a refusal
  nobody meant there blocks and kills nothing, and the test fails at its own timeout.
- The live runner image carries no test marker: the container guard needs a
  throwaway image built from it with the marker added.
- README: no hand-run refusal; end a blocked hook only after the job is cancelled
  and its worker is gone; drop the DYLD_INSERT_LIBRARIES claim, which runner
  v2.338.2's source does not support for the hook's step.
- job-started.sh re-reads the hook's parent last before the kill.
- block() re-reads the hook's own parent every 5 s, with the proof's reads, and
  exits non-zero once that parent is no longer the one it started under: only the
  parent waits on the hook, and with the worker gone no step can run. It never
  signals anything; a failed read keeps it blocking. The README's ps-then-kill
  instruction is gone: cancelling the job is enough.
- The harness's container guard refuses the host's initial PID namespace
  (pid:[4026531836]), and its probe refuses any process in /proc that is neither
  the harness nor above it (builtins only).
- The harness recognises a block by the hook's own "this hook blocks" line, not
  by a silence; a new case has the parent end after the block.
…ood; a block must hold

- hook-test-harness.sh: four `$$` had become `$` (the namespace read, the
  not-PID-1 check, the ancestry walk's start, a comment), so the container guard
  could never pass. Restored.
- job-started.sh: under a shell other than bash, which need not set $PPID, the
  hook blocks for good again; that branch has no exit.
- The harness takes a block as holding only once the hook, after its "this hook
  blocks (pid N)" line, starts a second /bin/sleep with it and its parent still
  running (at most 150 polls of /proc, 0.1 s apart); otherwise it reports unproven.
…s /proc/self

- The non-bash branch turns errexit off: the runner starts sh with -e
  (ScriptHandlerHelpers.cs:19), and two failed sleeps must not end the hook.
- The block loop reads its parent from /proc/self/stat and ends only when that
  /proc numbers the hook as $$.
- README: right before the kill only the start time and the parent are read
  again; the self-ending block's limit (a process between worker and hook) is
  stated; the harness's persistence bound is polls plus scheduling.
Ending a block releases nothing when the hook's parent is the worker itself, as
the runner starts it; a process between them that exits while the worker lives
lets the worker finish the step. Comment lines only.
…nt readers

hook-test-harness.sh hands the hook an event path (GITHUB_EVENT_PATH); it is started
only by the hook's tests, no workflow starts it, and it decides nothing about what a
run does, so a Release run may still take main's run.
…ner job

The hook's isolated tests (its refusals, the signal to a proven worker, the block
and its end) run in CI again, as main's refusal tests did, now in a confined
throwaway container on GitHub's ubuntu-24.04: the check "Hook kill tests
(container)", on every pull request (drafts included) and every push to main.

- hook-test.Dockerfile: oven/bun pinned by digest, jq, procps, python3, a
  non-root user and the marker the harness guards on; not the runner image.
- hook-test-container.sh: starts the container detached and confined, prints and
  checks its isolation before any test starts, and fails on any skip or any count
  but 8 pass.
- The isolated refusals also cover a fork's pull_request_review_comment.
- README: where each test runs, the pid-reuse limit, ps comm as the macOS proof.
…' image truly

- hook-kill-tests.yml ends with a step, independent of the container script, that
  fails unless the files the container wrote say status 0 and exactly 0 fail;
  8 pass with no skip; the workflow test pins that step, and that the job has no
  continue-on-error and no needs.
- Comments, the skip warning and the README no longer say the tests' image is
  built from the runner image; the README says that a blocked hook and its fake
  parent end with the container, and that on macOS only the allow path runs.
…ache

The container copies every top-level entry of the checkout except .ci-cache, the
Bun install cache setup-ci restores into the workspace on GitHub's runners, so the
required check never spends its copy timeout on that cache. find's -exec ... +
form fails when any cp fails, and the copy must hold bunfig.toml and node_modules.
@devswha devswha changed the title ci(runner): job-started.sh refuses fork jobs on the Mac runner too ci(runner): job-started.sh refuses fork jobs on the Mac runner too, tested in a hosted container Nov 16, 2026
…tHub's checks

The local merge gate runs Fast checks in the runner image, where the seven isolated
job-started hook tests skip, and an admin merge through it would skip the check
"Hook kill tests (container)", which runs them on GitHub's runner. So a PR that
touches scripts/self-hosted-runner/ or scripts/self-hosted-runner.test.ts waits for
GitHub's checks.
@devswha
devswha merged commit e16ac10 into main Nov 16, 2026
28 of 29 checks passed
@devswha
devswha deleted the ci/mac-runner-refuses-forks branch November 16, 2026 21:02
@devswha

devswha commented Nov 16, 2026

Copy link
Copy Markdown
Owner Author

Merge pass

Merged head 48db3df426b5 as e16ac1076f4f on GitHub's checks, with no unresolved review threads.

Reviewer Verdict Note
claude CLEAR
codex CLEAR

Merge pass note for #3984 (ci(runner): job-started.sh refuses fork jobs on the Mac runner too, tested in a hosted container).

What it does: the self-hosted runners' job-started hook refuses any job whose code comes from a fork, now on the Mac runner too. To stop a refused job it sends one signal to its direct parent, and only when that parent is proven to be the runner's worker; otherwise it blocks and signals nothing. A new check, "Hook kill tests (container)", runs the hook's refusal and kill tests on GitHub's hosted runner inside a throwaway confined container, on every pull request and every push to main. It becomes a required check after this merge, by the maintainer's decision of 2026-11-17.
CodeRabbit reviewed only the first head, so the reviewers' findings and what became of each are written here.
How it was reviewed: the hook, its harness and the test plan were read in stages by two reviewers before anything ran; the kill tests then ran only inside confined containers (no network, capabilities dropped, a private PID namespace shown first); two reviewers read the public heads without executing the hook.
Sent back for: a test that could reach a kill on a host; an instruction to stop a process by its number; a guard that inferred instead of proving a private PID namespace; and, at the first public head, the most important one: with the kill tests behind an isolation guard that skips, CI no longer tested that the hook refuses a fork's job, nor its kill, which main's CI does today. That is why the container job exists: all 14 of main's refusal cases are in it, with the kill.
Checked at this head: the hook is byte-identical to the reviewed one; the new job cannot pass without testing (a skip, a missing or stale result file, an early exit or any other count fails it); it ran green on its first run (52 s; isolation proofs printed and checked before the tests; 8 of 8); on hosts and in the runner containers only the allow-path test starts the hook, under a parent that can never pass the proof.
Limits, stated in the description and accepted: between the hook's last check and its signal the parent could exit and its process id be reused (a shell cannot close that); on macOS ps comm is the only proof of the executable; an orphaned hook adopted by a same-user child subreaper named Runner.Worker would pass the proof (no such process exists; the runner's source sets no subreaper); a blocked hook that cannot read its parent never ends; the hook allows an event it does not know; a pull request can edit this workflow like any other; the job downloads its base image and packages on every run.
Follow-ups for the CI lane: the job's failures for outside reasons are counted over its first runs before it is made required; scripts/self-hosted-runner/vm-runner.sh stop and the launcher tests' pattern kill get their own pull request; the README gains the four limits that only the description states.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant