hostns

package
v1.14.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 15, 2026 License: MPL-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package hostns builds the PROFILE_HOST_NS debug root in the host mount namespace.

It does NOT fork the mount namespace: the debug session runs in the host's mount namespace so tools that manage host mounts (zpool, mount, umount) actually affect the host. The Nix toolset is layered in via an overlay whose scratch mounts live under a per-session directory and are removed on teardown, so the only lasting footprint is what the session deliberately creates on the host.

Index

Constants

This section is empty.

Variables

View Source
var HostBinds = []string{"dev", "proc", "sys", "run", "system", "var", "etc"}

HostBinds are the live host mounts bind-mounted into the debug root so tools can reach the running node: devices, kernel filesystems, runtime sockets (/run, /system), live configuration (/etc), and data (/var). They are recursively bind-mounted and made shared, so a mount a session creates under them (e.g. `zpool create -m /var/tank`) propagates to the host, and unmounts propagate back. The session manages host mounts as if it were in the host namespace (which it is). Flags (nodev, nosuid, noexec) are inherited from the already-compliant host mounts.

/var is bound even though the session's own scratch (merged, image, overlay uppers) lives under it: Setup marks those scratch mounts MS_UNBINDABLE, so the recursive /var bind skips them and cannot nest merged into itself.

Functions

func Setup

func Setup(snapshotMounts []mount.Mount, baseDir, varBase string) (merged string, teardown func() error, err error)

Setup builds the debug chroot root in the CURRENT (host) mount namespace:

  • the image snapshot mounted read-only at baseDir/image (via fsopen, so the many- layer overlay does not go through containerd's mount.All, whose CLONE_FS worker would mount it in a way that escapes cleanup);
  • an overlay root (lower=/ plus a disk-backed upper under varBase) at baseDir/merged;
  • the image's /nix overlaid at merged/nix (disk-backed upper);
  • HostBinds recursively bind-mounted and shared into merged.

It returns the merged root (for the child to chroot into) and a teardown func. Teardown makes merged's subtree private and then recursively unmounts merged, so it removes ONLY our scratch mounts: the host's own mounts, and anything the session propagated to the host (e.g. a created zfs pool), are left intact.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL