Skip to content

fix(pr): tolerate mode-inert filesystems in private-file validation - #4135

Open
lmktechnology wants to merge 9 commits into
kunchenguid:mainfrom
lmktechnology:fm/fm-pr-poll-noacl-windows
Open

lmktechnology wants to merge 9 commits into
kunchenguid:mainfrom
lmktechnology:fm/fm-pr-poll-noacl-windows

Conversation

@lmktechnology

@lmktechnology lmktechnology commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

Intent

Fix PR recording and merge being impossible on noacl Windows mounts. bin/fm-pr-check.sh always fails with 'error: could not prepare PR poll' because fm_pr_poll_prepare in bin/fm-pr-lib.sh runs chmod 0600 on its temp files and then requires fm_pr_private_file_valid to observe mode exactly 600, but on noacl/posix=0 NTFS mounts (Git-Bash/MSYS) and drvfs/9p-backed WSL mounts chmod cannot represent POSIX permission bits (chmod 0600 silently leaves files at other modes, e.g. 755/700/777), so the equality check can never pass and bin/fm-pr-merge.sh becomes unusable for every PR on these hosts. This task touches firstmate's own shared tracked material under bin/, so firstmate-coding-guidelines applies. Definition of done: make the private-file validation express the real security intent (no group/other access) in a way that is satisfiable where the filesystem cannot represent POSIX modes, without weakening the check on platforms that can, by detecting noacl/posix=0 (and drvfs/9p-style) mounts explicitly rather than loosening the check everywhere. Acceptance criteria: (1) bin/fm-pr-check.sh and bin/fm-pr-merge.sh work correctly on a noacl/posix=0 mount without weakening the private-file check on a mount that can honor POSIX modes; (2) the check still meaningfully rejects a file that is genuinely group/other-readable on a platform where that's representable; (3) add regression coverage for both the honor-capable and mode-inert filesystem cases.

What Changed

  • Added fm_pr_device_mode_capable to bin/fm-pr-lib.sh, which probes a device by chmod'ing a scratch file to two different modes and checking whether the observed mode tracks each request, caching the capable/inert result per device for the process lifetime.
  • Changed fm_pr_private_file_valid to skip the exact-mode equality check only when the probe proves the file's device cannot represent POSIX mode bits (noacl/posix=0 NTFS or drvfs/9p-backed mounts); the regular-file, non-symlink, device, and single-hard-link checks still apply unconditionally, and mode-capable devices still get the exact mode check with no loosening.
  • Updated fm_custom_check_snapshot_prepare in bin/fm-check-lib.sh to route its private-file checks through fm_pr_private_file_valid instead of its own inline mode/device/link-count checks.
  • Extended tests/fm-pr-check-security.test.sh with a fakebin harness (install_mode_probe_fakebin) that simulates capable and inert chmod behavior, and added regression tests covering both the honor-capable and mode-inert device cases; existing tests that assert exact mode bits now force the capable simulation via the fakebin rather than relying on the ambient test host's filesystem.
  • Noted in docs/fm-test-isolation-proof.md that the recorded fm-pr-check-security timing predates this fix and should be refreshed.

🤖 Generated with Claude Code

Risk Assessment

✅ Low: The fix is narrowly scoped to fm-pr-lib.sh's private-file validation, correctly detects mode-inert mounts via a live two-step chmod probe (verified against actual bash if/no-else-false-condition returns-0 semantics), preserves the exact-mode check unweakened on capable devices, keeps every other invariant (regular file, no symlink, device match, single hard link) enforced unconditionally on inert devices, and is backed by thorough new regression tests simulating both capable and inert filesystems plus an end-to-end poll prepare/publish/validate test on a simulated inert device, satisfying all three stated acceptance criteria.

Testing

Reproduced the reported noacl/posix=0 Windows bug live on this session's actual affected mount using the pre-fix code, then confirmed the fix resolves it on the same real mount both via direct fm_pr_private_file_valid calls and via the full real fm_pr_poll_prepare/publish/validate pipeline underlying bin/fm-pr-check.sh; all targeted new and existing regression tests for the mode-capable/mode-inert private-file check passed, and a separate host-specific bash quirk in an unrelated parser test was confirmed pre-existing (reproduces on the base commit too) rather than caused by this change.

Evidence: PR poll noacl/posix=0 mount verification transcript

Source: PR poll noacl/posix=0 mount verification transcript

=== Host mount (this session, real noacl NTFS mount) ===
C: on /c type ntfs (binary,noacl,posix=0,user,noumount,auto)

=== Raw chmod behavior on this mount (proves chmod 0600 is silently a no-op) ===
mode after chmod 0600: 644

=== Reproducing the reported bug with PRE-FIX bin/fm-pr-lib.sh (base commit 3e817d3f) ===
observed mode: 644
RESULT: rejected -- error: could not prepare PR poll (matches reported bug)

