hostmode

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: Apache-2.0 Imports: 17 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package hostmode implements host mode (FR-CORE-043): host processes reach emulated services by their real hostnames (storage.googleapis.com, LOCATION-docker.pkg.dev, ...) once the local CA is trusted.

Design

gcpemu runs unprivileged, so it can neither bind port 443 on the host nor edit /etc/hosts or the system resolver. Instead, `--host-mode` starts one small labelled container ("gcpemu-<id>-hostmode", image busybox running the gcpemu agent "host-frontend") on the instance's external network, which the Linux host reaches directly at the container's IP. The container:

  • relays :443 to the emulator's Google frontend (internal/frontend), which terminates TLS with a certificate from the instance CA for the requested name and passes HTTP/1.1, HTTP/2 and gRPC to the gateway (or the Artifact Registry listener for LOCATION-docker.pkg.dev);
  • relays :80 to the gateway (plain HTTP with Host routing);
  • serves DNS on :53: every hostname the gateway mounts and every LOCATION-docker.pkg.dev resolves to the container's IP; other names under the routed domains (googleapis.com, pkg.dev) go to the host's real upstream resolvers (never back to systemd-resolved, which would loop), everything else to the emulated Cloud DNS.

The user then points name resolution at it, either per domain with systemd-resolved (`resolvectl dns <bridge> <ip>` and `resolvectl domain <bridge> ~googleapis.com ~pkg.dev`), or with the /etc/hosts block printed by `gcpemu hosts`, and trusts the CA with `gcpemu ca install` (or SSL_CERT_FILE from `gcpemu env --trust`). `gcpemu env` prints these instructions (to stderr) when host mode is on. On macOS and Windows the container IP is not routable from the host, so host mode is Linux-only: an Instance elsewhere refuses it at start (UnsupportedOn), as does a Containerized Instance on a VM runtime (UnsupportedVM).

Index

Constants

View Source
const (
	StateDisabled = "disabled"
	StateStarting = "starting"
	StateReady    = "ready"
	StateError    = "error"
)

State values of Status.State.

View Source
const Image = "busybox:1.38"

Image runs the host-mode agent (any image works: the agent is a static binary). Pinned by tag; digest pinning is a release task.

Variables

View Source
var ErrLinuxOnly = errors.New("host mode is Linux-only: the host cannot reach container IPs inside a VM runtime; point clients at the emulator with `eval \"$(gcpemu env)\"` instead")

ErrLinuxOnly is why host mode is refused off Linux.

View Source
var ErrVMRelay = errors.New("host mode needs a host that can route to container networks, and this host cannot on its VM runtime")

ErrVMRelay is why an emulator on the host refuses host mode when its VM relay is on because the runtime is a VM runtime: its GOOS is linux, but the runtime keeps container networks where the host cannot route to them, as Docker Desktop on Linux does (#560).

View Source
var ErrVMRuntime = errors.New("host mode needs a host that can route to container networks, and this Containerized Instance is on a VM runtime")

ErrVMRuntime is why a Containerized Instance on a VM runtime refuses host mode: its GOOS is linux, but the host cannot route to the container's bridge IP (#492).

View Source
var RoutedDomains = []string{"googleapis.com", "pkg.dev"}

RoutedDomains are the DNS domains to route to the host-mode resolver.

Functions

func HostsBlockNames

func HostsBlockNames(mounted []string) []string

HostsBlockNames returns the names an /etc/hosts block must list: the mounted *.googleapis.com hosts and LOCATION-docker.pkg.dev for every Artifact Registry location. Other mounted names (accounts.google.com) are left out so that host browsers keep reaching Google.

func UnsupportedOn added in v0.6.0

func UnsupportedOn(goos string) error

UnsupportedOn reports why host mode cannot run on goos, or nil on Linux.

func UnsupportedRelay added in v0.10.0

func UnsupportedRelay(d vmrelay.Decision) error

UnsupportedRelay reports why host mode cannot run with the VM relay decision d, naming d's reason, or nil unless d is Unroutable: a relay forced on by GCPEMU_VM_RELAY, as on Linux CI, leaves the host routing.

func UnsupportedVM added in v0.10.0

func UnsupportedVM(d runtime.VMDecision) error

UnsupportedVM reports why host mode cannot run on the VM runtime d describes, naming d's reason so the user sees which GCPEMU_VM_RUNTIME override applies, or nil when d is off.

func UpstreamResolvers added in v0.9.0

func UpstreamResolvers(offline bool) []string

UpstreamResolvers returns the host's real DNS servers for names under the routed domains that the emulator does not serve, and for the Google front end's reads from real GCS (ADR 0021): systemd-resolved's upstream list if present, else non-loopback servers from /etc/resolv.conf, else public resolvers unless offline.

Types

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager runs the host-mode container.

func New

func New(env *emu.Env, hosts func() []string) *Manager

New returns a manager; hosts returns the gateway's mounted hosts.

func (*Manager) Start

func (m *Manager) Start()

Start brings the container up in the background; Status reports progress. Once the Instance has passed the start-time refusals (UnsupportedOn, UnsupportedVM), it never fails instance start (NFR-REL-003).

func (*Manager) Status

func (m *Manager) Status() Status

Status returns the current state.

func (*Manager) Stop

func (m *Manager) Stop()

Stop cancels a pending start. The container is removed with the instance's other containers.

func (*Manager) WaitReady

func (m *Manager) WaitReady(ctx context.Context) (Status, error)

WaitReady waits until host mode is ready or failed.

type Status

type Status struct {
	Enabled bool   `json:"enabled"`
	State   string `json:"state"`
	Error   string `json:"error,omitempty"`
	// IP is the frontend container's address (HTTPS :443, HTTP :80, DNS :53).
	IP string `json:"ip,omitempty"`
	// Interface is the host bridge interface the IP is reached through
	// (for systemd-resolved per-link DNS).
	Interface string `json:"interface,omitempty"`
	// Domains are the DNS domains to route to IP.
	Domains []string `json:"domains"`
	// Hosts are the names for an /etc/hosts block (exact names; registry
	// hosts expanded over every Artifact Registry location).
	Hosts []string `json:"hosts"`
	// CAFile is the CA to trust.
	CAFile string `json:"caFile,omitempty"`
}

Status is host mode's state, served at /_emu/v1/hostmode.

Jump to

Keyboard shortcuts

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