Skip to content

feat(linux): Pass the container's host name in ip= - #1235

Merged
urunc-bot[bot] merged 1 commit into
mainfrom
feat/linux-guest-hostname
Nov 30, 2026
Merged

urunc-bot[bot] merged 1 commit into
mainfrom
feat/linux-guest-hostname

Conversation

@ananos

@ananos ananos commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Description

The guest kernel takes its host name from the fifth field of ip= (net/ipv4/ipconfig.c), and urunc always writes urunc there. So every Linux guest calls itself urunc: a shell prompt reads root@urunc, and so does the console of every pod on k8s.

This patch fills that field with the container's host name instead:

  • the OCI spec's hostname: with nerdctl or docker that is --hostname, or the container ID's first 12 characters by default.
  • on Kubernetes, where containerd sets the spec's hostname for the pause container only, the first line of the file mounted at /etc/hostname, which holds the pod's name.

A name must match ^[A-Za-z0-9-]{1,64}$: ip= ends the host name at a ., and the kernel splits its command line on blanks, \v, \f, \r and 0xA0. Any other name is logged as a warning, and the guest keeps urunc.

Related issues

How was this tested?

  • Unit tests: TestLinuxCommandStringHostname (the filter, incl. ., \v, \r, 0xA0), TestGuestHostname (spec hostname, the /etc/hostname mount, first line only, a missing file, an invalid name) and TestGuestHostnameLogsARejectedName. go test ./pkg/unikontainers/..., go build ./... and go vet pass on Linux amd64.
  • golangci-lint v2.15 (the make lint image, run without -it): 0 issues. cspell with .github/linters/.cspell.json: 0 issues.
  • End to end on Linux amd64 with nerdctl and the same change on top of 5c6bc70 (the branch brig's bundle pins): brig run claude@refactor boots with ip=10.4.2.2::10.4.2.1:255.255.255.0:claude-code-refactor-20d51f16:eth0:off, and uname -n and /etc/hostname in the guest both read claude-code-refactor-20d51f16.
  • The e2e suites (make test_ctr, make test_nerdctl, ...) were not run locally; CI ran them on the previous revision. The Kubernetes path is covered by the unit tests above, not by a pod booted on a cluster.

LLM usage

Claude Opus 5.5 (Claude Code) wrote the patch and the unit test, and ran the checks above.

Checklist

  • I have read the contribution guide.
  • The linter passes locally (make lint).
  • The e2e tests of at least one tool pass locally (make test_ctr, make test_nerdctl, make test_docker, make test_crictl).
  • If LLMs were used: I have read the llm policy.

@netlify

netlify Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for urunc canceled.

Name Link
🔨 Latest commit 79a22c9
🔍 Latest deploy log https://app.netlify.com/projects/urunc/deploys/6b0d657a027071dbb3eb6665

@cmainas cmainas left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you @ananos for the PR.

The fix works well for nerdct/docker/ctr, but in K8s containerd has the weird behavior of setting the hostname field of the spec only in the pause container. Therefore, we will need to read /etc/hostname to get it in the Kubernetes path. We can do that in a followup or please integrate it with the other changes. There is also a small spelling issue.

Comment thread pkg/unikontainers/unikernels/linux.go Outdated
// container's, or urunc when it is unset or cannot be passed there. ':' and
// blanks would split the argument, and the kernel holds at most 64 bytes.
func kernelHostname(name string) string {
if name == "" || len(name) > maxHostnameLen || strings.ContainsAny(name, ": \t\n") {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We should have a stricter filter for the characters in hostname. The Linux kernel also uses the characters "\v, \f, \r" and 0xA0 to split the kernel boot arguments, so we can do the same. Also, since ip= uses . to split parameters, we should also reject .. The easiest thing to do would be to create a regexp with all the accepted characters as we do with annotations. For example, ^[A-Za-z0-9-]{1,64}$

// blanks would split the argument, and the kernel holds at most 64 bytes.
func kernelHostname(name string) string {
if name == "" || len(name) > maxHostnameLen || strings.ContainsAny(name, ": \t\n") {
return defaultHostname

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: We should log here that the hostname was rejected.

@ananos
ananos force-pushed the feat/linux-guest-hostname branch from e823ea4 to 86d80c8 Compare November 30, 2026 10:18

@cmainas cmainas left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you @ananos

The kernel sets its host name from the fifth field of ip=, which was
always "urunc". Fill it with the container's host name instead:

- the OCI spec's hostname, or, when it is empty, the first line of the
  file mounted at /etc/hostname. containerd sets the spec's hostname
  for a Kubernetes pause container only, so an application container
  carries its pod's name in that file.
- a name of letters, digits and '-', up to the kernel's 64 bytes. ip=
  ends the host name at a '.', and the kernel splits its command line
  on blanks, \v, \f, \r and 0xA0. Any other name is logged and the
  guest keeps "urunc".

PR: #1235
Signed-off-by: Anastassios Nanos <ananos@nubificus.co.uk>
Reviewed-by: Charalampos Mainas <cmainas@nubificus.co.uk>
Approved-by: Charalampos Mainas <cmainas@nubificus.co.uk>
@github-actions
github-actions Bot force-pushed the feat/linux-guest-hostname branch from 86d80c8 to 79a22c9 Compare November 30, 2026 12:00
@urunc-bot
urunc-bot Bot merged commit cfd4d88 into main Nov 30, 2026
5 of 7 checks passed
@cmainas
cmainas deleted the feat/linux-guest-hostname branch November 30, 2026 12:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants