route

package
v0.23.0 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EnvUserTokenHeader           = "USER_TOKEN_HEADER"
	EnvUserTokenEncodedKey       = "USER_TOKEN_ENCODED_KEY"
	EnvInternalAPIKeyHeader      = "INTERNAL_API_KEY_HEADER"
	EnvInternalAPIKey            = "INTERNAL_API_KEY"
	EnvClientAPIKeyHeader        = "CLIENT_API_KEY_HEADER"
	EnvClientAPIKey              = "CLIENT_API_KEY"
	EnvTraefikRoutesFile         = "TRAEFIK_ROUTES_FILE"
	EnvTraefikRouterPrefix       = "TRAEFIK_ROUTER_PREFIX"
	EnvTraefikService            = "TRAEFIK_SERVICE"
	EnvTraefikHost               = "TRAEFIK_HOST"
	EnvTraefikEntryPoints        = "TRAEFIK_ENTRYPOINTS"
	EnvTraefikCertResolver       = "TRAEFIK_CERT_RESOLVER"
	EnvTraefikMiddlewaresDefault = "TRAEFIK_MIDDLEWARES_DEFAULT"

	EnvTraefikMiddlewaresEnriched  = "TRAEFIK_MIDDLEWARES_ENRICHED"
	EnvTraefikMiddlewaresProtected = "TRAEFIK_MIDDLEWARES_PROTECTED"
	EnvTraefikMiddlewaresAdmin     = "TRAEFIK_MIDDLEWARES_ADMIN"
)
View Source
const (
	PolicyEnriched    = "enriched"
	PolicyProtected   = "protected"
	PolicyAdmin       = "admin"
	PolicyInternalKey = "internal-key"
)
View Source
const (
	TraefikAuthVerify     = "auth-verify"
	TraefikAuthEnrich     = "auth-enrich"
	TraefikRateLimitAdmin = "rate-limit-admin"
)

Traefik middlewares the shared policies apply at the proxy by default, as defined in the USH Traefik configuration.

Variables

View Source
var (
	ErrInvalidTraefikName    = fmt.Errorf("traefik name is empty or contains whitespace")
	ErrMissingTraefikService = fmt.Errorf("traefik routes file set without a traefik service")
	ErrMissingConfig         = fmt.Errorf("config missing")
	ErrInternalKeyTooShort   = fmt.Errorf("internal API key shorter than 32 characters")
	ErrSharedPolicyMapping   = fmt.Errorf("traefik middlewares of a shared policy cannot be mapped")
	ErrNotSharedPolicy       = fmt.Errorf("traefik middlewares replaced for a policy that is not a shared user policy")
)

Functions

func InternalKeyPolicy

func InternalKeyPolicy(cfg HeaderKey) modules.Option

InternalKeyPolicy registers the internal-key policy on the http module. Configure fails without a header or with an internal API key shorter than 32 characters.

func TraefikExporter

func TraefikExporter(cfg TraefikConfig) modules.Option

TraefikExporter adds a route exporter to the http module that writes the defined routes as Traefik configuration. The shared policies get their default Traefik middlewares, or those in SharedPolicyMiddlewares, when the service has registered them. Configure fails on an empty entry point or middleware name, or one containing whitespace, and on replaced middlewares that are empty or for a policy other than enriched, protected or admin.

func UserPolicies

func UserPolicies(cfg HeaderKey) modules.Option

UserPolicies registers the enriched, protected and admin policies on the http module. Configure fails without a header or a valid base64-encoded user token key.

Types

type Config

type Config struct {
	// UserToken.Key is the base64-encoded HS256 user token key.
	UserToken   HeaderKey
	InternalKey HeaderKey

	// ClientKey is for middleware.ClientKeyAuth. An empty Key disables the
	// check.
	ClientKey HeaderKey

	Traefik TraefikConfig
}

func ConfigFromEnv

func ConfigFromEnv() Config

ConfigFromEnv reads Config from the Env* variables, for a service to call from its settings. No variable is required here; the policy a key is for fails when it is loaded without one. Unset headers get the middleware.Default*Header values and an unset router prefix the Traefik service. SharedPolicyMiddlewares holds only the policies whose variable is set. PolicyMiddlewares is left for the service to set in code.

type HeaderKey

type HeaderKey struct {
	Header string
	Key    string
}

HeaderKey is a key and the request header it is sent in.

type TraefikConfig

type TraefikConfig struct {
	// RoutesFile is where the Traefik dynamic configuration is written. Empty
	// disables the export.
	RoutesFile string

	RouterPrefix string

	// Service is required when RoutesFile is set.
	Service string

	Host               string
	EntryPoints        []string
	CertResolver       string
	DefaultMiddlewares []string

	// PolicyMiddlewares adds Traefik middlewares to the exported routes of a
	// policy the service registers itself, e.g. {"bulk-upload": {"rate-limit-upload"}}.
	// The shared policies' Traefik middlewares are set with
	// SharedPolicyMiddlewares instead.
	PolicyMiddlewares map[string][]string

	// SharedPolicyMiddlewares replaces the Traefik middlewares of the enriched,
	// protected or admin policy, e.g. {"protected": {"auth-test-forward@docker"}}
	// where one Traefik serves several environments. A shared policy without an
	// entry keeps its default middlewares.
	SharedPolicyMiddlewares map[string][]string
}

Jump to

Keyboard shortcuts

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