Skip to content

fix(scripts): make the hand-written Lambda deploys safe and verifiable - #731

Merged
scttfrdmn merged 2 commits into
mainfrom
fix/sweep-orchestrator-deploy-guards
Oct 8, 2026
Merged

scttfrdmn merged 2 commits into
mainfrom
fix/sweep-orchestrator-deploy-guards

Conversation

@scttfrdmn

@scttfrdmn scttfrdmn commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Blocks the spawn-sweep-orchestrator redeploy that #725 needs. I read the script
I 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

defect why it survived
Account came from whatever credentials were ambient, unasserted Nothing ever pointed it at the wrong one — until something does. A profile name is not an account; a profile can be re-pointed
--environment "Variables={}" on every update That replaces the environment with nothing. The function has no variables set, so the wipe is indistinguishable from a no-op — and it ran under `
Reported success without verifying anything An HTTP 200 from update-function-code says the call was accepted, not that the function runs the new binary
set -e only A failure on the left of a pipe passes silently

Now: asserts the account before building anything, never passes
Variables={}, is set -euo pipefail, snapshots the live config before and
after, and compares the deployed CodeSha256 against the zip it just built —
fatally.

deploy-scheduler-handler.sh had the same Variables={} pattern and no account
assertion. 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.go gates the class rather than the instances:
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
— which is the
argument 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 || true and # deliberately NOT from AWS_REGION as the bugs they document. Comments are now stripped, and the region
check is line-anchored to an assignment — echo "note: AWS_REGION=$AWS_REGION is set but ignored" contains the substring REGION=$AWS_REGION, so a strings.Contains
flagged 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 new scripts/
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 own
go.mod. Discovery is now by find, with a guard that fails the build if it
matches 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 scripts build tag, so the module's only package was tag-gated —
meaning by default it had no packages at all, govulncheck ./... matched
nothing, 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 -tags plumbing the CI step needed for it.

And TestDependabotCoversEveryGoModule — an existing gate — correctly refused
the new module until it had a dependabot entry:

module /scripts is not watched by any gomod entry

Verified by reverting the discovery to find lambda -maxdepth 2: scripts/
matches zero times, so its gates would never run.

Verification

  • Wrong-account guard exercised in both directions against real credentials:
    spore-host-infra with a bogus SPAWN_LAMBDA_ACCOUNT refuses, and
    spore-host-dev (435415984226) refuses — both before the build step.
  • bash -n on both scripts; the 12-module loop run locally under bash as CI
    would (modules=12 fail=0).
  • gofmt, go vet, go test -short ./..., changelog gate, semgrep scan --config=auto --error (0 findings), yaml.safe_load on 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.

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
scttfrdmn force-pushed the fix/sweep-orchestrator-deploy-guards branch from f05ae12 to 7906c95 Compare October 8, 2026 02:25
@codecov

codecov Bot commented Oct 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit 7112119 into main Oct 8, 2026
7 checks passed
@scttfrdmn
scttfrdmn deleted the fix/sweep-orchestrator-deploy-guards branch October 8, 2026 02:37
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.

1 participant