Documentation
¶
Overview ¶
proxy/mtls.go
Index ¶
- Constants
- func LoadServerTLSConfigFromEnv() (*tls.Config, error)
- func ValidateDNSEntries(entries []string) error
- func ValidateDNSEntry(entry string) error
- func ValidateHTTPEntries(entries []string) error
- func ValidateHTTPEntry(entry string) error
- type Action
- type CIDRBlocker
- type ControlAPI
- type DNSAllowlist
- type DNSRule
- type DNSServer
- type DomainStats
- type HTTPAllowlist
- type HTTPProxy
- type HTTPRule
- type LogBuffer
- type LogEntry
- type MTLSCredentials
- func (c *MTLSCredentials) CACertPEM() []byte
- func (c *MTLSCredentials) ClientCertPEM() []byte
- func (c *MTLSCredentials) ClientKeyPEM() []byte
- func (c *MTLSCredentials) ClientTLSConfig() (*tls.Config, error)
- func (c *MTLSCredentials) ServerCertPEM() []byte
- func (c *MTLSCredentials) ServerKeyPEM() []byte
- func (c *MTLSCredentials) ServerTLSConfig() (*tls.Config, error)
- type Preset
- type PresetRegistry
- type ProxyConfig
- type Server
- type Source
Constants ¶
const ( EnvProxyTLSKey = "VIBEPIT_PROXY_TLS_KEY" EnvProxyTLSCert = "VIBEPIT_PROXY_TLS_CERT" EnvProxyCACert = "VIBEPIT_PROXY_CA_CERT" )
const ( DefaultUpstreamDNS = "9.9.9.9:53" DefaultDNSPort = 53 LogBufferCapacity = 10000 )
const SSHForwardPort = 2222
SSHForwardPort is the port the SSH forwarder listens on inside the proxy container.
Variables ¶
This section is empty.
Functions ¶
func LoadServerTLSConfigFromEnv ¶
LoadServerTLSConfigFromEnv reads PEM-encoded TLS material from environment variables and returns a tls.Config for the control API. Returns an error if any of the required env vars are missing — the control API must not start without mTLS.
func ValidateDNSEntries ¶
ValidateDNSEntries validates all allow-dns entries and returns the first error.
func ValidateDNSEntry ¶
ValidateDNSEntry validates a single allow-dns entry. Entry format is a domain pattern without port.
func ValidateHTTPEntries ¶
ValidateHTTPEntries validates all entries and returns the first error.
func ValidateHTTPEntry ¶
ValidateHTTPEntry validates a single allow-http entry. Entry format is "domain:port" where port is an exact number or '*'.
Types ¶
type CIDRBlocker ¶
type CIDRBlocker struct {
// contains filtered or unexported fields
}
func NewCIDRBlocker ¶
func NewCIDRBlocker(block, allow []string) *CIDRBlocker
type ControlAPI ¶
type ControlAPI struct {
// contains filtered or unexported fields
}
ControlAPI serves proxy status and configuration over HTTP.
func NewControlAPI ¶
func NewControlAPI(log *LogBuffer, config any, httpAllowlist *HTTPAllowlist, dnsAllowlist *DNSAllowlist) *ControlAPI
func (*ControlAPI) ServeHTTP ¶
func (a *ControlAPI) ServeHTTP(w http.ResponseWriter, r *http.Request)
type DNSAllowlist ¶
type DNSAllowlist struct {
// contains filtered or unexported fields
}
DNSAllowlist holds parsed DNS allow rules. Safe for concurrent use.
func NewDNSAllowlist ¶
func NewDNSAllowlist(entries []string) (*DNSAllowlist, error)
NewDNSAllowlist parses allow-dns entries (bare domains, no ports).
func (*DNSAllowlist) Add ¶
func (al *DNSAllowlist) Add(entries []string) error
Add parses new DNS entries and appends them atomically.
func (*DNSAllowlist) Allows ¶
func (al *DNSAllowlist) Allows(host string) bool
Allows checks whether a domain is permitted for DNS resolution.
type DNSRule ¶
type DNSRule struct {
Domain domainPattern
}
DNSRule represents a parsed allow-dns entry with a domain pattern.
type DNSServer ¶
type DNSServer struct {
// contains filtered or unexported fields
}
DNSServer is a filtering DNS server that checks queries against an allowlist and verifies resolved IPs against a CIDR blocklist.
func NewDNSServer ¶
func NewDNSServer(allowlist *DNSAllowlist, cidr *CIDRBlocker, log *LogBuffer, upstream string) *DNSServer
func (*DNSServer) ListenAndServe ¶
ListenAndServe starts the DNS server on the given address (e.g. ":53").
func (*DNSServer) ListenAndServeTest ¶
ListenAndServeTest starts a UDP DNS server on a random port for testing. Returns the address and a cleanup function.
func (*DNSServer) SetProxyIP ¶
SetProxyIP sets the IP address that host.vibepit will resolve to.
type DomainStats ¶
type HTTPAllowlist ¶
type HTTPAllowlist struct {
// contains filtered or unexported fields
}
HTTPAllowlist holds parsed HTTP allow rules. Safe for concurrent use.
func NewHTTPAllowlist ¶
func NewHTTPAllowlist(entries []string) (*HTTPAllowlist, error)
NewHTTPAllowlist parses allow-http entries into an HTTPAllowlist. Each entry must be "domain:port" (e.g. "github.com:443", "*.example.com:*").
func (*HTTPAllowlist) Add ¶
func (al *HTTPAllowlist) Add(entries []string) error
Add parses new entries and appends them atomically.
func (*HTTPAllowlist) Allows ¶
func (al *HTTPAllowlist) Allows(host, port string) bool
Allows checks whether a host:port pair is permitted.
type HTTPProxy ¶
type HTTPProxy struct {
// contains filtered or unexported fields
}
HTTPProxy is a filtering HTTP/HTTPS proxy that uses an allowlist and CIDR blocker to decide whether to forward or reject each request.
func NewHTTPProxy ¶
func NewHTTPProxy(allowlist *HTTPAllowlist, cidr *CIDRBlocker, log *LogBuffer, upstream string) *HTTPProxy
func (*HTTPProxy) SetHostVibepit ¶
SetHostVibepit configures the proxy to rewrite host.vibepit requests to the given gateway address. If allowedPorts is non-nil, only those ports are auto-allowed without requiring an explicit allowlist entry.
type HTTPRule ¶
type HTTPRule struct {
Domain domainPattern
Port string
}
HTTPRule represents a parsed allow-http entry with a domain pattern and port.
type LogBuffer ¶
type LogBuffer struct {
// contains filtered or unexported fields
}
func NewLogBuffer ¶
func (*LogBuffer) EntriesAfter ¶
EntriesAfter returns entries with ID > afterID in chronological order. When afterID is 0, it returns at most the last 25 entries.
func (*LogBuffer) Stats ¶
func (b *LogBuffer) Stats() map[string]DomainStats
type MTLSCredentials ¶
type MTLSCredentials struct {
CACert *x509.Certificate
ServerCert *x509.Certificate
ClientCert *x509.Certificate
// contains filtered or unexported fields
}
MTLSCredentials holds the ephemeral CA, server, and client certificates generated for a single vibepit session. The CA private key is not stored after signing — only the public cert is retained for verification.
func GenerateMTLSCredentials ¶
func GenerateMTLSCredentials(lifetime time.Duration) (*MTLSCredentials, error)
GenerateMTLSCredentials creates an ephemeral CA and signs a server cert (SAN: 127.0.0.1, EKU: serverAuth) and a client cert (EKU: clientAuth). The CA private key is discarded after signing.
func (*MTLSCredentials) CACertPEM ¶
func (c *MTLSCredentials) CACertPEM() []byte
func (*MTLSCredentials) ClientCertPEM ¶
func (c *MTLSCredentials) ClientCertPEM() []byte
func (*MTLSCredentials) ClientKeyPEM ¶
func (c *MTLSCredentials) ClientKeyPEM() []byte
func (*MTLSCredentials) ClientTLSConfig ¶
func (c *MTLSCredentials) ClientTLSConfig() (*tls.Config, error)
ClientTLSConfig returns a tls.Config for CLI commands calling the control API. It pins the ephemeral CA as the only trusted root and presents the client cert.
func (*MTLSCredentials) ServerCertPEM ¶
func (c *MTLSCredentials) ServerCertPEM() []byte
func (*MTLSCredentials) ServerKeyPEM ¶
func (c *MTLSCredentials) ServerKeyPEM() []byte
func (*MTLSCredentials) ServerTLSConfig ¶
func (c *MTLSCredentials) ServerTLSConfig() (*tls.Config, error)
ServerTLSConfig returns a tls.Config for the proxy control API server. It requires TLS 1.3 and verifies client certificates against the ephemeral CA.
type Preset ¶
type Preset struct {
Name string `yaml:"name"`
Group string `yaml:"group"`
Description string `yaml:"description"`
Domains []string `yaml:"domains"`
Matchers []string `yaml:"matchers"` // file glob patterns for project auto-detection
Includes []string `yaml:"includes"` // other preset names (meta-presets)
}
Preset defines a network allowlist preset with optional auto-detection matchers and the ability to include other presets.
type PresetRegistry ¶
type PresetRegistry struct {
// contains filtered or unexported fields
}
PresetRegistry holds all built-in presets in definition order.
func NewPresetRegistry ¶
func NewPresetRegistry() *PresetRegistry
NewPresetRegistry returns the built-in preset registry.
func (*PresetRegistry) All ¶
func (r *PresetRegistry) All() []Preset
All returns all presets in definition order.
func (*PresetRegistry) Expand ¶
func (r *PresetRegistry) Expand(names []string) []string
Expand resolves a list of preset names into a deduplicated flat list of domains, recursively expanding Includes with cycle detection.
type ProxyConfig ¶
type ProxyConfig struct {
AllowHTTP []string `json:"allow-http"`
AllowDNS []string `json:"allow-dns"`
BlockCIDR []string `json:"block-cidr"`
AllowCIDR []string `json:"allow-cidr"`
UpstreamDNS string `json:"upstream-dns"`
AllowHostPorts []int `json:"allow-host-ports"`
ProxyIP string `json:"proxy-ip"`
HostGateway string `json:"host-gateway"`
ProxyPort int `json:"proxy-port"`
ControlAPIPort int `json:"control-api-port"`
DNSPort int `json:"dns-port"`
SSHForwardAddr string `json:"ssh-forward-addr,omitempty"`
}
ProxyConfig is the JSON config file passed to the proxy container.