Skip to content

fix(status): --check-complete falls back to SSM when SSH cannot reach spored (#1493) - #1499

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/1493-status-ssm-fallback
Nov 2, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/1493-status-ssm-fallback

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Fixes #1493

What

spawn status <id> --check-complete exited 3 (error) when SSH to the instance failed: ssh's own exit status 255 was mapped straight to 3. When the bootstrap fails at useradd, the spawn:local-username user does not exist, so SSH is refused while spored has the failed record and exits 1. Now, when SSH cannot reach spored (ssh exits 255, or ssh cannot be started), spawn asks spored over SSM RunCommand. It uses the same RunShellScript call that keyless spawn status and spawn connect --no-public-ip already make, then exits with spored's code. If SSM fails too, the exit is still 3.

Design

  • checkCompleteViaSSH(ctx, runSSH, run ssmShellRunner, instance, stderr) int runs SSH first. Any status other than 255 is the remote command's answer and is returned as is, with no SSM call, so a normal poll costs the same as before. On 255 or a start failure, it prints ssh's diagnostic and a note to stderr, then calls checkCompleteOverSSM.
  • checkCompleteOverSSM is now shared by the new fallback and the existing keyless runStatusOverSSM --check-complete path. It maps the SSM result with checkCompleteCodeFromSSM: spored's 0/1/2/3 pass through, and anything else is 3. A TimedOut or Cancelled invocation reports -1 and a missing spored reports 127; these used to reach os.Exit unchanged. The documented contract is still 0=complete, 1=failed, 2=running, 3=error, from the flag help and docs-gen/status.md.
  • The seams are the existing ssmShellRunner type (cmd/terminate_flush.go) and a runSSH func that wraps sshCmd.Run() through sshExitStatus.
  • IAM: spawn status already lists ssm:SendCommand and ssm:GetCommandInvocation (docs/reference/cli-iam-actions.md). I ran make cli-iam-actions and it produced no diff.
  • The plain (non---check-complete) status path does not change.

Gate (cmd/status_check_complete_test.go)

  • SSH auth failure, then SSM, then the right code: ssh exits 255 with the issue's Permission denied text and SSM returns ResponseCode 1. The test expects exit 1, exactly one SendCommand to the right region and instance carrying spored's --check-complete, and ssh's diagnostic kept on stderr.
  • Codes pass through: codes 0 to 3 from SSM pass through. When SSH answers itself (codes 0 to 3), SSM is never called.
  • Failures are 3: an SSM error, a timeout (-1) and a missing spored (127) all give 3.
  • Real 255: sshExitStatus is checked against a real 255 exit from a child process (this test binary).
  • Wiring: an AST check that runStatus calls checkCompleteViaSSH and runStatusOverSSM calls checkCompleteOverSSM.

Each revert below compiled (go vet was clean), and the gate failed against it:

  1. Fallback replaced by return checkCompleteError: 3 tests fail, e.g. exit code = 3, want 1 (failed) and SSM RunCommand sent 0 times, want exactly 1.
  2. runStatus restored to the inline code == 255 → os.Exit(3) mapping: runStatus does not call checkCompleteViaSSH.
  3. SSM clamp removed: exit code = -1, want 3 and exit code = 127, want 3.

Checks

make check, make lint (0 issues in all 10 modules), semgrep scan --config=auto --error . and make cli-iam-actions (no diff) all pass. No help text changed. User data and the published bootstrap body do not change.

Not live-verified. No AWS calls were made; this needs a repeat of the issue's USER=wheel repro.

@scttfrdmn scttfrdmn added this to the v0.156.0 milestone Nov 2, 2026
@codecov

codecov Bot commented Nov 2, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 73.33333% with 8 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cmd/status.go 73.33% 8 Missing ⚠️

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit dedee58 into main Nov 2, 2026
9 checks passed
@scttfrdmn
scttfrdmn deleted the fix/1493-status-ssm-fallback branch November 2, 2026 18:51
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.

status --check-complete exits 3 (not 1) when the bootstrap failed before creating the login user: SSH auth fails and there is no SSM fallback

1 participant