Skip to content

docs: the enterprise path, the macOS gate user, and || exit 2 on pre - #30

Merged
pete-builds merged 19 commits into
mainfrom
docs/gate-own-user
Nov 13, 2026
Merged

pete-builds merged 19 commits into
mainfrom
docs/gate-own-user

Conversation

@pete-builds

@pete-builds pete-builds commented Oct 2, 2026 •

Copy link
Copy Markdown
Owner

Steps 1 and 4 of the enterprise path. Step 1 used to wait on a manual sudo run on a Mac. It is now a CI job, macos-gate, that runs on every push and pull request, and the macOS row is marked tested on the strength of that job. Draft. The fifth review found nothing blocking (merge with notes); its notes are in, below.

What changes

  • docs/enterprise.md: one recommended path, every part marked built and tested or designed only. Every managed-settings key and path was checked against the Claude Code docs pages, not memory: allowManagedHooksOnly, disableAllHooks, permissions.disableBypassPermissionsMode ("disable"), the com.anthropic.claudecode plist domain, HKLM\SOFTWARE\Policies\ClaudeCode, the file paths, and source precedence (only the highest-ranked managed source applies by default). It also notes that /goal doesn't run under allowManagedHooksOnly.
  • scripts/writ-gate-macos.sh: runs the gate as a hidden _writ account (no shell, no password) under two LaunchDaemons, from a root-owned program folder, with state in a fresh /var/db/writ; uninstall has the gate archive and empty that state, then removes the empty folders by name. Passes shellcheck; the generated plists pass plutil -lint.
  • docs/claude-code.md: the macOS setup, a first-run checklist, the local managed settings file, what the separate account does and does not protect, and || exit 2 on every pre hook. Claude Code runs the tool when a PreToolUse hook exits with any code but 2 and prints no decision. Tested in a headless session: with the hook pointing at a missing binary, a Bash touch ran; with || exit 2, it was blocked.
  • .github/workflows/ci.yml: the macos-gate job (below). Actions pinned by commit SHA, contents: read only, no secrets, so it runs the same on a fork's pull request.

The design, after four reviews

Every hole the reviews found in the last two rounds came from one mechanism: root changing the owner of a tree that _writ, or the normal user through an ACL _writ left, could shape (hard links to root files and root sockets, ACLs, 0777 folders). That mechanism is gone. Root never changes the owner of, or walks, anything the gate could have shaped.

  • Install never adopts state. If this run creates the _writ account and /var/db/writ exists, it refuses and names uninstall, which archives it. Root then creates the whole tree fresh in root-owned /var/db, each folder with install -d and an explicit owner and mode. There is no recursive chown anywhere.
  • A reinstall over a live gate keeps the state untouched. It boots out the daemons, removes the socket name, and recreates the two log files, after a tripwire: /var/db/writ, home, run, and log must have the expected owner and mode and no ACL (find -maxdepth 0 -acl), or it refuses.
  • Uninstall archives, then deletes, as the gate. It removes the gate's crontab, boots out launchd's user/350 domain and both daemons (waiting until launchctl print no longer finds them), then STOPs and KILLs uid 350 until pgrep finds nothing (bounded; it dies if anything survives). Unless --purge is given, root creates /var/db/writ-archive-<time>-<pid>.tar with umask 077 and noclobber, and the gate's account writes the tree into it as a tar stream, so it holds nothing the gate could not read; a failed tar or an unreadable archive stops the uninstall before anything is removed. The gate's account then runs chflags -R and rm -rf on the contents of home and run, so a folder swapped for a symlink can only aim it at what the gate could delete anyway. Root removes the two log files by name and rmdirs home, run, log, and /var/db/writ; if anything is left, it renames the whole folder to /var/db/writ-leftover-<time>-<pid> and makes that one directory root:wheel 700. Then it removes the account, group, crontab file, plists, and program.
  • Rollback of a failed install removes only what that run created, through the same steps.
  • Removed in the third round: own_state, unsafe_entries, state_to_root, the hand-back block, and every recursive chown. Removed in the fourth: root's rm -rf of the tree and its find -exec chflags.

Fifth review notes

  • N1 --no-checksum is removed: its check and its copy read the same name, so a rename between them could install another program. The SHA-256 is always required.
  • N2 A source that is a symbolic link or not a regular file is refused; the copy stops at 256 MiB (head -c); a mismatch names no hash.
  • N3 as_gate runs the command in a new session (setsid through the system perl), with stdin /dev/null and stdout and stderr through pipes, keeping its exit status; the comment says exactly that.
  • N4 After removing the state, uninstall removes the crontab and kills uid 350 once more, and warns if anything still runs as uid 350 at the end.
  • N5 Uninstall refuses if the _writ account does not have uid 350.
  • N6 safe_dir refuses an ACL on the program folder or any folder above it.
  • N7 The audit record is checked by extracting that one member to a file and running writ audit on it, not printed to the terminal.
  • N8 Uninstall removes files owned by uid 350 in /usr/lib/cron/jobs.
  • N9 scripts/check-gate-script.sh fails on any root-run recursive rm, chown, chmod, or chflags, or a root find on the state tree. The job runs it, then runs it on a copy with rm -rf "$STATE" added, which must fail. Run against the script at 393536e it fails on the old root find ... chflags and rm -rf "$STATE" lines. This static check is what guards against root walking the tree again.
  • Docs A paragraph on what a compromised gate account can still do: read and forge what the gate holds, stall uninstall or leave a leftover folder, and leave uid 350 files outside /var/db/writ that a fresh install's gate would own; so after a suspected compromise, sudo find /System/Volumes/Data -xdev -user 350 and remove what it finds before installing again.

Also from the fourth review:

  • Cron. crontab is setuid root and cron.deny lists only Guest, so _writ could install a crontab that outlives uninstall and runs under the next install's _writ. Uninstall and rollback remove it before stopping the gate and delete the tab file after the account; a fresh install refuses a tab file for _writ, or files owned by uid 350 in /usr/lib/cron/jobs (the at spool; at is off by default on macOS, so this checks files rather than atq).
  • Small. -uses may not start with 0 (Go reads it as octal); a reinstall waits for launchd to let the old daemons go; as_gate runs from / with the fixed PATH and stdin from /dev/null.

From the third review:

  • Grant parsing. Go's flag parsing stops at the first word that is not a flag, so grant -name session -uses 0 x -uses 5 passed the old check and would have signed an unlimited grant. WRIT_GATE_GRANT is now strict flag and value pairs from -name -tools -under -uses -ttl -renew-before, each at most once; anything else is refused.
  • Program folder. WRIT_GATE_LIBEXEC with //, a trailing /, or the state path in any letter case is refused.
  • Logs. chmod -h -N on the log folder, chown -h on the log files.
  • Docs. v0.2.0's SHA256SUMS covers the tarballs, so the docs verify the tarball (and slsa-verifier), extract it, then hash writ-hook; the pre-install shell uses /usr/bin/git and PATH=/usr/bin:/bin; checklist step 2 also runs dscl . -search /Groups PrimaryGroupID 350. Uninstall's new behaviour is stated plainly: it archives then deletes the keys and receipts, a later install makes fresh keys, restoring old receipts is a manual read-only act on the archive, and a removed gate's keys are retired. The sentences claiming a root chown could not be misled, and that kept state was safe because it was root's, are gone.

Earlier rounds, still in place

  • First review: retire and unretire removed (an earlier same-user gate's keys are exposed; delete ~/.writ by hand); the program in /usr/local/libexec/writ with every folder above it checked for root ownership and no group or world write; a required SHA-256 checked on a root-owned copy; a fixed PATH and umask 022; Ctrl-C and signals roll back; an existing _writ is reused only with uid and group 350, shell /usr/bin/false, hidden, password *, and a group with gid 350 and no members; a failed dscl -search is an error; a stray _writ group with no account is refused.
  • Second review: the log folder is root's; the script runs from main on its last line, so lines appended while it runs never run; the docs' first-run checklist, managed settings file, and pre-install precautions.
  • L2 of the first review still stands as documented: a failed reinstall keeps the account and state but not the program and plists it replaced.
  • The old open question about uid 350 reuse is moot: uninstall no longer leaves state behind for a later account to inherit.

What the macos-gate job proves

A GitHub-hosted macOS runner has passwordless sudo. The job builds writ-hook and writ, then, with the runner's own user (uid 501, not root) standing in for the user Claude Code's tools run as, requires:

  1. scripts/check-gate-script.sh passes on the script and fails on a copy with a root rm -rf "$STATE" added. An install with no checksum, a wrong one, or a source given as a symbolic link is refused, and leaves no account, daemon, program, folder, or state.
  2. An install whose program folder sits under a runner-owned folder, or a root-owned folder its group can write, is refused; so are a program folder inside /var/db/writ (also as //var/db/writ/bin or /VAR/DB/WRIT/bin) or with a .. segment, a grant with -uses 0, without -uses, under another name, or -uses 0 x -uses 5, and a stray _writ group with no account.
  3. An install of /usr/bin/false fails at key setup after creating the account, and removes all of it.
  4. A real install runs the gate as _writ under launchd from /usr/local/libexec/writ (root:wheel 755); no ACL on /var/db/writ or its folders; the log folder root:wheel 755, each log _writ 640.
  5. Keys. For each of the three seeds, root reads it and finds it 600 _writ, and the runner user's cat fails with Permission denied; listing the folder is refused the same way.
  6. Program. The runner user's rename and overwrite of the program, and a write into its folder, fail with Permission denied; the same rename as root succeeds.
  7. A Read call's pre and post through the socket are admitted and receipted, a call naming the gate's keys is refused, and receipts reports 1 receipt(s) verified, 0 invalid with the audit links intact. The receipt, copied out as root, verifies with writ verify ("verdict":"valid"), and a different response fails (tally_mismatch).
  8. A reinstall over the running gate keeps its receipts; with the account's shell changed to /bin/zsh, a reinstall is refused.
  9. Plants. As _writ, all of these succeed: hard links to /private/etc/hosts and to the root socket /private/var/run/syslog, a symlink to /private/etc/hosts, a FIFO, a file flagged uchg, the ACL everyone allow add_file,add_subdirectory,delete_child on the run folder, a 0777 folder in it, and a crontab. A reinstall then refuses (carries an ACL). uninstall leaves /private/etc/hosts and /private/var/run/syslog with the owner, group, mode, and link count they had before; /var/db/writ and /usr/lib/cron/tabs/_writ are gone; no uid 350 process is left; the archive is root:wheel 600, unreadable by the runner, and the audit record read out of it passes writ audit.
  10. An install over a leftover /var/db/writ with no account is refused, and so is one with a crontab for _writ planted as root; a clean install then gives a fresh tree with no ACL, a run folder the runner user cannot create a file in, and 0 receipt(s).
  11. With a file holding data that the gate cannot read (mode 000), uninstall stops on the tar failure: the keys are still there and no archive is left. Once the file is readable again, uninstall leaves no _writ account or group, daemon, process as uid 350, program, or /var/db/writ, and pre then blocks the next call.
  12. A fresh install with WRIT_GATE_GRANT narrowed to Read admits a Read and refuses a Bash call ("allows only Read"), and uninstall --purge writes no new archive.
  13. Swap. While uninstall --purge runs, the runner user, inside a 0777 folder the gate made in run, keeps replacing 20 folders with symlinks to /private/var/tmp/writ-victim (root:wheel 700, holding a sentinel) behind a 30,000-file folder that keeps rm busy. The sentinel survives, the folder is unchanged, and what the gate could not delete ends in a root:wheel 700 leftover folder. This is a smoke test, not a regression control: the protection comes from the delete running as uid 350, which cannot write the victim folder, and from a delete that does not follow links; it does not show the race can be won against the old code. The static check in N9 is the regression guard.

Runs: green on macOS 26.7.2 arm64 at the current head, https://github.com/pete-builds/writ-protocol/actions/runs/43443301946, on the first run with the fifth-review notes.

Not covered: a live Claude Code session against the installed gate (the job writes the hook events itself), the managed settings file, an interrupted install (the traps are in place, not exercised), and the Linux setup.

Follow-ups

  • as_gate depends on /usr/bin/perl for setsid; if Apple removes perl, it needs another way to start a new session.
  • writ-hook grant should refuse extra arguments (if fs.NArg() != 0). The script's strict parsing covers the installed grant; the Go change needs a subprocess test, more than a few lines, so it waits for after the build freeze.
  • A safe migration command for a gate that ran in place: copy the old ~/.writ receipts out as the normal user, with no root step that follows paths in the user's folder.
  • Restoring the previous program and plists when a reinstall fails.

Merge order

#28 and #29 are merged, and main is merged into this branch.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Tx4atDCeB6HjAm4bkeL9WZ

docs/enterprise.md is one recommended path for an organization: a central
gate over mTLS, keys in Vault, grants from directory groups, device
certificates from Jamf or Intune, managed settings that lock the hooks on,
and receipts to a SIEM and write-once storage, each marked built and tested
or designed only. Every Claude Code managed-settings key and path was checked
against the Claude Code documentation pages on 2026-10-02.

scripts/writ-gate-macos.sh runs the gate as a hidden _writ account under two
LaunchDaemons (the gate on a socket, and the grant renewal), with the binary
root-owned, and retires the seeds of a gate that ran in place.

Every pre hook in the docs now ends in `|| exit 2`: Claude Code runs the tool
when a PreToolUse hook exits with any code but 2 and prints no decision, so a
missing binary (127) let a Bash call run in a headless session; with the
fallback it was blocked.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
pete-builds and others added 18 commits November 12, 2026 22:18
No conflicts. README.md and docs/claude-code.md auto-merged: main's
playground line and central-gate row sit alongside this branch's
enterprise.md index line, the macOS setup, and || exit 2 on pre.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tx4atDCeB6HjAm4bkeL9WZ
A hosted macOS runner has passwordless sudo, so the gate gets its own
_writ account and LaunchDaemons as it would on a laptop. The runner user
stands in for the agent's user: reading the gate's seeds must be refused
for permission, while root reading the same files must succeed, so a
missing file cannot pass as a refusal. A Read call through the socket
must be admitted and receipted, and the receipt must verify with the writ
verifier outside the gate, against the response the job sent, while a
different response must not. Uninstall must leave no account, daemon,
process, or binary, and a hook must then fail closed.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tx4atDCeB6HjAm4bkeL9WZ
Run 43358454491 installed scripts/writ-gate-macos.sh with sudo on a
GitHub-hosted macOS 26.7.2 runner: the runner user was refused all three
seeds with Permission denied while root read them, a Read call through
the socket was receipted and verified with writ verify, and uninstall
left nothing running. Both docs now cite the job, and say what it does
not cover: a live Claude Code session, retire and unretire, and Linux.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tx4atDCeB6HjAm4bkeL9WZ
…nstall

install copied the binary into /usr/local/bin without making it, and
created the _writ account first, so on a Mac with no /usr/local/bin it
stopped with the account made and nothing else. It now places the binary
(making the folder root:wheel 755 when missing) before the account, and
on any failure undoes only what that run created: daemons, account,
state, binary, and folder. A failed reinstall keeps what was there.

The macos-gate job moves the runner's /usr/local/bin aside, requires an
install of /usr/bin/false to fail and leave nothing, requires a good
install to make the folder root:wheel 755 and uninstall cleanly, then
puts the folder back before the main test.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tx4atDCeB6HjAm4bkeL9WZ
Treating the agent's user as the attacker:
- H1: remove retire and unretire. As root they followed symlinks the
  user could plant, which could move the live gate's seeds or hand a
  root file to the user.
- H2: install into /usr/local/libexec/writ, a folder the script makes,
  and refuse if it or any folder above is a symlink, not root's, or
  writable by its group or everyone. On Intel Homebrew Macs
  /usr/local/bin is the user's, so the user could swap the program the
  renew daemon runs as _writ.
- M1: the SHA-256 is required (or --no-checksum), and is checked on a
  root-owned copy before it is moved into place, not on the source.
- M2: fixed PATH and umask 022 for everything run as root.
- L1: Ctrl-C, SIGTERM, and SIGHUP roll back like a failure.
- L3: an existing _writ account is reused only with uid and group 350,
  shell /usr/bin/false, hidden, and password "*".
- L4: a failed dscl search is an error, not a free uid.
- L5: uninstall makes the kept state root's; install gives it back.
- Reinstall: remove the stopped gate's socket before restarting, so the
  wait does not take the old socket for the new gate.
- WRIT_GATE_LIBEXEC and WRIT_GATE_GRANT for testing and narrowing.

The macos-gate job adds: missing and wrong checksum leave nothing; a
runner-owned and a group-writable parent are refused; key files are
600 _writ; the runner cannot rename, overwrite, or add to the program
folder while root can; a reinstall over a running gate keeps its state
and a changed account is refused; uninstall leaves only root-owned
state; a reinstall over it hands it back under a narrower grant that
admits Read and refuses Bash.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tx4atDCeB6HjAm4bkeL9WZ
On macOS 26, dscl prints IsHidden as "dsAttrTypeNative:IsHidden: 1",
so the account check refused the account the install itself had made
(CI run on fb3f9b3, reinstall step). Accept either form, and name the
value found when the password field does not match.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tx4atDCeB6HjAm4bkeL9WZ
The program lives in /usr/local/libexec/writ, in root-owned folders
only; the install takes a required SHA-256 from a release page or a
clean clone and runs with the system bash from a reviewed checkout.
retire and unretire are gone: an earlier same-user gate's keys are
exposed, and ~/.writ is deleted by hand. Say what the account does not
do (the hooks are the user's own unless managed) and what it assumes
(no NOPASSWD sudo, no unprompted Touch ID approvals); that the
standing grant is broad and how WRIT_GATE_GRANT narrows it; that a
reinstall over kept state reuses its keys; that uninstall leaves the
state root's; and that a failed reinstall does not restore the program
or plists. List what the macos-gate job now requires.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tx4atDCeB6HjAm4bkeL9WZ
- H1: a root chown -R follows hard links, so a gate that linked a root
  file into its home would be handed that file by the next install, and
  uninstall had the same flaw. Install now hands kept state back only to
  an account it just made, with nothing running as uid 350, and refuses
  unless every entry is a folder, a socket, or a single-named file; it
  then chowns with find -exec chown -h. Uninstall kills uid 350, removes
  every other name (which never touches the linked inode), then makes
  the rest root's the same way.
- M1: the log folder is root:wheel 755, and each install replaces the
  two log files with fresh ones, _writ 0640, so the gate cannot plant a
  link where launchd, as root, opens them.
- M2: everything runs from main, called on the last line with exit, so
  lines appended to the script while it runs never run.
- L1: WRIT_GATE_LIBEXEC may not hold . or .. segments or sit in the
  gate's state; the program folder is printed first.
- L2: WRIT_GATE_GRANT must keep -name session and set -uses above 0;
  the grant is printed before it is signed.
- L3: a failed install over state kept by uninstall gives it back to
  root rather than leave it owned by a uid with no account.
- L4: a _writ group with no _writ account is refused; a reused account's
  group must have gid 350 and no members.

The macos-gate job adds: those settings and the stray group refused; the
log folder root:wheel 755 with _writ 640 logs; and a hard link from
/private/etc/hosts planted by _writ, which must succeed, after which a
reinstall, an uninstall, a refused install over a link left in kept
state, and a clean install must all leave hosts root:wheel.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tx4atDCeB6HjAm4bkeL9WZ
Add a "before you run it" section (quit every agent session; confirm
the reviewed commit and a clean status right before sudo; take the
program and SHA-256 from the Releases page if any agent has run as this
user; /usr/bin/sudo from /bin/bash --noprofile --norc; an account
compromised before the install cannot be made safe by it) and a
ten-step first-run checklist for a real Mac. Show the local
managed-settings.json for the socket and /usr/local/libexec/writ, root:
wheel 644. Say the grant must keep -name session and set -uses above 0,
and correct the sentence on what installing again replaces. Say how
uninstall and install treat links in the kept state, that uninstall
needs the same WRIT_GATE_LIBEXEC, and list the new CI controls.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tx4atDCeB6HjAm4bkeL9WZ
Three review rounds found holes in one mechanism: root changing the
owner of a tree that _writ, or the user through an ACL _writ left, could
shape (hard links to root files and root sockets, ACLs, 0777 folders).
It is removed rather than patched again.

- Install never adopts state. With no _writ account, an existing
  /var/db/writ is refused, and root creates the whole tree fresh.
  own_state, unsafe_entries, state_to_root, and every recursive chown
  are gone.
- A reinstall over a live gate leaves the state as it is, after a
  tripwire: /var/db/writ, home, run, and log must have the expected
  owner and mode and no ACL, or it refuses.
- Uninstall boots out the daemons, checks launchd no longer has them,
  STOPs and KILLs uid 350 until none is left, archives /var/db/writ into
  a new root-only tar file in /var/db (unless --purge), clears file
  flags, and removes the tree with rm -rf, which removes names and
  follows no link.
- Rollback removes only the tree it created, the same way.
- WRIT_GATE_GRANT is parsed as strict flag and value pairs, so a stray
  word cannot hide a -uses 0 from the check while Go's flag parsing
  stops before the later value. WRIT_GATE_LIBEXEC refuses //, a
  trailing /, and the state path in any letter case.
- The log folder gets chmod -h -N; the log files chown -h.

CI: as _writ, plant hard links to /private/etc/hosts and the root
socket /private/var/run/syslog, a symlink, a FIFO, a uchg file, an ACL
on the run folder, and a 0777 folder; a reinstall must refuse the ACL;
uninstall must leave hosts and syslog as they were, remove
/var/db/writ, and leave a root:wheel 600 archive whose audit record
verifies; leftover state with no account must be refused; a clean
install must give a run folder the runner cannot write. A fresh install
makes new keys, and uninstall --purge writes no archive.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tx4atDCeB6HjAm4bkeL9WZ
Say plainly that uninstall archives the gate's keys and receipts to a
root-only tar file, then deletes them; that a later install refuses
leftover state and otherwise makes fresh keys; that old receipts come
back only by reading the archive, by hand; and that a removed gate's
keys are retired. Drop the sentences claiming a root chown could not be
misled and that kept state was safe because it was root's. Describe the
live-reinstall tripwire and the strict grant syntax. Verify a release
tarball against SHA256SUMS and slsa-verifier, then hash the extracted
writ-hook; use /usr/bin/git and PATH=/usr/bin:/bin before sudo; add
dscl . -search /Groups PrimaryGroupID 350 to the checklist. List what
the macos-gate job now requires.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tx4atDCeB6HjAm4bkeL9WZ
- HIGH: root's rm -rf of /var/db/writ, and its find -exec chflags,
  could be aimed outside the tree by a folder swapped for a symlink
  mid-walk. Both are gone. The gate's own account (as_gate, now with the
  fixed PATH and stdin from /dev/null) runs chflags -R and rm -rf on the
  contents of home and run, so a swap can only aim it at what the gate
  could delete anyway. Root then removes the two log files by name and
  rmdirs home, run, log, and /var/db/writ. If anything is left, the
  whole folder is renamed to /var/db/writ-leftover-<time>-<pid> and that
  one directory made root:wheel 700. Rollback uses the same routine.
- The archive is made by the gate's account, tar writing to stdout into
  the root-created 0600 file, so it cannot hold root-only files the gate
  linked in. A failed tar, or an unreadable archive, now stops the
  uninstall before anything is removed.
- Cron: uninstall and rollback remove _writ's crontab before stopping
  it, boot out launchd's user/350 domain, and remove the tab file after
  the account. A fresh install refuses a tab file for _writ or at jobs
  owned by uid 350.
- Small: -uses may not start with 0 (Go reads it as octal);
  --no-checksum takes only a root-owned file that is not a link; a
  reinstall waits for launchd to let the old daemons go.

CI: _writ installs a crontab, which uninstall must remove; a planted
tab file must stop a fresh install; a file the gate cannot read must
make uninstall stop with the keys still there and no archive left; and
while uninstall --purge runs, the runner flips folders in a gate-made
0777 folder between real folders and symlinks to a root-only victim
folder, whose sentinel must survive untouched.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tx4atDCeB6HjAm4bkeL9WZ
The unreadable file the control planted was empty, and tar does not open
an empty file, so the control could not fail tar (run on fbb2f54). It
now holds data. as_gate now runs from /, so a gate process never starts
in a folder it cannot read.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tx4atDCeB6HjAm4bkeL9WZ
Drop the false claim that root's deletion follows no link. Say that
uninstall removes the gate's crontab before stopping it; that the gate's
own account makes the archive and empties its folders while root only
removes names and empty folders; that the archive holds what the gate
could read and is read by listing or by printing one member, never
extracted whole as root; that a failed tar removes nothing; how a
leftover folder is set aside; to uninstall rather than reinstall a gate
you suspect; that --no-checksum takes only root-owned files; and add
the crontab file to first-run step 2. List the new CI controls.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tx4atDCeB6HjAm4bkeL9WZ
The swap control's run (on 23dc056) showed uninstall reporting
/var/db/writ as removed after it had moved it to a leftover folder.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tx4atDCeB6HjAm4bkeL9WZ
- N1: remove --no-checksum; its check and its copy read the same name,
  so a swap between them could install another program. The SHA-256 is
  always required.
- N2: refuse a source that is a symbolic link or not a regular file;
  copy at most 256 MiB with head -c; a mismatch names no hash.
- N3: as_gate runs the command in a new session through the system
  perl's setsid, with stdin /dev/null and stdout and stderr through
  pipes (cat), keeping its exit status; the comment says so.
- N4: after removing the state, uninstall removes the crontab and kills
  uid 350 once more, and warns if anything still runs as uid 350.
- N5: uninstall refuses if the _writ account does not have uid 350.
- N6: safe_dir refuses an ACL on the program folder or above it.
- N7: the printed hint extracts the audit record to a file and runs
  writ audit on it.
- N8: uninstall removes files owned by uid 350 in /usr/lib/cron/jobs.
- N9: scripts/check-gate-script.sh fails on a root-run recursive rm,
  chown, chmod, or chflags, or a find on the state tree; the macos-gate
  job runs it, then runs it on a copy with rm -rf "$STATE" added, which
  must fail. It also fails on the script at 393536e.

CI also refuses a source given as a symbolic link.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tx4atDCeB6HjAm4bkeL9WZ
Add what a compromised _writ can still do (read and forge what the gate
holds, stall uninstall or leave a leftover folder, leave uid 350 files
outside /var/db/writ that a fresh install's gate would own) and the find
to run before installing again. Drop --no-checksum; say the source must
be a regular file; check the archived audit record from a file rather
than printing it; say uninstall refuses a _writ without uid 350; list
the static check and the symlinked-source refusal among the CI controls.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tx4atDCeB6HjAm4bkeL9WZ
@pete-builds
pete-builds marked this pull request as ready for review November 13, 2026 14:37
@pete-builds
pete-builds merged commit 3b12f6f into main Nov 13, 2026
13 checks passed
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