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 ¶
const ( StateDisabled = "disabled" StateStarting = "starting" StateReady = "ready" StateError = "error" )
State values of Status.State.
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 ¶
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.
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).
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).
var RoutedDomains = []string{"googleapis.com", "pkg.dev"}
RoutedDomains are the DNS domains to route to the host-mode resolver.
Functions ¶
func HostsBlockNames ¶
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
UnsupportedOn reports why host mode cannot run on goos, or nil on Linux.
func UnsupportedRelay ¶ added in v0.10.0
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
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 (*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).
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.