From a98dd2a3c116a25982516f6269e462a4f8685ace Mon Sep 17 00:00:00 2001 From: qmuntal Date: Fri, 13 Nov 2026 11:17:14 +0100 Subject: [PATCH] eng: verify toolchain archive SHA-256 Pin the existing installer generator to the integrity-hardening change in microsoft/go-infra#691 and regenerate the installer. Validate the manifest digest and verify the downloaded archive before extraction, without adding signature verification or new dependencies. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- eng/_util/go-install.ps1 | 19 +++++++++++++++++-- eng/_util/go.mod | 2 +- eng/_util/go.sum | 2 ++ 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/eng/_util/go-install.ps1 b/eng/_util/go-install.ps1 index 2fb741f3d4..87768fd0a4 100644 --- a/eng/_util/go-install.ps1 +++ b/eng/_util/go-install.ps1 @@ -797,7 +797,8 @@ function Get-AkaMSRedirectTarget([string] $akaMsLink) { # https://github.com/PowerShell/PowerShell/issues/10875 function Get-OrNull($Target, $Property) { if ($Target -and $Target.PSObject.Properties[$Property]) { - return $Target.PSObject.Properties[$Property].Value + # Preserve arrays so callers can distinguish them from scalar property values. + return ,$Target.PSObject.Properties[$Property].Value } return $null } @@ -887,6 +888,11 @@ if ($DryRun) { return } +$ExpectedSHA256 = Get-OrNull $Arch 'sha256' +if ($ExpectedSHA256 -isnot [string] -or $ExpectedSHA256 -notmatch '\A[0-9a-fA-F]{64}\z') { + throw "The asset manifest does not contain a valid SHA-256 digest for '$DownloadLink'." +} + Measure-Action "Installation directory preparation" { Prepare-Install-Directory } Say-Verbose "Zip path: $ArchivePath" @@ -896,6 +902,15 @@ Say-Verbose "Downloading link $DownloadLink" try { Measure-Action "Package download" { DownloadFile -Source $DownloadLink -OutPath $ArchivePath } Say-Verbose "Download succeeded." + + # This checks integrity, not authenticity: the manifest and archive are both remote. + # An attacker able to replace both can supply a matching digest. Authenticity requires + # verifying the signature at pgpSignatureUrl against a locally pinned Microsoft public key. + $ActualSHA256 = (Get-FileHash -LiteralPath $ArchivePath -Algorithm SHA256).Hash + if ($ActualSHA256 -ne $ExpectedSHA256) { + throw "SHA-256 mismatch for '$ArchivePath'. Expected: $ExpectedSHA256. Actual: $ActualSHA256." + } + Say-Verbose "SHA-256 verification succeeded." } catch { $StatusCode = $null @@ -915,7 +930,7 @@ catch { Remove-FileSafely -Path $ArchivePath } - throw "Downloading has failed with error:`nUri: $DownloadLink`nStatusCode: $StatusCode`nError: $ErrorMessage" + throw "Downloading or verifying the archive has failed with error:`nUri: $DownloadLink`nStatusCode: $StatusCode`nError: $ErrorMessage" } Say "Extracting the archive." diff --git a/eng/_util/go.mod b/eng/_util/go.mod index 658f9c9a75..69db5b8b6c 100644 --- a/eng/_util/go.mod +++ b/eng/_util/go.mod @@ -9,7 +9,7 @@ go 1.26.0 require ( github.com/golang-jwt/jwt/v5 v5.3.1 github.com/microsoft/go-infra v0.0.21 - github.com/microsoft/go-infra/goinstallscript v1.3.0 + github.com/microsoft/go-infra/goinstallscript v1.3.1-0.20261113101331-48b97698e9cc golang.org/x/net v0.62.0 ) diff --git a/eng/_util/go.sum b/eng/_util/go.sum index a37ee4f25f..75a5bba0e3 100644 --- a/eng/_util/go.sum +++ b/eng/_util/go.sum @@ -36,6 +36,8 @@ github.com/microsoft/go-infra v0.0.21 h1:1LS9pnSST73+9+XhY40svE7P/hT5qbsrjkAxKDQ github.com/microsoft/go-infra v0.0.21/go.mod h1:jOetsM1g+txW4kK4CN+Hq+cJCNPVR5iXmy+ZzSMZMQA= github.com/microsoft/go-infra/goinstallscript v1.3.0 h1:KhCeWh9JjCVnPEsL6pb9IzrFShypBKyhlDNjUunonlc= github.com/microsoft/go-infra/goinstallscript v1.3.0/go.mod h1:SFsdKAEHdmGsGoh8FkksVaxoQ3rnnJ/TBqN09Ml/0Cw= +github.com/microsoft/go-infra/goinstallscript v1.3.1-0.20261113101331-48b97698e9cc h1:zrlmplsXtb+eK8TUqsZ9rum3bL5KlBwuD0wXAcilyXg= +github.com/microsoft/go-infra/goinstallscript v1.3.1-0.20261113101331-48b97698e9cc/go.mod h1:SFsdKAEHdmGsGoh8FkksVaxoQ3rnnJ/TBqN09Ml/0Cw= github.com/mitchellh/copystructure v1.2.0 h1:vpKXTN4ewci03Vljg/q9QvCGUDttBOGBIa15WveJJGw= github.com/mitchellh/copystructure v1.2.0/go.mod h1:qLl+cE2AmVv+CoeAwDPye/v+N2HKCj9FbZEVFJRxO9s= github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zxSIeXaQ=