|
3 | 3 | ## Desc: Install Docker. |
4 | 4 | ## Must be an independent step because it requires a restart before we |
5 | 5 | ## can continue. |
| 6 | +## Supply chain security: (docker-wincred) checksum validation |
6 | 7 | ################################################################################ |
7 | 8 |
|
| 9 | +#region functions |
| 10 | +Function Get-DockerWincredHash |
| 11 | +{ |
| 12 | + Param ( |
| 13 | + [Parameter(Mandatory = $True)] |
| 14 | + [string] $Release |
| 15 | +) |
| 16 | + |
| 17 | + $hashURL = "https://github.com/docker/docker-credential-helpers/releases/download/${Release}/checksums.txt " |
| 18 | + (Invoke-RestMethod -Uri $hashURL).ToString().Split("`n").Where({ $_ -ilike "*docker-credential-wincred-${Release}.windows-amd64.exe*" }).Split(' ')[0] |
| 19 | + |
| 20 | +} |
| 21 | +#endregion |
| 22 | + |
8 | 23 | Write-Host "Get latest release of Docker CE" |
9 | 24 | $mobyLatestReleaseVersion = (Invoke-RestMethod -Uri "https://api.github.com/repos/moby/moby/releases/latest").tag_name.Trim("v") |
10 | 25 | $dockerceUrl = "https://download.docker.com/win/static/stable/x86_64/" |
@@ -49,6 +64,17 @@ $dockerCredLatestRelease = Invoke-RestMethod -Uri "https://api.github.com/repos/ |
49 | 64 | $dockerCredDownloadUrl = $dockerCredLatestRelease.assets.browser_download_url -match "docker-credential-wincred-.+\.exe" | Select-Object -First 1 |
50 | 65 | Start-DownloadWithRetry -Url $dockerCredDownloadUrl -DownloadPath "C:\Windows\System32" -Name "docker-credential-wincred.exe" |
51 | 66 |
|
| 67 | +#region Supply chain security |
| 68 | +$distributor_file_hash = Get-DockerWincredHash -Release $dockerCredLatestRelease.name |
| 69 | +$local_file_hash = (Get-FileHash -Path 'C:\Windows\System32\docker-credential-wincred.exe' -Algorithm SHA256).Hash |
| 70 | + |
| 71 | +if ($local_file_hash -ne $distributor_file_hash) { |
| 72 | + Write-Host "hash must be equal to: ${distributor_file_hash}" |
| 73 | + Write-Host "actual hash is: ${local_file_hash}" |
| 74 | + throw 'Checksum verification failed, please rerun install' |
| 75 | +} |
| 76 | +#endregion |
| 77 | + |
52 | 78 | Write-Host "Download docker images" |
53 | 79 | $dockerImages = (Get-ToolsetContent).docker.images |
54 | 80 | foreach ($dockerImage in $dockerImages) { |
|
0 commit comments