fix(security): restrict Windows private files with fail-safe ACL ordering - #164
Open
raymondginger2018-sudo wants to merge 1 commit into
Open
Conversation
…ring PR HKUDS#148 introduced Windows ACL restriction for private storage paths, but ran icacls /inheritance:r before /grant:r. If the grant failed (service account, transient timeout, ...), the path was left with inherited ACEs stripped and no usable ACE for the current user, making it unopenable (e.g. 'attempt to write a readonly database' on Windows CI). HKUDS#158 reverted the original change for this reason. Redo the restriction in a fail-safe order: 1. grant the current user full control first (icacls /grant:r); 2. only then strip inherited ACEs (icacls /inheritance:r); 3. if the grant fails, leave inherited ACLs untouched so the path stays accessible; if the strip fails, the path is merely less restricted. Wire the restriction into open_private_file, harden_private_tree and _chmod so every private-storage entry point applies it on Windows, and add Windows-only tests asserting dangerous well-known ACEs are removed while the current user retains full control.
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
Redoes the Windows private-file ACL restriction from #148 in a fail-safe order, addressing the exact regression that forced the revert in #158.
Why #148 was reverted (#158)
The original
_restrict_windows_acl()ran:icacls <path> /inheritance:r(strip inherited ACEs)icacls <path> /grant:r <user>:F(grant the current user)If the grant failed (service account, transient timeout, ...), the path had already lost every inherited ACE and had no usable ACE for the current user — the file became unopenable, surfacing as
sqlite3.OperationalError: attempt to write a readonly databaseon the Windows lifecycle CI job.This fix — grant first, strip second, fail safe
_restrict_windows_acl()now:icacls <path> /grant:r <user>:Ficacls <path> /inheritance:rThe identity is resolved via
whoami(mbcs encoding,errors="replace"), same as the original PR.Wiring
_restrict_windows_acl()is applied at every private-storage entry point on Windows:open_private_file()— Windows branch calls_restrict_windows_acl(target)instead of no-opharden_private_tree()— removed theif os.name == "nt": return baseearly exit so the tree walk repairs ACLs too_chmod()— Windows branch calls_restrict_windows_acl(path)instead of returning earlyTests
New
tests/test_private_storage_windows.py(Windows-only, skipped elsewhere) asserts:Everyone,Authenticated Users,BUILTIN\Users) are removed after restriction(F)after restrictionVerified locally on Windows (3 passed) and POSIX suite unaffected (8 skipped as expected).
References