ingress

package
v0.41.0 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: MIT Imports: 23 Imported by: 0

Documentation

Overview

Package ingress is fuse-proxy: stable public tcp ports in front of guests that dial in over internal/tunnel.

a route is a public port that belongs to an owner (a vm id) and leads to one port inside that owner's guest. the port is the stable thing. which owner it belongs to can change, and that is the whole of what a migrate does here: the new vm adopts the old vm's ports, and the url every client holds keeps working without any of them learning that anything moved.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AdminHandler

func AdminHandler(p *Proxy, cfg AdminConfig) http.Handler

AdminHandler serves the admin api.

Types

type AdminConfig

type AdminConfig struct {
	Token string
	// PublicHost is the name or address clients and guests reach this machine
	// by. TunnelPort is the udp port guests dial.
	PublicHost    string
	TunnelPort    int
	ServerCertPEM string
	// Metrics serves GET /metrics. like /healthz it needs no token, matching
	// the orchestrator's /metrics, so a scraper never holds the admin token.
	Metrics http.Handler
}

AdminConfig is what the admin api needs beyond the proxy itself.

type Client

type Client struct {
	BaseURL string
	Token   string
	HTTP    *http.Client
}

Client is the orchestrator's end of the admin api.

func NewClient

func NewClient(baseURL, token string) *Client

NewClient returns a client with a timeout suited to small control calls.

func (*Client) Lookup

func (c *Client) Lookup(ctx context.Context, owner string) (orchestrator.IngressGrant, error)

Lookup implements orchestrator.IngressProxy.

func (*Client) Publish

Publish implements orchestrator.IngressProxy.

func (*Client) Unpublish

func (c *Client) Unpublish(ctx context.Context, owner string) error

Unpublish implements orchestrator.IngressProxy.

type Config

type Config struct {
	// StatePath is where owners and routes are persisted. routes have to
	// outlive the process: a proxy that came back with different ports would
	// have broken every url it exists to keep stable.
	StatePath string
	// PortMin and PortMax bound the public ports handed out, inclusive.
	PortMin, PortMax int
	// BindHost is the address public listeners bind, "" for all.
	BindHost string
	// HoldTimeout is how long a client connection waits for its guest to be
	// reachable before it is closed.
	HoldTimeout time.Duration
	Logger      *slog.Logger
	// Metrics is optional; nil records nothing.
	Metrics *Metrics
}

Config tunes a Proxy.

type Metrics added in v0.36.0

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

Metrics is fuse-proxy's prometheus metrics. a nil *Metrics records nothing, so a Proxy built without one (the tests) needs no special casing.

series labeled by owner are deleted when the owner is removed, so the label set is bounded by the live fleet rather than by every vm ever published.

func NewMetrics added in v0.36.0

func NewMetrics(reg prometheus.Registerer) *Metrics

NewMetrics creates and registers fuse-proxy's metrics on reg.

func (*Metrics) GuestConnected added in v0.36.0

func (m *Metrics) GuestConnected(owner string, replaced bool)

GuestConnected implements tunnel.Metrics.

func (*Metrics) GuestsConnected added in v0.36.0

func (m *Metrics) GuestsConnected(n int)

GuestsConnected implements tunnel.Metrics.

func (*Metrics) Handshake added in v0.36.0

func (m *Metrics) Handshake(result string)

Handshake implements tunnel.Metrics.

func (*Metrics) PathMigrated added in v0.36.0

func (m *Metrics) PathMigrated(owner string)

PathMigrated implements tunnel.Metrics.

func (*Metrics) Probe added in v0.36.0

func (m *Metrics) Probe(alive bool)

Probe implements tunnel.Metrics.

type Opener

type Opener interface {
	Open(ctx context.Context, owner string, port int) (net.Conn, error)
	Drop(owner string)
	Retire(owner string)
}

Opener is the part of tunnel.Server the proxy uses.

type PortSpec

type PortSpec struct {
	Name      string `json:"name"`
	GuestPort int    `json:"guest_port"`
}

PortSpec is one port of a Publish.

type Proxy

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

Proxy owns the routes and their listeners.

func New

func New(cfg Config) (*Proxy, error)

New loads the state file and reopens every route's listener.

func (*Proxy) Authenticate

func (p *Proxy) Authenticate(owner, token string) bool

Authenticate is the tunnel server's authenticator.

func (*Proxy) Close

func (p *Proxy) Close()

Close stops every listener.

func (*Proxy) Publish

func (p *Proxy) Publish(owner, token string, ports []PortSpec, adoptFrom string) ([]Route, error)

Publish creates or updates owner so that it has exactly ports, and returns its routes.

a route that already exists under the same name keeps its public port, so publishing again is how a token is rotated without the url moving. with adoptFrom, each name takes the public port of the same name under adoptFrom, and adoptFrom loses it. connections already running to the old guest are left alone: they are streams on the old guest's tunnel and end when it does.

func (*Proxy) Remove

func (p *Proxy) Remove(owner string) (bool, error)

Remove deletes owner, closes its ports and disconnects its guest.

func (*Proxy) Routes

func (p *Proxy) Routes(owner string) ([]Route, bool)

Routes returns owner's routes.

func (*Proxy) Start

func (p *Proxy) Start(t Opener)

Start attaches the tunnel and opens the listeners for every known route. it is separate from New because the tunnel server's authenticator is this proxy's Authenticate, so each needs the other to exist first.

type Route

type Route struct {
	Name       string `json:"name"`
	GuestPort  int    `json:"guest_port"`
	PublicPort int    `json:"public_port"`
}

Route is one published port.

Jump to

Keyboard shortcuts

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