Files
Triple-C/scripts/build-ssm-plugin.ps1
T
shadowdaoandClaude Opus 5.5 5b23dc1aec
Build App (Preview) / compute-version (pull_request) Successful in 5s
Secret Scan / scan (push) Successful in 8s
Secret Scan / scan (pull_request) Successful in 7s
Build App (Preview) / create-release (pull_request) Successful in 2s
Build App (Preview) / build-macos (pull_request) Successful in 6m42s
Build App (Preview) / build-linux (pull_request) Successful in 12m41s
Build App (Preview) / build-windows (pull_request) Successful in 13m57s
Build App (Preview) / test (pull_request) Successful in 23m29s
Build App (Preview) / prune-previews (pull_request) Successful in 3s
build: build session-manager-plugin from source, not AWS's binaries
AWS ships its prebuilt plugin as "AWS Content" under the AWS Customer
Agreement; the source is Apache-2.0. Replace the binary fetch with
scripts/build-ssm-plugin.sh (any triple, cross-compiles; universal via
lipo) and build-ssm-plugin.ps1 (Windows runner):

- source: tag 1.2.896.0 at commit 6430675a, GitHub archive SHA-256
  checked before extraction;
- Go 1.26.11 from go.dev, published SHA-256 checked before use;
- the repo's own build (GOPATH mode, vendored deps, -s -w,
  sessionmanagerplugin-main) with VERSION stamped to the tag, plus
  -trimpath, no VCS stamp, empty build id, CGO off;
- output must equal a pinned SHA-256 per target (reproducible builds).

Each platform job builds its own targets. Windows: the exe is now ours
and unsigned, so windows-sign.ps1 allowlists it and
windows-verify-signatures.ps1 requires it signed by the installer's own
certificate in the MSI and NSIS. THIRD_PARTY_NOTICES now carries the
source's LICENSE/NOTICE/THIRD-PARTY, the commit, every linked vendored
module's licence and Go's. AWS's GPG key and the AWS-signature checks
are gone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 08:12:11 -08:00

125 lines
6.8 KiB
PowerShell

# build-ssm-plugin.ps1 - build AWS's session-manager-plugin FROM SOURCE for
# Windows and put it where Tauri's bundle.externalBin expects it:
#
# app\src-tauri\binaries\session-manager-plugin-x86_64-pc-windows-msvc.exe
#
# The Windows runner's half of scripts/build-ssm-plugin.sh - read that header
# for the why. The same pins and the same build, so it must produce the same
# bytes (Go builds are reproducible across hosts); keep the two in step.
#
# 1. Source: AWS's tag 1.2.896.0 by COMMIT, as GitHub's archive of that
# commit, SHA-256 checked before extraction (and its top directory must
# name the commit).
# 2. Toolchain: Go, pinned, SHA-256 as published by go.dev, checked before use.
# 3. AWS's own build (GOPATH mode over the vendored deps, -ldflags "-s -w"),
# version stamped to the tag, made reproducible (-trimpath, no VCS stamp,
# empty build id, CGO off, GOAMD64=v1, nothing inherited).
# 4. The output must equal the pinned SHA-256.
#
# The result is UNSIGNED: in a release build Tauri presents it to the sign
# command (windows-sign.ps1 signs it with our certificate), and
# windows-verify-signatures.ps1 requires our signature on it in both installers.
#
# Needs tar.exe (bsdtar, in every Windows 10+). Idempotent.
$ErrorActionPreference = 'Stop'
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Add-Type -AssemblyName System.IO.Compression.FileSystem
$PluginVersion = '1.2.896.0'
$PluginCommit = '6430675a44032a551be1937fb27a2d3fdfeb27f7'
$SourceUrl = "https://codeload.github.com/aws/session-manager-plugin/tar.gz/$PluginCommit"
$SourceSha = '7C95BE411AD5F43D14D01460500BFD5A5AA0E28BA94815F8B049AF33A2C381B0'
$GoVersion = '1.26.11'
$GoSha = '71AE086F0137E665F855A811CC119152B6A783E0BBC1B906E709F46D80141EB0' # go1.26.11.windows-amd64.zip, go.dev
$BinarySha = '6D428E5FD77E76D9713F0C42B8EC39F2DE1031E5F3C567FEB73C7FE11B14B226'
$Triple = 'x86_64-pc-windows-msvc'
$repoRoot = Split-Path -Parent $PSScriptRoot
$destDir = Join-Path $repoRoot 'app\src-tauri\binaries'
$dest = Join-Path $destDir "session-manager-plugin-$Triple.exe"
$notices = Join-Path $repoRoot 'app\src-tauri\THIRD_PARTY_NOTICES'
function Get-Sha256([string]$Path) { (Get-FileHash -LiteralPath $Path -Algorithm SHA256).Hash.ToUpperInvariant() }
if (-not ((Select-String -LiteralPath $notices -SimpleMatch "Version: $PluginVersion" -Quiet) -and
(Select-String -LiteralPath $notices -SimpleMatch "Commit: $PluginCommit" -Quiet))) {
throw "$notices does not name plugin $PluginVersion at $PluginCommit - update it with the bump"
}
if ((Test-Path -LiteralPath $dest) -and ((Get-Sha256 $dest) -eq $BinarySha)) {
Write-Host "session-manager-plugin-$Triple.exe: already the pinned $PluginVersion build"
exit 0
}
$work = Join-Path ([IO.Path]::GetTempPath()) ('ssm-plugin-' + [guid]::NewGuid().ToString('N'))
New-Item -ItemType Directory -Path $work | Out-Null
$ProgressPreference = 'SilentlyContinue'
try {
$goZip = Join-Path $work 'go.zip'
Write-Host "Downloading Go $GoVersion (windows-amd64)"
Invoke-WebRequest -Uri "https://go.dev/dl/go$GoVersion.windows-amd64.zip" -OutFile $goZip -UseBasicParsing
$actual = Get-Sha256 $goZip
if ($actual -ne $GoSha) { throw "SHA-256 mismatch for the Go toolchain: got $actual, pinned $GoSha" }
[IO.Compression.ZipFile]::ExtractToDirectory($goZip, (Join-Path $work 'toolchain'))
$go = Join-Path $work 'toolchain\go\bin\go.exe'
$srcTgz = Join-Path $work 'source.tar.gz'
Write-Host "Downloading session-manager-plugin $PluginVersion source ($PluginCommit)"
Invoke-WebRequest -Uri $SourceUrl -OutFile $srcTgz -UseBasicParsing
$actual = Get-Sha256 $srcTgz
if ($actual -ne $SourceSha) { throw "SHA-256 mismatch for the plugin source: got $actual, pinned $SourceSha" }
$srcDir = Join-Path $work 'src'
New-Item -ItemType Directory -Path $srcDir | Out-Null
& tar.exe -xzf $srcTgz -C $srcDir
if ($LASTEXITCODE -ne 0) { throw "tar.exe could not extract the source ($LASTEXITCODE)" }
$goSpace = Join-Path $srcDir "session-manager-plugin-$PluginCommit"
if (-not (Test-Path -LiteralPath (Join-Path $goSpace 'src\sessionmanagerplugin-main'))) {
throw "the source archive is not the pinned commit's tree"
}
# A clean, fully specified Go environment for everything below.
foreach ($v in 'GOFLAGS', 'GOROOT', 'GOBIN', 'GOEXPERIMENT', 'GOTMPDIR') { Remove-Item "env:$v" -ErrorAction SilentlyContinue }
$gopath = Join-Path $work 'gopath'
$env:GOENV = 'off'; $env:GOTOOLCHAIN = 'local'; $env:GO111MODULE = 'off'; $env:GOPROXY = 'off'; $env:GOWORK = 'off'
$env:GOPATH = "$gopath;$(Join-Path $goSpace 'vendor')"
$env:GOCACHE = Join-Path $work 'cache'; $env:GOMODCACHE = Join-Path $work 'modcache'
$env:CGO_ENABLED = '0'; $env:GOAMD64 = 'v1'; $env:GOARM64 = 'v8.0'
# makefile pre-build: stamp the version with AWS's own generator.
[IO.File]::WriteAllText((Join-Path $goSpace 'VERSION'), $PluginVersion)
# version-gen runs on this host, so no GOOS/GOARCH yet.
Remove-Item env:GOOS, env:GOARCH -ErrorAction SilentlyContinue
Push-Location $goSpace
try { & $go run ./src/version/versiongenerator/version-gen.go | Out-Null } finally { Pop-Location }
if ($LASTEXITCODE -ne 0) { throw "version-gen failed ($LASTEXITCODE)" }
if (-not (Select-String -LiteralPath (Join-Path $goSpace 'src\version\version.go') -SimpleMatch "const Version = `"$PluginVersion`"" -Quiet)) {
throw 'the version stamp did not take'
}
# makefile copy-src: GOPATH mode, from a copy at the import path.
$pkgRoot = Join-Path $gopath 'src\github.com\aws\session-manager-plugin'
New-Item -ItemType Directory -Force -Path $pkgRoot | Out-Null
Copy-Item -Recurse -LiteralPath (Join-Path $goSpace 'src') -Destination $pkgRoot
$out = Join-Path $work 'session-manager-plugin.exe'
Write-Host "Building session-manager-plugin $PluginVersion for windows/amd64"
$env:GOOS = 'windows'; $env:GOARCH = 'amd64'
Push-Location $pkgRoot
try {
& $go build -trimpath -buildvcs=false -ldflags '-s -w -buildid=' -o $out `
github.com/aws/session-manager-plugin/src/sessionmanagerplugin-main
} finally { Pop-Location }
if ($LASTEXITCODE -ne 0) { throw "go build failed ($LASTEXITCODE)" }
$actual = Get-Sha256 $out
if ($actual -ne $BinarySha) {
throw "the windows/amd64 build is not the pinned binary: got $actual, pinned $BinarySha (source, toolchain or build flags changed)"
}
New-Item -ItemType Directory -Force -Path $destDir | Out-Null
Move-Item -LiteralPath $out -Destination $dest -Force
Write-Host "session-manager-plugin-$Triple.exe: session-manager-plugin $PluginVersion (unsigned; signed by the release build)"
} finally {
Remove-Item -Recurse -Force -LiteralPath $work -ErrorAction SilentlyContinue
}