Skip to content

write_file overwrite resets the file's ACL on Windows since #1214 #1236

Closed

Description

@Vasanthdev2004

Summary

Since #1214, overwriting an existing file with write_file replaces it with a new file by rename. On Windows the new file takes the folder's inherited ACL, so whatever was set on the original file is gone. A file the user had locked down ends up readable by everyone the folder allows, after Zero edits it.

Reproduction

Windows 11, NTFS. Same test on both commits: create a.txt, change its ACL with icacls, overwrite it through NewScopedWriteFileTool(root, nil).Run with overwrite: true, read the ACL back.

file before the overwrite b32f7ce4 (parent of #1214) main 8288ae81
one extra explicit entry, Everyone:(R) entry kept entry gone
inheritance removed, owner only (1 explicit entry, 0 inherited) unchanged 0 explicit, 11 inherited

The content is written correctly in every case. Only the security descriptor changes.

Cause

commitRootedFileOverwrite in internal/tools/file_commit.go stages the new bytes in a side file and publishes it with root.Rename. The side file is created fresh, so it carries the directory's inherited ACL, and the rename puts that file in the target's place. The staged file is given the target's permission bits, which on Windows is only the read-only attribute. Before #1214 the tool wrote into the existing file, which kept its descriptor.

edit_file publishes through the same function (commitRootedFileContents), so I expect the same there, but I only ran write_file.

I read the POSIX side and did not run it: the permission bits are copied, and nothing copies ownership, POSIX ACLs or extended attributes.

Direction

internal/fsutil already publishes config files on Windows with ReplaceFileW, which keeps the destination's DACL. Using that for the tool overwrite, or copying the target's security descriptor onto the staged file before the rename, would restore the old behaviour. #941 carries attributes, ACLs and ownership across the rename and could be rebuilt on top of main's file_commit.go for this.

A regression test on Windows can use the second row above: a file with inheritance removed must still have no inherited entries after an overwrite.

Activity

  1. added
    bug
    on Nov 19, 2026
  2. Vasanthdev2004 commented on Nov 20, 2026

    @Vasanthdev2004
    CollaboratorAuthor

    #1241 fixes the access control list on Windows.

    The other things the same rename loses are now tracked in #1242, so they stay open when this one closes: alternate data streams on Windows (measured, kept before #1214 and gone on main) and ownership, POSIX ACLs and extended attributes on Linux and macOS (read from the code, not run).

  3. added a commit that references this issue on Nov 23, 2026
    5289824
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions