Repository navigation
Approval-gated CI deploy of code-only Lambda changes (#1445) - #1450
Merged
Merged
Conversation
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.
Fixes #1445
This is the workflow half of #1445. The role half shipped in #1449. The role, its policy and the
productionenvironment are unchanged.What it adds
scripts/deploylambdasis a Go deployer in the scripts module. It calls AWS only through theawsCLI, behind a seam (lambdaCLI), so it adds no AWS SDK dependency. Its input isscripts/deploychecklist --jsonfor<prev tag>..<tag>.selectTargetsis the only place that decides:status: changedanddeploy_kind: code-only. Everything else goes in the record as "manual, not deployed": unchanged, manual, added and removed Lambdas, and every changed deploy input.get-function-configuration, then refuses unless all of these hold:Activeand its last update isSuccessful;PackageTypeisZip;Architecturesis the checklist build'sGOARCH;RuntimeandHandlerare what the component's own mechanisms declare at the tag (SAMRuntime:/Handler:, shell--runtime/--handler). All mechanisms must agree, the runtime must beprovided.*, and the handler must bebootstrap.go buildline (GOOS, GOARCH,-tags,-ldflagswith${SPAWN_VERSION}filled in) from the clean tag checkout. Any other token refuses. The zip hasbootstrapat its root, mode 0755, with a fixed timestamp, so the CodeSha256 is reproducible.get-function'sCode.Locationand checks that its sha matches the live CodeSha256.update-function-code --revision-id <snapshot>, then it polls until the update settles. Polls are counted, not timed.RuntimeVersionConfig, because Lambda moves the runtime version on an update under automatic runtime management. The record notes when that happens.spawn:version=<tag without v>withtag-resourceand reads it back.spawn:version, and fails the run. The functions after it are "not attempted"..github/workflows/deploy-lambdas.yamlhasworkflow_callandworkflow_dispatchtriggers, each withdry_run(boolean, default true). It has two jobs:planjob with no credentials. It refuses a non-vX.Y.Zref before anyone is asked to approve, and puts the checklist in its summary.deployjob. It setsenvironment: production,permissions: id-token: write, contents: read, pull-requests: write, andconcurrency: deploy-lambdas-productionwithcancel-in-progress: false.configure-aws-credentialsis pinned to the same SHA as in release.yaml, with the role. The record goes to the job summary and as a comment on the release PR, found the way the deploy-checklist job finds it. It is posted on failure too.release.yamlgets a newdeploy-lambdasjob:needs: goreleaser,uses: ./.github/workflows/deploy-lambdas.yaml. No existing job changed and none needs it, so a pending approval blocks nothing.Design decisions
Codeand must be documented"). Classifying them as manual was the alternative.Codeonly when the template's code location changes, and a parameter-only stack update leaves code and tags alone. The nextmake -C lambda/<x> deployfrom a release tag uploads its own build and assertsVersion(both Makefiles always pass it), which reconciles the drift.aws:cloudformation:stack-nametag) and the drift.sam deployneedscloudformation:*andiam:PassRole, which this role must never have.vars.LAMBDA_DEPLOY_MODE == 'live'.workflow_dispatchneeds the workflow file at the dispatched ref, so no tag up to and including v0.151.0 can run it. Without this switch, v0.152.0's release run, after approval, would be the deployer's first use, and live. With it, the first use is a dry run on the release path. Going live isgh variable set LAMBDA_DEPLOY_MODE --repo spore-host/spawn --body live. If you'd rather it be live from the start, change the expression tofalse.CGO_ENABLED=0, and the manual deploys cross-compile from macOS, where cgo is off. On an ubuntu runner a native amd64 build would otherwise link glibc.go run -ldflags "-X github.com/spore-host/spawn/cmd.Version=$V" . bootstrap-body, not the sweep script's barego run .. Matching how the published body was produced is the stronger check.TestBodyRenderMatchesTheReleasekeeps the two in step. The body is fetched over public HTTPS, as the script'scurldoes, so the role needs nos3:GetObject.sts get-caller-identity.Pre-flights not ported (the role doesn't grant the call)
deploy-custom-dns.sh: the Function URLAuthType == AWS_IAMcheck needslambda:GetFunctionUrlConfig. A code update doesn't change the URL config.lambda/dashboard-api/deploy.sh: the IAM role existence check needsiam:GetRole, and only matters on create.Every config write in the scripts is deliberately left out: timeout, memory, environment, runtime, role policies, log retention, Function URL and permissions. dashboard-api has two mechanisms with different ldflags, and the deployer uses the checklist's line (
-ldflags="-s -w").Gates, each watched failing against a compiling revert
TestEveryLambdaCallIsGrantedByTheCIRole: subcommands discovered from everycallLambdaliteral (AST), exactly oneawsexec, mapped kebab to Pascal against actions parsed from the script'sPOLICY_DOCUMENT; tag key against itsaws:TagKeys; plus a dynamic run whose calls must be in the static setget-function-url-configcalllambda:GetFunctionUrlConfignot granted"lambda:GetFunction"from the scriptversionTag = "spawn:deployed-version"TestOnlyChangedCodeOnlyLambdasAreDeployed(4 statuses × 3 kinds)&&to||inselectTargetsTestMismatchedLiveFunctionRefuses/TestArchitectureComesFromTheChecklistBuildTestRemoteShaMismatchRollsBackfalse &&on the sha checkTestConfigDiffRollsBackfalse &&on the diff checkTestDryRunMakesNoMutatingCall(mutating = any non-get-/list-verb)if d.dryRun && falseTestDeployRoleIsAssumedOnlyInTheProductionEnvironment: every job in every workflow that assumes the role or runs the deployerenvironment: staging/ removed / role ARN changed / scriptROLE_NAMEchangedTestDeployWorkflowDefaultsToDryRunAndBlocksNoReleaseJobfalse;deploy-checklistneeds: deploy-lambdasAlso added:
TestEveryOperatedLambdaIsDeployable: the real inventory (deploychecklist HEAD..HEAD) parses for all 9 Lambdas, and the body check is found for sweep-orchestrator.TestRealBuildZipLayout(non-short): a real sweep-orchestrator build twice, which gives one entrybootstrap, executable, and the same sha both times.internal/iamcoverage:scripts/deploylambdasis registered as not-a-principal for the SDK call-graph analysis, since it calls AWS only through the CLI, with a pointer to the gate above.Checks
GOTOOLCHAIN=go1.27.3 make check(from /private/tmp) passes. It includes golangci-lint, clean in all 10 modules, and the hermetic short tests.scripts/deploylambdastests pass, including the real build and the real body render.semgrep scan --config=auto --error .: 0 findings.actionlinton deploy-lambdas.yaml and release.yaml: clean. The one actionlint note in the repo, SC2001 in ci.yml, is already on main.Not exercised
There has been no
AssumeRoleWithWebIdentityand no live run; no AWS calls were made for this PR.