Repository navigation
Expand file tree
/
Copy pathinstall.ps1
More file actions
246 lines (223 loc) · 12.1 KB
/
Copy pathinstall.ps1
File metadata and controls
246 lines (223 loc) · 12.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
#!/usr/bin/env pwsh
<#
.SYNOPSIS
Install the hellbox CLI on Windows.
.DESCRIPTION
The Windows / PowerShell parallel to deploy.sh's binary-acquisition step:
resolve your architecture, download the release .exe, verify its SHA256 and
GitHub build-provenance attestation, cache it under ~/.hellbox/bin, and put
that directory on your user PATH.
It stops after installing. Configure AWS credentials, then run `hellbox
deploy` yourself (that command creates the AWS prerequisites, builds the DOOM
MicroVM image, launches it, and opens the tab).
No repo clone is required: the CloudFormation template and the capsule build
context are baked into the binary, so this script only needs to fetch the exe.
Environment overrides (these mirror deploy.sh):
HELLBOX_REPO default somoore/hellbox
HELLBOX_VERSION default latest, or a pinned tag like v1.0.17
HELLBOX_HOME default $env:USERPROFILE\.hellbox
HELLBOX_SKIP_ATTESTATION set to 1 to skip the attestation check (requires a
pinned HELLBOX_VERSION, never latest, AND
HELLBOX_I_UNDERSTAND_THE_RISK=1). Prefer building
from source over skipping verification.
.EXAMPLE
./install.ps1
.EXAMPLE
$env:HELLBOX_VERSION = "v1.0.17"; ./install.ps1
#>
[CmdletBinding()]
param()
$ErrorActionPreference = 'Stop'
# The release binary is ~20 MB; without this Invoke-WebRequest renders a
# per-byte progress bar that dominates the download time.
$ProgressPreference = 'SilentlyContinue'
function Info($m) { Write-Host "==> $m" -ForegroundColor Cyan }
function Warn($m) { Write-Host "warning: $m" -ForegroundColor Yellow }
function Die($m) { Write-Host "error: $m" -ForegroundColor Red; exit 1 }
function Have($name) { [bool](Get-Command $name -ErrorAction SilentlyContinue) }
$Repo = if ($env:HELLBOX_REPO) { $env:HELLBOX_REPO } else { 'somoore/hellbox' }
$Version = if ($env:HELLBOX_VERSION) { $env:HELLBOX_VERSION } else { 'latest' }
$HomeDir = if ($env:HELLBOX_HOME) { $env:HELLBOX_HOME } else { Join-Path $env:USERPROFILE '.hellbox' }
$BinDir = Join-Path $HomeDir 'bin'
$SkipAtt = ($env:HELLBOX_SKIP_ATTESTATION -eq '1')
# --- Target detection -------------------------------------------------------
# On 32-bit PowerShell running on 64-bit Windows (WOW64), PROCESSOR_ARCHITECTURE
# reports x86 while PROCESSOR_ARCHITEW6432 holds the real native arch. Prefer the
# native one so we don't wrongly reject a machine that can run the 64-bit build.
$nativeArch = if ($env:PROCESSOR_ARCHITEW6432) { $env:PROCESSOR_ARCHITEW6432 } else { $env:PROCESSOR_ARCHITECTURE }
switch ($nativeArch) {
'AMD64' { $arch = 'x86_64' }
'ARM64' { $arch = 'arm64' }
default { Die "unsupported architecture '$nativeArch' (hellbox ships x86_64 and arm64 Windows builds)" }
}
$asset = "hellbox-windows-$arch.exe"
# --- Resolve the release tag ------------------------------------------------
function Resolve-Tag {
if ($Version -ne 'latest') { return $Version }
if (Have gh) {
$t = gh release view --repo $Repo --json tagName --jq .tagName 2>$null
if ($LASTEXITCODE -eq 0 -and $t) { return $t.Trim() }
}
try {
$r = Invoke-RestMethod "https://api.github.com/repos/$Repo/releases/latest" `
-Headers @{ 'User-Agent' = 'hellbox-install' }
if ($r.tag_name) { return $r.tag_name }
} catch { }
Die "could not resolve the latest release for $Repo (set HELLBOX_VERSION to a tag like v1.0.17)"
}
$tag = Resolve-Tag
Info "hellbox $tag (windows-$arch)"
# --- Attestation gate -------------------------------------------------------
# The .sha256 sidecar ships from the same release as the binary, so it only
# proves the download wasn't truncated or corrupted: an attacker who can swap
# the asset can swap its sidecar too. The cryptographic trust anchor is the
# GitHub build-provenance attestation, bound to the release workflow identity
# and the tag's source ref. To trust nothing prebuilt, build from source
# (cd rs-cli; make release) instead of running this script.
# Both verifiers return $true/$false rather than exiting, so a bad *cache* can
# fall through to a fresh download while a bad *download* is a hard Die at the
# call site. Neither one runs the binary - the cache is trusted only after these
# pass, so `install.ps1` never executes an unverified exe (e.g. one left by a
# manual install or a tampered cache).
function Test-Attestation($file, $releaseTag) {
if ($SkipAtt) {
if ($Version -eq 'latest') {
Die 'HELLBOX_SKIP_ATTESTATION=1 requires a pinned HELLBOX_VERSION, not latest'
}
# Turning off the build-provenance trust anchor must be deliberate, not a
# stray env var: require an explicit risk acknowledgement so a copy-pasted
# HELLBOX_SKIP_ATTESTATION=1 alone cannot silently downgrade trust to the
# swappable .sha256 sidecar.
if ($env:HELLBOX_I_UNDERSTAND_THE_RISK -ne '1') {
Die ("HELLBOX_SKIP_ATTESTATION=1 disables the build-provenance trust anchor, leaving`n" +
" only the .sha256 sidecar, which an asset-swapping attacker can also swap.`n" +
" The trustless path is to build from source and set HELLBOX_BIN instead.`n" +
" To skip verification anyway, also set HELLBOX_I_UNDERSTAND_THE_RISK=1.")
}
Warn "SECURITY: attestation verification DISABLED for $Version. Integrity rests on the .sha256 sidecar alone, which is not tamper-evident. Prefer building from source (HELLBOX_BIN)."
return $true
}
if (-not (Have gh)) {
Die ("gh (GitHub CLI) is required to verify the build attestation for $asset.`n" +
" Install it with 'winget install GitHub.cli', or build from source. As a`n" +
" last resort, set HELLBOX_SKIP_ATTESTATION=1 with a pinned HELLBOX_VERSION`n" +
" and HELLBOX_I_UNDERSTAND_THE_RISK=1 (this disables the trust anchor).")
}
# --source-ref binds the check to this exact tag, so an older artifact from the
# same workflow (or a swapped asset+sidecar) fails rather than passing.
gh attestation verify $file --repo $Repo `
--signer-workflow "github.com/$Repo/.github/workflows/release.yml" `
--source-ref "refs/tags/$releaseTag" 2>$null
return ($LASTEXITCODE -eq 0)
}
function Test-Sha256($file, $sumFile) {
$expected = ((Get-Content $sumFile -Raw).Trim() -split '\s+')[0]
if (-not $expected) { Die "empty checksum file: $sumFile" }
$actual = (Get-FileHash $file -Algorithm SHA256).Hash
return ($actual -eq $expected.ToUpper())
}
# Download a release asset. Falls back to `gh release download` when the public
# URL fails, so a private HELLBOX_REPO (whose tag Resolve-Tag already found via
# gh) still installs - matching deploy.sh's authenticated-download fallback.
function Get-ReleaseAsset($assetName, $outFile) {
$url = "https://github.com/$Repo/releases/download/$tag/$assetName"
try {
Invoke-WebRequest $url -OutFile $outFile
return
} catch {
if (Have gh) {
Info "public download failed for $assetName - fetching via gh (private repo?)"
gh release download $tag --repo $Repo --pattern $assetName --output $outFile --clobber 2>$null
if ($LASTEXITCODE -eq 0 -and (Test-Path $outFile)) { return }
}
Die "could not download $assetName from $Repo ($tag): $($_.Exception.Message)"
}
}
# --- Download + verify (or re-verify an already-cached match) ---------------
New-Item -ItemType Directory -Force -Path $BinDir | Out-Null
$exe = Join-Path $BinDir 'hellbox.exe'
$sum = Join-Path $BinDir 'hellbox.exe.sha256'
$needDownload = $true
if ((Test-Path $exe) -and (Test-Path $sum)) {
if ($SkipAtt) {
# A local checksum sidecar is not a trust anchor: an attacker who replaced
# the cached executable can replace it too. With attestations disabled,
# never execute or reuse cache contents; fetch the explicitly pinned release.
Warn "attestation is disabled, so cached executables are never reused - re-downloading $tag"
} else {
# Re-verify the cache BEFORE trusting or running it. SHA256 first (integrity),
# then attestation (provenance). The attestation is bound to $tag, so a pass
# also proves the cache is this release. An older or tampered cache falls
# through to a fresh download without being executed.
$cacheOk = (Test-Sha256 $exe $sum) -and (Test-Attestation $exe $tag)
if ($cacheOk) {
Info "hellbox $tag already installed and verified at $exe"
$needDownload = $false
} else {
Warn "cached hellbox failed verification or is a different release - re-downloading"
}
}
}
if ($needDownload) {
$tmpExe = Join-Path $BinDir $asset
$tmpSum = "$tmpExe.sha256"
Info "Downloading $asset"
Get-ReleaseAsset $asset $tmpExe
Get-ReleaseAsset "$asset.sha256" $tmpSum
if (-not (Test-Sha256 $tmpExe $tmpSum)) {
$expected = ((Get-Content $tmpSum -Raw).Trim() -split '\s+')[0]
$actual = (Get-FileHash $tmpExe -Algorithm SHA256).Hash
Die "SHA256 mismatch for ${asset}:`n expected $expected`n got $actual"
}
Info "Verified SHA256 for $asset"
if (-not (Test-Attestation $tmpExe $tag)) {
Die "GitHub build-provenance attestation verification failed for $asset"
}
if (-not $SkipAtt) { Info "Verified GitHub build-provenance attestation for $asset" }
Move-Item -Force $tmpExe $exe
Move-Item -Force $tmpSum $sum
Info "Installed hellbox $tag to $exe"
}
# --- PATH -------------------------------------------------------------------
# Prepend, not append: if a stale hellbox already sits earlier on PATH (an old
# manual copy, say), appending would let the advertised `hellbox deploy` keep
# invoking that one. Prepending makes the binary we just verified win - both for
# future terminals (user PATH) and this session.
$normalizedBin = $BinDir.TrimEnd('\')
$userPath = [Environment]::GetEnvironmentVariable('Path', 'User')
$alreadyUserPath = ($userPath -split ';' | Where-Object { $_.TrimEnd('\') -ieq $normalizedBin }).Count -gt 0
if (-not $alreadyUserPath) {
$newPath = if ([string]::IsNullOrWhiteSpace($userPath)) { $BinDir } else { "$BinDir;$($userPath.TrimEnd(';'))" }
[Environment]::SetEnvironmentVariable('Path', $newPath, 'User')
Info "Added $BinDir to the front of your user PATH"
}
# This session: drop any existing entry, then prepend, so `hellbox` resolves here now.
$env:Path = "$BinDir;" + (($env:Path -split ';' | Where-Object { $_ -and ($_.TrimEnd('\') -ine $normalizedBin) }) -join ';')
# Warn if another hellbox is installed elsewhere. We prepend to *user* PATH, but
# new processes build PATH as machine-entries-then-user-entries, so a hellbox on
# the MACHINE PATH still shadows ours in fresh terminals (this session is fine --
# we patched it above). Call that out specifically, since the fix differs.
$other = Get-Command hellbox -All -ErrorAction SilentlyContinue |
Where-Object { $_.Source -and ($_.Source.TrimEnd('\') -ine $exe.TrimEnd('\')) } |
Select-Object -First 1
if ($other) {
$machinePath = [Environment]::GetEnvironmentVariable('Path', 'Machine')
$otherDir = (Split-Path $other.Source -Parent).TrimEnd('\')
$onMachine = ($machinePath -split ';' | Where-Object { $_.TrimEnd('\') -ieq $otherDir }).Count -gt 0
if ($onMachine) {
Warn "another hellbox is on the machine PATH at $($other.Source). New terminals resolve machine PATH before your user PATH, so they will run that one, not the copy just installed. Remove it, or invoke this build by full path: $exe"
} else {
Warn "another hellbox is on PATH at $($other.Source). This session and new terminals prefer the copy just installed; remove that one if you want it gone."
}
}
# --- Next steps -------------------------------------------------------------
Write-Host ''
Info 'hellbox is installed. Next steps:'
Write-Host ' 1. Configure AWS credentials (aws configure, SSO, or env vars).'
Write-Host ' hellbox reads the standard AWS credential chain, like the AWS CLI.'
Write-Host ' 2. Run: hellbox deploy'
Write-Host ' Creates the AWS prerequisites, builds the DOOM MicroVM image,'
Write-Host ' launches it, and opens the browser tab (about 4-5 minutes).'
Write-Host ''
Write-Host 'Tip: use current Chrome or Edge for the low-latency H.264 path (WebCodecs).'
Write-Host ' In a fresh terminal `hellbox` is on PATH; in this one it already works.'