Skip to content

Fix Windows ownership resolution using Win32_UserProfile SID translation#68

Merged
travis-hoover-glean merged 3 commits into
mainfrom
thoov/fix-windows-ownership-resolution
Apr 14, 2026
Merged

Fix Windows ownership resolution using Win32_UserProfile SID translation#68
travis-hoover-glean merged 3 commits into
mainfrom
thoov/fix-windows-ownership-resolution

Conversation

@travis-hoover-glean
Copy link
Copy Markdown
Contributor

@travis-hoover-glean travis-hoover-glean commented Apr 14, 2026

Summary

  • resolveProfileOwner() was using Get-Acl to read the ACL owner of the user's home directory, which returns NT AUTHORITY\SYSTEM on provisioned/managed machines where the profile directory is owned by SYSTEM. Since this is a truthy value, the ?? username fallback never triggers, causing all config files and directories to be owned by SYSTEM instead of the target user.
  • Replace with Win32_UserProfile CIM query that resolves the user SID from the Windows profile registry and translates it to an NTAccount name.

Before:
2026-04-14 at 16 06 53@2x

After:
2026-04-14 at 15 44 08@2x

Test plan

  • Verified on Windows VM (ARM64) running as SYSTEM via PsExec — all config files and parent directories correctly owned by TRAVISHOOVE8C46\thoov
  • CI passes
  • E2E ownership test passes on Windows CI runner

resolveProfileOwner() was using Get-Acl to read the ACL owner of the
user's home directory, which returns NT AUTHORITY\SYSTEM on provisioned
machines where the profile directory is owned by SYSTEM. Since this is a
truthy value, the ?? username fallback never triggers, causing all config
files to be owned by SYSTEM instead of the target user.

Replace with Win32_UserProfile CIM query that resolves the user SID from
the Windows profile registry and translates it to an NTAccount name.
This is the authoritative source for profile-to-user mapping regardless
of directory ACL ownership.

Fixes: PROD-23734
The E2E config test was using Get-Acl on the home directory to determine
the expected file owner, which returns NT AUTHORITY\SYSTEM on CI runners.
Update to use Win32_UserProfile SID translation, matching the production
code fix.

Also add unit tests for resolveProfileOwner to guard against regression
back to the Get-Acl approach.
@travis-hoover-glean travis-hoover-glean marked this pull request as ready for review April 14, 2026 23:07
@travis-hoover-glean travis-hoover-glean requested a review from a team as a code owner April 14, 2026 23:07
Export setOwnerWindowsBatch for testing and add 9 new test cases:

resolveProfileOwner:
- Verify home directory path is passed in the PowerShell command
- Return null when no Win32_UserProfile matches the path
- Return null on PowerShell timeout (ETIMEDOUT)

setOwnerWindowsBatch:
- No-op when paths array is empty
- Construct correct Set-Acl command for a single path
- Batch all paths into a single PowerShell call
- Escape single quotes in owner name
- Escape single quotes in file paths
- Log warning without throwing when PowerShell fails
@travis-hoover-glean travis-hoover-glean merged commit 51dab82 into main Apr 14, 2026
16 checks passed
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.

1 participant