Skip to content

Commit 1e3fc11

Browse files
committed
ci: probe the Windows runner's ProgramData permissions
1 parent 6255859 commit 1e3fc11

2 files changed

Lines changed: 52 additions & 0 deletions

File tree

‎.github/probe/probe.ps1‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
$ErrorActionPreference = 'Stop'
2+
function Assert-ProtectedLocation([string]$path) {
3+
$trusted = @('S-1-5-18', 'S-1-5-32-544', 'S-1-5-80-956008885-3418522649-1831038044-1853292631-2271478464', 'S-1-3-0')
4+
# Delete, DeleteSubdirectoriesAndFiles, ChangePermissions, TakeOwnership and GENERIC_ALL.
5+
$unsafe = 0x100D0040
6+
$directory = Get-Item -LiteralPath $path -Force
7+
while ($directory) {
8+
if ($directory -isnot [System.IO.DirectoryInfo] -or ($directory.Attributes -band [System.IO.FileAttributes]::ReparsePoint)) {
9+
throw ('Not a protected location: ' + $directory.FullName)
10+
}
11+
$acl = Get-Acl -LiteralPath $directory.FullName
12+
$owner = $acl.GetOwner([System.Security.Principal.SecurityIdentifier]).Value
13+
$open = @($acl.GetAccessRules($true, $true, [System.Security.Principal.SecurityIdentifier]) | Where-Object {
14+
$_.AccessControlType -eq 'Allow' -and $trusted -notcontains $_.IdentityReference.Value -and
15+
!($_.PropagationFlags -band [System.Security.AccessControl.PropagationFlags]::InheritOnly) -and
16+
([int64]$_.FileSystemRights -band $unsafe)
17+
})
18+
if ($trusted -notcontains $owner -or $open.Count -gt 0) { throw ('Not a protected location: ' + $directory.FullName) }
19+
$directory = $directory.Parent
20+
}
21+
}
22+
23+
whoami
24+
"elevated: " + ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
25+
"default owner: " + [System.Security.Principal.WindowsIdentity]::GetCurrent().Owner.Value
26+
"known folder: " + [Environment]::GetFolderPath('CommonApplicationData')
27+
foreach ($path in @('C:\', 'C:\ProgramData')) {
28+
$item = Get-Item -LiteralPath $path -Force
29+
$acl = Get-Acl -LiteralPath $path
30+
"== $path attributes=$($item.Attributes) owner=$($acl.GetOwner([System.Security.Principal.SecurityIdentifier]).Value) protected=$($acl.AreAccessRulesProtected)"
31+
foreach ($rule in $acl.GetAccessRules($true, $true, [System.Security.Principal.SecurityIdentifier])) {
32+
'{0} {1} 0x{2:x} inherit={3} propagate={4}' -f $rule.IdentityReference.Value, $rule.AccessControlType, [int64]$rule.FileSystemRights, $rule.InheritanceFlags, $rule.PropagationFlags
33+
}
34+
}
35+
try { Assert-ProtectedLocation 'C:\ProgramData'; 'CHECK OK C:\ProgramData' } catch { "CHECK REFUSED: $_" }

‎.github/workflows/probe.yml‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: Probe
2+
3+
on:
4+
push:
5+
branches: [ci-probe]
6+
7+
permissions:
8+
contents: read
9+
10+
jobs:
11+
probe:
12+
runs-on: windows-2022
13+
steps:
14+
- uses: actions/checkout@v6
15+
- name: Permissions of the updater's location
16+
shell: powershell
17+
run: .github/probe/probe.ps1

0 commit comments

Comments
 (0)