Documentation
¶
Overview ¶
Package enproxy provides a complete proxy implementation with support for HTTP, HTTP/2, and NASSH, with OAUTH authentication, all in a simple API to use.
This package glues together the default go net/http/httputil ReverseProxy packaged in proxy/httpp and the SSH over HTTPs implementation in proxy/nasshp together witha frontend server implemented using net/http, packaged in lib/khttp.
The simplest use of this library is via flags:
import (
// Secure random numbers.
"github.com/ccontavalli/enkit/lib/srand"
"github.com/ccontavalli/enkit/lib/kflags"
"flag"
)
flags := enproxy.DefaultFlags()
flags.Register(&kflags.GoFlagSet{FlagSet: flag.CommandLine})
// Parse flags after registering them!!
flag.Parse()
rng := rand.New(srand.Source)
proxy, err := enproxy.New(rng, enproxy.FromFlags(flags))
if err != nil {
...
}
proxy.Run()
You can, of course, create a proxy manually with the desired options. In that case, you want to use `WithConfig` and other `With.*` modifiers to set all the desired options.
Index ¶
- func OpenConfigBinding(rng *rand.Rand, flags *Flags) (config.StoreWorkspace, config.Store, config.Binding, bool, error)
- func ParseConfigBinding(binding config.Binding, defaultNasshRelayHost string) (Config, Warnings, error)
- type Config
- type ConfigNormalizer
- type Enproxy
- func (ep *Enproxy) ApplyConfigFile(name string, data []byte) error
- func (ep *Enproxy) ApplyConfigStruct(config Config) error
- func (ep *Enproxy) Close() error
- func (ep *Enproxy) ReloadConfig() error
- func (ep *Enproxy) Run() error
- func (ep *Enproxy) RunMetrics() error
- func (ep *Enproxy) RunProxy() error
- type Flags
- type Mapping
- type MetricsModule
- type MetricsTarget
- type MissingConfigPolicy
- type Modifier
- func FromFlags(flags *Flags) Modifier
- func WithAuthenticator(auth oauth.Authenticate) Modifier
- func WithConfig(config Config) Modifier
- func WithConfigFile(name string, data []byte) Modifier
- func WithConfigMissing(policy MissingConfigPolicy) Modifier
- func WithConfigStore(workspace config.StoreWorkspace, store config.Store, binding config.Binding) Modifier
- func WithDefaultConfigFile(name string, data []byte) Modifier
- func WithDefaultConfigStore(workspace config.StoreWorkspace, store config.Store, binding config.Binding) Modifier
- func WithDisabledAuthentication(disabled bool) Modifier
- func WithDisabledNasshAuthentication(disabled bool) Modifier
- func WithHttpFlags(flags *khttp.Flags) Modifier
- func WithHttpStarter(starter Starter) Modifier
- func WithLogging(logger logger.Logger) Modifier
- func WithMetricsFlags(flags *khttp.Flags) Modifier
- func WithMetricsStarter(starter Starter) Modifier
- func WithNasshpMods(nmods ...nasshp.Modifier) Modifier
- func WithOauthCookieStripper(baseCookie string) Modifier
- func WithOauthRedirector(rflags *oauth.RedirectorFlags) Modifier
- func WithPrometheus(gatherer prometheus.Gatherer, register prometheus.Registerer) Modifier
- func WithProxyMods(pmods ...httpp.Modifier) Modifier
- func WithUnsafeIgnoreAuthentication(unsafe bool) Modifier
- type Modifiers
- type NasshModule
- type NasshTarget
- type Options
- type ProxyModule
- type ProxyTarget
- type RouteRegistrar
- type Starter
- type Target
- type Warnings
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func OpenConfigBinding ¶
func OpenConfigBinding(rng *rand.Rand, flags *Flags) (config.StoreWorkspace, config.Store, config.Binding, bool, error)
OpenConfigBinding opens the config store entry selected by flags.
The explicit return reports whether the caller selected an explicit --config path instead of the implicit default config target.
Types ¶
type Config ¶
type Config struct {
ProxyModules map[string]ProxyModule
NasshModules map[string]NasshModule
MetricsModules map[string]MetricsModule
// Which URLs to map to which modules or targets.
Mapping []Mapping
// Extra domains for which to obtain a certificate.
Domains []string
// List of allowed tunnels.
Tunnels []string
}
Config is the content of the proxy configuration file.
func EffectiveConfig ¶
EffectiveConfig returns NormalizeConfig for backward compatibility.
func NormalizeConfig ¶
NormalizeConfig returns a copy of config with representable runtime defaults applied explicitly.
type ConfigNormalizer ¶
type ConfigNormalizer struct {
// contains filtered or unexported fields
}
ConfigNormalizer materializes the effective config seen by CLI inspection and runtime reload.
NormalizeConfig applies representable target defaults and cross-cutting policy rewrites that are part of the config enproxy will actually use. The result is what Parse, ApplyConfigStruct, config check, and config print all consume so those paths stay in sync.
func NewConfigNormalizer ¶
func NewConfigNormalizer(defaultNasshRelayHost string, withoutAuthentication, unsafeIgnoreAuthentication bool) (*ConfigNormalizer, error)
NewConfigNormalizer returns a normalizer configured with the provided runtime defaults and authentication policy.
func (*ConfigNormalizer) NormalizeConfig ¶
func (normalizer *ConfigNormalizer) NormalizeConfig(config Config) (Config, Warnings, error)
NormalizeConfig returns a copy of config with representable runtime defaults and policy rewrites applied explicitly.
func (*ConfigNormalizer) ParseConfigBinding ¶
func (normalizer *ConfigNormalizer) ParseConfigBinding(binding config.Binding) (Config, Warnings, error)
ParseConfigBinding loads the bound config as the current Config format, normalizes representable defaults, and validates the resulting config.
type Enproxy ¶
type Enproxy struct {
// contains filtered or unexported fields
}
func New ¶
New constructs an Enproxy by applying modifiers in order.
Modifier order is part of the API. Callers are expected to choose a coherent sequence, and later modifiers override earlier ones.
func (*Enproxy) ApplyConfigFile ¶
func (*Enproxy) ApplyConfigStruct ¶
func (*Enproxy) ReloadConfig ¶
ReloadConfig reloads the active config from the configured store binding.
func (*Enproxy) RunMetrics ¶
type Flags ¶
type Flags struct {
Http *khttp.Flags
Oauth *oauth.RedirectorFlags
Nassh *nasshp.Flags
Prometheus *khttp.Flags
// ConfigStore controls the backend used to resolve and read --config.
ConfigStore *factory.Flags
// ConfigPath identifies the config entry to read from ConfigStore.
ConfigPath string
// ConfigMissing controls what happens when the selected config is missing.
ConfigMissing MissingConfigPolicy
DisabledAuthentication bool
UnsafeIgnoreAuthentication bool
}
Flags represents command line flags necessary to define a proxy.
func DefaultFlags ¶
func DefaultFlags() *Flags
DefaultFlags returns the default flags.
The default is generally a valid, working, one except for mandatory configuration parameters.
type MetricsModule ¶
type MetricsModule struct {
}
type MetricsTarget ¶
type MetricsTarget struct {
}
type MissingConfigPolicy ¶
type MissingConfigPolicy string
const ( MissingConfigAuto MissingConfigPolicy = "auto" MissingConfigEmbedded MissingConfigPolicy = "embedded" MissingConfigError MissingConfigPolicy = "error" )
func (MissingConfigPolicy) Valid ¶
func (m MissingConfigPolicy) Valid() bool
type Modifier ¶
Modifier updates enproxy construction options.
Modifiers are applied in order, and later modifiers win. In particular, config source modifiers such as FromFlags, WithConfig, WithConfigFile, and WithConfigStore intentionally override earlier config sources.
func FromFlags ¶
FromFlags applies the current CLI configuration to enproxy.
Like every other modifier, order matters: later modifiers may override the config source, HTTP starter, metrics starter, or authentication configured here. FromFlags is intentionally a thin wrapper around the corresponding With* modifiers. It also loads the selected config store binding immediately, so apply WithDefaultConfigFile before FromFlags if you want embedded fallback to participate in missing-config handling.
func WithAuthenticator ¶
func WithAuthenticator(auth oauth.Authenticate) Modifier
func WithConfig ¶
func WithConfigFile ¶
WithConfigFile parses the provided config immediately and overrides any earlier config source modifier.
func WithConfigMissing ¶
func WithConfigMissing(policy MissingConfigPolicy) Modifier
func WithConfigStore ¶
func WithConfigStore(workspace config.StoreWorkspace, store config.Store, binding config.Binding) Modifier
WithConfigStore installs an explicitly selected config store binding and loads it immediately.
Order matters: later config source modifiers override earlier ones. Apply WithDefaultConfigFile before WithConfigStore if you want the embedded config to be used as the missing-config fallback when the missing-config policy allows it.
func WithDefaultConfigFile ¶
WithDefaultConfigFile provides an embedded fallback config used when the selected config is missing and the missing-config policy allows it.
Order matters: apply this before WithConfigStore or FromFlags if you want it to affect their eager config loading.
func WithDefaultConfigStore ¶
func WithDefaultConfigStore(workspace config.StoreWorkspace, store config.Store, binding config.Binding) Modifier
WithDefaultConfigStore installs the implicit default config store binding and loads it immediately.
Order matters: later config source modifiers override earlier ones. Apply WithDefaultConfigFile before WithDefaultConfigStore if you want the embedded config to be used as the missing-config fallback when the missing-config policy allows it.
func WithDisabledNasshAuthentication ¶
WithDisabledNasshAuthentication disables authentication only for NASSH routes.
func WithHttpFlags ¶
func WithHttpStarter ¶
func WithLogging ¶
func WithMetricsFlags ¶
func WithMetricsStarter ¶
func WithNasshpMods ¶
func WithOauthCookieStripper ¶
func WithOauthRedirector ¶
func WithOauthRedirector(rflags *oauth.RedirectorFlags) Modifier
func WithPrometheus ¶
func WithPrometheus(gatherer prometheus.Gatherer, register prometheus.Registerer) Modifier
func WithProxyMods ¶
type Modifiers ¶
type Modifiers []Modifier
func RuntimeModifiersFromFlags ¶
RuntimeModifiersFromFlags returns the non-config modifiers implied by flags.
Callers that already hold a config snapshot can combine these with WithConfig to validate or start enproxy without reopening the configured store.
type NasshModule ¶
type NasshModule struct {
RelayHost string
}
type NasshTarget ¶
type NasshTarget struct {
RelayHost string
}
type ProxyModule ¶
type ProxyTarget ¶
type RouteRegistrar ¶
RouteRegistrar records an HTTP handler for one route produced by modulePlan.Map.
If from is nil, the mapping's configured From value is used. A non-nil from lets a module expand one mapping into multiple concrete routes, such as module-owned paths or relay host aliases. label is used for routing metadata and diagnostics; handler is the HTTP handler to install if the config commits.
type Starter ¶
Starter is a function capable of starting a web server.
Requires providing a logger, an http.Handler (typically some form of mux), and a list of domains for which an https certificate is necessary.
func StarterFromFlags ¶
StarterFromFlags creates a starter from kserver.Flags.
type Target ¶
type Target struct {
Proxy *ProxyTarget
Nassh *NasshTarget
Metrics *MetricsTarget
}