runtimeconfig

package
v0.0.14 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2026 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultHarpoonMaxResponseBytes = 100 * 1024
	DefaultHarpoonMaxRedirects     = 5
)
View Source
const (
	DefaultAdminUILogBufferEvents = 2000
	DefaultProxyCheckInterval     = 60 * time.Second
)

These full-client extension defaults live beside the canonical profile loader because runtime flavors must recognize their harmless legacy values without importing pkg/config.

View Source
const (
	ProfileEnvName     = "TUNNEL_CLIENT_PROFILE"
	ProfileFileEnvName = "TUNNEL_CLIENT_PROFILE_FILE"
	ProfileDirEnvName  = "TUNNEL_CLIENT_PROFILE_DIR"
	ConfigEnvName      = "TUNNEL_CLIENT_CONFIG"
)
View Source
const DefaultControlPlaneBaseURL = defaultControlPlaneBaseURL

DefaultControlPlaneBaseURL is the canonical production default shared by runtime and full-client administrative commands.

Variables

This section is empty.

Functions

func BuildTLSBundle

func BuildTLSBundle(fs *pflag.FlagSet, lookupEnv func(string) (string, bool)) (*tlsconfig.Bundle, error)

BuildTLSBundle exposes the shared CA-bundle loader for narrow adapters.

func ControlPlaneURLPathRaw

func ControlPlaneURLPathRaw(fs *pflag.FlagSet, lookupEnv func(string) (string, bool)) string

ControlPlaneURLPathRaw exposes shared flag/environment precedence for administrative commands that do not need the full runtime loader.

func DefaultProfileDir

func DefaultProfileDir(lookupEnv func(string) (string, bool)) (string, error)

DefaultProfileDir returns the XDG-backed default profile directory.

func EnvProxyConfigured

func EnvProxyConfigured(lookupEnv func(string) (string, bool)) bool

func LoadFullFromFlagSet

func LoadFullFromFlagSet(fs *pflag.FlagSet, lookupEnv func(string) (string, bool)) (*Config, CloudflaredSettings, LoadContext, error)

LoadFullFromFlagSet loads the shared production core for the full client and returns the approved companion settings plus the effective lookup used for full-only adapters. The returned Config never grows full-client-only fields.

func NormalizeControlPlaneURLPath

func NormalizeControlPlaneURLPath(raw string) (string, error)

NormalizeControlPlaneURLPath validates and normalizes the optional control-plane URL prefix.

func NormalizeExtraHeaders

func NormalizeExtraHeaders(source string, headers map[string]string) (map[string]string, error)

NormalizeExtraHeaders validates operator-supplied HTTP headers and returns a canonical copy. HTTP field names are case-insensitive, so conflicting case variants are rejected instead of depending on Go map iteration order.

func ParseProxyCheckInterval

func ParseProxyCheckInterval(raw string) (time.Duration, error)

ParseProxyCheckInterval is the canonical parser for the full-client proxy health extension and its runtime profile/environment compatibility gate.

func ParseURL

func ParseURL(raw string) (*url.URL, error)

ParseURL exposes the shared URL validator for full-client adapters.

func ProfilePath

func ProfilePath(name string, explicitDir string, lookupEnv func(string) (string, bool)) (string, string, error)

ProfilePath returns the on-disk path for a named profile.

func ProxyLogFields

func ProxyLogFields(proxyURL *url.URL, source ProxySource) []any

ProxyLogFields builds log fields for proxy metadata, redacting credentials.

func RedactProxyURL

func RedactProxyURL(proxyURL *url.URL) string

func RegisterFlags

func RegisterFlags(fs *pflag.FlagSet, flavor Flavor)

RegisterFlags attaches only the approved customer runtime flags to fs. The normal runtime intentionally omits cloudflared flags; the cloudflared flavor adds only the approved companion settings.

func RegisterTLSFlags

func RegisterTLSFlags(fs *pflag.FlagSet)

RegisterTLSFlags exposes the shared CA-bundle flag for narrow adapters such as the full client's administrative command surface.

func ResolveControlPlanePath

func ResolveControlPlanePath(baseURL *url.URL, urlPath, routePath string) *url.URL

ResolveControlPlanePath resolves routePath from the control-plane host root plus urlPath.

func ResolveProfileDir

func ResolveProfileDir(explicitDir string, lookupEnv func(string) (string, bool)) (string, error)

ResolveProfileDir returns the directory used to store named profile files.

func ValidateControlPlaneAPIKey

func ValidateControlPlaneAPIKey(key string) error

ValidateControlPlaneAPIKey verifies that key can be safely used as an HTTP bearer token. It deliberately returns redacted errors: callers must not expose any key-derived details while reporting configuration failures.

func ValidateFullProfileBytes

func ValidateFullProfileBytes(path string, data []byte) error

ValidateFullProfileBytes validates full-client profile contents without resolving referenced secrets. Shared field syntax remains owned here; only the approved full-only extension keys are additionally allowed.

func ValidateFullProfileFile

func ValidateFullProfileFile(path string) error

ValidateFullProfileFile parses a full-client profile through the same canonical schema while allowing approved full-only extension fields.

func ValidateProfileBytes

func ValidateProfileBytes(path string, data []byte) error

ValidateProfileBytes parses profile contents without resolving referenced secrets.

func ValidateProfileFile

func ValidateProfileFile(path string) error

ValidateProfileFile parses a profile file without resolving referenced secrets.

func ValidateProfileName

func ValidateProfileName(name string) error

ValidateProfileName verifies that name can be mapped to exactly one YAML file.

func ValidateTunnelID

func ValidateTunnelID(tunnelID string) error

ValidateTunnelID verifies that the tunnel id matches the runtime contract.

func WriteUsage

func WriteUsage(fs *pflag.FlagSet, w io.Writer)

WriteUsage prints the runtime CLI usage text for the provided flag set.

Types

type CloudflaredConfig

type CloudflaredConfig struct {
	Runtime     Config
	Cloudflared CloudflaredSettings
}

CloudflaredConfig composes the shared runtime configuration with the only extra settings accepted by the runtime-cloudflared artifact.

func LoadCloudflaredFromFlagSet

func LoadCloudflaredFromFlagSet(fs *pflag.FlagSet, lookupEnv func(string) (string, bool)) (*CloudflaredConfig, error)

LoadCloudflaredFromFlagSet builds runtime-cloudflared configuration from parsed flags, adding only the approved companion settings.

type CloudflaredSettings

type CloudflaredSettings struct {
	// Token is the pre-provisioned remotely managed Cloudflare Tunnel token.
	// It is kept in memory only and is passed to cloudflared through its
	// TUNNEL_TOKEN environment variable, never argv.
	Token string
	// Managed fetches the remotely managed Cloudflare Tunnel runtime token from
	// tunnel-service during startup. A configured Token takes precedence so
	// existing pre-provisioned deployments remain unchanged.
	Managed bool
	// Path overrides sibling-binary discovery for source builds and tests.
	Path string
	// ReadyTimeout bounds startup while waiting for cloudflared /ready.
	ReadyTimeout time.Duration
}

CloudflaredSettings defines the optional bundled Cloudflare Tunnel companion process. A configured token or explicit managed mode enables supervision; otherwise the normal tunnel-client runtime is unchanged.

func (CloudflaredSettings) Enabled

func (c CloudflaredSettings) Enabled() bool

Enabled reports whether the bundled cloudflared companion should run.

type Config

type Config struct {
	ControlPlane ControlPlaneConfig
	Logging      LoggingConfig
	Health       HealthConfig
	Process      ProcessConfig
	MCP          MCPConfig
	Harpoon      HarpoonConfig
	TLS          *tlsconfig.Bundle
	Runtime      RuntimeConfig
}

Config captures the runtime values required to start the tunnel client.

func Load

func Load(args []string, flavor Flavor, lookupEnv func(string) (string, bool)) (*Config, error)

Load builds a runtime configuration by combining CLI flag arguments with environment variables. Flags take precedence over environment variables, environment variables over YAML/profile values, and defaults apply last.

func LoadFromFlagSet

func LoadFromFlagSet(fs *pflag.FlagSet, lookupEnv func(string) (string, bool)) (*Config, error)

LoadFromFlagSet builds normal runtime configuration from parsed flags.

type ConfigSource

type ConfigSource struct {
	Path        string
	ProfileName string
	ProfilePath string
	ProfileDir  string
	ProfileFile bool
}

ConfigSource describes the config file selected for this process.

func ResolveConfigSource

func ResolveConfigSource(fs *pflag.FlagSet, lookupEnv func(string) (string, bool)) (ConfigSource, error)

ResolveConfigSource returns the config file selected by flags or environment.

type ControlPlaneConfig

