frontend

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2026 License: Apache-2.0 Imports: 14 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 frontend is the emulator's "Google front end": a TLS terminator that lets unmodified clients reach emulated services by their real hostnames (storage.googleapis.com, pubsub.googleapis.com, LOCATION-docker.pkg.dev, ...) over HTTPS, HTTP/2 and gRPC (FR-INT-007, FR-CORE-043).

Design

The frontend is one TCP listener in the emulator process (endpoint "frontend", dynamic port unless --port frontend=N). For each connection it completes a TLS handshake with a certificate issued by the instance's local CA (env.CA) for the requested SNI, offering ALPN "h2" and "http/1.1", then pipes the decrypted byte stream unchanged to:

  • the Artifact Registry listener for LOCATION-docker.pkg.dev, or
  • the gateway for every other name.

Both backends speak HTTP/1.1 and prior-knowledge h2c on the same port, so whichever protocol the client negotiated works end to end, including gRPC, streaming and trailers, and the Host / :authority header arrives untouched; the gateway's host routing (emu.Router Mount hosts) then picks the service. Only names the emulator serves get a certificate: the gateway's mounted hosts and LOCATION-docker.pkg.dev. A connection without SNI (a client dialing an IP address, such as kube-apiserver calling an admission webhook) gets a certificate for "localhost" and every IP address of the host, which includes the container networks' gateway addresses.

Port 443 is reached from containers through small TCP relays rather than by binding it on the host (which needs root): the GKE node agent listens on 169.254.169.254:443 in every node, and the host-mode container (internal/hostmode) listens on its own address. Both resolve the served names to themselves with the DNS Relay in this package.

Index

Constants

View Source
const Endpoint = "frontend"

Endpoint is the frontend's name in emu.Endpoints (and netplane.Addr).

View Source
const NetworkOption = 65400

NetworkOption is the EDNS0 local option (RFC 6891 private range) with which a VPC's DNS relay tells the emulated Cloud DNS the VPC network a query comes from ("projects/P/global/networks/N"), so that private zones are answered only on the networks they are bound to (FR-DNS-004).

Variables

This section is empty.

Functions

func IsRegistryHost

func IsRegistryHost(name string) bool

IsRegistryHost reports whether name is an Artifact Registry Docker host, LOCATION-docker.pkg.dev.

func ListenDNS

func ListenDNS(addr string, h mdns.Handler) (stop func(), err error)

ListenDNS serves h on addr over UDP and TCP and returns once both are listening; stop shuts them down.

func Network

func Network(m *mdns.Msg) string

Network returns the VPC network a query carries in NetworkOption, or "".

func Normalize

func Normalize(name string) string

Normalize lower-cases a DNS name and strips the trailing dot.

func Pipe

func Pipe(client, server net.Conn)

Pipe copies between client and server in both directions. When the server side ends, the client gets a half-close and the connection is torn down shortly after; a client half-close is passed on and the server may keep answering.

func Relay

func Relay(l net.Listener, target string) error

Relay accepts TCP connections on l and pipes each to target (used by the in-container 443 relays). It returns when l is closed.

func Serves

func Serves(hosts []string, name string) bool

Serves reports whether name is served by the frontend given the gateway's mounted hosts.

func SetNetwork

func SetNetwork(m *mdns.Msg, network string) *mdns.Msg

SetNetwork returns a copy of m that carries network in NetworkOption.

Types

type DNS

type DNS struct {
	// Answer returns the IPv4 address for name (normalized, no trailing
	// dot), or nil when the name is relayed.
	Answer func(name string) net.IP
	// Upstreams returns the servers (host:port) a name is relayed to;
	// none yields SERVFAIL.
	Upstreams func(name string) []string
	// TTL of synthesized answers (default 60 s).
	TTL uint32
	// Network, when set, tags relayed queries with the VPC network they
	// come from (NetworkOption).
	Network string
}

DNS is a small resolver that answers the names a relay serves with its own address and relays everything else upstream. The GKE node agent (cluster DNS upstream) and the host-mode container use it so that *.googleapis.com names the emulator serves resolve to their 443 relay.

func (*DNS) ServeDNS

func (d *DNS) ServeDNS(w mdns.ResponseWriter, req *mdns.Msg)

ServeDNS implements mdns.Handler.

type Frontend

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

Frontend is the TLS-terminating front end.

func New

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

New returns a frontend serving the names hosts returns (the gateway's mounted hosts) plus LOCATION-docker.pkg.dev.

func (*Frontend) Addr

func (f *Frontend) Addr() string

Addr returns the listener address ("" before Start).

func (*Frontend) Close

func (f *Frontend) Close() error

Close stops the listener and open connections.

func (*Frontend) Hosts

func (f *Frontend) Hosts() []string

Hosts returns the exact hostnames served (registry hosts match by pattern; see IsRegistryHost).

func (*Frontend) Serves

func (f *Frontend) Serves(name string) bool

Serves reports whether the frontend serves name.

func (*Frontend) Start

func (f *Frontend) Start() error

Start opens the listener on the configured bind address and records the "frontend" endpoint. A dynamic port comes from --port-range, except in a Containerized Instance, whose published range ports forwarding rules and LoadBalancer Services need (ADR 0012).

func (*Frontend) TLSConfig

func (f *Frontend) TLSConfig() *tls.Config

TLSConfig returns the server TLS configuration (exported for tests and for in-process listeners that want the same certificates).

Jump to

Keyboard shortcuts

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