proxy

package
v0.24.1 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2026 License: Apache-2.0 Imports: 35 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	AVAHI_DNS_CLASS_IN    = uint16(0x01)
	AVAHI_DNS_TYPE_CNAME  = uint16(0x05)
	MAX_ENTRIES_PER_GROUP = 15
)
View Source
const (
	STRIKE = utils.SHIELD_STRIKE
	TEMP   = utils.SHIELD_TEMP
	PERM   = utils.SHIELD_PERM
)
View Source
const LazyWakeBudget = 30 * time.Second

LazyWakeBudget bounds how long a request waits for a dormant container before being told to retry.

View Source
const ProbeHeader = "X-Cosmos-Container"
View Source
const ProbeParam = "__cosmos_probe"

ProbeParam marks the status HEAD the UI sends to a route (see HostChip). ProbeHeader carries the answer when Cosmos replies instead of the app.

View Source
const TunnelLBForwardedHeader = "x-cstln-lb-forwarded"

TunnelLBForwardedHeader marks a request already load-balanced by an upstream constellation node.

Variables

View Source
var DefaultTunnelLB = &TunnelLoadBalancer{}

Functions

func API_ShieldBans added in v0.24.0

func API_ShieldBans(w http.ResponseWriter, req *http.Request)

API_ShieldBans godoc @Summary List SmartShield strikes and bans @Description Returns every client with a strike or ban history on this node (the cluster's union when the constellation is up) @Tags shield @Produce json @Security BearerAuth @Success 200 {object} utils.APIResponse @Failure 403 {object} utils.HTTPErrorResult @Router /api/shield/bans [get]

func API_ShieldUnban added in v0.24.0

func API_ShieldUnban(w http.ResponseWriter, req *http.Request)

API_ShieldUnban godoc @Summary Unban a SmartShield client @Description Clears a client's strikes and bans everywhere, and the abuse counter that drops its TCP/UDP connections @Tags shield @Accept json @Produce json @Security BearerAuth @Param body body ShieldUnbanRequest true "Client to unban" @Success 200 {object} utils.APIResponse @Failure 400 {object} utils.HTTPErrorResult @Failure 403 {object} utils.HTTPErrorResult @Router /api/shield/unban [post]

func AdminOnlyWithRedirect added in v0.18.0

func AdminOnlyWithRedirect(w http.ResponseWriter, req *http.Request, route utils.ProxyRouteConfig) error

func BotDetectionMiddleware

func BotDetectionMiddleware(next http.Handler) http.Handler

botDetectionMiddleware checks if the User-Agent is a known bot

func BuildFromConfig

func BuildFromConfig(router *mux.Router, config utils.ProxyConfig) *mux.Router

func CleanPathMiddleware added in v0.21.0

func CleanPathMiddleware(next http.Handler) http.Handler

Borrowed from the net/http package. (Thanks mux!)

func CleanUp added in v0.15.0

func CleanUp()

func CleanUpSocket added in v0.17.0

func CleanUpSocket()

func GetActiveProxies added in v0.15.0

func GetActiveProxies() []string

func GetClientID

func GetClientID(r *http.Request, route utils.ProxyRouteConfig) string

GetClientID returns the source IP of a request, honouring X-Forwarded-For from trusted proxies and authenticated constellation peers.

func GetShield added in v0.15.0

func GetShield() int

func GetShieldIdentity added in v0.24.0

func GetShieldIdentity(r *http.Request, clientIP string) string

GetShieldIdentity is what budgets and bans are keyed on: the Cosmos user when the request is authenticated, otherwise the source IP. Many users behind one NAT then no longer share one budget.

func HandoffConnContext added in v0.24.0

func HandoffConnContext(ctx context.Context, c net.Conn) context.Context

HandoffConnContext is the http.Server ConnContext that tags requests coming from the socket proxy with the port they were accepted on.

func HandoffPort added in v0.24.0

func HandoffPort(r *http.Request) (string, bool)

HandoffPort returns the socket-proxy port a request came in on, false for a request accepted directly by the HTTP server.

func IPInRange added in v0.17.0

func IPInRange(ip, cidr string) (bool, error)

func InitInternalSocketProxy added in v0.17.0

func InitInternalSocketProxy()

func InitShieldSync added in v0.24.0

func InitShieldSync()

InitShieldSync wires the ban store to the constellation bucket.

func InitSocketShield added in v0.17.0

func InitSocketShield()

func InitUDPShield added in v0.17.0

func InitUDPShield()

func IsAllowedToConnect added in v0.24.0

func IsAllowedToConnect(shieldID string, policy utils.SmartShieldPolicy, userConsumed userUsedBudget) bool

IsAllowedToConnect checks bans, then strikes the client if its usage is beyond the policy times the strictness factor.

func LoggedInOnlyWithRedirect added in v0.18.0

func LoggedInOnlyWithRedirect(w http.ResponseWriter, req *http.Request, route utils.ProxyRouteConfig) error

func NewProxy

func NewProxy(targetHost string, AcceptInsecureHTTPSTarget bool, DisableHeaderHardening bool, route utils.ProxyRouteConfig) (*httputil.ReverseProxy, error)

NewProxy takes target host and creates a reverse proxy

func PublishAllMDNSFromConfig added in v0.16.0

func PublishAllMDNSFromConfig()

func RestartMDNS added in v0.16.3

func RestartMDNS()

func RouteTo

func RouteTo(route utils.ProxyRouteConfig) http.Handler

func RouterGen

func RouterGen(route utils.ProxyRouteConfig, router *mux.Router, destination http.Handler) *mux.Route

func SmartShieldMiddleware

func SmartShieldMiddleware(shieldID string, route utils.ProxyRouteConfig) func(http.Handler) http.Handler

func StartBudgetEnforcer added in v0.17.0

func StartBudgetEnforcer()

func StartHTTPHandoff added in v0.24.0

func StartHTTPHandoff(srv *http.Server, withTLS bool)

StartHTTPHandoff serves the handed-off connections with srv, over TLS (srv.TLSConfig) when withTLS, and over plain HTTP in every case. Call it before the socket proxy starts; srv.Shutdown closes the listeners.

func StopAllProxies added in v0.17.0

func StopAllProxies()

func TCPSmartShieldMiddleware added in v0.17.0

func TCPSmartShieldMiddleware(shieldID string, route utils.ProxyRouteConfig) func(net.Conn) net.Conn

func TunnelRouteTo added in v0.22.0

func TunnelRouteTo(tunnel utils.ConstellationTunnel, lb *TunnelLoadBalancer) http.Handler

func UDPSmartShieldMiddleware added in v0.17.0

func UDPSmartShieldMiddleware(shieldID string, route utils.ProxyRouteConfig) func([]byte, net.Addr) []byte

Types

type PortClaim added in v0.24.0

type PortClaim struct {
	Pair    PortsPair
	IsLocal bool
}

PortClaim is one route's bid for a listening port.

type PortsPair added in v0.15.7

type PortsPair struct {
	From    string
	To      string
	Targets []utils.TunnelTarget
	// contains filtered or unexported fields
}

func ResolvePortClaims added in v0.24.0

func ResolvePortClaims(claims []PortClaim) (accepted []PortsPair, shadowed []string, conflicts []string)

ResolvePortClaims picks one route per port: a local claim always beats a tunnel advertisement for the same port.

type ProxyInfo added in v0.17.0

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

type Publisher added in v0.16.0

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

func NewPublisher added in v0.16.0

func NewPublisher() (*Publisher, error)

func (*Publisher) Close added in v0.16.0

func (p *Publisher) Close()

func (*Publisher) Fqdn added in v0.16.0

func (p *Publisher) Fqdn() string

func (*Publisher) UpdateCNAMES added in v0.16.3

func (p *Publisher) UpdateCNAMES(cnames []string, ttl uint32) error

type ShieldClientStatus added in v0.24.0

type ShieldClientStatus struct {
	ClientID     string     `json:"clientID"`
	Status       string     `json:"status"` // perm, temp, strike, clear
	BlockedUntil *time.Time `json:"blockedUntil,omitempty"`
	History      []UserBan  `json:"history"`
}

type ShieldUnbanRequest added in v0.24.0

type ShieldUnbanRequest struct {
	ClientID string `json:"clientID"`
}

ShieldUnbanRequest is the body of the unban endpoint.

type SmartResponseWriterWrapper

type SmartResponseWriterWrapper struct {
	http.ResponseWriter
	ClientID     string // shield identity (user or IP)
	ClientIP     string
	Status       int
	Bytes        int64
	ThrottleNext int
	TimeStarted  time.Time
	TimeEnded    time.Time
	RequestCost  int
	Method       string
	// contains filtered or unexported fields
}

func (*SmartResponseWriterWrapper) Flush

func (w *SmartResponseWriterWrapper) Flush()

func (*SmartResponseWriterWrapper) Hijack

func (*SmartResponseWriterWrapper) IsOver

func (w *SmartResponseWriterWrapper) IsOver() bool

func (*SmartResponseWriterWrapper) Write

func (w *SmartResponseWriterWrapper) Write(p []byte) (int, error)

func (*SmartResponseWriterWrapper) WriteHeader

func (w *SmartResponseWriterWrapper) WriteHeader(status int)

WriteHeader prices the request once its outcome is known: non-GET costs 5 requests, an error response 30 times that, so failed logins and scraping exhaust a budget far faster than browsing does.

type TCPConnectionWrapper added in v0.17.0

type TCPConnectionWrapper struct {
	Conn         net.Conn
	TimeStarted  time.Time
	TimeEnded    time.Time
	ClientID     string
	Packets      int64
	Bytes        int64
	IsOver       bool
	ShieldID     string
	Policy       utils.SmartShieldPolicy
	IsPrivileged bool

	Route utils.ProxyRouteConfig
	// contains filtered or unexported fields
}

func TCPSmartShieldWrapper added in v0.17.0

func TCPSmartShieldWrapper(conn net.Conn, shieldID string, route utils.ProxyRouteConfig, policy utils.SmartShieldPolicy) *TCPConnectionWrapper

func (*TCPConnectionWrapper) Close added in v0.17.0

func (w *TCPConnectionWrapper) Close() error

func (*TCPConnectionWrapper) LocalAddr added in v0.17.0

func (w *TCPConnectionWrapper) LocalAddr() net.Addr

Implement the missing methods to satisfy the net.Conn interface

func (*TCPConnectionWrapper) Read added in v0.17.0

func (w *TCPConnectionWrapper) Read(b []byte) (int, error)

func (*TCPConnectionWrapper) RemoteAddr added in v0.17.0

func (w *TCPConnectionWrapper) RemoteAddr() net.Addr

func (*TCPConnectionWrapper) SetDeadline added in v0.17.0

func (w *TCPConnectionWrapper) SetDeadline(t time.Time) error

func (*TCPConnectionWrapper) SetReadDeadline added in v0.17.0

func (w *TCPConnectionWrapper) SetReadDeadline(t time.Time) error

func (*TCPConnectionWrapper) SetWriteDeadline added in v0.17.0

func (w *TCPConnectionWrapper) SetWriteDeadline(t time.Time) error

func (*TCPConnectionWrapper) Write added in v0.17.0

func (w *TCPConnectionWrapper) Write(b []byte) (int, error)

type TunnelLoadBalancer added in v0.22.0

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

func (*TunnelLoadBalancer) Select added in v0.22.2

func (lb *TunnelLoadBalancer) Select(keys []string, routeName string, mode string, sticky bool, stickyKey string) string

Select picks a key from the given list using the configured LB mode. Keys can be numeric indices ("0","1") for regular routes or device names for constellation tunnels. "load_based" needs per-key metrics; without them (this path) it degrades to round-robin.

func (*TunnelLoadBalancer) SelectTarget added in v0.22.0

func (lb *TunnelLoadBalancer) SelectTarget(targets []utils.TunnelTarget, routeName string, mode string, sticky bool, stickyKey string) *utils.TunnelTarget

SelectTarget is a convenience wrapper for constellation tunnel targets.

type UDPConnectionInfo added in v0.17.0

type UDPConnectionInfo struct {
	ClientID     string
	ShieldID     string
	BytesSent    int64
	LastActivity time.Time
	RouteName    string
}

type UDPSmartShieldState added in v0.17.0

type UDPSmartShieldState struct {
	sync.Mutex
	Connections map[string]*UDPConnectionInfo
}

type UserBan added in v0.17.0

type UserBan = utils.ShieldBan

func GetLastBan added in v0.17.0

func GetLastBan(clientID string) *UserBan

Jump to

Keyboard shortcuts

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