Skip to content

Commit 4106557

Browse files
EliahKaganclaude
andcommitted
Add a diagnostic job that probes process-token and file ownership
Temporarily add a `diag-token` job to `.github/workflows/cygwin-test.yml` that creates an empty directory through several distinct code paths and reports the NTFS Owner of each. The intent is to demonstrate empirically that the Owner asymmetry described in the next commit ("Cover submodule working trees in safe.directory on Cygwin") falls out of which kinds of processes appear in the ancestry of the file-creating call -- specifically whether a Cygwin or Cygwin-derived runtime (`cygwin1.dll` for Cygwin git; `msys-2.0.dll` loaded by Git for Windows's bundled MSYS2 `sh.exe` for shell-dispatched subcommands like `git submodule`) has rewritten the process token's `TokenOwner` field at DLL initialization. The job runs on `windows-latest` with the same Cygwin install used by the existing test jobs. It runs two scripts in sequence: the first through PowerShell, the second through Cygwin's bash. Each test creates an empty directory and reports its Owner via `Get-Acl` (PowerShell side) or `stat -c '%U(%u)'` (Cygwin side). PowerShell-side tests: - A: PowerShell `New-Item -ItemType Directory` - B: PowerShell-spawned Git for Windows `git init` (reports the Owner of both the parent directory and `.git`) - C: `cmd.exe`-spawned `mkdir` - G: PowerShell-spawned Git Bash that re-invokes PowerShell, whose `New-Item` creates the directory -- a Win32-only chain interrupted by a single Cygwin link in the middle Cygwin-side tests: - D: Cygwin `mkdir` - E: Cygwin-spawned Cygwin `git init` (reports the Owner of both the parent directory and `.git`) - F: Cygwin-spawned Git for Windows `git init` (reports the Owner of both the parent directory and `.git`) Observed results ---------------- A run of this job on this commit produces: | Test | Owner of created directory | | ---- | ----------------------------------------- | | A | `BUILTIN\Administrators` | | B | `BUILTIN\Administrators` (both paths) | | C | `BUILTIN\Administrators` | | G | `runneradmin` (uid 197108) | | D | `runneradmin` (uid 197108) | | E | `runneradmin` (uid 197108) (both paths) | | F | `runneradmin` (uid 197108) (both paths) | Tests A, B, and C run in process trees containing only Win32 binaries (PowerShell, Git for Windows `git.exe`, `cmd.exe`). Their tokens hold the kernel-default `TokenOwner` for `runneradmin`'s full administrative access token, which is `BUILTIN\Administrators` because `runneradmin` is the built-in local Administrator account (RID 500) and `FilterAdministratorToken=0` exempts it from UAC token filtering. Test B also reports `BUILTIN\Administrators` for the `git init`-created `.git`, confirming that `CreateProcessW`'s token duplication propagates the parent's `TokenOwner` to the child Win32 binary. Tests D, E, F, and G run with Cygwin's bash somewhere in the parent chain. Cygwin's `cygheap_user::init` calls `NtSetInformationToken(hProcToken, TokenOwner, &user_sid, ...)` at DLL initialization, which rewrites the `TokenOwner` field from `BUILTIN\Administrators` to the user SID. The mutation is inherited by every descendant via `CreateProcessW` token duplication. Tests F and G are the load-bearing cases for the next commit's mechanism explanation. Test F's child is a Git for Windows `git.exe`, which performs no token-rewriting of its own but inherits the already-mutated token from its Cygwin bash parent and produces a user-owned `.git` directory. Test G strengthens this by replacing git with a fresh PowerShell that uses its own `New-Item` builtin: the only Cygwin-family runtime in the chain is the intermediate `bash.exe`, the entry and exit are both ordinary Win32 shells, and the resulting directory is still user-owned. So no part of the mechanism depends on git, MSYS2 sh dispatch, or any property of the final-link binary -- it depends only on whether *some* process in the ancestry loaded a Cygwin-family runtime, which carries forward through every subsequent `CreateProcessW`. This `diag-token` job, like the `reproduce-safe-dir` matrix added in the previous commit, is temporary and should be removed before this work is integrated. Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 8fc41fb commit 4106557

1 file changed

Lines changed: 102 additions & 0 deletions

File tree

‎.github/workflows/cygwin-test.yml‎

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,108 @@ jobs:
102102
run: |
103103
pytest --color=yes -p no:sugar --instafail -vv ${{ matrix.additional-pytest-args }}
104104
105+
diag-token:
106+
runs-on: windows-latest
107+
108+
env: *cygwin-env
109+
110+
defaults: *cygwin-defaults
111+
112+
steps:
113+
- *force-lf
114+
- *checkout
115+
- *install-cygwin
116+
117+
- name: PowerShell-side token state and file-creation tests
118+
shell: pwsh
119+
run: |
120+
$repo = "D:\a\GitPython\GitPython"
121+
Write-Host "==================== whoami /all (PowerShell) ===================="
122+
whoami /all
123+
Write-Host ""
124+
Write-Host "==================== System policy: NoDefaultAdminOwner ===================="
125+
try {
126+
$val = (Get-ItemProperty 'HKLM:\System\CurrentControlSet\Control\Lsa' -Name NoDefaultAdminOwner -ErrorAction Stop).NoDefaultAdminOwner
127+
Write-Host "NoDefaultAdminOwner = $val (0=Admin-owner, 1=Object-creator)"
128+
} catch {
129+
Write-Host "NoDefaultAdminOwner not set (default applies)"
130+
}
131+
Write-Host ""
132+
Write-Host "==================== Test A: PowerShell New-Item directory ===================="
133+
$td = "$repo\test-pwsh-mkdir"
134+
New-Item -ItemType Directory -Path $td -Force | Out-Null
135+
$acl = Get-Acl -LiteralPath $td
136+
Write-Host "Owner of $td : $($acl.Owner)"
137+
Remove-Item $td -Force
138+
Write-Host ""
139+
Write-Host "==================== Test B: PowerShell-spawned Git for Windows git init ===================="
140+
$td2 = "$repo\test-pwsh-gitinit"
141+
New-Item -ItemType Directory -Path $td2 -Force | Out-Null
142+
Push-Location $td2
143+
& "C:\Program Files\Git\bin\git.exe" init 2>&1 | Out-Null
144+
Pop-Location
145+
$acl1 = Get-Acl -LiteralPath $td2
146+
$acl2 = Get-Acl -LiteralPath "$td2\.git"
147+
Write-Host "Owner of $td2 (PowerShell-created) : $($acl1.Owner)"
148+
Write-Host "Owner of $td2\.git (Win git init-created) : $($acl2.Owner)"
149+
Remove-Item $td2 -Recurse -Force
150+
Write-Host ""
151+
Write-Host "==================== Test C: cmd.exe-spawned mkdir ===================="
152+
$td3 = "$repo\test-cmd-mkdir"
153+
cmd.exe /c "mkdir `"$td3`""
154+
$acl = Get-Acl -LiteralPath $td3
155+
Write-Host "Owner of $td3 : $($acl.Owner)"
156+
Remove-Item $td3 -Force
157+
Write-Host ""
158+
Write-Host "==================== Test G: PowerShell -> Git Bash -> PowerShell New-Item ===================="
159+
$td4 = "$repo\test-pwsh-bash-pwsh-mkdir"
160+
$scriptPath = "$repo\inner-mkdir.ps1"
161+
"New-Item -ItemType Directory -Path '$td4' -Force | Out-Null" |
162+
Set-Content -Path $scriptPath -Encoding utf8
163+
$env:MSYS2_ARG_CONV_EXCL = '*'
164+
try {
165+
& "C:\Program Files\Git\bin\bash.exe" -c "powershell.exe -NoProfile -ExecutionPolicy Bypass -File '$scriptPath'" 2>&1 | Out-Null
166+
} finally {
167+
Remove-Item Env:MSYS2_ARG_CONV_EXCL -ErrorAction SilentlyContinue
168+
}
169+
if (Test-Path -LiteralPath $td4) {
170+
$acl = Get-Acl -LiteralPath $td4
171+
Write-Host "Owner of $td4 (PowerShell -> bash -> PowerShell New-Item) : $($acl.Owner)"
172+
Remove-Item $td4 -Force
173+
} else {
174+
Write-Host "Owner of $td4 (PowerShell -> bash -> PowerShell New-Item) : (directory not created)"
175+
}
176+
Remove-Item $scriptPath -Force -ErrorAction SilentlyContinue
177+
178+
- name: Cygwin-side token state and file-creation tests
179+
run: |
180+
set +e
181+
echo "==================== id (Cygwin) ===================="
182+
id
183+
echo
184+
echo "==================== Test D: Cygwin mkdir ===================="
185+
td="$(pwd)/test-cygwin-mkdir"
186+
mkdir "$td"
187+
echo "Owner: $(stat -c '%U(%u)' "$td")"
188+
rmdir "$td"
189+
echo
190+
echo "==================== Test E: Cygwin-spawned Cygwin git init ===================="
191+
td2="$(pwd)/test-cygwin-gitinit"
192+
mkdir "$td2"
193+
( cd "$td2" && git init -q )
194+
echo "Owner of $td2 (Cygwin-mkdir) : $(stat -c '%U(%u)' "$td2")"
195+
echo "Owner of $td2/.git (Cygwin git init) : $(stat -c '%U(%u)' "$td2/.git")"
196+
rm -rf "$td2"
197+
echo
198+
echo "==================== Test F: Cygwin-spawned Git for Windows git init ===================="
199+
td3="$(pwd)/test-cygwin-spawns-wingit"
200+
mkdir "$td3"
201+
( cd "$td3" && /cygdrive/c/Program\ Files/Git/bin/git.exe init -q )
202+
echo "Owner of $td3 (Cygwin-mkdir) : $(stat -c '%U(%u)' "$td3")"
203+
echo "Owner of $td3/.git (Cygwin->Win git init): $(stat -c '%U(%u)' "$td3/.git")"
204+
rm -rf "$td3"
205+
true
206+
105207
reproduce-safe-dir:
106208
strategy:
107209
matrix:

0 commit comments

Comments
 (0)