type ControlPlaneConfig struct {
	BaseURL               *url.URL
	UnixSocketPath        string
	URLPath               string
	TunnelID              types.TunnelID
	OrganizationID        string
	APIKey                string
	MaxInFlightRequests   int
	PollTimeout           time.Duration
	PollDeadlineGuardrail time.Duration
	// PollChannels is an explicit, sorted allowlist of channels to drain. When
	// PollChannelsConfigured is false, polling remains wire-compatible with
	// older clients and sends no channel query parameters.
	PollChannels           []types.Channel
	PollChannelsConfigured bool
	// PollBackoffMin/PollBackoffMax allow overriding the poller's retry window.
	// Zero values fall back to the internal defaults.
	PollBackoffMin    time.Duration
	PollBackoffMax    time.Duration
	ClientCertificate *tlsconfig.ClientCertificate
	ExtraHeaders      map[string]string
	// MCPServerInfoHeader returns metadata generated from effective MCP channel
	// bindings and sent as a protected control-plane header. It is not
	// operator-configurable.
	MCPServerInfoHeader func() (string, error)
	HTTPProxy           *url.URL
	HTTPProxySource     ProxySource
}

ControlPlaneConfig defines how the client reaches the tunnel control plane.

func (ControlPlaneConfig) PollDeadlineGuardrailOrDefault

func (c ControlPlaneConfig) PollDeadlineGuardrailOrDefault() time.Duration

PollDeadlineGuardrailOrDefault returns the configured client deadline guardrail or its runtime default.

func (ControlPlaneConfig) PollDeadlineTimeoutOrDefault

func (c ControlPlaneConfig) PollDeadlineTimeoutOrDefault() time.Duration

PollDeadlineTimeoutOrDefault returns the client HTTP/context deadline for one poll cycle.

func (ControlPlaneConfig) PollTimeoutOrDefault

func (c ControlPlaneConfig) PollTimeoutOrDefault() time.Duration

PollTimeoutOrDefault returns the configured requested service wait or its runtime default.

type Flavor

type Flavor string

Flavor selects the deliberately narrow runtime configuration surface.

The flavor is part of the compile-time artifact boundary: the normal runtime never registers or accepts cloudflared configuration, while the cloudflared runtime accepts only the approved companion settings in addition to the shared runtime surface.

const (
	// FlavorFull lets the full client reuse the same production runtime
	// loader while layering its UI/debug-only settings in pkg/config.
	FlavorFull               Flavor = "full"
	FlavorRuntime            Flavor = "runtime"
	FlavorRuntimeCloudflared Flavor = "runtime-cloudflared"
)

type HarpoonConfig

type HarpoonConfig struct {
	AllowPlaintextHTTP   bool
	MaxResponseBytes     int
	MaxRedirects         int
	AdditionalTransports []HarpoonTransportKind
	Targets              []HarpoonTarget
	HostClassifier       HarpoonHostClassifierConfig
	HTTPProxy            *url.URL
	HTTPProxySource      ProxySource
}

HarpoonConfig captures configuration for the embedded harpoon MCP server.

func (HarpoonConfig) AdditionalTransportEnabled

func (h HarpoonConfig) AdditionalTransportEnabled(kind HarpoonTransportKind) bool

AdditionalTransportEnabled reports whether a transport is enabled.

type HarpoonHostClassifierConfig

type HarpoonHostClassifierConfig struct {
	IncludeSuffix   []string
	IncludeRegex    []string
	IncludeLoopback bool
	IncludePrivate  bool
}

HarpoonHostClassifierConfig controls which hosts are treated as private.

type HarpoonTarget

type HarpoonTarget struct {
	Label          string
	Description    string
	BaseURL        *url.URL
	UnixSocketPath string
}

HarpoonTarget describes a configured harpoon target.

type HarpoonTransportKind

type HarpoonTransportKind string

HarpoonTransportKind enumerates supported harpoon transports.

const (
	HarpoonTransportHTTPStreamable HarpoonTransportKind = "http-streamable"
)

type HealthConfig

type HealthConfig struct {
	ListenAddr string
	UnixSocket string
	URLFile    string
}

HealthConfig defines the health server behavior.

type LoadContext

type LoadContext struct {
	LookupEnv func(string) (string, bool)
	Source    ConfigSource
	RawConfig []byte
}

LoadContext exposes the effective lookup and selected source produced by the shared loader so full-client-only adapters can apply their own settings without reimplementing shared precedence or profile parsing.

type LogFormat

