Skip to content

Verify spored on the Windows launch path, and fail closed (#879) - #881

Merged
scttfrdmn merged 3 commits into
mainfrom
fix/879-verify-windows-spored
Oct 13, 2026
Merged

scttfrdmn merged 3 commits into
mainfrom
fix/879-verify-windows-spored

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Closes #879 · advisory GHSA-q59f-6gc3-qj2p (private draft)

The defect

Every Windows spawn launch ran user-data that copied spored-windows-amd64.exe out of S3 and registered it as a SYSTEM service — no checksum, no signature. The Linux bootstrap has verified both and failed closed since GHSA-3x4q-99gh-fxhx, which described two such paths; this was a third, and the only one on a live launch path. It also carried on when the download failed, leaving a Windows spore with no lifecycle at all.

The material was always there: every release publishes the Windows binary's .sha256 and KMS .sig.

The fix

The bootstrap now downloads binary, .sha256 and .sig from the same source, verifies both, and only then installs. A source that fails is skipped and the next tried; if none verifies, nothing is installed and the console says so.

Windows PowerShell 5.1 on Windows 11+, deliberately not PowerShell 7. EC2Launch runs <powershell> user-data with the built-in powershell.exe, and PowerShell 7 isn't preinstalled even on Windows 11 — requiring it would mean downloading an unverified installer before verifying spored. Two consequences:

  • the key is embedded as its P-256 X/Y coordinates, because .NET Framework 4.8 has no ImportSubjectPublicKeyInfo but does have ECDsa.Create(ECParameters). They're derived at generation time from the same SigningKeyPEM Linux uses, so Linux and Windows can't verify against different keys (TestWindowsKeyIsTheLinuxKey);
  • the release signature is ASN.1 DER, and .NET's VerifyHash takes IEEE P1363 r||s, so the script converts.

The verifier lives in pkg/sporedinstall/windows.go beside the Linux one, and is spliced into the user-data after Sprintf so nothing in the PowerShell can be read as a format verb.

Executed, not string-matched

CI can't run Windows PowerShell 5.1, but GitHub's ubuntu-latest ships PowerShell 7, and every API used exists in both. In PowerShell $aws can be a script block, so the test substitutes a fake aws serving objects from a temp dir and runs the whole generated install — source order, refusal, fallback, fail-closed ending:

case result
verified binary installed
tampered regional source, good fallback regional refused, fallback installed, and the installed bytes are the genuine ones
every source tampered nothing installed, console says so
matching .sha256, signature from a different key — the bucket-write case refused
.sig missing refused
.sha256 missing refused
no signing key in the build checksum still required (mirrors Linux SPORED_SIG_VERIFY=0)
DER integers of 33 bytes and of fewer than 32 both verify — a fixed-width converter would silently reject some launches

In CI a missing pwsh fails rather than skips.

Five reverts of the PowerShell, each failing as required: signature never checked; checksum mismatch ignored; fail-open install; a naive fixed-width DER converter; a refusal ending the search instead of trying the next source. A sixth — removing the download-time .sig check — correctly passes, because Test-SporeBinary then can't read the absent signature and refuses anyway.

Against the real release: the generated verifier, run in pwsh with the real key, accepts the actual v0.128.0 spored.exe from S3 and refuses a tampered copy.

Two gates on the rendered user-data (cmd/)

  • service install must be reachable only through a successful verification, must appear once, and the old straight-to-disk aws s3 cp $uri $exe must be gone. Both regressions — an ungated install and the verifier not being spliced — fail it.
  • the whole <powershell> block must parse under PowerShell's own parser. A syntax error in user-data fails nothing in spawn — EC2Launch logs it on the instance — and would leave every Windows spore without spored. An injected stray brace fails it.

Rendered user-data is 8.4 KB, under EC2's 16 KB cap (also asserted).

The manual installers

Five comments that cited the deleted script were rewritten to name the callers that actually parse spored version (spawn upgrade-spored, the release guard) — that output contract is still load-bearing.

Not yet done: a real Windows launch

Everything above runs PowerShell 7 on .NET 10. It does not prove behaviour under Windows PowerShell 5.1 on .NET Framework on a real instance — the one thing CI can't do. I'd like to validate that before merging: a short-lived Windows instance launched with a locally built spawn, confirming spored is verified and installed from the console output, then terminated and leak-checked. That's a billable launch, so it waits for an OK.

🤖 Generated with Claude Code

The Windows launch bootstrap copied spored-windows-amd64.exe out of S3 and
registered it as a SYSTEM service with no checksum or signature check, and
carried on when the download failed. GHSA-3x4q-99gh-fxhx covered two such paths;
this was a third, and the only one on a live launch path.

It now downloads .sha256 and .sig beside the binary from the same source,
verifies both, and only then installs. A failing source is skipped; if none
verifies, nothing is installed and the console says so.

Targets Windows PowerShell 5.1 on Windows 11+, not PowerShell 7: EC2Launch runs
user-data with the built-in powershell.exe, and requiring 7 would mean
downloading an unverified installer first. The key is embedded as P-256 X/Y
coordinates derived from the same SigningKeyPEM Linux uses (.NET Framework has
no ImportSubjectPublicKeyInfo), and the DER signature is converted to P1363.

Executed in tests rather than string-matched: CI runs pwsh, and a fake aws lets
the whole generated install run against signed fixtures and the real v0.128.0
artifact. The rendered <powershell> block is also parse-checked.

install-spored.sh is deleted (spawn upgrade-spored is the verified replacement);
install-spored.ps1 is regenerated from the same verifier, since Windows has no
upgrade-spored yet (#234).

Closes #879
…c key (#879)

TestWindowsAcceptsEveryDERIntegerShape signed up to 400 times looking for a
short (<32-byte) DER integer, which occurs about once per 256; it missed ~4% of
the time and CI hit that. Now 5000 tries (~1e-17).

gitleaks flagged the spored signing PUBLIC key's coordinates in the generated
install-spored.ps1 as generic-api-key. Allowlisted by exact line shape rather
than path, verified against two negative controls. The allowlists are now
separate tables, because within one table paths and regexes combine with AND.
@codecov

codecov Bot commented Oct 13, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 68.88889% with 14 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pkg/sporedinstall/windows.go 69.69% 5 Missing and 5 partials ⚠️
cmd/launch_config.go 66.66% 2 Missing and 2 partials ⚠️

📢 Thoughts on this report? Let us know!

The previous commit validated the allowlist against gitleaks 8.30.1 locally and
moved it to the [[allowlists]] form. CI pins 8.21.2, which does not know
[[allowlists]] and so ignored the whole config — including the existing path
allowlist, so CI failed with sixteen findings instead of two.

In 8.21.2 a single legacy [allowlist] ORs its paths and regexes (later versions
AND them), so the line regex goes back into that one table. Verified with the
8.21.2 binary: history clean, and a different secret in the same file and a
non-hex value under the same variable name are both still caught. The config
records the version sensitivity.
@scttfrdmn

Copy link
Copy Markdown
Contributor Author

Validated on a real Windows instance

The last open item. Windows Server 2025 (ami-00d8aa800578d8b12, Amazon-owned), m7i.large, us-east-1, dev account, launched with spawn built from this branch. Server 2025 runs the same Windows PowerShell 5.1 / .NET Framework 4.8 as Windows 11; EC2 has no public Windows 11 AMIs.

Installed and running, verified at boot, read over SSM with AWS-RunPowerShellScript:

PS=5.1.26100.33451  edition=Desktop  CLR=4.0.30319.42000
OS=Microsoft Windows Server 2025 Datacenter
service: Running / Automatic
binary: present, 69055488 bytes          <- exact size of the published v0.128.0 .exe
spored version 0.128.0
out: spawn: spored verified from s3://spawn-binaries-us-east-1/spawn/spored-windows-amd64.exe

Refusals, under the real .NET Framework, using the generated Test-SporeBinary against the real release artifacts on the instance:

genuine binary, genuine .sha256 + .sig           => ACCEPTED
tampered binary, original .sha256                => REFUSED: checksum mismatch
tampered binary, MATCHING .sha256, genuine .sig  => REFUSED: signature does not verify against the spore.host key
genuine binary, one-byte-flipped .sig            => REFUSED: signature does not verify against the spore.host key

The third row is the one that matters: what someone able to write the bucket would produce, and only the .NET Framework ECDSA path can refuse it. PowerShell 7 in CI could not vouch for that path; this does.

Cleaned up and leak-checked. Terminated; the launch-created security group deleted; then independently: root volume NotFound, SG NotFound, 0 non-terminated instances, 0 ENIs, 0 EIPs, 0 DNS records. ~13 min of runtime, ≈ $0.04.

CI fixes since opening

  • Test — TestWindowsAcceptsEveryDERIntegerShape was flaky: a short DER integer occurs ~1/256, and 400 tries missed it ~4% of the time. Now 5000 (~1e-17). Passing.
  • Secret Scan (gitleaks) — a false positive on the public key's coordinates in the generated .ps1. My first fix was validated against gitleaks 8.30 locally, but CI pins 8.21.2, which ignores the newer [[allowlists]] form entirely — so CI went from 2 findings to 16. Re-done and verified with the 8.21.2 binary itself, including two negative controls. The config now records its version sensitivity. CI's gitleaks download is itself unverified (Security workflow downloads the gitleaks binary with no checksum #885).

Found by this validation, filed separately (none caused by this PR)

@scttfrdmn
scttfrdmn merged commit 4163be4 into main Oct 13, 2026
7 checks passed
@scttfrdmn
scttfrdmn deleted the fix/879-verify-windows-spored branch October 13, 2026 06:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Verify spored on the Windows launch path, and fail closed

1 participant