Documentation
¶
Index ¶
- Constants
- Variables
- func API_ShieldBans(w http.ResponseWriter, req *http.Request)
- func API_ShieldUnban(w http.ResponseWriter, req *http.Request)
- func AdminOnlyWithRedirect(w http.ResponseWriter, req *http.Request, route utils.ProxyRouteConfig) error
- func BotDetectionMiddleware(next http.Handler) http.Handler
- func BuildFromConfig(router *mux.Router, config utils.ProxyConfig) *mux.Router
- func CleanPathMiddleware(next http.Handler) http.Handler
- func CleanUp()
- func CleanUpSocket()
- func GetActiveProxies() []string
- func GetClientID(r *http.Request, route utils.ProxyRouteConfig) string
- func GetShield() int
- func GetShieldIdentity(r *http.Request, clientIP string) string
- func HandoffConnContext(ctx context.Context, c net.Conn) context.Context
- func HandoffPort(r *http.Request) (string, bool)
- func IPInRange(ip, cidr string) (bool, error)
- func InitInternalSocketProxy()
- func InitShieldSync()
- func InitSocketShield()
- func InitUDPShield()
- func IsAllowedToConnect(shieldID string, policy utils.SmartShieldPolicy, userConsumed userUsedBudget) bool
- func LoggedInOnlyWithRedirect(w http.ResponseWriter, req *http.Request, route utils.ProxyRouteConfig) error
- func NewProxy(targetHost string, AcceptInsecureHTTPSTarget bool, DisableHeaderHardening bool, ...) (*httputil.ReverseProxy, error)
- func PublishAllMDNSFromConfig()
- func RestartMDNS()
- func RouteTo(route utils.ProxyRouteConfig) http.Handler
- func RouterGen(route utils.ProxyRouteConfig, router *mux.Router, destination http.Handler) *mux.Route
- func SmartShieldMiddleware(shieldID string, route utils.ProxyRouteConfig) func(http.Handler) http.Handler
- func StartBudgetEnforcer()
- func StartHTTPHandoff(srv *http.Server, withTLS bool)
- func StopAllProxies()
- func TCPSmartShieldMiddleware(shieldID string, route utils.ProxyRouteConfig) func(net.Conn) net.Conn
- func TunnelRouteTo(tunnel utils.ConstellationTunnel, lb *TunnelLoadBalancer) http.Handler
- func UDPSmartShieldMiddleware(shieldID string, route utils.ProxyRouteConfig) func([]byte, net.Addr) []byte
- type PortClaim
- type PortsPair
- type ProxyInfo
- type Publisher
- type ShieldClientStatus
- type ShieldUnbanRequest
- type SmartResponseWriterWrapper
- func (w *SmartResponseWriterWrapper) Flush()
- func (w *SmartResponseWriterWrapper) Hijack() (net.Conn, *bufio.ReadWriter, error)
- func (w *SmartResponseWriterWrapper) IsOver() bool
- func (w *SmartResponseWriterWrapper) Write(p []byte) (int, error)
- func (w *SmartResponseWriterWrapper) WriteHeader(status int)
- type TCPConnectionWrapper
- func (w *TCPConnectionWrapper) Close() error
- func (w *TCPConnectionWrapper) LocalAddr() net.Addr
- func (w *TCPConnectionWrapper) Read(b []byte) (int, error)
- func (w *TCPConnectionWrapper) RemoteAddr() net.Addr
- func (w *TCPConnectionWrapper) SetDeadline(t time.Time) error
- func (w *TCPConnectionWrapper) SetReadDeadline(t time.Time) error
- func (w *TCPConnectionWrapper) SetWriteDeadline(t time.Time) error
- func (w *TCPConnectionWrapper) Write(b []byte) (int, error)
- type TunnelLoadBalancer
- type UDPConnectionInfo
- type UDPSmartShieldState
- type UserBan
Constants ¶
const ( AVAHI_DNS_CLASS_IN = uint16(0x01) AVAHI_DNS_TYPE_CNAME = uint16(0x05) MAX_ENTRIES_PER_GROUP = 15 )
const ( STRIKE = utils.SHIELD_STRIKE TEMP = utils.SHIELD_TEMP PERM = utils.SHIELD_PERM )
const LazyWakeBudget = 30 * time.Second
LazyWakeBudget bounds how long a request waits for a dormant container before being told to retry.
const ProbeHeader = "X-Cosmos-Container"
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.
const TunnelLBForwardedHeader = "x-cstln-lb-forwarded"
TunnelLBForwardedHeader marks a request already load-balanced by an upstream constellation node.
Variables ¶
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 ¶
botDetectionMiddleware checks if the User-Agent is a known bot
func BuildFromConfig ¶
func CleanPathMiddleware ¶ added in v0.21.0
Borrowed from the net/http package. (Thanks mux!)
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 GetShieldIdentity ¶ added in v0.24.0
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
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
HandoffPort returns the socket-proxy port a request came in on, false for a request accepted directly by the HTTP server.
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 SmartShieldMiddleware ¶
func StartBudgetEnforcer ¶ added in v0.17.0
func StartBudgetEnforcer()
func StartHTTPHandoff ¶ added in v0.24.0
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 TunnelRouteTo ¶ added in v0.22.0
func TunnelRouteTo(tunnel utils.ConstellationTunnel, lb *TunnelLoadBalancer) http.Handler
func UDPSmartShieldMiddleware ¶ added in v0.17.0
Types ¶
type PortsPair ¶ added in v0.15.7
type PortsPair struct {
From string
To string
Targets []utils.TunnelTarget
// contains filtered or unexported fields
}
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
type ShieldClientStatus ¶ added in v0.24.0
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 (w *SmartResponseWriterWrapper) Hijack() (net.Conn, *bufio.ReadWriter, error)
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
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 UDPSmartShieldState ¶ added in v0.17.0
type UDPSmartShieldState struct {
sync.Mutex
Connections map[string]*UDPConnectionInfo
}