Documentation
¶
Overview ¶
Package traefik generates Traefik's dynamic configuration (§5.7). Traefik polls it through its HTTP provider; users never write Traefik config.
Index ¶
- Constants
- Variables
- func Entrypoints(addrs map[string]string) []string
- func IsProbe(name string) bool
- func MergeCustom(out, custom map[string]any)
- func MiddlewareName(id string) string
- func PresetOrder(typ string) int
- func PublicPreset(typ string, raw json.RawMessage) json.RawMessage
- func ValidateCustom(text string, gen map[string]any) (map[string]any, error)
- func ValidatePreset(typ string, raw, prev json.RawMessage) (json.RawMessage, error)
- func WithStatic(base []string, s Settings) []string
- type BasicAuth
- type Buffering
- type Certificate
- type CircuitBreaker
- type Compress
- type Dynamic
- type Extras
- type HTTPConfig
- type Headers
- type IPAllowList
- type IPStrategy
- type InFlightReq
- type LoadBalancer
- type Middleware
- type PassiveHealth
- type Protection
- type Provider
- func (p *Provider) Config() Dynamic
- func (p *Provider) ConfigFor(sc Scope) Dynamic
- func (p *Provider) EdgeConfig(node string) map[string]any
- func (p *Provider) Generated() map[string]any
- func (p *Provider) Merged() map[string]any
- func (p *Provider) Redacted() map[string]any
- func (p *Provider) ServeHTTP(w http.ResponseWriter, r *http.Request)
- type ProxyProtocol
- type RateLimit
- type RateLimitRedis
- type RedirectRegex
- type RedirectScheme
- type Retry
- type Router
- type RouterTLS
- type Scope
- type Server
- type Service
- type ServiceRoute
- type Settings
- type SourceCriterion
- type StripPrefix
- type TCPConfig
- type TCPIPAllowList
- type TCPLoadBalancer
- type TCPMiddleware
- type TCPRoute
- type TCPRouter
- type TCPServer
- type TCPServersTransport
- type TCPService
- type TLSConfig
- type TLSOptions
- type TLSStore
- type UDPConfig
- type UDPLoadBalancer
- type UDPRoute
- type UDPRouter
- type UDPService
Constants ¶
const ( ProbeHeader = "X-Syncloud-Probe" ProbeSuffix = "_probe" )
The uptime monitor marks its probes with ProbeHeader. They reach the app through a router and Traefik service named after the route plus ProbeSuffix, whose metrics and access lines are left out of traffic (port names and domain IDs never contain "_", so no route can collide).
const AgentRouteName = "syncloud-agent"
AgentRouteName is the TCP route that passes agent.<domain>:443 to the agent gateway.
const DefaultDialTimeout = "5s"
DefaultDialTimeout bounds connecting to a task (over the private network).
const DefaultReadTimeout = "180s"
DefaultReadTimeout bounds reading a whole request on the public entrypoints (Traefik's own is 60s).
const DefaultUnhealthyAfter = 10
DefaultUnhealthyAfter is the failed requests in a row after which Traefik takes a task out of rotation.
const (
// DevRegistryHost is the registry's hostname before a base domain exists.
DevRegistryHost = "registry.localhost"
)
const FailureWindow = "10s"
FailureWindow is how long Traefik keeps a task it gave up on out of rotation (and the span its failures must fall in).
const MiddlewareDeny = "syncloud-deny"
MiddlewareDeny answers 403 to everyone: blocked clients' routers use it (Traefik 3.7 has no ipDenyList).
const RegistryReadTimeout = "30m"
RegistryReadTimeout is the registry entrypoint's: a push sends each image layer in one request, and a large layer over a slow link takes minutes (cut off, the push fails with 499).
const RegistryRouteName = "syncloud-registry-tls"
RegistryRouteName is the TCP route that passes registry.<domain>:443 to the registry entrypoint.
const SettingCustom = "traefik.custom"
SettingCustom holds the custom configuration as YAML.
const SettingGlobal = "traefik.settings"
SettingGlobal holds the global Traefik settings as JSON.
Variables ¶
var ControllerScope = Scope{Platform: true}
ControllerScope is the controller's own Traefik.
var MiddlewareKinds = []string{
"addPrefix", "basicAuth", "buffering", "chain", "circuitBreaker", "compress", "contentType", "digestAuth", "errors",
"forwardAuth", "grpcWeb", "headers", "ipAllowList", "inFlightReq", "passTLSClientCert", "rateLimit", "redirectRegex",
"redirectScheme", "replacePath", "replacePathRegex", "retry", "stripPrefix", "stripPrefixRegex",
}
MiddlewareKinds are Traefik's HTTP middleware types.
var PresetTypes = []string{
"ip-allowlist", "rate-limit", "basic-auth", "redirect-www", "cors", "security-headers", "circuit-breaker", "compress", "retry",
}
Middleware presets (§5.7): the toggles users attach to services, rendered into Traefik middlewares. A route applies them in a fixed order, so access checks run before anything else.
var ( // SecretSafe is what a bypass secret may contain (it sits in a rule). SecretSafe = regexp.MustCompile(`^[A-Za-z0-9._~-]{16,128}$`) )
Functions ¶
func Entrypoints ¶
Entrypoints are the flags of extra TCP entrypoints (name -> address), sorted by name: the public database endpoints (Phase 12e).
func IsProbe ¶ added in v0.1.4
IsProbe reports whether a Traefik router or service name ("svc-…_probe@http") is an uptime probe twin.
func MergeCustom ¶
MergeCustom adds custom routers, services, middlewares and transports (validated not to collide with generated names) to a configuration.
func MiddlewareName ¶
MiddlewareName is a preset's Traefik name.
func PresetOrder ¶
PresetOrder sorts attached presets the way a route applies them.
func PublicPreset ¶
func PublicPreset(typ string, raw json.RawMessage) json.RawMessage
PublicPreset strips secrets (password hashes) from a stored config.
func ValidateCustom ¶
ValidateCustom parses and checks custom YAML against the generated configuration gen (as served, without custom parts). It returns the configuration to merge.
func ValidatePreset ¶
func ValidatePreset(typ string, raw, prev json.RawMessage) (json.RawMessage, error)
ValidatePreset checks and normalizes a preset's config. For basic-auth, new passwords are hashed, and a user given without a password keeps the hash from prev (the stored config being replaced).
func WithStatic ¶
WithStatic replaces the "--log.level" flag of base flags and appends the other static flags.
Types ¶
type Buffering ¶
type Buffering struct {
MaxRequestBodyBytes int64 `json:"maxRequestBodyBytes"`
}
Buffering limits request bodies.
type Certificate ¶
Certificate holds PEM content inline (Traefik accepts content or a path).
type CircuitBreaker ¶
type CircuitBreaker struct {
Expression string `json:"expression"`
}
type Dynamic ¶
type Dynamic struct {
HTTP HTTPConfig `json:"http"`
TCP *TCPConfig `json:"tcp,omitempty"`
UDP *UDPConfig `json:"udp,omitempty"`
TLS *TLSConfig `json:"tls,omitempty"`
}
Dynamic is the subset of Traefik's dynamic configuration we generate.
type Extras ¶
type Extras struct {
// contains filtered or unexported fields
}
Extras caches what the database adds to the generated configuration: middleware presets with their attachments, and the custom configuration.
func (*Extras) Chain ¶
Chain returns a service's middlewares and whether one replaces the default retry.
func (*Extras) CustomText ¶
CustomText returns the stored YAML.
func (*Extras) Definitions ¶
func (e *Extras) Definitions() map[string]Middleware
Definitions returns the preset middlewares.
type HTTPConfig ¶
type Headers ¶
type Headers struct {
STSSeconds int `json:"stsSeconds,omitempty"`
STSIncludeSubdomains bool `json:"stsIncludeSubdomains,omitempty"`
FrameDeny bool `json:"frameDeny,omitempty"`
ContentTypeNosniff bool `json:"contentTypeNosniff,omitempty"`
BrowserXSSFilter bool `json:"browserXssFilter,omitempty"`
ReferrerPolicy string `json:"referrerPolicy,omitempty"`
AccessControlAllowOriginList []string `json:"accessControlAllowOriginList,omitempty"`
AccessControlAllowMethods []string `json:"accessControlAllowMethods,omitempty"`
AccessControlAllowHeaders []string `json:"accessControlAllowHeaders,omitempty"`
AccessControlAllowCredentials bool `json:"accessControlAllowCredentials,omitempty"`
AccessControlMaxAge int `json:"accessControlMaxAge,omitempty"`
AddVaryHeader bool `json:"addVaryHeader,omitempty"`
}
type IPAllowList ¶
type IPAllowList struct {
SourceRange []string `json:"sourceRange"`
}
type IPStrategy ¶ added in v0.3.0
type IPStrategy struct {
Depth int `json:"depth"`
}
type InFlightReq ¶ added in v0.3.0
type InFlightReq struct {
Amount int `json:"amount"`
SourceCriterion *SourceCriterion `json:"sourceCriterion,omitempty"`
}
InFlightReq caps a client's concurrent requests.
type LoadBalancer ¶
type LoadBalancer struct {
Servers []Server `json:"servers"`
PassHostHeader bool `json:"passHostHeader"`
PassiveHealth *PassiveHealth `json:"passiveHealthCheck,omitempty"`
}
type Middleware ¶
type Middleware struct {
StripPrefix *StripPrefix `json:"stripPrefix,omitempty"`
RedirectScheme *RedirectScheme `json:"redirectScheme,omitempty"`
RedirectRegex *RedirectRegex `json:"redirectRegex,omitempty"`
Retry *Retry `json:"retry,omitempty"`
RateLimit *RateLimit `json:"rateLimit,omitempty"`
BasicAuth *BasicAuth `json:"basicAuth,omitempty"`
IPAllowList *IPAllowList `json:"ipAllowList,omitempty"`
Headers *Headers `json:"headers,omitempty"`
Compress *Compress `json:"compress,omitempty"`
CircuitBreaker *CircuitBreaker `json:"circuitBreaker,omitempty"`
Buffering *Buffering `json:"buffering,omitempty"`
InFlightReq *InFlightReq `json:"inFlightReq,omitempty"`
}
func RenderPreset ¶
func RenderPreset(typ string, raw json.RawMessage) (Middleware, error)
RenderPreset builds the Traefik middleware for a stored preset.
type PassiveHealth ¶ added in v0.3.6
type PassiveHealth struct {
FailureWindow string `json:"failureWindow"`
MaxFailedAttempts int `json:"maxFailedAttempts"`
}
PassiveHealth is Traefik's judgement of each server by the requests it sends it: MaxFailedAttempts failures in a row within FailureWindow take the server out of rotation for that long.
type Protection ¶ added in v0.3.0
type Protection struct {
// Limits are skipped by requests that bypass them (rate limit,
// concurrent requests); Always run for every request (body limit).
Limits, Always []string
// Deny are client CIDRs answered with 403.
Deny []string
// Requests from BypassIPs, with header BypassHeader set to
// BypassSecret, or under BypassPaths skip the limits.
BypassIPs []string
BypassHeader, BypassSecret string
BypassPaths []string
}
Protection is a project's traffic protection on its routes (Phase 25).
type Provider ¶
type Provider struct {
// Token must be presented in TokenHeader (the config carries TLS keys).
Token string
TokenHeader string
// ControllerURL is where Traefik reaches the controller.
ControllerURL string
// RegistryURL is where Traefik reaches the registry ("" disables its route).
RegistryURL string
// RegistryEntrypoint is the address of Traefik's own registry entrypoint
// ("" serves the registry on websecure): TLS connections to the registry
// host on 443 are passed there, for its longer read timeout.
RegistryEntrypoint string
// BaseDomain returns the current base domain ("" until one is set, §5.0.2).
BaseDomain func() string
// HTTPSPort is the public HTTPS port when it is not 443 (development).
HTTPSPort string
// Certificates returns the TLS certificates to serve.
Certificates func() []Certificate
// DefaultCertificate is served when no other certificate matches the
// SNI, or there is none (nil: Traefik's self-signed one).
DefaultCertificate func() *Certificate
// ServiceRoutes returns the routes of user services.
ServiceRoutes func() []ServiceRoute
// Middlewares returns the preset middlewares routes refer to.
Middlewares func() map[string]Middleware
// Custom returns the validated raw configuration merged into the
// generated one ("Advanced", §5.7).
Custom func() map[string]any
// MeshControllerURL is the controller as edge nodes reach it over the
// private network (§8.5).
MeshControllerURL func() string
// Settings returns the global settings (nil: the defaults).
Settings func() Settings
// TCPRoutes returns the public database endpoints (only served with a
// base domain: they need certificates) and public TCP ports of services.
TCPRoutes func() []TCPRoute
// UDPRoutes returns public UDP ports of services.
UDPRoutes func() []UDPRoute
// GitHost returns the built-in Git server's hostname ("" when it is
// off, §5.8); GitServerURL is where Traefik reaches it.
GitHost func() string
GitServerURL string
// ProbeToken, when set, gives every service route a twin for the
// uptime monitor's probes (requests carrying ProbeHeader with this
// value), so its checks never count as the service's traffic.
ProbeToken string
// EdgePool reports nodes of edge pools (they serve the platform's
// routes, as the controller does).
EdgePool func(node string) bool
}
Provider serves the dynamic config to Traefik.
func (*Provider) ConfigFor ¶ added in v0.3.0
ConfigFor builds the dynamic configuration of one Traefik replica.
func (*Provider) EdgeConfig ¶
EdgeConfig is the configuration for a node's Traefik (§8.5): on an edge pool node the controller's routes and certificates, on a project's own load balancer only that project's routes (D22), with the controller reached over the private network; the registry stays on the controller's own Traefik.
type ProxyProtocol ¶ added in v0.2.2
type ProxyProtocol struct {
Version int `json:"version"`
}
ProxyProtocol makes Traefik send the client's address first (PROXY protocol).
type RateLimit ¶
type RateLimit struct {
Average int `json:"average"`
Burst int `json:"burst"`
Period string `json:"period,omitempty"`
SourceCriterion *SourceCriterion `json:"sourceCriterion,omitempty"`
// Redis shares the counters between Traefik replicas (Phase 25).
Redis *RateLimitRedis `json:"redis,omitempty"`
}
type RateLimitRedis ¶ added in v0.3.0
type RateLimitRedis struct {
Endpoints []string `json:"endpoints"`
Password string `json:"password,omitempty"`
DB int `json:"db"`
}
RateLimitRedis is where a rate limit keeps its counters.
type RedirectRegex ¶
type RedirectScheme ¶
type Scope ¶ added in v0.3.0
Scope is the Traefik replica a configuration is for: Platform replicas (the controller and edge pools) serve the dashboard and every project on the default ingress; any node serves the projects that chose it (D22).
type Service ¶
type Service struct {
LoadBalancer LoadBalancer `json:"loadBalancer"`
}
type ServiceRoute ¶
type ServiceRoute struct {
Name string
Host string
Servers []string
// Middlewares are attached presets, in the order to apply them. With
// OwnRetry set, one of them replaces the default retry.
Middlewares []string
OwnRetry bool
// Path limits the route to a prefix ("" = the whole host); StripPrefix
// removes it before forwarding. RedirectTo answers with a permanent
// redirect to that host instead of forwarding (Phase 15c).
Path string
StripPrefix bool
RedirectTo string
// Ingress is who serves the route (nil: the controller and edge pools).
Ingress *ingress.Target
// Protect is its project's protection (nil: none, Phase 25).
Protect *Protection
}
ServiceRoute is one public route to a service's tasks (§5.7).
type Settings ¶
type Settings struct {
// Static: entrypoints and proxy behaviour.
LogLevel string `json:"logLevel"` // DEBUG | INFO | WARN | ERROR
// Responding timeouts of the public entrypoints ("" = the default:
// DefaultReadTimeout, then Traefik's; "0s" disables the limit). The
// registry has its own entrypoint and RegistryReadTimeout.
ReadTimeout string `json:"readTimeout"`
WriteTimeout string `json:"writeTimeout"`
IdleTimeout string `json:"idleTimeout"`
// TrustedIPs are proxies (a CDN or a load balancer) whose
// X-Forwarded-* headers are kept; from anyone else they are replaced.
TrustedIPs []string `json:"trustedIPs"`
// ProxyProtocol accepts the PROXY protocol from TrustedIPs, for load
// balancers that pass the client address that way.
ProxyProtocol bool `json:"proxyProtocol"`
// HTTP3 serves HTTP/3 (QUIC) on the HTTPS port as well.
HTTP3 bool `json:"http3"`
// Upstream connections to tasks.
DialTimeout string `json:"dialTimeout"`
ResponseHeaderTimeout string `json:"responseHeaderTimeout"`
MaxIdleConnsPerHost int `json:"maxIdleConnsPerHost"`
// Dynamic: defaults for every service route.
RedirectHTTPS bool `json:"redirectHttps"` // HTTP requests to service domains redirect to HTTPS
MinTLS string `json:"minTls"` // "1.2" | "1.3"
SNIStrict bool `json:"sniStrict"` // refuse TLS clients without a known server name
RetryAttempts int `json:"retryAttempts"` // 0 disables the default retry
// UnhealthyAfter is how many requests to a task must fail in a row
// before Traefik stops sending it any (for FailureWindow).
UnhealthyAfter int `json:"unhealthyAfter"`
HSTSSeconds int `json:"hstsSeconds"` // 0 sends no Strict-Transport-Security
Compress bool `json:"compress"` // gzip/brotli/zstd responses
MaxBodyMB int `json:"maxBodyMb"` // request body limit, 0 = unlimited
}
Settings are the cluster-wide Traefik options (§5.7) for every replica, on the controller and on edge nodes. The static ones become command-line flags, so changing them restarts Traefik; the dynamic ones are part of the served configuration and apply within seconds.
func DefaultSettings ¶
func DefaultSettings() Settings
DefaultSettings are what a fresh install uses.
func ParseSettings ¶
ParseSettings reads stored settings; missing fields keep their defaults.
func (Settings) StaticArgs ¶
StaticArgs are the command-line flags for every Traefik replica, added after the built-in ones.
type SourceCriterion ¶
type SourceCriterion struct {
IPStrategy *IPStrategy `json:"ipStrategy,omitempty"`
RequestHeaderName string `json:"requestHeaderName,omitempty"`
}
SourceCriterion says how a client is told apart: by its address (the connection's, or X-Forwarded-For at a depth) or by a request header.
type StripPrefix ¶
type StripPrefix struct {
Prefixes []string `json:"prefixes"`
}
type TCPConfig ¶
type TCPConfig struct {
Routers map[string]TCPRouter `json:"routers"`
Services map[string]TCPService `json:"services"`
Middlewares map[string]TCPMiddleware `json:"middlewares,omitempty"`
ServersTransports map[string]TCPServersTransport `json:"serversTransports,omitempty"`
}
TCPConfig carries the public database endpoints (Phase 12e): TLS is terminated by Traefik and routed by SNI.
type TCPIPAllowList ¶
type TCPIPAllowList struct {
SourceRange []string `json:"sourceRange"`
}
type TCPLoadBalancer ¶
type TCPMiddleware ¶
type TCPMiddleware struct {
IPAllowList *TCPIPAllowList `json:"ipAllowList,omitempty"`
}
type TCPRoute ¶
type TCPRoute struct {
// Host picks the route by SNI; empty takes any TLS connection on the
// entrypoint (a dedicated port).
Name, Entrypoint, Host string
Servers []string // host:port
Allow []string // client CIDRs (empty: anyone)
Plain bool // no TLS: any plain connection on the entrypoint
// Passthrough forwards the TLS connection undecrypted (the server
// terminates it); ProxyProtocol sends the client's address first, in
// ProxyVersion of the PROXY protocol (0: version 1).
Passthrough, ProxyProtocol bool
ProxyVersion int
// Ingress is who serves the route (nil: the controller and edge pools).
Ingress *ingress.Target
}
TCPRoute is one public TLS endpoint (a database's), or with Plain a public TCP port of a service passed through as is (Phase 15c).
type TCPServersTransport ¶ added in v0.2.2
type TCPServersTransport struct {
ProxyProtocol *ProxyProtocol `json:"proxyProtocol,omitempty"`
}
TCPServersTransport sets how Traefik connects to a TCP service's servers.
type TCPService ¶
type TCPService struct {
LoadBalancer TCPLoadBalancer `json:"loadBalancer"`
}
type TLSConfig ¶
type TLSConfig struct {
Certificates []Certificate `json:"certificates,omitempty"`
Options map[string]TLSOptions `json:"options,omitempty"`
Stores map[string]TLSStore `json:"stores,omitempty"`
}
type TLSOptions ¶
type TLSOptions struct {
MinVersion string `json:"minVersion"`
SNIStrict bool `json:"sniStrict,omitempty"`
ALPNProtocols []string `json:"alpnProtocols,omitempty"`
}
TLSOptions is Traefik's tls.options entry.
type TLSStore ¶ added in v0.1.2
type TLSStore struct {
DefaultCertificate *Certificate `json:"defaultCertificate,omitempty"`
}
TLSStore sets the certificate for connections no other one matches, such as clients that send no SNI.
type UDPConfig ¶
type UDPConfig struct {
Routers map[string]UDPRouter `json:"routers"`
Services map[string]UDPService `json:"services"`
}
UDPConfig carries public UDP ports of services (Phase 15c).
type UDPLoadBalancer ¶
type UDPLoadBalancer struct {
Servers []TCPServer `json:"servers"` // {address}
}
type UDPRoute ¶
type UDPRoute struct {
Name, Entrypoint string
Servers []string // host:port
Ingress *ingress.Target
}
UDPRoute is a public UDP port of a service.
type UDPService ¶
type UDPService struct {
LoadBalancer UDPLoadBalancer `json:"loadBalancer"`
}