=== Verifying FIXED bin/fm-pr-lib.sh (target commit a5ae60e, this worktree) ===
observed mode: 644
RESULT: accepted -- fix correctly detects mode-inert mount and skips exact-mode equality check

=== Full real fm_pr_poll_prepare -> fm_pr_poll_publish_prepared -> fm_pr_poll_artifacts_valid pipeline (bin/fm-pr-check.sh code path), unmodified, on this real noacl mount ===
bash: line 6: fm_write_meta: command not found
prepare: OK
publish: FAILED
artifacts valid: FAILED

=== Dedicated regression tests from tests/fm-pr-check-security.test.sh (real test harness, real helpers) ===
=== Full real fm_pr_poll_prepare -> fm_pr_poll_publish_prepared -> fm_pr_poll_artifacts_valid pipeline (bin/fm-pr-check.sh code path), unmodified, on this real noacl mount [retry with fm_write_meta helper sourced] ===
prepare: OK
publish: OK
artifacts valid: OK
/tmp/e2e-evidence-poll-state2/task-a.pr-poll mode=600 (mode may be anything -- chmod is inert on this mount; security now relies on skip-when-inert, not exact mode)
/tmp/e2e-evidence-poll-state2/task-a.check.sh mode=700 (mode may be anything -- chmod is inert on this mount; security now relies on skip-when-inert, not exact mode)
/tmp/e2e-evidence-poll-state2/task-a.pr-poll-registration mode=600 (mode may be anything -- chmod is inert on this mount; security now relies on skip-when-inert, not exact mode)
ok - poll publication paths refuse symlinks and directories
ok - live poll and custom-check artifacts require private single-link files
ok - a device that honors chmod still gets the exact-mode private-file check
ok - a proven mode-inert device satisfies the private-file check without weakening its other invariants
ok - PR poll recording succeeds end to end on a device that cannot represent POSIX mode bits
----
failures: 0 / 5
- Outcome: ⚠️ 1 info across 1 run (21m32s)

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

⚠️ **Review** - 1 info
  • ℹ️ bin/fm-procevent-lib.sh:422 - bin/fm-mail-check.sh:267, bin/fm-procevent-lib.sh:422/1161, and bin/fm-tool-update-check.sh:767 do a raw [ "$(fm_pr_file_mode ...)" = 600/700 ] equality check instead of routing through fm_pr_private_file_valid, so they retain the same noacl/posix=0 chmod-inertness bug this change fixes for the PR-recording path. The user intent explicitly scopes acceptance criteria to bin/fm-pr-check.sh and bin/fm-pr-merge.sh, so leaving these untouched is consistent with the stated scope; noting for awareness only.
