mirror of
https://github.com/actions/runner-images.git
synced 2025-12-20 06:35:47 +00:00
[Windows] Add signature validator for MongoDB (#8304)
This commit is contained in:
@@ -17,7 +17,7 @@ function Install-Binary
|
|||||||
The list of arguments that will be passed to the installer. Required for .exe binaries.
|
The list of arguments that will be passed to the installer. Required for .exe binaries.
|
||||||
|
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
Install-Binary -Url "https://go.microsoft.com/fwlink/p/?linkid=2083338" -Name "winsdksetup.exe" -ArgumentList ("/features", "+", "/quiet")
|
Install-Binary -Url "https://go.microsoft.com/fwlink/p/?linkid=2083338" -Name "winsdksetup.exe" -ArgumentList ("/features", "+", "/quiet") -ExpectedSignature "XXXXXXXXXXXXXXXXXXXXXXXXXX"
|
||||||
#>
|
#>
|
||||||
|
|
||||||
Param
|
Param
|
||||||
@@ -28,7 +28,8 @@ function Install-Binary
|
|||||||
[String] $Name,
|
[String] $Name,
|
||||||
[Parameter(Mandatory, ParameterSetName="LocalPath")]
|
[Parameter(Mandatory, ParameterSetName="LocalPath")]
|
||||||
[String] $FilePath,
|
[String] $FilePath,
|
||||||
[String[]] $ArgumentList
|
[String[]] $ArgumentList,
|
||||||
|
[String] $ExpectedSignature
|
||||||
)
|
)
|
||||||
|
|
||||||
if ($PSCmdlet.ParameterSetName -eq "LocalPath")
|
if ($PSCmdlet.ParameterSetName -eq "LocalPath")
|
||||||
@@ -41,6 +42,19 @@ function Install-Binary
|
|||||||
$filePath = Start-DownloadWithRetry -Url $Url -Name $Name
|
$filePath = Start-DownloadWithRetry -Url $Url -Name $Name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($PSBoundParameters.ContainsKey('ExpectedSignature'))
|
||||||
|
{
|
||||||
|
if ($ExpectedSignature)
|
||||||
|
{
|
||||||
|
Test-FileSignature -FilePath $filePath -ExpectedThumbprint $ExpectedSignature
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw "ExpectedSignature parameter is specified, but no signature is provided."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
# MSI binaries should be installed via msiexec.exe
|
# MSI binaries should be installed via msiexec.exe
|
||||||
$fileExtension = ([System.IO.Path]::GetExtension($Name)).Replace(".", "")
|
$fileExtension = ([System.IO.Path]::GetExtension($Name)).Replace(".", "")
|
||||||
if ($fileExtension -eq "msi")
|
if ($fileExtension -eq "msi")
|
||||||
@@ -687,3 +701,23 @@ function Get-HashFromGitHubReleaseBody {
|
|||||||
}
|
}
|
||||||
return $result
|
return $result
|
||||||
}
|
}
|
||||||
|
function Test-FileSignature {
|
||||||
|
param(
|
||||||
|
[Parameter(Mandatory=$true)]
|
||||||
|
[string]$FilePath,
|
||||||
|
[Parameter(Mandatory=$true)]
|
||||||
|
[string]$ExpectedThumbprint
|
||||||
|
)
|
||||||
|
|
||||||
|
$signature = Get-AuthenticodeSignature $FilePath
|
||||||
|
|
||||||
|
if ($signature.Status -ne "Valid") {
|
||||||
|
throw "Signature status is not valid. Status: $($signature.Status)"
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($signature.SignerCertificate.Thumbprint.Contains($ExpectedThumbprint) -ne $true) {
|
||||||
|
throw "Signature thumbprint do not match expected"
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Output "Signature for $FilePath is valid"
|
||||||
|
}
|
||||||
@@ -22,7 +22,7 @@ $installDir = "c:\PROGRA~1\MongoDB"
|
|||||||
$binaryName = "mongodb-windows-x86_64-$LatestVersion-signed.msi"
|
$binaryName = "mongodb-windows-x86_64-$LatestVersion-signed.msi"
|
||||||
$downloadURL = "https://fastdl.mongodb.org/windows/$BinaryName"
|
$downloadURL = "https://fastdl.mongodb.org/windows/$BinaryName"
|
||||||
$installArg = "INSTALLLOCATION=$installDir ADDLOCAL=all"
|
$installArg = "INSTALLLOCATION=$installDir ADDLOCAL=all"
|
||||||
Install-Binary -Url $downloadURL -Name $binaryName -ArgumentList ("/q","/i","${env:Temp}\$binaryName", $installArg)
|
Install-Binary -Url $downloadURL -Name $binaryName -ArgumentList ("/q","/i","${env:Temp}\$binaryName", $installArg) -ExpectedSignature (Get-ToolsetContent).mongodb.signature
|
||||||
|
|
||||||
|
|
||||||
# Add mongodb to the PATH
|
# Add mongodb to the PATH
|
||||||
|
|||||||
@@ -463,7 +463,8 @@
|
|||||||
"version": "5.7"
|
"version": "5.7"
|
||||||
},
|
},
|
||||||
"mongodb": {
|
"mongodb": {
|
||||||
"version": "5.0"
|
"version": "5.0",
|
||||||
|
"signature": "F2D7C28591847BB2CB2B1C2A0C59459FDC728A38"
|
||||||
},
|
},
|
||||||
"nsis": {
|
"nsis": {
|
||||||
"version": "3.08"
|
"version": "3.08"
|
||||||
|
|||||||
@@ -399,7 +399,8 @@
|
|||||||
"version": "8.0"
|
"version": "8.0"
|
||||||
},
|
},
|
||||||
"mongodb": {
|
"mongodb": {
|
||||||
"version": "5.0"
|
"version": "5.0",
|
||||||
|
"signature": "F2D7C28591847BB2CB2B1C2A0C59459FDC728A38"
|
||||||
},
|
},
|
||||||
"nsis": {
|
"nsis": {
|
||||||
"version": "3.08"
|
"version": "3.08"
|
||||||
|
|||||||
Reference in New Issue
Block a user