fix(provision): write managed hook scripts atomically at 0o755#143
Merged
Conversation
The hook writers wrote each script at mkstemp's 0600 default and set the exec bit in a SEPARATE chmod step — and omi-enforce.py never got a chmod at all. When a re-provision runs as root and the B2 guard-config hardening then chowns the hook to root, that 0600 window (or the never-widened enforce hook) is unreadable by the agent user, so `python3 omi-enforce.py` fails with EACCES mid-reprovision — the transient "the guard hook is dead" blip. Thread mode= through _write_managed/_write_if_absent into atomic_write_text (which already applies the mode to the temp file BEFORE the rename), and drop the separate post-rename dest.chmod(0o755) at all five hook sites. The destination is now never briefly at 0600. Adds a regression test asserting every provisioned hook is 0o755 (world-readable, so a chown-root can't render it unreadable). Full suite: 725 passed, 1 skipped; ruff clean. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JFuGddPx3UhUkcC74KBXZB
CryptoJones
added a commit
that referenced
this pull request
Jul 2, 2026
Atomic-0o755 hook provisioning fix (#143): managed hook scripts get their mode set on the temp file before the atomic rename, so a root-run re-provision never leaves a hook briefly at 0600 (unreadable by the agent user after the B2 chown-root) — the transient omi-enforce.py EACCES blip. Version 3.7.7 -> 3.7.8 (pyproject + __init__ + uv.lock); CHANGELOG. Full suite: 725 passed, 1 skipped; ruff clean. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JFuGddPx3UhUkcC74KBXZB
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes the transient "the guard hook is dead" blip:
python3 omi-enforce.pyfailing with EACCES right after a re-provision.Root cause: the managed-hook writers (
omi-enforce.py,omi-guard.sh,omi-gate-reset.sh,git-fresh-base.sh,secret-output-guard.sh) wrote each script atmkstemp's 0600 default and set the exec bit in a separatedest.chmod(0o755)step — andomi-enforce.pynever got a chmod at all.atomic_write_textalready applies amodeto the temp file before the rename, but the writers never passed one. So when a re-provision runs as root and the B2 hardening thenchowns the hook toroot, that 0600 window (or the never-widened enforce hook) is unreadable by the agent user -> EACCES.Fix: thread
mode=through_write_managed/_write_if_absentintoatomic_write_text, passmode=0o755at all five hook sites, and drop the now-redundant post-renamechmod. The destination lands 0755 atomically and is never briefly at 0600, so a subsequentchown rootcan't render it unreadable.Verification
ruff check .-> cleanpytest-> 725 passed, 1 skippedtest_managed_hook_scripts_are_written_0755_atomicallyasserts every provisioned hook is0o755(fails if a writer reverts to the bare 0600 write).Staged under
[Unreleased]; the version bump/tag is a separate batched release step.🤖 Generated with Claude Code
Proudly Made in Nebraska. Go Big Red! 🌽 https://xkcd.com/2347/