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; on native Windows runtime.Unusable says so first, ADR 0008).
Index ¶
Constants ¶
const ( StateDisabled = "disabled" StateStarting = "starting" StateReady = "ready" StateError = "error" )
State values of Status.State.
const Image = "busybox:1.37"
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 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.
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. 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.