Skip to content

Windows: restrictive file modes are unenforced (private key, state home, config, secrets) — route every mutation through fsroot #405

Open
2 of 8 issues completed

Description

@David-Noble-at-work

The gap

Go's os.Chmod on Windows toggles only the read-only attribute. Every writable file reports mode 0666 regardless of the mode requested, so a 0600 intent is silently not enforced there.

This surfaced during the #373 Windows campaign: seven test assertions fail on the windows leg with permission = 666, want 600 (and -rw-rw-rw-, want 0600). Those assertions are being moved into _unix_test.go files — the mode bits are genuinely a Unix subject and the assertions are meaningless on Windows — but scoping them removes the only coverage that restrictive-mode intent is honored anywhere, so the gap is filed here rather than lost in the move.

Why it matters

The sharpest case is writ secret: encryption.decrypt_sops_file writes plaintext derived from an encrypted source. On Unix that lands at 0600. On Windows it lands writable-by-all-with-access, governed only by whatever ACLs the containing directory happens to inherit.

Affected call sites asserting restrictive modes today:

  • internal/document — Write (YAML/JSON) at 0600, and the caller-supplied perm override
  • pkg/op/provider/file — Copy, WriteBytes, and Observe's reported mode
  • cmd/writ/writ/deploy — the SOPS chain integration (secret and note at 0600)

The question to settle

Does writ need a Windows ACL equivalent — restricting the file to the current user via icacls or golang.org/x/sys/windows — or is inherited directory ACL protection (a layer root under the user profile) sufficient, making this a documented platform-semantics ruling instead of a defect?

The inherited-ACL premise is worth testing rather than assuming: a layer root outside the user profile (a shared drive, C:\ProgramData) would break it silently, and nothing currently asserts otherwise.

Deliberately not resolved in #373

Phase 3e is a test-classification phase; designing an ACL path there would block the campaign's actual goal (the platform gate) behind unrelated product work. Ruled 2026-08-13.

Refs #373. Plan: docs/plans/windows-phase-3e.md (cluster 4, Q3).

Plan and design documents

Kind Document
Plan docs/plans/windows-native-permissions.md

Sub-issues

Sub-issues

2 of 8 Issues completed
Loading 8 sub-issues

Activity

  1. David-Noble-at-work commented on Aug 14, 2026

    @David-Noble-at-work
    ContributorAuthor

    Corrected and re-scoped (2026-08-13). Two things in the original filing are wrong, and the disposition has been reversed.

    1. The headline case was wrong. I filed this naming writ secret's decrypted output as the sharpest instance. Enumerating the actual call sites found worse: pkg/signing/signing.go:202 writes a private key at 0600 into a directory created at 0700 — both unenforced on Windows. The run index and state home (internal/cli/index.go), the user config (internal/cli/config.go), and the self-install manifest are in the same set.

    2. The surface is far larger than the seven failing tests. 84 direct os.* mutation calls live outside fsroot; 31 of them pass a restrictive permission. A fix confined to the file provider — or to fsroot alone, as first proposed — would have looked complete and missed the private key.

    3. Disposition reversed: this is not deferred, and the tests are not being scoped away. The original ruling was "file the issue, move the assertions to _unix_test.go." That is superseded: Windows permissions must be enforced natively, so a product that accepts 0600 and silently produces an unrestricted file is wrong on Windows, not correctly platform-scoped. The seven failures are reclassified bucket 1 and will be cleared by enforcement rather than by scoping. This work lands before the complexity debt (#312 phase 8).

    Rulings

    1. Enforce natively. No documented resignation.
    2. Every mutation through fsroot — all 84 sites, zero exemptions, harnesses and docgen included. A rule with carve-outs erodes; this one is mechanically guardable.
    3. Mechanism: golang.org/x/sys/windows — already a direct dependency, and cmd/writ/writ/snapshot/protect_darwin.go sets the precedent for platform-specific protection via x/sys. No icacls shell-out.
    4. Mapping: private-vs-not. perm&0o077 == 0 → a protected DACL (inheritance broken) granting owner + SYSTEM + Administrators; otherwise the inherited default. Restricting SYSTEM/Administrators is theater and breaks backup/AV tooling. Accepted: 0640 and 0600 are indistinguishable on Windows.
    5. file.Observe reports the real mode plus a DACL-derived restricted fact. Nothing fabricated.

    Breaking inheritance is the load-bearing detail — without a protected DACL the file keeps its parent's inherited ACEs and stays accessible regardless of what is granted.

    Plan

    docs/plans/windows-native-permissions.md — four phases: fsroot API + Windows enforcement (proved by DACL read-back tests before any call site moves), migrate the 31 security-relevant sites, migrate the remaining 53, then the lint guard banning direct os.* mutations outside pkg/fsroot plus the Observe access fact.

    Coverage increases rather than shrinking: _windows_test.go asserts the ACE set; _unix_test.go keeps the mode-bit assertions.

    Refs #373.

  2. changed the title [-]Windows: 0600 permission intent is unenforced (writ secret decrypted output unrestricted)[/-] [+]Windows: restrictive file modes are unenforced (private key, state home, config, secrets) — route every mutation through fsroot[/+] on Aug 14, 2026
  3. 7 remaining items

  4. David-Noble-at-work commented on Nov 9, 2026

    @David-Noble-at-work
    ContributorAuthor

    star github triage sweep added this issue to Triage: devlore, for the rule it breaks:

    • no-evidence: no Evidence of completion section
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions