fix(windows): cast AceFlags and AccessMask to int in NUL PowerShell 5.1 script #178
No reviewers
Labels
No labels
kind
bug
kind
chore
kind
docs
kind
feature
kind
performance
kind
question
priority
critical
priority
high
priority
low
risk
high
risk
low
risk
medium
status
blocked
status
confirmed
status
duplicate
status
invalid
status
needs-info
status
wontfix
ci: approved
No milestone
No project
No assignees
3 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Beanstalk!178
Loading…
Reference in a new issue
No description provided.
Delete branch "cfw34683/Beanstalk:fix/windows-nul-aceflags-cast"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Fixes
System.InvalidCastException: Specified cast is not valid.inWinNul.GrantScripton Windows PowerShell 5.1 when setting up\Beanstalk\NUL access for AppContainers.Cause
In Windows PowerShell 5.1,
$ace.AceFlagsis abyte-backed enum (System.Security.AccessControl.AceFlags). Running-band [Security.AccessControl.AceFlags]::InheritOnlythrowsInvalidCastExceptioninside the PowerShell DLRCallSite(Object, AceFlags).Fix
$ace.AceFlags,[Security.AccessControl.AceFlags]::InheritOnly, and$ace.AccessMaskto[int]before-bandinagent/Core/WindowsNul.cs.agent/tests/agent_core/NulChecks.cs.Verification
InvalidCastExceptionin Windows PowerShell 5.1 againstRawSecurityDescriptorand verified the[int]-cast version succeeds (BINARY_LEN: 72).AgentCoreTests.csprojcleanly (0 Warning(s), 0 Error(s)).Possibly related, for context:
Full
beanstalk-agent sandbox-checkreport from Windows 10.0.19045 (nightly-299-b3e6a7d9):Has this been fully ran?
@review
Recommendation: Approve. The code is ready: only testing is left. The casts address the reported PowerShell 5.1 exception, but the full elevated setup and subsequent sandbox access have not been shown working on the affected Windows machine. Recommend approval; not approved on the forge.
The change casts the ACE values before the bitwise checks so Windows PowerShell 5.1 can inspect NUL’s access entries. It is small and keeps the existing setup design, but its automated check does not exercise the fix.
Testing before merging (1) (runs on the systems it can change; it doesn't hold the recommendation)
agent/Core/WindowsNul.cs:154: The reported reproduction covers the expression, but not the complete setup on a machine where AppContainers cannot open NUL. (more on the line) Do: On the affected Windows 10 machine, run this head’s setup, repeat sandbox-check including NUL and Git, reboot, and repeat the check to verify the scheduled task.Questions (1) (not confirmed from the code; they don't hold the recommendation)
agent/tests/agent_core/NulChecks.cs:48: Is there a current ACL input for which the changed PowerShell decision produces an incorrect result?Checks: Still running: 5 checks.
More: does it help, other systems, switches, what was read
Does it help: Unproven end to end. The author reports that a PowerShell 5.1 reproduction succeeds with the casts and produces a 72-byte descriptor; the posted sandbox report is from the base build and still shows NUL and Git failing.
Other systems: The changed script runs on Windows both during elevated setup and from the SYSTEM boot task. Linux does not run it. The reported reproduction does not show the complete setup, a sandboxed NUL open, or the boot task working.
Switches: None.
Reviewed:
9a1118bbe9againstb3e6a7d97a: Read AGENTS.md, CONTRIBUTING.md, the full diff and commit, and both changed files in full. Traced references to the setup, boot task and test entry point; skimmed the reported sandbox run and CI test references. No review checklist or pull request template was present. Other repository files were not read in full.; nothing run (a code review).Checked and fine:
Testing: No commands from the project were run, as required for this review. The author reports a clean test-project build and an isolated PowerShell reproduction; CI was still running.
Overlaps and merge order: Unknown; the network is closed.
Automated code review by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.
@ -152,3 +152,3 @@$has = $falseforeach ($ace in $acl) {if ($ace -is [Security.AccessControl.CommonAce] -and $ace.AceQualifier -eq 'AccessAllowed' -and -not ($ace.AceFlags -band [Security.AccessControl.AceFlags]::InheritOnly) -and $ace.SecurityIdentifier -eq $sid -and (($ace.AccessMask -band 0x1201bf) -eq 0x1201bf)) { $has = $true }if ($ace -is [Security.AccessControl.CommonAce] -and $ace.AceQualifier -eq 'AccessAllowed' -and -not ([int]$ace.AceFlags -band [int][Security.AccessControl.AceFlags]::InheritOnly) -and $ace.SecurityIdentifier -eq $sid -and (([int]$ace.AccessMask -band 0x1201bf) -eq 0x1201bf)) { $has = $true }L1 (should fix): The reported reproduction covers the expression, but not the complete setup on a machine where AppContainers cannot open NUL.
When: The posted Windows 10 sandbox check is from the base build and reports both NUL and Git failing; it does not show that this head grants access now and again after reboot.
Do: On the affected Windows 10 machine, run this head’s setup, repeat sandbox-check including NUL and Git, reboot, and repeat the check to verify the scheduled task.
Yes — verified on the affected Windows 10.0.19045 machine:
GrantScriptelevated via Windows PowerShell 5.1 (-EncodedCommand):beanstalk-agent sandbox-checkimmediately afterwards — AppContainer went from failingnulandgit(recommended mode: none) to every check passing:(Note: the machine was rebooted to verify the scheduled boot task
\Beanstalk\NUL access for AppContainersre-applying the DACL on startup; the task embeds the sameGrantScript.)@review
Recommendation: Approve. The cast fixes the PowerShell 5.1 failure, and the affected Windows 10 machine subsequently passed the NUL and Git sandbox checks. The author also reports that the boot task reapplied the permissions after a restart. Recommend approval; not approved on the forge.
The change lets Windows sandbox setup grant AppContainers access to NUL on affected systems, allowing sandboxed Git and builds to run. It adds a small script assertion without changing the intended permissions.
Since the last review (on
9a1118bbe9)Resolved: L1 (The reported reproduction covers the expression, but not the complete setup on a machine w…)
Checks: Still running: 5 checks.
More: does it help, other systems, switches, what was read
Does it help: Yes. On Windows 10 10.0.19045, the author reports that NUL and Git changed from failing to passing after the patched grant script ran; every AppContainer check then passed.
Other systems: The changed script runs only on Windows during elevated setup and at boot; Linux agent behavior is unchanged. The reported run covers the affected Windows 10 machine.
Switches: None.
Reviewed:
749e8ecab7againstadde94bc90: Read AGENTS.md, CONTRIBUTING.md, the full diff, commit log, WindowsNul.cs and NulChecks.cs in full; skimmed references to WinNul and the recorded Windows run. No review checklist or pull request template was found.; nothing run (a code review).Checked and fine:
Testing: The author reports a clean AgentCoreTests build, a PowerShell 5.1 reproduction and patched run, and a successful affected-machine sandbox check and reboot verification. CI checks are still running; no commands or tests were run for this review.
Overlaps and merge order: None found in the supplied information.
Automated code review by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.