Repository navigation
fix(connect,launch): run one-shot commands over SSM (#1306); launch flags for spored metrics/tracing/idle-cpu (#1308) - #1337
Merged
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
… spored metrics/tracing/idle-cpu --session-manager, groups closed to SSH, failed key injection) now runs the command with SSM RunCommand as the SSH login user and exits with its status, instead of opening an interactive session that dropped it. The SSH path passes the remote status through too. --tracing, --tracing-exporter, --tracing-sampling and --idle-cpu-threshold write the spawn:* tags spored reads at boot, validated; docs/self-hosted-monitoring.md uses them and keeps the create-tags route for running instances. Fixes #1306 Fixes #1308
scttfrdmn
force-pushed
the
fix/1306-1308-connect-tags
branch
from
October 26, 2026 23:16
1c6ae96 to
e9c44e7
Compare
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 #1306
Fixes #1308
#1306: one-shot
spawn connect <linux> -- <cmd>over SSMThe four SSM paths (no public IP,
--session-manager, security groups closed to SSH, failed key injection) all go through a newconnectOverSSM. A one-shot command runs over SSM RunCommand (AWS-RunShellScriptvia the existingClient.RunShellScript); only a command-less connect opens the interactive session. The v0.145.0 "closed port + one-shot = immediate error" is gone. That case now runs the command too, with a note saying so.Why RunCommand, not
start-session --document-name AWS-StartInteractiveCommand: RunCommand returns the exit code (ResponseCode), keeps stdout and stderr apart, and needs neither the AWS CLI nor the session-manager-plugin locally. A session runs on a PTY, which merges the two streams, and it does not hand the remote status back to the caller.Trade-offs, all documented in the code, the CHANGELOG and the
--session-managerhelp:--ttyhas no effect (a note says so);TimedOutis reported).User: RunCommand runs as root, so the script drops to the SSH login user,
resolveSSHUser(--user>spawn:local-username> ec2-user). It runssudo -H -u $u -- $loginshell -c "$cmd"from that user's home, which matches sshd. The command travels base64-encoded, so nothing needs quoting. An unknown user exits 255, ssh's code for "could not run anything".Exit codes: a new
remoteExitErroris mapped byexitForError. The SSH path now passes the remote status through too (remoteExitaroundssh.Run()), rather than exiting 1 for any failure. That is listed under Changed, so a script sees the same code whichever transport connect picked. Windows' SSM one-shot path is unchanged.No new permission: the caller already needs
ssm:SendCommand/GetCommandInvocationfor key injection andstatusover SSM, and the instance role already hasAmazonSSMManagedInstanceCore.#1308: launch flags for spored's settings
--metrics,--metrics-port,--metrics-bind,--metrics-path,--tracing,--tracing-exporter,--tracing-sampling,--idle-cpu-threshold. They becomeLaunchConfig.Observability(newaws.SporedObservability) andLaunchConfig.IdleCPUPercent, andbuildTagswritesspawn:metrics-{enabled,port,bind,path},spawn:tracing-{enabled,exporter,sampling}andspawn:idle-cpu.They are validated by
LaunchConfig.ValidateSporedSettings, both inrunLaunchbefore any AWS call and insidebuildTagsfor SDK callers:localhost;/;Tracing is limited to the
stdoutexporter.xrayis refused with the reason: the spored role spawn creates has noxray:PutTraceSegments, and users must not add IAM by hand. spored's own default exporter is xray, so--tracingalways writesspawn:tracing-exporter=stdout. No flag was added forspawn:tracing-endpoint, because nothing readsTracingConfig.Endpoint. Both are filed as #1335.spawn:tracing-endpointstays onexternallyWrittenTags, and the other eight entries are removed.docs/self-hosted-monitoring.mdnow leads withspawn launch ... --metrics --metrics-bind 0.0.0.0. Thecreate-tags+ spored restart route is kept, under "An instance that is already running".The flags are classified in the sweep manifest as honoured: every sweep row starts from
buildLaunchConfig's struct, and the flag variables are read inlaunch_config.go. The Windows table marks them honoured too, since the Windows service runs the samerunDaemon.Tag budget, filed as #1336:
maximalConfig(46 tags) plus every #1308 setting comes to 54, which is over EC2's 50. The documented monitoring setup fits at 49 (TestMonitoringSettingsFitOnAMaximalLaunch).buildTagshas never refused over-limit launches itself (80--tags already build 134 tags); #1336 proposes making it refuse them.Gates, each watched failing against a revert that compiles
connectOverSSMalways opens a session (if false {)TestConnectOverSSMRunsTheOneShotCommandconnectViaSessionManagerdirectlyTestRunConnectSendsEverySSMPathThroughConnectOverSSM(AST, discovers calls in runConnect),TestRunConnectUsesLinuxConnectTransportconnectViaSessionManagerdirectlyTestRunConnectSendsEverySSMPathThroughConnectOverSSMexitForErrorignores the remote statusTestRunOneShotOverSSMPropagatesStatusAndStreams,TestExitForErrorPassesTheRemoteStatusFailed+code mapped to nilTestRunOneShotOverSSMPropagatesStatusAndStreamssudo -u(runs as root)TestOneShotSSMScriptRunsAsTheLoginUserTestConnectChecksTheSSHPortAndSendsOneShotToSSMWhenClosedssh.Run()not wrapped inremoteExitTestSSHToInstancePassesTheRemoteStatus(AST)TestSporedSettingsSurviveTheTagHandOff(Launch on substrate, then spored's ownloadConfigFromEC2Tags),TestMonitoringSettingsFitOnAMaximalLaunchTestSporedSettingsSurviveTheTagHandOff,TestSpawnTagContractTestSporedSettingsAreValidatedTestSporedSettingsAreValidated,TestSporedSettingFlagsAreValidatedTestSporedSettingFlagsReachTheLaunchConfig--idle-cpu-threshold 0acceptedTestSporedSettingFlagsAreValidated--metrics/ uses a nonexistent flagTestMonitoringDocLaunchesWithMetricsFlagsTestOneShotSSMScriptRunsTheCommandIntactruns the generated script under/bin/sh, withgetent/sudoshims. It checks a command full of quotes,$HOME, and doubled spaces arrives intact, that the cwd is the user's home, that stderr stays separate, that exit 7 comes back as 7, and that an unknown user exits 255. It is skipped on Windows.TestDocumentedLaunchTagsAreAcceptedstill passes.Checks
make check: everything passes exceptcheck-build-tags, which fails identically on unmodified origin/main on this machine (the /private/tmp path issue); checked in a pristine worktree.make lint: 0 issues in all 10 modules.semgrep scan --config=auto --error .: clean.make api-snapshotcommitted (additions only).make gen-docscommitted;make check-docsis clean.Not verified
No live AWS run, so RunCommand against a real instance has not been tried: the sudo drop,
getenton AL2023/Ubuntu, and whether anohup ... &one-shot (the README example) survives AWS-RunShellScript's completion. The metrics/tracing flags have not been tried on a real spored boot either; the round trip is substrate tags into spored's own parser.