Repository navigation
fix(scripts): make the hand-written Lambda deploys safe and verifiable - #731
Merged
Merged
Conversation
Found while preparing the spawn-sweep-orchestrator redeploy that #725 needs. These functions have no CloudFormation stack, so the script is the only record of how they are configured, and a defect in one is discovered by running it against production. That has now happened twice. deploy-sweep-orchestrator.sh: - Took its account from whatever credentials were ambient, with no assertion. Now asserts before building anything. A profile NAME is not an account; a profile can be re-pointed. - Sent `--environment "Variables={}"` on EVERY update, which replaces the function's environment with nothing. Indistinguishable from a no-op on a function with no variables set, which is why it survived nine months — and it ran under `|| true`, so the wipe could not even fail loudly. - Reported success without checking anything. Now compares the deployed CodeSha256 against the zip it just built: an HTTP 200 from update-function-code says the call was accepted, not that the function runs the new binary. - set -e -> set -euo pipefail. deploy-scheduler-handler.sh had the same Variables={} pattern and no account assertion. Both fixed. The region hardening it already has (from the duplicate-function incident earlier) is unchanged. Adds scripts/deploy_scripts_test.go gating the whole class: account asserted, region never assigned from AWS_REGION, no Variables={}, no `|| true`, and the CodeSha256 comparison present and fatal. It found three real defects in deploy-scheduler-handler.sh on its first run. The gate initially produced two FALSE positives by scanning raw text: these scripts explain their own hazards in comments, so "this used to end in || true" and "deliberately NOT from AWS_REGION" were reported as the bugs they document. Comments are now stripped and the region check is line-anchored. CI: the nested-module step enumerated lambda/* by name, so scripts/ would have been tested nowhere — the shape of #136 one level up. Discovery is now by find, with a guard that fails the build if it matches nothing, and an existing gate (TestDependabotCoversEveryGoModule) correctly caught that the new module also needed a dependabot entry.
govulncheck discovers modules by find — correctly — and the scripts module's only package was behind a `scripts` build tag. So by default the module had NO packages, `govulncheck ./...` matched nothing, and the security job exited 1. The tag was there to keep a normal run from reading files outside the module, but the files it reads are the sibling deploy scripts in the same directory. It was isolating the module from itself. Removing it also removes the -tags plumbing the CI step needed.
scttfrdmn
force-pushed
the
fix/sweep-orchestrator-deploy-guards
branch
from
October 8, 2026 02:25
f05ae12 to
7906c95
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Blocks the
spawn-sweep-orchestratorredeploy that #725 needs. I read the scriptI was about to run against production, and did not like it.
These functions have no CloudFormation stack, so the script is the only
record of how they are configured, and a defect in one is discovered by running
it against production. That has now happened twice.
deploy-sweep-orchestrator.sh--environment "Variables={}"on every updateupdate-function-codesays the call was accepted, not that the function runs the new binaryset -eonlyNow: asserts the account before building anything, never passes
Variables={}, isset -euo pipefail, snapshots the live config before andafter, and compares the deployed
CodeSha256against the zip it just built —fatally.
deploy-scheduler-handler.shhad the sameVariables={}pattern and no accountassertion. Both fixed. Its region hardening, from the duplicate-function incident
earlier in this work, is unchanged.
The gate, and its own two false positives
scripts/deploy_scripts_test.gogates the class rather than the instances:account asserted, region never assigned from
AWS_REGION, noVariables={},no
|| true, and theCodeSha256comparison present and fatal. It found threereal defects in
deploy-scheduler-handler.shon its first run — which is theargument for a class gate over fixing the one script I happened to be reading.
It also produced two false positives, worth recording because the cause is
general: these scripts explain their own hazards in comments, so scanning raw
text reported
# this used to end in || trueand# deliberately NOT from AWS_REGIONas the bugs they document. Comments are now stripped, and the regioncheck is line-anchored to an assignment —
echo "note: AWS_REGION=$AWS_REGION is set but ignored"contains the substringREGION=$AWS_REGION, so astrings.Containsflagged the warning about the hazard as the hazard.
CI could not have run any of it
The nested-module step enumerated
lambda/*by name, so the newscripts/module would have been built, vetted and tested nowhere — the shape of #136
one level up, where the root
go test ./...cannot reach a directory with its owngo.mod. Discovery is now byfind, with a guard that fails the build if itmatches nothing (a silently-empty loop being the failure mode that produced #136
in the first place).
And that discovery immediately caught my own first attempt. I had put the new
test behind a
scriptsbuild tag, so the module's only package was tag-gated —meaning by default it had no packages at all,
govulncheck ./...matchednothing, and the security job exited 1. The tag was supposedly isolating a normal
run from files outside the module, but the files it reads are the sibling deploy
scripts in the same directory. It was isolating the module from itself. Gone,
along with the
-tagsplumbing the CI step needed for it.And
TestDependabotCoversEveryGoModule— an existing gate — correctly refusedthe new module until it had a dependabot entry:
Verified by reverting the discovery to
find lambda -maxdepth 2:scripts/matches zero times, so its gates would never run.
Verification
spore-host-infrawith a bogusSPAWN_LAMBDA_ACCOUNTrefuses, andspore-host-dev(435415984226) refuses — both before the build step.bash -non both scripts; the 12-module loop run locally underbashas CIwould (
modules=12 fail=0).gofmt,go vet,go test -short ./..., changelog gate,semgrep scan --config=auto --error(0 findings),yaml.safe_loadon both workflow files.Not changed: the function's architecture. It is x86_64 while the rest of the
suite is arm64, and the build matches it. Changing architecture is a separate
decision from shipping a code fix, and doing both at once would make a failure
ambiguous.