Fix elevation request ACLs on PowerShell 7
Config Central CI Config Central passed all CI integrity checks.
Beffroi/config-central/pipeline/head This commit looks good Details

This commit is contained in:
Dandaedre 2026-10-19 12:26:58 +02:00
parent 61b89859a0
commit b1d6b0eeee
3 changed files with 38 additions and 1 deletions

View File

@ -124,3 +124,4 @@ open until it is run on disposable machines with the required account setups.
- [x] Preserve signed WinGet HRESULT bits without UInt32 overflow and test diagnostic capture.
- [x] Rename the bundled default machine to beffroi-laptop and document switching existing setups.
- [x] Use PowerShell 7-compatible ACL application for elevation requests; add Windows-only permission regression tests (Windows execution pending).

View File

@ -14,7 +14,7 @@ function Protect-ElevationFile {
$acl.AddAccessRule([Security.AccessControl.FileSystemAccessRule]::new($currentSid, 'FullControl', 'Allow'))
$acl.AddAccessRule([Security.AccessControl.FileSystemAccessRule]::new('BUILTIN\Administrators', 'FullControl', 'Allow'))
$acl.AddAccessRule([Security.AccessControl.FileSystemAccessRule]::new('NT AUTHORITY\SYSTEM', 'FullControl', 'Allow'))
[System.IO.File]::SetAccessControl($Path, $acl)
Set-Acl -LiteralPath $Path -AclObject $acl -ErrorAction Stop
}
function Invoke-ElevatedPackageBatch {

View File

@ -24,3 +24,39 @@ Describe 'Elevation host selection' {
}
}
}
Describe 'Elevation request file protection' -Skip:(-not $IsWindows) {
It 'restricts a request file to the user, administrators, and SYSTEM' {
InModuleScope Elevation -Parameters @{ Root = $TestDrive } {
param($Root)
$path = Join-Path $Root 'request [test].json'
'{}' | Set-Content -LiteralPath $path
Protect-ElevationFile -Path $path
$acl = Get-Acl -LiteralPath $path
$acl.AreAccessRulesProtected | Should -BeTrue
$rules = @($acl.GetAccessRules($true, $true, [Security.Principal.SecurityIdentifier]))
$expected = @(
[Security.Principal.WindowsIdentity]::GetCurrent().User.Value
'S-1-5-32-544'
'S-1-5-18'
) | Sort-Object -Unique
@($rules.IdentityReference.Value | Sort-Object -Unique) | Should -Be $expected
foreach ($rule in $rules) {
$rule.IsInherited | Should -BeFalse
$rule.AccessControlType | Should -Be 'Allow'
$rule.FileSystemRights | Should -Be 'FullControl'
}
Get-Content -LiteralPath $path -Raw | Should -Match '^{}'
}
}
It 'propagates ACL write failures' {
InModuleScope Elevation -Parameters @{ Root = $TestDrive } {
param($Root)
$path = Join-Path $Root 'failed-request.json'
'{}' | Set-Content -LiteralPath $path
Mock Set-Acl { throw 'ACL write denied' }
{ Protect-ElevationFile -Path $path } | Should -Throw '*ACL write denied*'
}
}
}