Repository navigation
feat(connect): inject SSH key over SSM when we don't hold the launch key - #114
Merged
Merged
Conversation
`spawn connect` to an instance whose launch key isn't on this machine — or that has no key at all — used to drop straight to a Session Manager shell. Instances launched headlessly by lagotto/cohort are keyless by design (the launcher had no SSH key on disk), so interactive SSH was impossible. Now, when findSSHKey can't locate a local key for the instance, connect ensures spawn's managed ED25519 keypair exists and appends its public key to the login user's authorized_keys over SSM RunCommand, then SSHes with the matching private key. If injection isn't possible (no SSM agent / no SSM permissions / command fails) it falls back to the Session Manager shell as before. - pkg/aws/ssm.go: RunShellScript — Linux sibling of RunPowerShell (AWS-RunShellScript, polls to completion). - cmd/connect.go: injectSSHKeyViaSSM + authorizedKeyInjectionScript (pure, unit-tested). The script is idempotent (grep-guarded append), sets correct perms/ownership, resolves the home dir via getent, and rejects unsafe user / key content so it can't break out of the single-quoted literal. Completes the lagotto#19 chain: lagotto launches keyless spores; connect can now reach them interactively when needed.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Adds substrate-backed tests for the Linux SSM RunCommand helper that connect's key-injection uses, plus a timeout-doesn't-hang guard. Closes the patch-coverage gap on the SSM plumbing.
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.
Why
spawn connectto an instance whose launch key isn't on this machine — or that has no key at all — dropped straight to a Session Manager shell. Instances launched headlessly by lagotto/cohort are keyless by design (the launcher had no SSH key on disk, lagotto#19), so interactive SSH was impossible. Per the design discussion: if connect can't find a key, it should inject one over SSM; if the spore never needs interactive connect, no harm done.What
When
findSSHKeycan't locate a local key for the instance, connect now:authorized_keysover SSM RunCommand.If injection isn't possible (no SSM agent / no SSM permissions / command fails), it falls back to the Session Manager shell exactly as before — no regression for instances that genuinely can't be reached.
pkg/aws/ssm.go:RunShellScript— Linux sibling of the existingRunPowerShell(AWS-RunShellScript, polls to completion).cmd/connect.go:injectSSHKeyViaSSM+authorizedKeyInjectionScript(pure, unit-tested). The script is idempotent (grep-guarded append), sets correct perms (700/.ssh, 600/authorized_keys) and ownership, resolves the home dir viagetent(not hardcoded), and rejects unsafe user / key content so it can't break out of the single-quoted shell literal.Tests
make checkgreen.Chain
Completes the lagotto#19 work: lagotto launches keyless spores via
launcher.Provision(#113);spawn connectcan now reach them interactively when a human wants in.