Skip to content

feat(plugin): reach spored's push API over SSM on keyless instances (#855) - #1243

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/plugin-ssm-855
Oct 20, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/plugin-ssm-855

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Fixes #855

Decision taken (option 1 of the issue, the owner default)

Run the push-API request on the instance over ssm:SendCommand (curl to 127.0.0.1:7777, with the token read on the box). This reuses the RunShellScript machinery spawn extend uses (#1113). There is no Parameter Store polling and no new spored code.

What changes

  • cmd/plugin_push.go adds a pushTransport interface. install, its preflight and status poll, list, status and remove all go through it, so the payload code is the same on every path (pluginInstallPayload). The implementations:
    • sshPush: the existing SSH token read and port-forward.
    • ssmPush: renders POSIX-sh scripts. The body is base64 in a root-only (umask 077) /run/spawn-push-<nonce> file, staged across several SendCommands when it exceeds 16 KiB of base64. SSM documents are capped at 64 KB and the per-parameter limit is undocumented, so the chunk size is deliberately conservative.
      • The token goes into a header file via the printf builtin, so it never appears in a command line. curl runs with --noproxy '*'.
      • The script prints SPAWN_PUSH_STATUS <code> <bytes> and then the body, so a response cut short by SSM's 24,000-character stdout limit is reported as truncated rather than parsed. Staging files are removed.
    • fallbackPush: tries SSH first and switches to SSM for this call and every later one, but only on errPushUnreachable, meaning the API was never reached (token read failed, the tunnel failed to start, or the dial failed). An SSH answer, even an HTTP error, is returned unchanged, so an install is never sent twice. If both fail, the error names both and the command exits non-zero.
  • Which transport is used:
    • A raw host that spawn cannot resolve uses SSH, as before.
    • A resolved instance with no public IP uses SSM.
    • A resolved instance with a public IP uses SSH, falling back to SSM.
  • resolvePluginSSHHost is removed. Its "instance has no public IP to SSH to" error was the failure this issue describes.
  • Help for spawn plugin install updated; gen-docs regenerated.

Gates, each watched failing against a revert that compiles

  • TestPluginInstallOnAKeylessInstanceGoesOverSSMWithTheSamePayload (small and chunked bodies). It runs the recorded SSM scripts for real under sh, with the instance's paths rewritten into a temp dir and the loopback URL pointed at a recording httptest spored. It asserts:

    • spored received byte-for-byte the payload the SSH path sends;
    • the Authorization header carries the on-instance token, and no SendCommand contains the token;
    • the large body was chunked, and no staging files are left behind.

    Reverting the keyless case to SSH made it fail ("transport SSH, want SSM"). Dropping the staging chunks made it fail ("payload over SSM differs ... 694 vs 49846 bytes").

  • TestPluginPushFallsBackToSSMOnlyWhenSSHCannotReachTheAPI covers three cases: unreachable SSH falls back and stays on SSM; an answered SSH install is not retried; if both fail, the error names both. Disabling the fallback made it fail.

  • TestChoosePushTransport failed when I reverted the no-public-IP case.

  • TestPluginPushOverSSMReportsTheAnswer and TestParseSSMPushOutputRefusesATruncatedAnswer cover status, 412 preflight, truncation and the case where there was no HTTP answer.

Checks

  • make check passes every step except check-build-tags, which fails identically on unmodified main on this machine.
  • lint: 0 issues. semgrep: 0 findings (two test-only nosemgreps: the sandbox exec.Command, the same pattern as bootstrap_spot_replacement_test.go, and an httptest handler write).
  • gen-docs committed.

Not verified

  • No live AWS run. Not yet checked on a real instance: SendCommand accepting a 16 KiB-chunk script, base64 -d and curl on AL2023/Ubuntu/Rocky, and spored answering.
  • ensureHostIdentity (for a plugin's local SSH-based steps such as mutagen) still assumes SSH. A plugin whose local steps SSH to the instance still needs SSH. That is the plugin's own requirement, not the push API's.

@scttfrdmn scttfrdmn added this to the v0.138.0 milestone Oct 20, 2026
@codecov

codecov Bot commented Oct 20, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 57.51295% with 82 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cmd/plugin_push.go 64.74% 41 Missing and 8 partials ⚠️
cmd/plugin.go 38.88% 30 Missing and 3 partials ⚠️

📢 Thoughts on this report? Let us know!

…855)

Plugin install/list/status/remove go through a pushTransport. An instance
without a public IP is reached by running curl to the loopback push API on
the instance over SSM SendCommand (token read on the box, body staged in
chunks); one with a public IP tries SSH first and falls back to SSM only
when SSH could not reach the API, so an answered install is never repeated.
@scttfrdmn
scttfrdmn merged commit 3fac480 into main Oct 20, 2026
12 of 13 checks passed
@scttfrdmn
scttfrdmn deleted the fix/plugin-ssm-855 branch October 20, 2026 18:39
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.

spawn plugin install requires SSH, so it cannot work on a keyless SSM-only instance

1 participant