Repository navigation
launch: fix progress UX, connect hint, and DNS error reporting - #348
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
|
Added the fix for #349 (the real DNS root cause): |
Four user-facing launch bugs found while running `spawn launch` and piping the
output:
1. Stacked progress boxes on non-TTY. The box redraw uses an ANSI clear-screen
that no-ops when stdout isn't a terminal, so each step reprinted the whole
box (~15 stacked boxes when captured). Add TTY detection (os.Stdout mode
ModeCharDevice); non-TTY now prints one line per step transition, TTY keeps
the in-place redraw.
2. Misaligned emoji boxes. The rocket/party emoji are double-width but counted
as one column, so the right border was ragged. New boxLine/displayWidth
compute wide-rune (emoji/CJK) display width and pad to a fixed interior width.
Unit-tested (displayWidth cases + every box line == boxWidth interior cols).
3. Broken connect hint. Success printed `ssh -i ~/.ssh/id_rsa ec2-user@ip`,
which fails Permission denied when the launch key isn't id_rsa. Now suggests
`spawn connect <name>`, which resolves the real launch key (matches the
Windows + DNS branches). Verified live: `spawn connect` runs a command
successfully where the old raw-ssh hint failed.
4. DNS failure was opaque AND SSH'd as the wrong user. registerDNS connected as
the local $USER (plat.GetUsername() = e.g. "scttfrdmn"), which the EC2 key
doesn't authorize, so it failed with Permission denied before ever reaching
the API, then reported a generic "DNS API call failed". Now: SSH as ec2-user
(the user the launch key authorizes), and the script captures the real HTTP
status/body. Verified live: DNS path now reaches the API and returns the real
status (HTTP 404 {"error":"not found"} on the dev account) instead of a
swallowed SSH error. Message notes it's non-fatal + points at `spawn connect`.
Live-verified end-to-end on a t4g.small (terminated + leak-checked). build/vet/
gofmt clean; pkg/progress + cmd tests green (excl. pre-existing TestCatalogValid
#392).
The real bug behind the DNS failure: spawnPublicKeyForUserData installed the WRONG key for the instance's local-matching user. When the named key pair had no adjacent .pub file (e.g. created via `aws ec2 create-key-pair`, which returns only the private key), it silently fell back to ~/.ssh/id_rsa.pub — so the local user's authorized_keys trusted id_rsa, but the operator connects with the named key → Permission denied. That also killed DNS registration (SSHes in as that user) before it reached the API. `ec2-user` only worked because AWS installs the named EC2 key pair for the AMI default user, masking the bug. - pkg/sshkey.PublicKeyForName: prefer <key>.pub, else DERIVE the public key from the private key (ssh.ParsePrivateKey + MarshalAuthorizedKey); error on passphrase-protected keys. PublicKeyFromPrivateFile exposed + unit-tested (derives-when-no-pub, prefers-pub-file, missing-key-errors). - spawnPublicKeyForUserData uses it and NEVER substitutes a different key when a keyName is given — errors loudly instead. Only the no-keyName path keeps the platform default. - registerDNS SSHes as the local-matching user (plat.GetUsername()), reverting a wrong hardcoded-ec2-user stopgap. The default login user differs by distro (ubuntu/rocky/admin/ec2-user); spawn's model is a local-matching user. VERIFIED LIVE (t4g.small, .pub-less key, terminated+leak-checked): SSH as the local user `scttfrdmn` with the named key now succeeds (uid=1001, wheel) where it previously got Permission denied; DNS registration now SSHes in successfully and reaches the transport. A SEPARATE, now-visible issue remains (commented on #349): the dns-updater Lambda URL is IPv6-only and the instance has no IPv6 route, so curl fails exit 6 — a DNS-transport reachability problem, not the SSH/user bug. Tests green (pkg/sshkey, pkg/progress); vet/gofmt clean.
The DNS-registration transport hardening for #349: - curl -4: the dns-updater Lambda URL is dual-stack (A + AAAA) but IPv4-only instances have no IPv6 route, so force IPv4. - Retry the WHOLE SSH exec (fresh session each attempt, up to 4 min, bounded best-effort since DNS is non-fatal). The launch flow's shallow port-22 readiness check returns before cloud-init finishes, so the first attempts can fail with SSH Permission denied (local user's authorized_keys not written yet) or curl exit 6 (public-name resolution not up). Both are session-level — re-establishing a new session recovers, where a loop inside one early session can't. Recovers cleanly from the Permission-denied case (verified live). - Real HTTP status/body in the error instead of a swallowed generic message. Known residual (characterized live, environmental, not a spawn bug): on t4g.small in the dev account, early-boot outbound *public* DNS resolution can take ~4-5 min to become reliable — long after IMDS (link-local) and SSH (port 22) are up — so registration can still miss the window. DNS registration is non-fatal (the instance is usable via public IP / spawn connect), and this account's endpoint returns HTTP 404 regardless, so this is left as a bounded best-effort wait rather than chased further. Root cause sits in instance/VPC DNS boot timing, or is better solved by moving registration into spored (which runs after network-ready) — tracked on #349.
…ces) The flakiness class we kept hitting (DNS reg exit 6, local-user login, plugin-configure timing) traces to acting on an instance before cloud-init finishes. `spawn plugin install` went straight to the remote half as soon as SSH was reachable — but sshd opens ~30s before cloud-init completes, so the local user, keys, and network/DNS may not be ready yet. Measured the boot timeline live: from port-22-open, spored flips active at the same moment cloud-init reports done (~36s), because spored is the last bootstrap step. So "spored active over SSM" is a deterministic "fully provisioned" signal — the same one `spawn launch` already uses (verifySporedReady). Route plugin install through it: new ensureInstanceReady(region, id) builds a regional client and reuses verifySporedReady; runPluginInstall calls it before the remote half when the instance is spawn-resolvable. Best-effort (warns and proceeds for a bare hostname). VERIFIED LIVE: install now prints "Waiting for the instance to be ready..." then proceeds cleanly with no race. Note on parallelism (investigated, deliberately NOT done): the pre-launch steps (SSH key/IAM/security group) total ~1.1s and are mostly no-ops; the launch's real cost is the boot wait (~36s, inherently sequential). Parallelizing ~1s of setup would require making the non-thread-safe progress renderer concurrent and risk garbled output — not a safe trade for sub-second gains.
Two related fixes to spawn's "the instance creates a user matching YOUR login, and you log in as that user" model: 1. Normalize the controller username. GetUsername returned the raw $USER, which the bootstrap's ValidateUsername (^[a-z][a-z0-9_-]*) rejects for common macOS/Windows names — SFriedman, Scott, john.doe all FAILED the launch. Add security.NormalizeUsername (lowercase, invalid chars → '-', strip leading non-letters, trim to 32, fall back to "spore") and apply it in GetUsername: SFriedman → sfriedman, john.doe → john-doe. Deterministic; unit-tested. 2. spawn connect now logs in as the local-matching user. It defaulted the SSH user to ec2-user (the AMI default), not the user the bootstrap created and installed your key for — so "connect" wasn't "log in as you". Default to the instance's spawn:local-username tag, falling back to ec2-user only when the tag is absent (older instances). --user still overrides. Windows has no per-user account (key authorized for Administrator); connect still uses Administrator there — documented in the changelog. VERIFIED LIVE: launch + `spawn connect <id>` (no --user) → whoami=scttfrdmn, HOME=/home/scttfrdmn (was ec2-user before). build/vet/gofmt clean; pkg/platform + pkg/security + cmd tests green (excl. pre-existing #392).
Roll up the plugin + launch-hardening work merged since v0.72.0 (#347, #348): plugin lifecycle (as_user, env_passthrough, ssh_config identity, reconcile, full-lifecycle install, orphan cleanup, strict template syntax) and launch robustness (deterministic readiness gate, username normalization + log-in-as-you, progress UX, connect hint, DNS curl -4/retry, silent-key-substitution fix). MINOR: backward-compatible features + fixes, no breaking changes.
Summary
Four user-facing
spawn launchbugs, all found by running a real launch and all verified live (t4g.small, terminated + leak-checked).1. Stacked progress boxes on non-TTY (Fixed)
The animated box redraw uses an ANSI clear-screen that no-ops when stdout isn't a terminal — so piping/capturing
spawn launchreprinted the entire box on every step (~15 stacked boxes). Now detects a non-TTY stdout and prints a clean one-line-per-step log; the in-place redraw is kept only for interactive terminals.2. Misaligned emoji boxes (Fixed)
🚀/🎉are double-width but were counted as one column, so the right║was ragged. NewboxLine/displayWidthpad to a fixed interior width accounting for wide runes (emoji/CJK). Unit-tested.3. Broken connect hint (Fixed)
Success printed
ssh -i ~/.ssh/id_rsa ec2-user@<ip>, which failsPermission deniedwhen the launch key isn'tid_rsa. Now suggestsspawn connect <name>(resolves the real launch key, falls back to SSM) — matching the Windows/DNS branches. Verified:spawn connectruns where the old hint failed.4. DNS failure opaque + wrong SSH user (Fixed)
registerDNSSSH'd into the instance as the local$USER(which the EC2 key doesn't authorize → Permission denied before the API was ever called), then reported a generic "DNS API call failed". Now connects asec2-userand surfaces the real HTTP status/body. Verified live: the DNS path now reaches the API and returns the real status (HTTP 404 on the dev account) instead of a swallowed SSH error. Registration stays non-fatal; the message points at the public-IP /spawn connectfallback.Testing
Instance Readybox,spawn connect uxtesthint, and actionable DNS message.spawn connectverified working; DNS API reached (real 404). Instance terminated + leak-checked.go build/vet/gofmtclean;pkg/progress(new alignment/width tests) +cmdgreen except pre-existingTestCatalogValid(feat(plugin): permissions declaration block (#388) #392).Part of the 2026-07 audit CLI-consistency goals.