Skip to content

fc: give every microVM its own guest hostname - #1074

Open
cdalar wants to merge 3 commits into
mainfrom
ai/fc-guest-hostname
Open

fc: give every microVM its own guest hostname#1074
cdalar wants to merge 3 commits into
mainfrom
ai/fc-guest-hostname

Conversation

@cdalar

@cdalar cdalar commented Sep 1, 2026

Copy link
Copy Markdown
Owner

Summary

  • Every Firecracker VM onctl creates booted with the same guest OS hostname (onctl-runner), regardless of its actual VM name — because bake-fc-image.sh's debootstrap runs in a chroot that can't isolate the UTS namespace, so it bakes one fixed placeholder hostname into the base rootfs image, and nothing at VM-creation time overrode it per-VM.
  • DebugfsRootfsPreparer.Prepare now takes a hostname parameter and, when non-empty, rewrites /etc/hostname in the per-VM writable rootfs copy — same "edit the ext4 image via debugfs -w, no mount, no root needed" technique already used for SSH-key injection. Shared the "build script, run debugfs -w" plumbing into a new runDebugfsScript helper.
  • ProviderFC.Deploy passes server.Name through a new sanitizeGuestHostname (lowercase, [a-z0-9-] only, 63-byte RFC 1123 cap) before handing it to Prepare — needed because arbitrary VM names aren't guaranteed hostname-safe (fcTapName/fcMAC already hash the name for the same reason), and because this value is written into a debugfs script verbatim, so an unsanitized name could otherwise inject extra script commands.
  • Every microVM (whatever created it — the onctl-runners controller's runner pool, onctl create run by hand, the sandboxes feature, etc.) now gets a guest hostname matching its actual VM name.

Test plan

  • make (build + go mod tidy + go fmt) — clean
  • go test ./pkg/cloud/... ./internal/providerfc/... — all pass, including new tests: TestDebugfsRootfsPreparer_Prepare_InjectsHostname, _NoHostname, _HostnameDebugfsFails, and TestSanitizeGuestHostname (charset/case/length edge cases)
  • golangci-lint run ./pkg/cloud/... ./internal/providerfc/... — 0 issues
  • go vet ./..., gofmt -l on changed files — clean
  • Note: go test ./cmd/... has 3 pre-existing failures (TestReadConfig_NoConfigDirectory, TestActionCmd_DownloadFile_404, TestCreateFlagsBindToViper) reproduced identically on unmodified origin/main — unrelated to this change, not touched by this PR

🤖 Generated with Claude Code

https://claude.ai/code/session_01TB8wdxuaLyoYZBkfcD1vzv

…ault

debootstrap runs in a chroot that can't isolate the UTS namespace, so the
baked Firecracker rootfs image always carries one fixed placeholder
hostname (bake-fc-image.sh writes "onctl-runner" into it). Every VM
booted from that image reported the same guest hostname, regardless of
its actual onctl VM name — noticeable via `hostname`/`uname -n` inside
the guest, and in anything that shells out and reads it (e.g. a GitHub
Actions runner's "Machine name" in its job log, previously patched
around per-caller in onctl-runners' own bootstrap script rather than
fixed here).

DebugfsRootfsPreparer.Prepare now takes a hostname and, when non-empty,
rewrites /etc/hostname in the per-VM rootfs copy via the same
debugfs-without-mounting technique already used for SSH key injection
(factored the shared "write script, run debugfs -w" bit into
runDebugfsScript). ProviderFC.Deploy passes server.Name through
sanitizeGuestHostname (safe hostname charset, 63-byte RFC 1123 cap) —
needed both because arbitrary VM names aren't guaranteed hostname-safe
(fcTapName/fcMAC already hash the name for the same reason) and because
the value lands in a debugfs script verbatim, so an unsanitized name
could inject extra script commands.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TB8wdxuaLyoYZBkfcD1vzv

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1167fb20ad

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread pkg/cloud/fc.go Outdated
sanitizeGuestHostname previously truncated overlong names to a flat 63-byte
prefix, so two VM names sharing the same first 63 sanitized bytes (e.g. a
controller-generated run ID appended after a long shared prefix) collided on
the same guest hostname. Reserve the last 9 bytes for a hyphen and an
8-hex-char hash of the full name so truncated names stay distinct.

Addresses a Codex review comment on PR #1074.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SKUJRDCaXe4RnU6BXLatcs

cdalar commented Sep 1, 2026

Copy link
Copy Markdown
Owner Author

Build (stable) failed on 1fa5bf0, but it's not this PR's failure: github.com/cdalar/onctl/cmd failed only on TestActionCmd_DownloadFile_404 (cmd/coverage_test.go:153), which hits the live external endpoint https://httpstat.us/404 and expects a 404 — this run got a 502 Bad Gateway from that service instead. Nothing in this PR touches cmd/; this diff only changes pkg/cloud/fc.go and its tests. This matches one of the 3 pre-existing failures already called out in the PR description as reproducing identically on unmodified main. The job has already auto-requeued on this commit; watching for it to go green.


Generated by Claude Code

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.

2 participants