fix(§3.3): Replace credential-store with http.extraHeader for WinRM auth

credential-store --file fails in WinRM on Windows (path escaping, no helper
binary resolution in non-interactive shell). Switch to http.extraHeader:

  git -c credential.helper=       -c 'http.extraHeader=Authorization: Basic <b64>'       clone ...

Advantages:
- No credential helper binary needed
- No temp file (no cleanup required)
- Token never in URL, command display, or Write-Host output
- Works in WinRM non-interactive sessions (no TTY dependency)
- GCM still cleared by credential.helper= prefix

§1.5 compliant: Base64 is in git process argv (not logged by Write-Host).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Simone
2026-05-10 22:16:44 +02:00
parent 73fca1c74a
commit 73bb9b182b
+9 -19
View File
@@ -248,23 +248,19 @@ try {
# Disable interactive credential prompts — WinRM has no TTY
$env:GIT_TERMINAL_PROMPT = '0'
# Clear any system credential helper (e.g. GCM) that may try to open UI/TTY.
# '-c credential.helper=' (empty) resets the helper chain before we inject ours.
$credHelperArgs = @('-c', 'credential.helper=')
# Credentials via temp .git-credentials file (§1.5: token never in URL, argv, or logs)
$tmpCreds = $null
# Build git config args:
# - credential.helper= (empty) clears GCM and any system credential helper
# - http.extraHeader injects Basic auth without credential helpers, temp files,
# or modifying the clone URL (§1.5: token never in URL, argv display, or logs)
$gitConfigArgs = @('-c', 'credential.helper=')
if ($patUser -and $patPass) {
$uri = [uri]$cloneUrl
$credLine = "$($uri.Scheme)://${patUser}:${patPass}@$($uri.Host)"
$tmpCreds = "C:\CI\tmp_gc_$([guid]::NewGuid().ToString('N'))"
[System.IO.File]::WriteAllText($tmpCreds, $credLine)
$credHelperArgs += @('-c', "credential.helper=store --file $tmpCreds")
$b64 = [Convert]::ToBase64String(
[Text.Encoding]::UTF8.GetBytes("${patUser}:${patPass}"))
$gitConfigArgs += @('-c', "http.extraHeader=Authorization: Basic $b64")
}
$gitArgs = $credHelperArgs + $gitArgs
$gitArgs = $gitConfigArgs + $gitArgs
try {
Write-Host "[Guest] Cloning $cloneUrl (branch: $branch)..."
& git @gitArgs 2>&1 | ForEach-Object { Write-Host "[Guest Clone] $_" }
if ($LASTEXITCODE -ne 0) {
@@ -280,12 +276,6 @@ try {
throw "git checkout $commit failed in guest (exit $LASTEXITCODE)"
}
}
} finally {
# Always delete credentials file (§1.5: cleanup)
if ($tmpCreds -and (Test-Path $tmpCreds)) {
Remove-Item $tmpCreds -Force -ErrorAction SilentlyContinue
}
}
} -ArgumentList $CloneUrl, $CloneBranch, $CloneCommit, $GuestWorkDir, $gitPatUser, $gitPatPass, $CloneSubmodules.IsPresent
Write-Host "[Invoke-RemoteBuild] Guest clone complete."