Skip to content

Verify spored by its heartbeat tag; report AccessDenied as AccessDenied (#1053, #1126) - #1196

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/1053-1126-spored-verification
Oct 19, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/1053-1126-spored-verification

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

What

Post-launch spored verification (cmd/launch_posthook.go, called from launch_single Step 10b and plugin's ensureInstanceReady) now waits for spored's own spawn:last-heartbeat tag, per the owner decision on #1053. SSM is consulted alongside it as a second signal (a successful spored status / Get-Service spored still verifies, and can answer before the first heartbeat), but SSM being absent or refused is never the verdict.

  • No new IAM. The heartbeat is read with ec2:DescribeInstances, which the documented baseline (EC2ReadAndLaunch) grants on * unconditioned. ec2:DescribeTags was deliberately not used: the baseline only grants it under an ec2:ResourceTag/spawn:managed condition, which a Describe call cannot satisfy. No IAM policy in this repo was changed.
  • Windows is covered by the same path. spored's writeHeartbeatTag is in pkg/agent/agent.go (no build constraint) and is called from checkAndAct on every OS; a gate checks this for GOOS=linux and windows.
  • AccessDenied is AccessDenied (Launch reports "spored never came up" when the caller merely lacks ssm:DescribeInstanceInformation (AccessDenied is polled as "not online yet") #1126). pkg/aws: WaitForSSMOnline, RunShellScript and RunPowerShell now return an *AccessDeniedError naming ssm:DescribeInstanceInformation / ssm:SendCommand / ssm:GetCommandInvocation at once instead of polling it until the timeout. During launch verification an SSM refusal only disables the SSM signal (the heartbeat still answers) and is named in the timeout message if nothing arrives. A refused ec2:DescribeInstances stops verification immediately with "spored could not be verified ... your credentials lack ec2:DescribeInstances ... the instance itself may be fine", never "spored never came up".
  • Exit codes unchanged. No heartbeat and no SSM answer within the budget (5 min Linux, 10 min Windows) is still the existing "spored never came up" failure, exit 1, honouring --terminate-on-error; the message now says which evidence was missing and what SSM saw. A missing instance profile still fails fast (wraps ErrSSMUnreachable), and a stopped/terminated instance now fails fast too.
  • --wait-for-ssh=false (spored-availability preflight for regions without a bucket; spored verification is missing on Windows and possibly on non-single launch paths #878): still the escape hatch, per the scope in spored-availability preflight for regions without a bucket; spored verification is missing on Windows and possibly on non-single launch paths #878's correction comment, but no longer silent. It prints that spored was not verified, help text says it skips spored verification too, and --output json gains spored_verified.

Gates (each watched failing against a compiling revert)

Gate Revert that compiles Result
TestVerifySpored_SSMDeniedButHeartbeatVerifies, _NoSSMAgentButHeartbeatVerifies case false && l.Heartbeat != "" both FAIL
TestVerifySpored_DescribeDeniedIsUnverifiableAndNamed case false && err != nil && IsAccessDenied(err); also if false && errors.As(err, &unverifiable) in the launch message FAIL each
TestVerifySpored_TimeoutNamesTheRefusedSSMAction if false && IsAccessDenied(oerr); case false && IsAccessDenied(perr) FAIL each (the first also fails the SSM-denied test via the call count)
TestVerifySpored_NoHeartbeatTimesOut (asserts the existing verdict, poll count across the budget, not unverifiable) —
TestHeartbeatTagIsWhatSporedWritesOnEveryOS agent key spawn:heartbeat; _ = a.writeHeartbeatTag in checkAndAct FAIL each
TestSkippedSporedVerificationIsAnnounced } else if false {; } + if false { FAIL each
TestWaitForSSMOnline_AccessDeniedIsTerminalAndNamed (fake SSM over httptest) _ = denied in isOnline FAIL
TestRunCommand_AccessDeniedIsTerminalAndNamed (shell + PowerShell) false && d != nil for SendCommand; same for GetCommandInvocation FAIL each

All polling tests run on an injected clock and count calls through the sporedSignals seam; no wall-clock bounds.

Checks

make check: every step passes except check-build-tags, which fails identically on an unmodified origin/main worktree on this machine (/private/tmp paths in test/e2e/tier2_test.go, tier3_test.go). make api-snapshot committed (additions only). make gen-docs + check-docs clean. semgrep scan --config=auto --error clean on touched files.

Not done / follow-ups

Fixes #1053
Fixes #1126
Refs #878

@codecov

codecov Bot commented Oct 19, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 69.18605% with 53 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cmd/launch_posthook.go 67.64% 27 Missing and 6 partials ⚠️
pkg/aws/spored_liveness.go 74.00% 10 Missing and 3 partials ⚠️
cmd/launch_single.go 0.00% 5 Missing ⚠️
pkg/aws/ssm.go 85.71% 1 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

…ed (#1053, #1126, #878)

spawn launch now waits for spored's spawn:last-heartbeat tag (read with
ec2:DescribeInstances, already in the IAM baseline) and uses SSM only as
a second signal. AMIs without amazon-ssm-agent no longer fail with a
false "spored never came up". SSM AccessDenied is terminal and names
the refused action; a refused DescribeInstances is reported as
"could not be verified", not as a broken instance. --wait-for-ssh=false
now says it skipped verification.
@scttfrdmn
scttfrdmn force-pushed the fix/1053-1126-spored-verification branch from ba64e96 to d4b7cae Compare October 19, 2026 22:12
@scttfrdmn
scttfrdmn merged commit e7dfcb5 into main Oct 19, 2026
8 checks passed
@scttfrdmn
scttfrdmn deleted the fix/1053-1126-spored-verification branch October 19, 2026 22:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant