config

package
v0.9.4 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthPolicy added in v0.9.0

type AuthPolicy struct {
	ID    string   `toml:"id"`
	Users []string `toml:"users,omitempty"` // allowed user IDs (passkey login)
	// Header overrides the identity header name (default x-Gatecrash-User).
	Header string `toml:"header,omitempty"`
	// SecretHash is the bcrypt hash of a machine-generated service secret for
	// non-interactive clients (CI, scripts, webhooks). It is generated server-side
	// and shown once. Clients send it as the HTTP Basic password — by convention
	// with the username "service" (the username is not checked). A service secret
	// grants access INDEPENDENT of the Users list, so it is for trusted automation.
	SecretHash string `toml:"secret_hash,omitempty"`
}

AuthPolicy is a reusable authentication requirement that tunnels can share. A request authenticates if it is a logged-in user in Users, OR (optionally) it presents the machine-generated service secret via HTTP Basic.

type Config

type Config struct {
	Server     ServerConfig `toml:"server"`
	TLS        TLSConfig    `toml:"tls"`
	Update     UpdateConfig `toml:"update"`
	Tunnel     []Tunnel     `toml:"tunnel"`
	Redirect   []Redirect   `toml:"redirect"`
	IPPolicy   []IPPolicy   `toml:"ip_policy"`
	AuthPolicy []AuthPolicy `toml:"auth_policy"`
}

func GenerateNew

func GenerateNew() (*Config, error)

GenerateNew creates a new Config with auto-generated defaults (random secret, random SSH port, default bind address and cert dir).

func Load

func Load(path string) (*Config, error)

Load reads config from the given path. If the file doesn't exist, it creates a default config with auto-generated values.

func (*Config) AllHostnames

func (c *Config) AllHostnames() []string

AllHostnames returns all hostnames that need TLS certificates, including tunnel hostnames, admin host, and redirect source hostnames.

func (*Config) CheckIntervalDuration

func (c *Config) CheckIntervalDuration() time.Duration

func (*Config) LookupSecretHash

func (c *Config) LookupSecretHash(tunnelID string) string

LookupSecretHash returns the bcrypt hash for a tunnel ID, or "" if not found.

func (*Config) Save

func (c *Config) Save(path string) error

Save writes the config to disk as self-documenting TOML with comments.

func (*Config) Validate added in v0.8.17

func (c *Config) Validate() error

Validate checks cross-field tunnel invariants that the TOML schema can't express — in particular access-control combinations that would silently not be enforced, which would be a security footgun if accepted.

type IPPolicy added in v0.9.0

type IPPolicy struct {
	ID          string    `toml:"id"`
	Ranges      []IPRange `toml:"range,omitempty"`
	EnrollToken string    `toml:"enroll_token,omitempty"`
}

IPPolicy is a reusable source-IP allowlist that tunnels can share. Access is granted to any client in Ranges (permanent) or holding a live self-service grant. EnrollToken, when set, exposes a shareable self-enrollment link.

type IPRange added in v0.9.0

type IPRange struct {
	CIDR    string `toml:"cidr" json:"cidr"`
	Comment string `toml:"comment,omitempty" json:"comment,omitempty"`
}

IPRange is one entry in an IP policy: a CIDR or single IP with an optional human comment for documentation.

type Redirect

type Redirect struct {
	From         string `toml:"from"`
	To           string `toml:"to"`
	PreservePath bool   `toml:"preserve_path"`
}

type ServerConfig

type ServerConfig struct {
	Secret    string `toml:"secret"`
	SSHPort   int    `toml:"ssh_port"`
	HTTPSPort int    `toml:"https_port"`
	HTTPPort  int    `toml:"http_port"`
	AdminHost string `toml:"admin_host"`
	BindAddr  string `toml:"bind_addr"`
}

type TLSConfig

type TLSConfig struct {
	ACMEEmail string `toml:"acme_email"`
	CertDir   string `toml:"cert_dir"`
	Staging   bool   `toml:"staging"`
}

type Tunnel

type Tunnel struct {
	ID             string   `toml:"id"`
	Type           string   `toml:"type"`
	Hostnames      []string `toml:"hostnames,omitempty"`
	ListenPort     int      `toml:"listen_port,omitempty"`
	SecretHash     string   `toml:"secret_hash,omitempty"`
	PreserveHost   bool     `toml:"preserve_host,omitempty"`
	TLSPassthrough bool     `toml:"tls_passthrough,omitempty"`
	// IPPolicy / AuthPolicy reference reusable access policies by ID. They are
	// independent gates: when both are set a request must pass both (AND). Auth
	// policies apply to HTTP tunnels only.
	IPPolicy   string `toml:"ip_policy,omitempty"`
	AuthPolicy string `toml:"auth_policy,omitempty"`
}

type UpdateConfig

type UpdateConfig struct {
	Enabled       bool   `toml:"enabled"`
	CheckInterval string `toml:"check_interval"`
	GitHubRepo    string `toml:"github_repo"`
}

type Watcher

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

Watcher watches a config file for changes and sends validated configs on a channel.

func NewWatcher

func NewWatcher(path string) *Watcher

NewWatcher creates a new config file watcher.

func (*Watcher) OnChange

func (w *Watcher) OnChange() <-chan *Config

OnChange returns a channel that receives new valid configs.

func (*Watcher) OnError

func (w *Watcher) OnError() <-chan error

OnError returns a channel that receives config parse errors.

func (*Watcher) Start

func (w *Watcher) Start()

Start begins watching the config file. Must be called in a goroutine.

func (*Watcher) Stop

func (w *Watcher) Stop()

Stop stops watching.

Jump to

Keyboard shortcuts

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