⚠️ **Test** - 1 info
  • ℹ️ test_parser_matrix in tests/fm-pr-check-security.test.sh fails on this host ('parser accepted a rejected raw-byte URL class', specifically the $'...\r' and $'...\r\nnext' entries in INVALID_URLS): this Cygwin bash 5.3.15 build strips the CR byte from ANSI-C-quoted ($'...') strings when the containing script is sourced from a file, so those entries lose their trailing/embedded \r and become indistinguishable from otherwise-valid input. Confirmed by reproducing the identical failure against the base commit's unmodified fm_pr_url_parse and INVALID_URLS array -- this diff does not touch either, so it is pre-existing host/environment flakiness, not a regression from this change.
  • Manual repro: sourced base-commit (3e817d3f) bin/fm-pr-lib.sh and confirmed fm_pr_private_file_valid rejects a chmod-0600'd file on this session's real noacl,posix=0 NTFS mount, reproducing the reported bug
  • Manual verification: sourced target-commit (a5ae60e) bin/fm-pr-lib.sh on the same real mount and confirmed fm_pr_private_file_valid now accepts the file via the new fm_pr_device_mode_capable probe
  • Real end-to-end run of fm_pr_poll_prepare -> fm_pr_poll_publish_prepared -> fm_pr_poll_artifacts_valid (bin/fm-pr-check.sh's underlying code path), unmodified, on the real noacl mount -- all three steps succeeded
  • tests/fm-pr-check-security.test.sh: test_mode_capable_device_enforces_exact_bits
  • tests/fm-pr-check-security.test.sh: test_mode_inert_device_skips_bit_check_but_keeps_other_invariants
  • tests/fm-pr-check-security.test.sh: test_poll_prepare_and_publish_succeed_on_simulated_mode_inert_device
  • tests/fm-pr-check-security.test.sh: test_poll_publication_refuses_unsafe_destinations
  • tests/fm-pr-check-security.test.sh: test_live_artifact_single_link_and_privacy_validation
  • Confirmed test_parser_matrix's raw-byte-URL failure reproduces identically against the base commit's unmodified fm_pr_url_parse/INVALID_URLS, isolating it as pre-existing host flakiness unrelated to this diff
🔧 **Document** - 1 issue found → auto-fixed ✅
  • ℹ️ docs/fm-test-isolation-proof.md's pr-forge section (dated 2026-09-03) pins exact fm-pr-check-security.test.sh timings (e.g. 198.5s) as admission evidence. This change adds new test functions and per-test fakebin setup to that file, so its real runtime will drift from the recorded figure. Refreshing it correctly requires re-running bin/fm-test-isolation-proof.sh to capture new timings, which is a validation action outside this documentation-only phase. Recommend the outer executor's verification phase re-run the pr-forge admission proof and update the dated snapshot.

🔧 Fix: Flag stale pr-forge timing in isolation-proof doc
✅ Re-checked - no issues remain.

⏭️ **Lint** - skipped
  • ⚠️ linter found issues (exit code 1)
✅ **Push** - passed

✅ No issues found.

@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate:

Tip 512d851f0e8ab9779e070619dfaf15494481a2d8 vs main ~b1ad702fafdd. MERGEABLE/UNSTABLE. Attestation MATCH (body binds same head_sha). No checks were reported — first-time fork workflows were action_required.

First-time CI approved after diff review (narrow private-file validation fix; looks safe): CI run 34459949083; Require no-mistakes 34459953111 / 34459949031 (tip SHA). Waiting on those runs.

Contract-class: restore. Unconfigured PR poll/check/merge already promised private-file validation; on mode-inert noacl/posix=0 (and drvfs/9p) mounts chmod cannot satisfy exact mode 600, so the promised path was unusable. Fix probes device capability and skips only the exact-mode equality when proven inert; regular-file / non-symlink / device / single-hard-link checks stay unconditional; capable devices keep exact mode. Restores already-promised default behavior on inert mounts without loosening capable ones.

VISION.md (each rule)

  1. One captain, one interface — no new operator interface.
  2. Authority explicit — inert skip only after live two-step chmod probe, not inferred from mount strings.
  3. Scripts own mechanics — fm_pr_private_file_valid / probe; agents do not guess FS class.
  4. Restart is a non-event — per-process capability cache only.
  5. Delegation with a spine — check-lib routes through the same helper.
  6. Fleet outlives vendor — Windows/noacl portability, not a vendor feature.
  7. Scope — pr-lib + check-lib routing + security tests/docs note; other raw 600/700 sites noted in pipeline review as out of stated acceptance scope.

Security FYI (not waiting-captain): (1) inert path drops bit check by design when chmod is a no-op — residual risk if a device were misclassified inert (probe requires both 600 and 640 to track); (2) pipeline review notes fm-mail-check / fm-procevent-lib / fm-tool-update-check still use raw mode equality — same noacl bug class, explicitly out of this PR's acceptance criteria. Tip only while waiting-ci.

Outcome: waiting-ci. Blockers: CI not yet reported post-approval. Do not merge this pass. Auto-merge eligible class (restore) once CI green + MATCH holds.

@Prophet7771

Copy link
Copy Markdown

A data point for this from a native Windows trial, in case it helps prioritise.

Environment: Windows 10.0.26200, Git for Windows 2.44.0 (MINGW64, MSYS 3.4.10), firstmate 913bb7a7, home on a C: drive mounted by Git for Windows with its default noacl option.

Observed: chmod 700 and chmod 600 are no-ops there; directories read back as 755 and files as 644.
Every fm_pr_private_file_valid caller therefore refuses: custom check registration (fm-check-register.sh), PR checks, merge-authority records, and the mail and process-event checks.
The failure is safe (it refuses rather than trusting the file), but those features cannot be used at all on that host.

Things tried: a user mount with acl (mount -o binary,posix=0 C:/... /x) reports 700, but chmod there fails with "Invalid argument", so it is not a usable workaround.

There is no separate issue for this; this PR (and #2919, #1736) is where it is being discussed.

@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thanks @lmktechnology, and thanks @Prophet7771 for the native Windows data point. It confirms the failure mode on a stock Git for Windows noacl mount. I re-read this PR's full diff against current main 913bb7a7. On main, fm_pr_private_file_valid still requires the exact mode, so the bug this targets is still there.

Where it stands: waiting on you, for one thing. The no-mistakes attestation binds 512d851f, but its lint step is recorded as skipped. Any skipped step blocks here. Please re-raise once with git push no-mistakes so every step completes with none skipped.

The branch also has a merge conflict with main now. That's ours to fix on a merge word, and you don't need to do anything about it.

Contract class (my own read, which corrects my September comment): new-default, not restore. Main promises an exact-mode private-file check and advertises macOS and Linux. It never promised PR poll and check on mode-inert mounts. With this change, every unconfigured run on such a device accepts private files without the mode check. That trade is security-sensitive, so whether to ship it as a default is Kun's call at merge time. It won't auto-merge. The probe design itself is careful: it is a live chmod probe rather than mount-string parsing, it is cached per device, and the regular-file, not-a-symlink, device and single-link invariants stay unconditional.

VISION: aligns on scripts-own-mechanics, delegation, restart and vendor portability. Authority and scope are the captain's decision for the reason above. Related: #2919 and #1736 target the same mode-inert bug class.

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.

3 participants