type LogFormat int

LogFormat enumerates the supported logging formats.

const (
	LogFormatUnset LogFormat = iota
	LogFormatStructText
	LogFormatJSON
)

func ParseLogFormat

func ParseLogFormat(raw string) (LogFormat, error)

ParseLogFormat converts the provided raw string into a LogFormat value.

func (LogFormat) String

func (f LogFormat) String() string

String implements fmt.Stringer.

type LoggingConfig

type LoggingConfig struct {
	Level         slog.Level
	Format        LogFormat
	File          string
	HTTPRawUnsafe bool
}

LoggingConfig defines logging behavior for the client.

type MCPChannelBinding

type MCPChannelBinding struct {
	Channel           types.Channel
	TransportKind     MCPTransportKind
	ServerURL         *url.URL
	UnixSocketPath    string
	Command           string
	CommandArgs       []string
	ClientCertificate *tlsconfig.ClientCertificate
	HTTPProxy         *url.URL
	HTTPProxySource   ProxySource
}

MCPChannelBinding maps one tunnel-service channel to one MCP transport.

Exactly one binding may exist per channel. The reserved harpoon channel is supplied by the embedded Harpoon server, not by user MCP config. Streamable HTTP bindings may carry proxy and mTLS settings; stdio bindings deliberately ignore HTTP-only settings because they communicate over child-process stdin/stdout rather than a network socket.

type MCPConfig

type MCPConfig struct {
	ServerURL         *url.URL
	UnixSocketPath    string
	Command           string
	CommandArgs       []string
	TransportKind     MCPTransportKind
	ClientCertificate *tlsconfig.ClientCertificate
	ChannelBindings   []MCPChannelBinding
	// AllowNoMain is set only for an explicit poll allowlist that excludes main.
	// It keeps zero-value MCPConfig compatibility for older callers.
	AllowNoMain bool
	// StartupWaitTimeout enables an opt-in startup gate for the main
	// HTTP-streamable MCP listener. Zero preserves legacy behavior.
	StartupWaitTimeout time.Duration
	// StdioSendInitializedNotification opts stdio bindings into completing the
	// MCP lifecycle when an older caller omits notifications/initialized. False
	// preserves the legacy verbatim-forwarding behavior for existing servers.
	StdioSendInitializedNotification bool
	ConnectionMaxTTL                 time.Duration
	MaxConcurrentRequests            int
	ExtraHeaders                     map[string]string
	DiscoveryExtraHeaders            map[string]string
	HTTPProxy                        *url.URL
	HTTPProxySource                  ProxySource
}

MCPConfig captures configuration for the Model Context Protocol integration.

The legacy top-level ServerURL/Command fields mirror the main channel so older call sites can keep reading cfg.MCP.ServerURL while the dispatcher routes from ChannelBindings. New connector/channel behavior should be modeled as an MCPChannelBinding first, then projected to the legacy fields only for compatibility.

func (*MCPConfig) ChannelBindingFor

func (c *MCPConfig) ChannelBindingFor(channel types.Channel) *MCPChannelBinding

ChannelBindingFor returns the configured binding for the provided channel.

func (*MCPConfig) MainChannelBinding

func (c *MCPConfig) MainChannelBinding() *MCPChannelBinding

MainChannelBinding returns the binding for the main channel, if configured.

type MCPTransportKind

type MCPTransportKind string

MCPTransportKind describes the available MCP transport types.

const (
	MCPTransportHTTPStreamable MCPTransportKind = "http-streamable"
	MCPTransportStdio          MCPTransportKind = "stdio"
	MCPTransportInMemory       MCPTransportKind = "in-memory"
)

type ProcessConfig

type ProcessConfig struct {
	PIDFile string
}

ProcessConfig defines process-level runtime settings.

type ProxySource

type ProxySource string

ProxySource describes where an effective proxy value originated.

const (
	ProxySourceNone        ProxySource = "none"
	ProxySourceEnvironment ProxySource = "environment"
	ProxySourceIgnored     ProxySource = "ignored"
)

func (ProxySource) String

func (s ProxySource) String() string

type RuntimeConfig

type RuntimeConfig struct {
	ConfigFile         string
	ConfigFileContents []byte
	ProfileName        string
	ProfilePath        string
	ProfileDir         string
	ProfileFile        bool
}

RuntimeConfig captures startup metadata that is useful for diagnostics but does not affect runtime behavior.

Jump to

Keyboard shortcuts

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