Repository navigation
Description
Summary
Logging into a freshly-launched instance as the local-matching user (spawn's design: it creates a Linux user mirroring the controller's $USER and installs the SSH key for it) can silently fail with Permission denied (publickey). This also broke DNS registration (which SSHes in as that user) and produced a misleading ssh -i ~/.ssh/id_rsa … success hint.
Discovered during live testing: spawn launch then the printed connect path failed Permission denied, and DNS registration failed for the same reason before it ever reached the DNS API.
Root cause (the real bug)
spawnPublicKeyForUserData(plat, keyName) (cmd/launch_config.go) resolves the key pair's public key to install into $LOCAL_USERNAME's authorized_keys:
if keyName != "" {
if priv, err := sshkey.Resolve(plat.HomeDir, keyName); err == nil {
if pub, err := os.ReadFile(priv + ".pub"); err == nil { // <-- needs a local .pub
return pub, nil
}
}
}
pub, err := plat.ReadPublicKey() // <-- SILENT fallback to ~/.ssh/id_rsa.pubIf the resolved private key has no adjacent .pub file (e.g. a key pair created via aws ec2 create-key-pair, which returns only the private key), it silently falls back to ~/.ssh/id_rsa.pub — a different key. The instance then trusts id_rsa for the local user, but the operator connects with the key pair they named → Permission denied. (ec2-user happens to work only because AWS installs the named EC2 key pair for the AMI's default user — masking the bug.)
Impact
- The local-matching user — the whole point of spawn's user model — can be unusable via SSH, even though the launch "succeeded".
- DNS registration SSHes in as that user and fails before calling the API.
- The success connect hint was wrong (see launch: fix progress UX, connect hint, and DNS error reporting #348 — already changed to
spawn connect <name>).
Fixes needed
- Don't silently substitute a key. In
spawnPublicKeyForUserData, when akeyNameis given but no.pubexists, derive the public key from the private key (parse it, marshal the authorized_keys line) instead of falling back to an unrelatedid_rsa.pub. If it truly can't be resolved, fail loudly rather than install a mismatched key. - Use the local-matching user everywhere, not a hardcoded default.
registerDNS(cmd/launch_posthook.go) must SSH as$LOCAL_USERNAME(plat.GetUsername()), never a hardcodedec2-user— the default login user differs across distros (ubuntu/rocky/admin/ec2-user) and contradicts the user model. (A prior stopgap that hardcodedec2-useris being reverted.)
Repro
aws ec2 create-key-pair --key-name k --query KeyMaterial --output text > ~/.spawn/keys/k # no .pub
spawn launch test --key-name k --instance-type t4g.small --region us-east-1 --yes
ssh -i ~/.spawn/keys/k <localuser>@<ip> # Permission denied — instance trusts id_rsa, not k
Verification target
- Deriving
.pubfrom the private key makes$LOCAL_USERNAMElogin work with the named key pair. - DNS registration reaches the API as the local user (no Permission denied).
- Confirm across at least one non-
ec2-userdistro (e.g. Ubuntu →ubuntu).
Activity
scttfrdmn commentedon Jul 13, 2026
Update: primary bug fixed + verified; a second (separate) DNS issue surfaced
Fixed & live-verified: with public-key-derivation-from-private in place, SSH as the local-matching user now works with a
.pub-less named key pair:(previously
Permission denied). DNS registration now SSHes in as that local user successfully.registerDNSusesplat.GetUsername()(local-matching user), not a hardcoded default.Separate issue now visible (was masked before): DNS registration still fails, but now with a real error —
could not reach DNS API (curl exit 6): 000. Root cause: the dns-updater Lambda URL (…lambda-url.us-east-1.on.aws) resolves to IPv6-only addresses, and the instance has no IPv6 route, so curl can't connect (exit 6 = couldn't resolve/route host). This is a reachability problem in the DNS-registration transport, independent of the SSH/user bug — likely wantscurl -4, or the registration should go through spored/signed-request path rather than curl-from-instance. Filing/So tracking separately if desired; the error is now at least diagnosable thanks to the message fix (#348).launch: fix local-user lockout from silent SSH-key substitution (#349)
launch: DNS registration over IPv4 + retry the whole SSH exec (#349)
scttfrdmn commentedon Jul 14, 2026
DNS-registration transport hardened (pushed to #348 branch); residual is environmental
Committed (fix/launch-ux, f4ff2d3):
Permission denied(local user's authorized_keys not written yet) orcurl exit 6. Re-establishing a new session recovers the Permission-denied case (verified live) where an in-session loop can't.Residual (characterized across ~7 live instances; environmental, not a spawn bug)
On
t4g.smallin the dev account (942542972736), early-boot outbound public DNS resolution stays unavailable for ~4-5 minutes — long after IMDS (link-local 169.254) and SSH (port 22) are up. registerDNS's sessions getcurl exit 6the whole time, while a manual session ~5 min post-boot resolves instantly. So registration can still miss even a 4-min window. Two independent facts make this not worth chasing further here:spawn connect.The original reported bug is fixed (silent SSH-key substitution + wrong login user — see the key-derivation + local-user commits, verified live). The remaining transport residual is best addressed by moving DNS registration into spored (runs after the instance is network-ready, sidestepping the controller-SSH-into-early-boot race entirely) — proposing that as the real fix, tracked here. Leaving #349 open for that follow-up.
launch: fix local-user lockout from silent SSH-key substitution (#349)
launch: DNS registration over IPv4 + retry the whole SSH exec (#349)
launch: fix progress UX, connect hint, and DNS error reporting (#348)
fix(spawn): close remaining 2026-06 audit findings (#175) (#364)
scttfrdmn commentedon Jul 17, 2026
Folding in the 2026-06 audit's DNS-over-SSH finding (from #175). That audit flagged
registerDNSshelling out tosshwith host-key verification disabled (StrictHostKeyChecking=no,UserKnownHostsFile=/dev/null) — an MITM window on the controller→instance hop used to register DNS. The recommended fix is the same one this issue already tracks: move DNS registration into spored (runs in-instance after the network is up, over the signed dns-updater path), which sidesteps the controller-SSH hop and its host-key exposure entirely. So the #175 finding is a duplicate of this — capturing it here so it isn't lost when #175 closes.scttfrdmn commentedon Jul 21, 2026
Fixed and shipped in spawn v0.73.0 (issue was left open by oversight).
Both fixes from this report are in
mainand released:spawnPublicKeyForUserData(cmd/launch_config.go) now callssshkey.PublicKeyForName, which reads the adjacent.pubif present and otherwise derives the public key from the private key (PublicKeyFromPrivateFile→ssh.ParsePrivateKey+MarshalAuthorizedKey); passphrase-protected keys error clearly. It never falls back to~/.ssh/id_rsa.pub, and fails loudly if the key can't be resolved. So a key pair created viaaws ec2 create-key-pair(private-only, no.pub) now installs the correct public half for the local-matching user.registerDNS(cmd/launch_posthook.go:124) usesplat.GetUsername()($USER), never a hardcodedec2-user.Covered by tests in
pkg/sshkey/sshkey_test.go:TestPublicKeyForName_DerivesFromPrivateWhenNoPubFile,_PrefersPubFile,_MissingKeyErrors(all green). Changelog entry under [0.73.0].