← Back to Pull requests

(feat) build: port the 0600/0700 file-mode discipline to Windows (issue #974) #1527

Closed
unknown closed this pull request without merging on Oct 21, 2026 13:46 UTC
View on GitHub
unknown unknown commented on Sep 10, 2026 00:41 UTC
Author

The 0700 / 0600 discipline was roughly forty raw mode integers spread across thirteen files,
every one of them reaching a std::os::unix symbol. This states the intent once — this belongs to
its owner and to nobody else
— and puts the per-target mechanism behind it.

#974 stays OPEN, and the partition is:

  • AC1 and AC4 — delivered and verified on this runtime. Both name properties of the code as it

  • builds and runs here, and both are graded by gates that can fail: the abstraction exists and the
    ~40 sites route through it; no Unix permission test body was edited and the suite is green.
  • AC2 and AC3 — implemented, execution deferred to #978. AC2 names a property of files on

  • Windows
    . No CI job compiles this crate for Windows, so nothing here can fail it, and booking it
    as delivered would pass it vacuously (CONTRIBUTING.md § Writing an acceptance criterion). The
    one artifact that could evidence AC2 is the #[cfg(windows)] test set AC3 asks for — the same
    unrun thing, seen twice. #978 builds the job that grades both.

    The Part of #974. body links are deliberate: the issue is incomplete until that job exists.

    What the recon actually found — this revises the project record

    Recon #40 measured a live Windows credential file: SYSTEM, Administrators and the owning user, all
    FullControl, and no Users, Everyone or Authenticated Users. In practice that already is
    the 0600 equivalent, so this is not closing a hole. What it is: every one of those ACEs is
    INHERITED
    , so the file carries no DACL of its own and follows the profile directory silently if
    that ever changes. src/file_policy.rs's module docs open on that finding; ADR-0038 § Context is
    the record.

    The shape, and why (AC1)

    src/file_policy.rs — open_owner_only, owner_only_file, owner_only_dir, copy_policy,
    owner_is_current_user, owner_is_current_user_nofollow, owner_only_deviation. Named after what
    callers mean, not after what either platform does. The alternative — gating each of the ~40 sites —
    makes a security property into forty independent chances to get one wrong; the reasoning is
    ADR-0038 § Decision 1 and § Alternatives considered.

    The Windows mechanism (AC2, and #28's substance)

    windows_impl::write_owner_only_dacl writes an explicit PROTECTED DACL:

  • files D:P(A;;FA;;;SY)(A;;FA;;;BA)(A;;FA;;;<sid>), directories the same with OICI

  • P is the whole point — without it these ACEs are a floor the parent can widen, which is the

  • inherited-only state above
  • <sid> is this process's own token user, read through crate::control_transport::our_user_sid,

  • never a literal and never configurable

    No dependency added: windows-sys has been in the graph on this target since #1513 and every call
    is in a feature already enabled, so Cargo.lock is byte-identical.

    The read-back matches the alias the renderer may substitute

    The two sides of the read-back come from different calls with different alias policies:
    ConvertSecurityDescriptorToStringSecurityDescriptorW substitutes a two-letter constant for a
    well-known SID, while ConvertSidToStringSidW — how this crate learns its own SIDs — is documented
    always to produce S-1-…. Under the built-in Administrator account the owner ACE therefore reads
    back as LA and matches neither our SID string nor the SY/BA floor, and roster_backup refuses
    a real roster write over a formatting difference. sddl_alias_for maps the domain-relative user
    RIDs that carry one (500 → LA, 501 → LG) and owner_only_dacl_defect matches each owner both as
    written and as its alias. It cannot widen the policy — an alias is admitted only where our own SID
    is the account it stands for — and being a suffix match on a string it is graded by ordinary tests
    here. The rendering itself has been observed nowhere; #1530 observes it and settles the set.

    The AC3 tests assert INHERITED-vs-EXPLICIT, not "the owner can read it"

    an_inherited_ace_is_rejected_however_correct_its_trustees_are is the one AC3 names: a DACL
    carrying the right three trustees but marked inherited is REJECTED. an_unprotected_dacl_is_rejected
    does the same for an unprotected descriptor. Both are ordinary unit tests that run on macOS and
    Linux today, because the SDDL writer and the read-back predicate are target-neutral text — only the
    syscalls are cfg(windows).

    The five #[cfg(windows)] tests in mod windows are committed and have never run. ci-ok is
    the only required check and no job compiles this crate for Windows, so landing them red is
    unavailable; #978 is where they get graded.

    Unix behaviour is unchanged (AC4)

    No Unix permission test body was edited. The seven in src/paths.rs and the rest across
    claude_state, cli, config/render, config/write_lock, observability, usage_store, swap,
    canary, daemon/canonical, daemon/commands and use_account are #[cfg(unix)]-gated with their
    assertions intact; the imports they need moved into the gated preamble.

    One mechanism did change beneath that, and ADR-0038 § Positive now records it rather than claiming
    byte-for-byte identity: write_preserving_mode applied the source's policy with
    file.set_permissions — fchmod on the held fd — and copy_policy applies it by path. Same mode,
    same moment, same-user writer throughout, so no privilege boundary moves.

    One source-shape guard also moved, and it is not a permission test: src/roster_backup.rs pinned
    the literal string permissions().mode(), which the production code no longer spells. It now pins
    file_policy::owner_only_deviation(&target), the same obligation stated against the abstraction,
    and its canary moved in lockstep.

    What the ADR records as bounded rather than settled

  • The create-then-tighten window's parent-directory cover holds for callers staging inside this

  • crate's own tree, and not for write_private_file (<path>.tmp lands in path's own directory,
    which write_export takes from the operator) nor for write_preserving_mode's
    ~/.claude.json.tmp. #1528 carries the atomic owner-only create that removes the window;
    control_transport already builds a SECURITY_ATTRIBUTES for CreateNamedPipeW, so the crate is
    past std on that API.
  • A third per-target difference: a filesystem that cannot hold the policy degrades on Unix and fails

  • CLOSED on Windows.
  • The nine #714 drift fixtures are Unix-only here; #1529 owns writing their Windows equivalents

  • or recording per fixture why none exists. #978 runs committed tests and does not cover that.

    Measured

    Windows target at 49561e8, cargo check --target x86_64-pc-windows-msvc --all-targets: 156 → 89
    error lines; the mode / from_mode / uid cluster is at 0. Three as_raw_fd errors surfaced
    that the .mode() failure on the same expression had been masking — they belong to the flock port,
    on the same lines as libc::flock / LOCK_EX.

    At f903c16: fmt, clippy -D warnings, RUSTDOCFLAGS="-D warnings" cargo doc, build, test
    (ok. 2403 passed; 0 failed; 14 ignored), check-no-security-framework.sh (70 packages),
    cargo deny check advisories sources licenses, every doc-gates script, and the msrv job
    reproduced on 1.87.0 (2403 passed) are all green locally.

    Part of #974. Toward #28, which stays open.

    🤖 Generated with Claude Code

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: alexey-pelykh Review duration: 59825m
    All Vouch review confidence checks passed
    Residual risk 0.22 = Change Risk (0.52) × (1 − Review Confidence (0.57)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    56%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #1527"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 56.8% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52% (MEDIUM) · Higher = larger blast radius
    52%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 56.8% · Lower = rushed or shallow review
    56.8%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 22.5% · Safe to merge
    22.5%