proxy

package
v1.0.0-beta.3 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2026 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

Package proxy abstracts the reverse proxy / gateway (Goma Gateway). Routes and middlewares are written as individual YAML files in Goma's watched file- provider directory; an in-memory implementation backs dev and tests. TLS termination, ACME issuance, and renewal are owned by Goma — Miabi only declares routes/middlewares and (for custom certs) supplies the PEM.

Index

Constants

View Source
const ConfigEncryptionKeyEnv = "GOMA_CONFIG_ENCRYPTION_KEY"

ConfigEncryptionKeyEnv is the passphrase shared with Goma Gateway. When set, Miabi encrypts sensitive rendered config (middleware rules and inline TLS certificate/key material) so it is never written to the provider directory as plaintext. It MUST match Goma's GOMA_CONFIG_ENCRYPTION_KEY, which the gateway uses to decrypt the same fields at load/reload. Empty disables encryption.

Variables

This section is empty.

Functions

func RenderBundle

func RenderBundle(routes []RenderedRoute, mws []RenderedMiddleware) ([]byte, error)

RenderBundle produces a combined routes+middlewares Goma config document (the shape Goma's HTTP provider consumes). Used to serve a remote node's Goma over the control plane's HTTP provider endpoint.

func RenderMiddleware

func RenderMiddleware(mw RenderedMiddleware) ([]byte, error)

RenderMiddleware produces the YAML file content for a middleware.

func RenderRoute

func RenderRoute(route RenderedRoute) ([]byte, error)

RenderRoute produces the YAML file content for a route (exported for tests).

Types

type Backend

type Backend struct {
	Endpoint string // e.g. http://mb-app-1:8080
	Weight   int    // relative weight; probability = weight / sum(weights)
}

Backend is a single upstream for a route. Weight enables canary / weighted load-balancing across backends; 0 means unweighted (single backend).

type CertPair

type CertPair struct {
	CertPEM string
	KeyPEM  string
}

CertPair is a user-supplied (custom) certificate, inlined as PEM.

type Goma

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

Goma drives Goma Gateway via its file provider: each route and middleware is written as a YAML file in Goma's watched provider directory, which Goma hot-reloads and merges. ACME is handled by Goma's global certManager; custom certs are inlined into the route's tls block.

func NewGoma

func NewGoma(dir string) *Goma

NewGoma returns a Goma file-provider Manager writing into dir.

func (*Goma) SyncRegistry

func (g *Goma) SyncRegistry(_ context.Context, cfg RegistryProxy) error

SyncRegistry writes the built-in registry's gateway config (route + HTTPS redirect, forwardAuth, and namespace-rewrite middlewares) to its own file, or removes the file when disabled / incompletely configured. Idempotent.

func (*Goma) SyncWorkspace

func (g *Goma) SyncWorkspace(_ context.Context, workspaceID uint, routes []RenderedRoute, mws []RenderedMiddleware) error

SyncWorkspace writes (or removes) a workspace's single Goma config file holding all its routes and middlewares. The file is replaced atomically, so Goma always reads a route and the middlewares it references together.

type Manager

type Manager interface {
	// SyncWorkspace replaces a workspace's entire proxy config — all its routes and
	// middlewares — atomically. Passing no routes and no middlewares removes the
	// workspace's config entirely.
	SyncWorkspace(ctx context.Context, workspaceID uint, routes []RenderedRoute, mws []RenderedMiddleware) error
	// SyncRegistry writes (or, when disabled, removes) the built-in registry's
	// gateway route + middlewares.
	SyncRegistry(ctx context.Context, cfg RegistryProxy) error
}

Manager applies desired proxy state. A workspace's routes and middlewares are written together as one unit (Goma resolves a route's middleware references within the same file), so the whole workspace is the unit of sync rather than individual resources. Implementations must be idempotent.

type Memory

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

Memory is an in-process Manager used when no real gateway is configured (dev/tests). It records the desired routes and middlewares per workspace.

func NewMemory

func NewMemory() *Memory

func (*Memory) GetRoute

func (m *Memory) GetRoute(id uint) (RenderedRoute, bool)

GetRoute returns the recorded route (used in tests).

func (*Memory) SyncRegistry

func (m *Memory) SyncRegistry(_ context.Context, cfg RegistryProxy) error

SyncRegistry records the registry proxy config (no-op store for the in-memory manager; the Goma manager writes the actual gateway file).

func (*Memory) SyncWorkspace

func (m *Memory) SyncWorkspace(_ context.Context, workspaceID uint, routes []RenderedRoute, mws []RenderedMiddleware) error

SyncWorkspace replaces the recorded state for a workspace: it drops the workspace's previous routes/middlewares and stores the supplied set.

type RegistryProxy

type RegistryProxy struct {
	Enabled     bool   // false removes the registry config
	Host        string // public host, e.g. registry.<domain>
	Upstream    string // http://mb-registry:5000
	AuthURL     string // forwardAuth target, e.g. http://miabi:9000/internal/registry/auth
	TLSProvider string // certManager provider ("" = gateway default)
}

RegistryProxy is the desired gateway config for the built-in Docker registry: a single route (host → upstream) fronted by the HTTPS-redirect, forwardAuth, and namespace-rewrite middlewares. Rendered to a dedicated file, separate from the per-workspace configs.

type RenderedMiddleware

type RenderedMiddleware struct {
	ID          uint
	WorkspaceID uint // namespaces the Goma name (mb-ws<id>-<name>); routes reference it the same way
	Name        string
	Type        string
	Paths       []string
	Rule        map[string]interface{}
}

RenderedMiddleware is the desired Goma middleware definition.

type RenderedRoute

type RenderedRoute struct {
	ID          uint
	WorkspaceID uint // namespaces the Goma name (mb-ws<id>-<name>) to avoid cross-workspace collisions
	Name        string
	Path        string
	Hosts       []string
	Methods     []string
	Rewrite     string    // path rewrite
	Middlewares []string  // referenced middleware names
	Backends    []Backend // one or more weighted upstreams
	Certs       []CertPair
	// TLSProvider names the Goma certManager provider that serves this route's
	// cert (multi-provider certManager). Empty = the gateway's default provider.
	TLSProvider string
	// TLSNone marks a route that opts out of TLS entirely; it renders an explicit
	// tls.provider: "none" so the gateway never tries to obtain a cert for it.
	TLSNone bool
	// Disabled renders the route with Goma's `enabled: false` so the gateway keeps
	// it defined but stops serving it. Zero value (false) = enabled, matching
	// Goma's default. Preferred over dropping the route, which doesn't reliably
	// take effect across the file/HTTP providers.
	Disabled bool
	// AdvancedYAML, when set, is a raw Goma route config that supersedes the
	// structured fields; Miabi still forces name/backends/tls into it.
	AdvancedYAML string
}

RenderedRoute is the desired Goma route. Backends (the upstreams) are injected by the caller from the application's network alias(es). A single backend means all traffic goes there; multiple weighted backends enable canary splits.

Jump to

Keyboard shortcuts

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